/** * CovCatcher constructor. * @param string $testName * @param array $options * @throws Exception */ public function __construct($testName = null, array $options = array()) { if (!class_exists('\\JBZoo\\Data\\Data')) { throw new Exception('jbzoo/data required for CovCatcher'); } if (!class_exists('\\JBZoo\\Utils\\Env')) { throw new Exception('jbzoo/utils required for CovCatcher'); } $this->_initConfig($options); $this->_hash = $this->_getPrefix($testName) . '_' . md5(serialize($this->_config->getArrayCopy()) . '|' . $testName); if (Env::hasXdebug()) { $covFilter = new \PHP_CodeCoverage_Filter(); $covFilter->addDirectoryToWhitelist($this->_config->get('src')); $this->_coverage = new \PHP_CodeCoverage(null, $covFilter); } }
/** * @return string */ protected function _getHash() { // Check depends $mixins = $this->_options->get('autoload', [], 'arr'); $hashes = []; foreach ($mixins as $mixin) { $hashes[$mixin] = md5_file($mixin); } ksort($hashes); $options = $this->_options->getArrayCopy(); $options['functions'] = array_keys($options['functions']); ksort($options); $hashed = ['less' => $this->_less, 'less_md5' => md5_file($this->_less), 'base' => $this->_base, 'mixins' => $hashes, 'options' => $options]; $hashed = serialize($hashed); $hash = md5($hashed); // md5 is faster than sha1! return $hash; }
/** * {@inheritdoc} */ public function request($url, $args = array(), array $options = array()) { $result = null; // Merge with default $options = array_merge($this->_defaultOptions, (array) $options); $options = new Data($options); // Prepare options for request $args = is_string($args) ? $args : (array) $args; $timeout = (int) $options->get('timeout'); $isDebug = (int) $options->get('debug'); $sslVerify = (int) $options->get('ssl_verify'); $headers = (array) $options->get('headers'); $userAgent = trim($options->get('user_agent')); $resultType = Str::clean($options->get('response'), true); // Prepare options for cache $isCache = (int) $options->get('cache'); $cacheTTL = (int) $options->get('cache_ttl'); $cacheId = array('url' => $url, 'data' => $args, 'options' => $options->getArrayCopy()); try { // Check cache if ($isCache && ($result = $this->_cms['cache']->get($cacheId, self::CACHE_GROUP))) { return $result; } $method = $this->_getMethod($options->get('method')); // Add args to url for GET methods if (self::METHOD_GET === $method) { $url = Url::addArg($args, $url); $args = array(); } // Request via CMS API $apiResp = $this->_request($url, $args, new Data(array('timeout' => $timeout, 'headers' => $headers, 'method' => $method, 'debug' => $isDebug, 'user_agent' => $userAgent, 'ssl_verify' => $sslVerify))); } catch (\Exception $e) { $apiResp = new Data(array('body' => 'CrossCMS Error: ' . $e->getMessage() . PHP_EOL . PHP_EOL . $e->getTraceAsString(), 'headers' => array(), 'code' => 0)); } // Prepare response format $response = $this->_compactResponse($apiResp); $result = $this->_getResultByType($response, $resultType); // Store to cache if ($isCache && null !== $result) { $this->_cms['cache']->set($cacheId, $result, self::CACHE_GROUP, true, $cacheTTL); } return $result; }