Ejemplo n.º 1
0
 /**
  * @return \Nano\Util\Cookie
  */
 protected function cookie()
 {
     if (null === $this->cookie) {
         $this->cookie = new \Nano\Util\Cookie(\Nano::app()->config->get('web')->domain);
     }
     return $this->cookie;
 }
Ejemplo n.º 2
0
Archivo: App.php Proyecto: visor/nano
 public function backup()
 {
     if (null === $this->backup) {
         $this->backup = \Nano::app();
     }
     \Nano::setApplication(null);
 }
Ejemplo n.º 3
0
Archivo: Nano.php Proyecto: visor/nano
 /**
  * @return void
  * @param \Nano\Application|null $app
  * @throws \Nano\Exception
  */
 public static function setApplication(\Nano\Application $app = null)
 {
     if (null === self::$app || null === $app) {
         self::$app = $app;
         return;
     }
     throw new \Nano\Exception('Application inctance already created');
 }
Ejemplo n.º 4
0
 public function testShouldLoadMessageFileOnce()
 {
     $file = \Nano::app()->rootDir . DIRECTORY_SEPARATOR . 'messages' . DIRECTORY_SEPARATOR . 'ru' . DIRECTORY_SEPARATOR . 'article';
     $mock = $this->getMock('Nano\\L10n\\Dictionary', array('getMessageFileName'), array(new \Nano\L10n\Locale('ru')));
     $mock->expects($this->once())->method('getMessageFileName')->withAnyParameters()->will($this->returnValue($file));
     self::assertTrue($mock->loadMessages('article', null));
     self::assertTrue($mock->loadMessages('article', null));
 }
Ejemplo n.º 5
0
 public function testParameters()
 {
     $route = new \Nano\Route\Subdomain('(?P<p1>some)', '(?P<p2>some)');
     $_SERVER['HTTP_HOST'] = 'some.' . Nano::app()->config->get('web')->domain;
     self::assertTrue($route->match('some'));
     self::assertArrayHasKey('p1', $route->matches());
     self::assertArrayHasKey('p2', $route->matches());
 }
Ejemplo n.º 6
0
 public function testShouldRestoreOnlyWhenBackupExists()
 {
     $original = Nano::app();
     $this->mixin->backup();
     self::assertNull(Nano::app());
     $this->mixin->restore();
     $this->mixin->restore();
     self::assertSame($original, Nano::app());
 }
