/** * @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; }
public function backup() { if (null === $this->backup) { $this->backup = \Nano::app(); } \Nano::setApplication(null); }
/** * @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'); }
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)); }
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()); }
public function testShouldRestoreOnlyWhenBackupExists() { $original = Nano::app(); $this->mixin->backup(); self::assertNull(Nano::app()); $this->mixin->restore(); $this->mixin->restore(); self::assertSame($original, Nano::app()); }
/** * @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; }
/** * @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(); }
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; }
/** * @return null * @param string $message * @throws \Nano\Exception\InternalError */ protected function internalError($message = null) { $this->markRendered(); \Nano::app()->errorHandler()->notFound($message); }
/** * Преобразовывает имя класса модуля в имя файла модуля * * @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); }
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')); }
public function testAppShouldReturnStoredValue() { self::assertNull(Nano::app()); Nano::setApplication($GLOBALS['application']); self::assertSame($GLOBALS['application'], Nano::app()); }
public function internalErrorAction() { \Nano::app()->errorHandler()->internalError('Message from action'); }
protected function reloadConfig() { self::setObjectProperty(Nano::app()->config, 'config', null); self::setObjectProperty(Nano::app()->config, 'routes', null); Nano::app()->config->name(); }
public function testConfigureShouldSetupCurrentApplication() { $this->application->withConfigurationFormat('php')->withRootDir($GLOBALS['application']->rootDir)->configure(); self::assertSame($this->application, Nano::app()); }
/** * @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; }
/** * @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(); }