public function index($value, $parameters = array()) { $pi = pathinfo($value); if (Pattern::matches('resized$', $pi['dirname'])) { $dir = preg_replace('/resized$/', '', $pi['dirname']); $value = Path::assemble($dir, $pi['basename']); } return $value; }
/** * Detects the current environment * * @return mixed */ public static function detect() { $uri = Request::getURL(); // get configured environments $environments = Config::get("_environments"); if (is_array($environments)) { foreach ($environments as $environment => $patterns) { foreach ($patterns as $pattern) { if (Pattern::matches($pattern, $uri)) { return $environment; } } } } return NULL; }
/** * Detects the current environment * * @param array $config Config to look through * @return mixed */ public static function detect($config) { // get current URL, this is probably called before the config is ready, // so we cannot simply use Request::getURL() $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https://' : 'http://'; $port = (int) $_SERVER['SERVER_PORT']; $host = $_SERVER['HTTP_HOST']; $url = $scheme . $host; if ($scheme === 'https://' && $port !== 443 || $scheme === 'http://' && $port !== 80) { $url .= ':' . $port; } // get configured environments $environments = array_get($config, '_environments', null); if (is_array($environments)) { foreach ($environments as $environment => $patterns) { foreach ($patterns as $pattern) { if (Pattern::matches($pattern, $url)) { return $environment; } } } } return null; }
public function lazyCompilation() { $p = new Pattern('('); try { $p->matches('irrelevant'); $this->fail('Expected exception not thrown', NULL, 'lang.FormatException'); } catch (FormatException $expected) { // OK } }
/** * is * Determine if a given string matches a given pattern * * @deprecated Use Pattern::matches() instead * * @param string $pattern Pattern to look for in $value * @param string $value String to look through * @return boolean */ public static function is($pattern, $value) { Log::warn("Use of Statamic_Helper::is() is deprecated. Use Pattern::matches() instead.", "core", "Statamic_Helper"); return Pattern::matches($pattern, $value); }