コード例 #1
0
ファイル: AbstractModule.php プロジェクト: splot/framework
 /**
  * Returns directory where this module is located.
  * 
  * @return string
  */
 public function getModuleDir()
 {
     if ($this->moduleDir) {
         return $this->moduleDir;
     }
     $this->moduleDir = dirname(Debugger::getClassFile($this));
     return $this->moduleDir;
 }
コード例 #2
0
 /**
  * Configures and provides the cache object that should be used for container cache.
  *
  * This method is called by the framework on the very first step of configuration phase
  * at which point the container doesn't exist yet.
  *
  * @param string $env Application environment.
  * @param boolean $debug Debug on or off.
  * @return ContainerCacheInterface
  */
 public function provideContainerCache($env, $debug)
 {
     $containerCacheDir = dirname(Debugger::getClassFile($this)) . '/cache/' . $env . '/container';
     return new ContainerCache(new FileStore($containerCacheDir), $this->name . '__' . $env);
 }
コード例 #3
0
 public function testGetClassFile()
 {
     $this->assertEquals(realpath(__FILE__), Debugger::getClassFile($this));
     $this->assertEquals(realpath(__FILE__), Debugger::getClassFile(get_called_class()));
     $this->assertEquals(realpath(dirname(__FILE__) . '/../TestFixtures/Collection.php'), Debugger::getClassFile(new Collection()));
 }
コード例 #4
0
ファイル: Framework.php プロジェクト: splot/framework
 /**
  * Performs application and its dependency injection container configuration by loading appropriate files
  * into the config and the container from the application dir and all the modules.
  * 
  * @param  AbstractApplication $application Application to be ran.
  * @param  string              $env         [optional] Environment in which the application should be ran. Default: `dev`.
  * @param  boolean             $debug       [optional] Should application be ran in debug mode? Default: `true`.
  */
 protected function doConfigureApplication(AbstractApplication $application, $env = 'dev', $debug = true)
 {
     $container = $application->getContainer();
     // load framework parameters and services definition from YML file
     $container->loadFromFile(__DIR__ . '/framework.yml');
     // set parameters to be what the framework has been initialized with
     $container->setParameter('framework_dir', __DIR__);
     $container->setParameter('application_dir', dirname(Debugger::getClassFile($application)));
     $container->setParameter('env', $env);
     $container->setParameter('debug', $debug);
     $container->setParameter('not_debug', !$debug);
     // maybe application wants to provide some high-priority parameters as well?
     $container->loadFromArray(array('parameters' => $application->loadParameters($env, $debug)));
     // already register Whoops to handle errors, so it also works during config
     $container->get('whoops')->register();
     // we're gonna stick to the config dir defined at this point
     $configDir = rtrim($container->getParameter('config_dir'), DS);
     // prepare the config, but make it reusable in the cached container as well
     // so we're gonna modify the definition to include existing files when needed
     $configDefinition = $container->getDefinition('config');
     // doing it like this to make sure that env config file is loaded after the base
     $configFiles = array_merge(FilesystemUtils::glob($configDir . '/config.{yml,yaml,php}', GLOB_BRACE), FilesystemUtils::glob($configDir . '/config.' . $env . '.{yml,yaml,php}', GLOB_BRACE));
     foreach ($configFiles as $file) {
         $configDefinition->addMethodCall('loadFromFile', array($file));
     }
     // now that we have the config built, let's get it
     $config = $container->get('config');
     // pass some necessary parameters from the config
     $container->setParameter('log_file', $config->get('log_file'));
     $container->setParameter('log_level', $config->get('log_level'));
     // configure modules one by one
     foreach ($application->getModules() as $module) {
         $this->configureModule($module, $application, $env, $debug);
     }
     // configure the application
     $application->configure();
 }