/** * Adds a script registration hook * * @param \Ponticlaro\Bebop\ScriptsLoader\Patterns\ScriptsHook $hook */ public function addHook(ScriptsHook $hook) { if (!$hook->getBaseUrl() && !is_null($this->base_url)) { $hook->setBaseUrl($this->base_url); } $this->hooks->set($hook->getId(), $hook); return $this; }
/** * Call magic method to allow any request method/verb * * @param string $method Method/Verb of the request * @param array $args Array with all the arguments * @return Ponticlaro\Bebop\HttpClient\Response Response object */ public function __call($method, $args) { // Define URL $url = isset($args[0]) && is_string($args[0]) ? $this->__url . '/' . $args[0] : $this->__url; // Get current call configuration array $call_config = isset($args[1]) ? $args[1] : array(); // Get current call headers $call_headers = isset($call_config['headers']) && is_array($call_config['headers']) ? $call_config['headers'] : array(); // Get current call cookies $call_cookies = isset($call_config['cookies']) && is_array($call_config['cookies']) ? $call_config['cookies'] : array(); // Unset headers and cookies before mixing with config collection if (isset($call_config['headers'])) { unset($call_config['headers']); } if (isset($call_config['cookies'])) { unset($call_config['cookies']); } // Mix with cached configuration $this->__config->set($call_config); $this->__headers->set($call_headers); $this->__cookies->set($call_cookies); // Build final request configuration $config = $this->__config->getAll(); $config['headers'] = $this->__headers->getAll(); $config['cookies'] = $this->__cookies->getAll(); // Build args array $args = array($url, $config); // Make request and return response return self::__makeRequest($method, $args); }
/** * Adds a function to execute when the target '$env' is active * * @param string $env Target environment ID * @param string $fn Function to execute */ public function onEnv($env, $fn) { if (is_callable($fn)) { if (is_string($env)) { $this->env_configs->set($env, $fn); } elseif (is_array($env)) { foreach ($env as $env_key) { $this->env_configs->set($env_key, $fn); } } } return $this; }