Ejemplo n.º 7
0
 /**
  * @return string
  */
 protected function getSubDomain()
 {
     if (\Nano::app()->config->get('web')->domain === $_SERVER['HTTP_HOST']) {
         return null;
     }
     $result = preg_replace('/\\.' . preg_quote(\Nano::app()->config->get('web')->domain, '/') . '$/i', '', $_SERVER['HTTP_HOST']);
     $result = strToLower($result);
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * @return \Nano\Helper
  * @param string $name
  *
  * @throws \Nano\Exception\HelperNotFound
  */
 protected function search($name)
 {
     $className = \Nano\Names::helperClass($name);
     if (class_exists($className, false)) {
         return $className;
     }
     $classPath = \Nano\Names::applicationFile($className);
     if (!\Nano::app()->loader->loadFileWithClass($className, $classPath)) {
         throw new \Nano\Exception\HelperNotFound($name);
     }
     return new $className();
 }
Ejemplo n.º 9
0
 protected function getMessageFileName($locale, $baseName, $module)
 {
     $name = $this->generateKey($baseName, $module);
     $path = DIRECTORY_SEPARATOR . 'messages' . DIRECTORY_SEPARATOR . $locale;
     $result = \Nano::app()->rootDir . $path . DIRECTORY_SEPARATOR . $name;
     if (null === $module) {
         return file_exists($result) ? $result : null;
     }
     if (file_exists($result)) {
         return $result;
     }
     $result = \Nano::app()->modules->getPath($module, $path . DIRECTORY_SEPARATOR . $baseName);
     if (file_exists($result)) {
         return $result;
     }
     return null;
 }
Ejemplo n.º 10
0
 /**
  * @return null
  * @param string $message
  * @throws \Nano\Exception\InternalError
  */
 protected function internalError($message = null)
 {
     $this->markRendered();
     \Nano::app()->errorHandler()->notFound($message);
 }
Ejemplo n.º 11
0
Archivo: Names.php Proyecto: visor/nano
 /**
  * Преобразовывает имя класса модуля в имя файла модуля
  *
  * @return string
  * @param string $className
  *
  * @throws \Nano\Application\Exception\ModuleNotFound
  */
 public static function moduleFile($className)
 {
     $fileName = self::removeNamespace($className, self::NAMESPACE_MODULE);
     $module = \Nano\Application\Modules::namespaceToName(self::extractFirstNamespace($fileName));
     if (!\Nano::app()->modules->active($module)) {
         throw new \Nano\Application\Exception\ModuleNotFound($module);
     }
     $prefix = \Nano::app()->modules->getPath($module);
     $fileName = self::removeNamespace($fileName);
     return self::classNameToFile($prefix, $fileName);
 }
Ejemplo n.º 12
0
 public function testConvertModulePluginsClassToFile()
 {
     $someRoot = Nano::app()->modules->getPath('some', 'plugins');
     $otherRoot = Nano::app()->modules->getPath('other', 'plugins');
     self::assertEquals($someRoot . DS . 'Foo.php', \Nano\Names::moduleFile('\\Module\\Some\\Plugin\\Foo'));
     self::assertEquals($otherRoot . DS . 'Foo.php', \Nano\Names::moduleFile('\\Module\\Other\\Plugin\\Foo'));
 }
Ejemplo n.º 13
0
 public function testAppShouldReturnStoredValue()
 {
     self::assertNull(Nano::app());
     Nano::setApplication($GLOBALS['application']);
     self::assertSame($GLOBALS['application'], Nano::app());
 }
Ejemplo n.º 14
0
Archivo: Raise.php Proyecto: visor/nano
 public function internalErrorAction()
 {
     \Nano::app()->errorHandler()->internalError('Message from action');
 }
Ejemplo n.º 15
0
 protected function reloadConfig()
 {
     self::setObjectProperty(Nano::app()->config, 'config', null);
     self::setObjectProperty(Nano::app()->config, 'routes', null);
     Nano::app()->config->name();
 }
Ejemplo n.º 16
0
 public function testConfigureShouldSetupCurrentApplication()
 {
     $this->application->withConfigurationFormat('php')->withRootDir($GLOBALS['application']->rootDir)->configure();
     self::assertSame($this->application, Nano::app());
 }
Ejemplo n.º 17
0
 /**
  * @return boolean|null
  * @param \Nano\Routes $routes
  * @param string $url
  *
  * @throws \Nano\Exception\NotFound
  */
 public function dispatch(\Nano\Routes $routes, $url)
 {
     $route = $this->getRoute($routes, $url);
     if (null !== $route) {
         $this->run($route);
         return null;
     }
     if ($this->custom) {
         $result = $this->custom->dispatch();
         if (false === $result) {
             throw new \Nano\Exception\NotFound('Custom dispatcher fails for: ' . $url, $route);
         }
         return $result;
     }
     if (\Nano::app()->errorHandler()) {
         \Nano::app()->errorHandler()->notFound('Route not found for: ' . $url);
     }
     return null;
 }
Ejemplo n.º 18
0
 /**
  * @return null
  * @param \Nano\Controller\Response $response
  * @param boolean $forceExit
  */
 protected function send(\Nano\Controller\Response $response, $forceExit = false)
 {
     if (ob_get_level() > 0) {
         ob_end_clean();
     }
     if (\Nano::app()->dispatcher->controllerInstance() && false === $forceExit) {
         \Nano::app()->dispatcher->controllerInstance()->markRendered();
         \Nano::app()->dispatcher->controllerInstance()->setResponse($response);
     }
     $response->send();
 }