/** * Resolve an instance of the given task name. * * <code> * // Resolve an instance of a task * $task = Command::resolve('application', 'migrate'); * * // Resolve an instance of a task wtihin a bundle * $task = Command::resolve('bundle', 'foo'); * </code> * * @param string $bundle * @param string $task * @return object */ public static function resolve($bundle, $task) { $identifier = Bundle::identifier($bundle, $task); // First we'll check to see if the task has been registered in the // application IoC container. This allows all dependencies to be // injected into tasks for more testability. if (IoC::registered("task: {$identifier}")) { return IoC::resolve("task: {$identifier}"); } // If the task file exists, we'll format the bundle and task name // into a task class name and resolve an instance of the so that // the requested method may be executed. if (file_exists($path = Bundle::path($bundle) . 'tasks/' . $task . EXT)) { require $path; $task = static::format($bundle, $task); return new $task(); } }
/** * Dynamically resolve items from the application IoC container. * * <code> * // Retrieve an object registered in the container * $mailer = $this->mailer; * * // Equivalent call using the IoC container instance * $mailer = IoC::resolve('mailer'); * </code> */ public function __get($key) { if (IoC::registered($key)) { return IoC::resolve($key); } }
/** * Dynamically resolve items from the application IoC container. * * <code> * // Retrieve an object registered in the container as "mailer" * $mailer = $this->mailer; * * // Equivalent call using the IoC container instance * $mailer = IoC::resolve('mailer'); * </code> */ public function __get($key) { if (IoC::registered($key)) { return IoC::resolve($key); } throw new \OutOfBoundsException("Attempting to access undefined property [{$key}] on controller."); }
public function testCanUnregisterRegistered() { $testClass = 'test'; IoC::register($testClass, function () { }); $this->assertTrue(IoC::registered($testClass)); IoC::unregister($testClass); $this->assertFalse(IoC::registered($testClass)); }
} /** * The bundle publisher is responsible for publishing bundle * assets to their correct directories within the install, * such as the web accessible directory. */ if (!IoC::registered('bundle.publisher')) { IoC::singleton('bundle.publisher', function () { return new Tasks\Bundle\Publisher(); }); } /** * The Github bundle provider installs bundles that live on * Github. This provider will add the bundle as a submodule * and will update the submodule so that the bundle is * installed into the bundle directory. */ if (!IoC::registered('bundle.provider: github')) { IoC::singleton('bundle.provider: github', function () { return new Tasks\Bundle\Providers\Github(); }); } /** * The "help" task provides information about * artisan usage. */ if (!IoC::registered('task: help')) { IoC::singleton('task: help', function () { return new Tasks\Help(); }); }
/** * The bundle repository is responsible for communicating with * the Laravel bundle sources to get information regarding any * bundles that are requested for installation. */ if (!IoC::registered('bundle.repository')) { IoC::singleton('bundle.repository', function () { return new Tasks\Bundle\Repository(); }); } /** * The bundle publisher is responsible for publishing bundle * assets to their correct directories within the install, * such as the web accessible directory. */ if (!IoC::registered('bundle.publisher')) { IoC::singleton('bundle.publisher', function () { return new Tasks\Bundle\Publisher(); }); } /** * The Github bundle provider installs bundles that live on * Github. This provider will add the bundle as a submodule * and will update the submodule so that the bundle is * installed into the bundle directory. */ if (!IoC::registered('bundle.provider: github')) { IoC::singleton('bundle.provider: github', function () { return new Tasks\Bundle\Providers\Github(); }); }
*/ if (IoC::registered('doctrine::cache.provider')) { $cache = IoC::resolve('doctrine::cache.provider'); } else { $cache = new Doctrine\Common\Cache\ArrayCache(); } /** * Register the cache provider with the Doctrine configuration. */ $config = new Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); /** * Resolve and register the meta-data driver. */ if (IoC::registered('doctrine::metadata.driver')) { $driverImpl = IoC::resolve('doctrine::metadata.driver', array($config)); } else { $driverImpl = $config->newDefaultAnnotationDriver(Config::get('doctrine::config.models')); } $config->setMetadataDriverImpl($driverImpl); /** * Register the proxy configuration with Doctrine. */ $config->setProxyDir(Config::get('doctrine::config.proxy.directory')); $config->setProxyNamespace(Config::get('doctrine::config.proxy.namespace')); $config->setAutoGenerateProxyClasses(Config::get('doctrine::config.proxy.auto_generate')); /** * Register an EntityManager in the IoC container as an instance. */ $em = EntityManager::create(array('pdo' => Laravel\Database::connection()->pdo), $config);