/** * Get value from content by css selector * * @param ApistMethod $method * @param Crawler $rootNode * @return array|null|string|Crawler */ public function getValue(ApistMethod $method, Crawler $rootNode = null) { if (is_null($rootNode)) { $rootNode = $method->getCrawler(); } $result = $rootNode->filter($this->selector); return $this->applyResultCallbackChain($result, $method); }
/** * @param $httpMethod * @param $url * @param $blueprint * @param array $options * * @return array * @throws \GuzzleHttp\Exception\GuzzleException */ protected function request($httpMethod, $url, $blueprint, $options = []) { $url = Uri::resolve($this->getBaseUrl(), $url); $this->currentMethod = new ApistMethod($this->getGuzzle(), $url, $blueprint); $this->lastMethod = $this->currentMethod; $this->currentMethod->setMethod($httpMethod); $result = $this->currentMethod->get($options); $this->currentMethod = null; return $result; }
/** * @param $content * @param $blueprint * @return array|string */ protected function parse($content, $blueprint) { $this->currentMethod = new ApistMethod($this, null, $blueprint); $this->currentMethod->setContent($content); $result = $this->currentMethod->parseBlueprint($blueprint); $this->currentMethod = null; return $result; }
/** * @param $blueprint * @return ApistFilter */ public function each($blueprint = null) { $callback = $blueprint; if (is_null($callback)) { $callback = function ($node) { return $node; }; } if (!is_callable($callback)) { $callback = function ($node) use($blueprint) { return $this->method->parseBlueprint($blueprint, $node); }; } return $this->node->each($callback); }
/** * @param ApistMethod $method * @param $node * @return mixed */ protected function callResourceMethod(ApistMethod $method, $node) { $arguments = $this->arguments; array_unshift($arguments, $node); return call_user_func_array([$method->getResource(), $this->methodName], $arguments); }