Exemple #1
0
 public function register(Neptune $neptune)
 {
     $neptune['view'] = function ($neptune) {
         $creator = new ViewCreator($neptune);
         foreach ($neptune->getTaggedServices('neptune.view.extensions') as $service) {
             $creator->addExtension($service);
         }
         return $creator;
     };
     $neptune['view.listener'] = function ($neptune) {
         return new ViewListener($neptune, 'view');
     };
 }
Exemple #2
0
 protected function getViewFilename($view)
 {
     $pos = strpos($view, ':');
     if (!$pos) {
         //no module has been supplied, so use the app directory
         return sprintf('%sapp/views/%s', $this->neptune->getRootDirectory(), $view);
     }
     //the template is in a module
     $module = substr($view, 0, $pos);
     $view = substr($view, $pos + 1);
     //check for an overriding template in the app/ folder
     $override = sprintf('%sapp/views/%s/%s', $this->neptune->getRootDirectory(), $module, $view);
     if (file_exists($override)) {
         return $override;
     }
     return sprintf('%sviews/%s', $this->neptune->getModuleDirectory($module), $view);
 }
Exemple #3
0
 public function register(Neptune $neptune)
 {
     $neptune['twig.options'] = function ($neptune) {
         $defaults = ['strict_variables' => true];
         return array_merge($defaults, $neptune['config']->get('twig', []));
     };
     $neptune['twig'] = function ($neptune) {
         $environment = new TwigEnvironment($neptune['twig.loader'], $neptune['twig.options']);
         foreach ($neptune->getTaggedServices('twig.extensions') as $service) {
             $environment->addExtension($service);
         }
         $environment->addGlobal('app', $neptune);
         return $environment;
     };
     $neptune['twig.loader'] = function ($neptune) {
         return new FilesystemLoader($neptune);
     };
     $neptune['twig.exception_listener'] = function ($neptune) {
         return new TwigExceptionListener($neptune['twig']);
     };
 }
 /**
  * Check the default configuration of all services doesn't break.
  */
 public function testLoadAllDefaultServices()
 {
     $neptune = new Neptune('/path/to/root');
     $neptune->addService(new CacheService());
     $neptune->addService(new DatabaseService());
     $neptune->addService(new FormService());
     $neptune->addService(new MonologService());
     $neptune->addService(new RoutingService());
     $neptune->addService(new SecurityService());
     $neptune->addService(new SessionService());
     $neptune->addService(new SwiftmailerService());
     $neptune->addService(new ViewService());
     $services_property = new \ReflectionProperty($neptune, 'services');
     $services_property->setAccessible(true);
     $this->assertSame(9, count($services_property->getValue($neptune)));
 }
Exemple #5
0
 public function testGetRootDirectoryAppendsTrailingSlash()
 {
     $neptune = new Neptune('/no/trailing/slash');
     $this->assertSame('/no/trailing/slash/', $neptune->getRootDirectory());
 }
Exemple #6
0
 public function routeModules(Neptune $neptune)
 {
     foreach ($neptune->getModules() as $module) {
         $this->routeModule($module, $neptune);
     }
 }