public function offsetGet($offset) { if (isset($this->modules[$offset])) { return $this->modules[$offset]; } Exception::toss('The module "%s" does not exist.', $offset); }
public function offsetGet($name) { if (isset($this->routes[$name])) { return $this->routes[$name]; } Exception::toss('Cannot get route "%s" because it does not exist.', $name); }
public function get($name) { if (isset($this->cache[$name])) { return $this->cache[$name]; } if (isset($this->loading[$name])) { throw new CircularReferenceException($name, array_keys($this->loading)); } $this->loading[$name] = true; $class = call_user_func($this->filter, $name); if (!class_exists($class)) { Exception::toss('The class "%s" does not exist.', $class); } $args = []; foreach ($this->args as $instanceof => $instanceofArgs) { if ($this->is($class, $instanceof)) { $args = array_merge($args, $instanceofArgs()); } } $class = new ClassReflector($class); $class = $class->newInstanceArgs($args); foreach ($this->callbacks as $instanceof => $callback) { if ($this->is($class, $instanceof)) { $callback($class); } } unset($this->loading[$name]); if ($this->transient) { return $class; } return $this->cache[$name] = $class; }
public function mergeNamedArgs(array $params, $caseSensitive = false) { $merged = []; foreach ($params as $name => $value) { if (is_numeric($name)) { $merged[(int) $name] = $value; } elseif (!$caseSensitive) { $params[strtolower($name)] = $value; } } foreach ($this->getParameters() as $param) { $pos = $param->getPosition(); $name = $caseSensitive ? $param->getName() : strtolower($param->getName()); if (array_key_exists($name, $params)) { $merged[$pos] = $params[$name]; } elseif (array_key_exists($pos, $params)) { $merged[$pos] = $params[$pos]; } elseif ($param->isOptional()) { $merged[$pos] = $param->getDefaultValue(); } else { Exception::toss('The required parameter "%s" for "%s()" was not specified.', $param->getName(), $this->__toString()); } } return $merged; }
public function get($name) { if (isset($this->routes[$name])) { return $this->routes[$name]; } Exception::toss('The route "%s" does not exist.', $name); }
public function mergeNamedArgs(array $params, $caseSensitive = false, $throw = true) { // resulting merged parameters will be stored here $merged = array(); // apply strict position parameters and case sensitivity foreach ($params as $name => $value) { if (is_numeric($name)) { $merged[(int) $name] = $value; } elseif (!$caseSensitive) { $params[strtolower($name)] = $value; } } // we check each parameter and set accordingly foreach ($this->getParameters() as $param) { $pos = $param->getPosition(); $name = $caseSensitive ? $param->getName() : strtolower($param->getName()); if (array_key_exists($name, $params)) { $merged[$pos] = $params[$name]; } elseif (array_key_exists($pos, $params)) { $merged[$pos] = $params[$pos]; } elseif ($param->isOptional()) { $merged[$pos] = $param->getDefaultValue(); } elseif ($throw) { Exception::toss('The required parameter "%s" for "%s::%s()" was not specified.', $param->getName(), $this->getClass()->getName(), $this->getName()); } else { $meged[$pos] = null; } } return $merged; }
public function redirect($uri = null, array $params = []) { if (headers_sent()) { Exception::toss('Cannot redirect to "%s" from the view because output has already started.', $uri); } (new RequestUri($this->format($uri, $params)))->redirect(); }
public function __invoke($data) { $decoded = json_decode($data); if ($error = json_last_error()) { Exception::toss('The JSON string "%s" was unable to be parsed because: %s', $data, $this->errorMessages[$error]); } return $decoded; }
public function __invoke() { $decoded = json_decode(file_get_contents($this->file)); if ($error = json_last_error()) { Exception::toss('The JSON file "%s" was unable to be parsed with message: ' . $this->errorMessages[$error], $this->file); } return $decoded; }
public function current() { $callable = current($this->callables); if (!is_callable($callable)) { Exception::toss('The item at offset "%s" must be callable. Type of "%s" supplied.', $this->key(), gettype($instance)); } return $callable; }
public function get($name) { foreach ($this->injectors as $injector) { if ($injector->has($name)) { return $injector->get($name); } } Exception::toss('The service "%s" does not exist.', $name); }
public function __construct($file) { if (!function_exists('yaml_parse_file')) { Exception::toss('In order to use the YAML config adapter you must install the PECL YAML extension. See http://php.net/yaml for more information.'); } if (!is_file($this->file = $file)) { Exception::toss('The YAML configuration file "%s" does not exist.', $file); } }
private function translateRequest(RequestInterface $request) { if ($request instanceof CliInterface) { return $request->getCommand(); } if ($request instanceof HttpInterface) { return $request->getMethod() . ' ' . $request->getUri()->getRequest(); } Exception::toss('Unable to translate request "%s".', get_class($request)); }
public function addPath($path, $check = true) { $path = $this->root ? $this->root . '/' . $path : $path; if ($real = realpath($path)) { $this->paths[] = $real; } elseif ($check) { Exception::toss('The path "%s" does not exist.', $path); } return $this; }
public function current() { $instance = current($this->instances); if (!is_object($instance)) { Exception::toss('The item at offset "%s" must be an object instance. Type of "%s" supplied.', $this->key(), gettype($instance)); } if (!$instance instanceof $this->instanceof) { Exception::toss('The instance at offset "%s" must be an instance of "%s". Instance of "%s" supplied.', $this->key(), $this->instanceof, get_class($instance)); } return $instance; }
private function resolveController() { $this->events->trigger(self::EVENT_ROUTE, $this->controllers, $this->request, $this->router); if (!$this->router->route($this->request)) { Exception::toss('The router could not find a suitable controller for the request "%s".', $this->request); } $controller = $this->request->getParam($this->config['controller-param']); if (!$this->controllers->has($controller)) { Exception::toss('The controller "%s" could not be found.', $controller); } return $this->controllers->get($controller); }
private function validate(ModuleInterface $module) { foreach ($module->dependencies() as $name => $version) { if (!$this->has($name)) { Exception::toss('The module "%s" is required by the module "%s".', $name, $module->name()); } $version = new SemVer($version); if (!$version->is($this->get($name)->version())) { Exception::toss('The module "%s", currently at version "%s", is required to be at version "%s" by the module "%s".', $name, $this->get($name)->version(), $version, $module->name()); } } }
public function __construct(callable $callable) { if ($callable instanceof Closure || is_string($callable) && function_exists($callable)) { $this->reflector = new FunctionReflector($callable); } elseif (is_array($callable)) { $this->reflector = new MethodReflector($callable[0], $callable[1]); } elseif (is_object($callable)) { $this->reflector = new ClassReflector($callable); } if (!$this->reflector) { Exception::toss('The callable could not be reflected.'); } }
public static function detect(callable $callable) { if ($callable instanceof \Closure || function_exists($callable)) { return new \ReflectionFunction($callable); } if (is_array($callable)) { return new MethodReflector($callable[0], $callable[1]); } if (is_object($callable)) { return new ClassReflector($callable); } Exception::toss('The callable could not be reflected.'); }
private function getFiltersFor(ReflectorInterface $reflector) { $filters = []; foreach ($reflector->getDocBlock()->getTags(static::DOC_TAG_FILTER) as $filter) { $parts = explode(' ', $filter->value(), 2); $class = trim($parts[0]); $value = isset($parts[1]) ? trim($parts[1]) : ''; if (!class_exists($class)) { Exception::toss('The filter "%s" specified for "%s" does not exist.', $class, $reflector->__toString()); } $filters[] = new $class($value); } return $filters; }
public function __invoke(ControllerAbstract $controller, ClassReflector $class, MethodReflector $method, array &$context) { foreach ($method->getParameters() as $param) { if (!($type = $param->getClass())) { continue; } $type = $type->getName(); $name = $param->getName(); if (isset($context[$name])) { $value = $context[$name]; } elseif ($param->isDefaultValueAvailable()) { $value = $param->getDefaultValue(); } else { Exception::toss('Cannot type-hint "%s" in "%s" because the request does not contain the parameter and a default value was not specified.', $name, $method->__toString()); } $context[$name] = new $type($value); } }
public function __invoke(ControllerAbstract $controller, $class, $method) { $request = $controller->request(); foreach ($method->getParameters() as $param) { if (!($type = $param->getClass())) { continue; } $type = $type->getName(); $name = $param->getName(); if ($request->hasParam($name)) { $value = $request->getParam($name); } elseif ($param->isDefaultValueAvailable()) { $value = $param->getDefaultValue(); } else { Exception::toss('Cannot type-hint "%s" in "%s::%s()" because the request does not contain the parameter and a default value was not specified.', $name, $class->getName(), $method->getName()); } $request->setParam($name, new $type($value)); } }
public function load($class) { if (class_exists($class, false)) { return true; } if (isset($this->included[$class])) { Exception::toss('The class "%s" was supposed to be found in "%s". A potential cause is when a class name does not match PSR-0 standards.', $class, $this->included[$class]); } $subject = str_replace($this->separators, DIRECTORY_SEPARATOR, $class) . $this->suffix; if (isset($this->map[$class])) { include $found = $this->map[$class]; } elseif ($this->locator && ($found = $this->locator->locate($subject))) { include $found; } elseif (is_file($found = __DIR__ . '/../../' . $subject)) { include $found; } if ($found) { $this->map[$class] = $found; $this->included[$class] = $found; return true; } return false; }
public function extend($parent) { // the child is the current script $child = $this->getScript(); // child views cannot extend themselves if ($parent === $child) { Exception::toss('Child view cannot extend itself.'); } // if the child has already extended a parent, don't do anything if (in_array($child, $this->extendStack)) { return $this; } // the extend stack makes sure that extend doesn't trigger recursion $this->extendStack[] = $child; // set the parent $this->parentScript = $parent; return $this; }
private function validateFunctions() { foreach ($this->classConfig->requiredFunctions as $function) { if (!function_exists($function)) { Exception::toss('The function "%s" is required by the module "%s".', $function, $this->name); } } }
private function checkReadonly() { if ($this->readonly) { Exception::toss('Cannot modify the configuration because it is readonly.'); } }
private function resolveAdapterFromFile($config) { $adapter = explode('.', $config); $adapter = end($adapter); $adapter = 'Europa\\Config\\Adapter\\From\\' . ucfirst($adapter); if (!class_exists($adapter)) { Exception::toss('The import adapter "%s" autodetected from "%s" cannot be found.', $config, $adapter); } return new $adapter(); }
private function generateErrorHandler($data) { return function ($errno, $errstr, $errfile, $errline, $errcontext) use($data) { Exception::toss('Unable to parse YAML string "%s" with error: %s', $data, $errstr); }; }
public function __construct($file) { if (!is_file($this->file = $file)) { Exception::toss('The INI config file "%s" does not exist.', $file); } }
public static function get($name = self::DEFAULT_INSTANCE) { if (!isset(self::$instances[$name])) { Exception::toss('Could not find application instance "%s".', $name); } return self::$instances[$name]; }