* @return array the dependencies of the specified class. */ protected function getDependencies($class) { if (isset($this->_reflections[$class])) { return [$this->_reflections[$class], $this->_dependencies[$class]]; } $dependencies = []; $reflection = new ReflectionClass($class); $constructor = $reflection->getConstructor(); if ($constructor !== null) { foreach ($constructor->getParameters() as $param) { if ($param->isDefaultValueAvailable()) { $dependencies[] = $param->getDefaultValue(); } else { $c = $param->getClass(); $dependencies[] = Instance::of($c === null ? null : $c->getName());
{ if (isset($this->_reflections[$class])) { return [$this->_reflections[$class], $this->_dependencies[$class]]; } $dependencies = []; $reflection = new ReflectionClass($class); $constructor = $reflection->getConstructor(); if ($constructor !== null) { foreach ($constructor->getParameters() as $param) { if ($param->isDefaultValueAvailable()) { $dependencies[] = $param->getDefaultValue();
* @param array $config configurations to be applied to the new instance * @return object the newly created instance of the specified class */ protected function build($class, $params, $config) { /* @var $reflection ReflectionClass */ list ($reflection, $dependencies) = $this->getDependencies($class); foreach ($params as $index => $param) { $dependencies[$index] = $param; } $dependencies = $this->resolveDependencies($dependencies, $reflection);
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
{ if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return call_user_func($type, $params); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); } else { throw new InvalidConfigException("Unsupported configuration type: " . gettype($type));
if (isset($this->_modules[$id])) { if ($this->_modules[$id] instanceof Module) { return $this->_modules[$id]; } elseif ($load) { Yii::trace("Loading module: $id", __METHOD__); /* @var $module Module */ $module = Yii::createObject($this->_modules[$id], [$id, $this]); $module->setInstance($module); return $this->_modules[$id] = $module; } } return null;
// module and controller map take precedence if (isset($this->controllerMap[$id])) { $controller = Yii::createObject($this->controllerMap[$id], [$id, $this]); return [$controller, $route]; } $module = $this->getModule($id); if ($module !== null) { return $module->createController($route); } if (($pos = strrpos($route, '/')) !== false) { $id .= '/' . substr($route, 0, $pos);
* @param array $params the parameters to be passed to the action * @return mixed the result of the action. * @throws InvalidRouteException if the requested route cannot be resolved into an action successfully */ public function runAction($route, $params = []) { $parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params);
$params = $this->catchAll; unset($params[0]); } try { Yii::trace("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } else { $response = $this->getResponse(); if ($result !== null) { $response->data = $result;
try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $config = require(__DIR__ . '/../config/web.php'); (new yii\web\Application($config))->run();
$_GET = [ 'r' => 'afisha/delivery/list', 'cat' => '1', ]; $_SERVER = [ 'HOME' => '/nonexistent', 'USER' => 'www', 'FCGI_ROLE' => 'RESPONDER', 'QUERY_STRING' => 'r=afisha/delivery/list&cat=1', 'REQUEST_METHOD' => 'GET', 'CONTENT_TYPE' => '', 'CONTENT_LENGTH' => '', 'SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/index.php?r=afisha/delivery/list&cat=1', 'DOCUMENT_URI' => '/index.php', 'DOCUMENT_ROOT' => '/local/www/gts.tv/web', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_SCHEME' => 'https', 'HTTPS' => 'on', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_SOFTWARE' => 'nginx/1.10.3', 'REMOTE_ADDR' => '3.89.163.156', 'REMOTE_PORT' => '45346', 'SERVER_ADDR' => '80.93.48.101', 'SERVER_PORT' => '443', 'SERVER_NAME' => 'gts.tv', 'REDIRECT_STATUS' => '200', 'SCRIPT_FILENAME' => '/local/www/gts.tv/web/index.php', 'PATH_INFO' => '', 'PATH_TRANSLATED' => '/local/www/gts.tv/web/index.php', 'HTTP_ACCEPT' => '*/*', 'HTTP_USER_AGENT' => 'claudebot', 'HTTP_HOST' => 'gts.tv', 'PHP_SELF' => '/index.php', 'REQUEST_TIME_FLOAT' => 1711704302.4347391, 'REQUEST_TIME' => 1711704302, ];