$constructor = $reflection->getConstructor(); if ($constructor !== null) { foreach ($constructor->getParameters() as $param) { if (version_compare(PHP_VERSION, '5.6.0', '>=') && $param->isVariadic()) { break; } elseif ($param->isDefaultValueAvailable()) { $dependencies[] = $param->getDefaultValue(); } else { $c = $param->getClass(); $dependencies[] = Instance::of($c === null ? null : $c->getName()); } } } $this->_reflections[$class] = $reflection; $this->_dependencies[$class] = $dependencies; return [$reflection, $dependencies];
{ // Because: https://bugs.php.net/bug.php?id=74980 if (PHP_VERSION_ID >= 70100 && strpos($message, 'Narrowing occurred during type inference. Please file a bug report') !== false) { return null; } return parent::handleError($code, $message, $file, $line); } /** * @inheritdoc */ public function getExceptionName($exception)
foreach ($constructor->getParameters() as $param) { if (version_compare(PHP_VERSION, '5.6.0', '>=') && $param->isVariadic()) { break; } elseif ($param->isDefaultValueAvailable()) { $dependencies[] = $param->getDefaultValue(); } else { $c = $param->getClass(); $dependencies[] = Instance::of($c === null ? null : $c->getName()); } } } $this->_reflections[$class] = $reflection;
* @return object the newly created instance of the specified class * @throws NotInstantiableException If resolved to an abstract class or an interface (since 2.0.9) */ 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 static::$container->invoke($type, $params); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); }
$config['settings'] = $settings; } } // Create the plugin /** @var Plugin $plugin */ $plugin = Craft::createObject($config, [$handle, Craft::$app]); if ($row !== null) { $this->_setPluginMigrator($plugin, $row['id']); } return $plugin;
foreach ($this->_enabledPluginInfo as $handle => &$row) { // Clean up the row data $row['settings'] = Json::decode($row['settings']); $row['installDate'] = DateTimeHelper::toDateTime($row['installDate']); try { $plugin = $this->createPlugin($handle, $row); } catch (InvalidPluginException $e) { $plugin = null; } if ($plugin !== null) { // If we're not updating, check if the plugin's version number changed, but not its schema version.
/** * Initializes things that should happen after the main Application::init() */ private function _postInit() { // Load the plugins $this->getPlugins()->loadPlugins(); $this->_isInitialized = true; // Fire an 'init' event if ($this->hasEventHandlers(WebApplication::EVENT_INIT)) { $this->trigger(WebApplication::EVENT_INIT);
public function init() { $this->state = self::STATE_INIT; $this->_preInit(); parent::init(); $this->ensureResourcePathExists(); $this->_postInit(); $this->debugBootstrap(); } /** * @inheritdoc */
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
$this->state = self::STATE_BEGIN; $this->preInit($config); $this->registerErrorHandler($config); Component::__construct($config); } /** * Pre-initializes the application. * This method is called at the beginning of the application constructor. * It initializes several important application properties.
* * @param array $config */ public function __construct(array $config = []) { Craft::$app = $this; parent::__construct($config); } /** * Initializes the application. */ public function init()
$config = $this->resolveDependencies($config); if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies); } $object = $reflection->newInstanceArgs($dependencies); foreach ($config as $name => $value) { $object->$name = $value; }
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 static::$container->invoke($type, $params); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); }
if (defined('CRAFT_SITE') || defined('CRAFT_LOCALE')) { $config['components']['sites']['currentSite'] = defined('CRAFT_SITE') ? CRAFT_SITE : CRAFT_LOCALE; } // Initialize the application /** @var \craft\web\Application|craft\console\Application $app */ $app = Craft::createObject($config); // If there was a max_input_vars error, kill the request before we start processing it with incomplete data if ($lastError && strpos($lastError['message'], 'max_input_vars') !== false) { throw new ErrorException($lastError['message']); }
// Load Craft // ----------------------------------------------------------------------------- $appType = 'web'; return require __DIR__.'/bootstrap.php';
if (getenv('CRAFT_STORAGE_PATH')) { define('CRAFT_STORAGE_PATH', getenv('CRAFT_STORAGE_PATH')); } // Craft define('CRAFT_BASE_PATH', $root); $app = require $root.'/vendor/craftcms/cms/bootstrap/web.php'; $app->run();