コード例 #1
0
ファイル: Migrate.php プロジェクト: studio-v/nano
 /**
  * @return Nano_Db
  */
 public function getDb()
 {
     if (null === $this->db) {
         $this->setDb(Nano::db());
     }
     return $this->db;
 }
コード例 #2
0
ファイル: Application.php プロジェクト: visor/nano
 /**
  * @return \Nano\Application
  *
  * @throws \Nano\Application\Exception\InvalidConfiguration
  */
 public function configure()
 {
     if (!$this->offsetExists('configFormat')) {
         throw new Application\Exception\InvalidConfiguration('Configuration format not specified');
     }
     \Nano::setApplication($this);
     if (!$this->offsetExists('rootDir')) {
         $this->withRootDir(getCwd());
     }
     if (!$this->offsetExists('publicDir')) {
         $this->withPublicDir($this->rootDir . DIRECTORY_SEPARATOR . self::PUBLIC_DIR_NAME);
     }
     if (!$this->offsetExists('modulesDir')) {
         $this->withModulesDir($this->rootDir . DIRECTORY_SEPARATOR . self::MODULES_DIR_NAME);
     }
     if (!$this->offsetExists('sharedModulesDir')) {
         $this->withSharedModulesDir($this->nanoRootDir . DIRECTORY_SEPARATOR . self::MODULES_DIR_NAME);
     }
     if ('cli' !== php_sapi_name()) {
         $this->errorHandler = new Application\ErrorHandler();
     }
     $this->readOnly('config', new Application\Config($this->rootDir . DIRECTORY_SEPARATOR . 'settings', $this->configFormat));
     $this->setupErrorReporting();
     return $this;
 }
コード例 #3
0
ファイル: C.php プロジェクト: studio-v/nano
 public final function __construct(Nano_Dispatcher $dispatcher)
 {
     $this->dispatcher = $dispatcher;
     $this->helper = Nano::helper();
     $this->plugins = new SplObjectStorage();
     $this->plugins->addAll(Nano::config('plugins'));
 }
コード例 #4
0
ファイル: CookieTest.php プロジェクト: visor/nano
 /**
  * @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;
 }
コード例 #5
0
ファイル: ScriptsTest.php プロジェクト: studio-v/nano
 protected function getTag($group, $condition)
 {
     $url = Nano::config('assets')->url . '/scripts/' . $this->getBase() . '/' . $group . '.js';
     $time = fileMTime($this->files->get($this, DS . 'input') . DS . 'file1');
     $template = '%s<script type="text/javascript" src="%s"></script>%s';
     return sprintf($template, $condition ? '<!--[if ' . $condition . ']>' : null, $url . '?' . $time, $condition ? '<![endif]-->' : null);
 }
コード例 #6
0
ファイル: Nano.php プロジェクト: studio-v/nano
 /**
  * @return Nano
  */
 public static function instance()
 {
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
コード例 #7
0
ファイル: StylesTest.php プロジェクト: studio-v/nano
 protected function getTag($name, $media, $condition)
 {
     $url = Nano::config('assets')->url . '/styles/' . $this->getBase() . '/' . $name . '.css';
     $time = fileMTime($this->files->get($this, DS . 'input') . DS . 'file1');
     $template = '%s<link rel="stylesheet" type="text/css" href="%s" %s/>%s';
     return sprintf($template, $condition ? '<!--[if ' . $condition . ']>' : null, $url . '?' . $time, $media ? 'media="' . $media . '" ' : null, $condition ? '<![endif]-->' : null);
 }
コード例 #8
0
ファイル: Assets.php プロジェクト: studio-v/nano
 /**
  * @return Assets_Scripts
  */
 public static function script()
 {
     if (null === self::$script) {
         self::$script = new Assets_Scripts();
         self::$script->setOutput(Nano::config('assets')->path);
     }
     return self::$script;
 }
コード例 #9
0
ファイル: DictionaryTest.php プロジェクト: visor/nano
 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));
 }
コード例 #10
0
ファイル: SqlSelectTest.php プロジェクト: studio-v/nano
 public function testLimit()
 {
     self::assertEquals('select * from t limit 1', sql::select(sql::ALL)->from('t')->limit(1)->toString(Nano::db()));
     self::assertEquals('select * from t limit 20, 10', sql::select(sql::ALL)->from('t')->limit(10, 20)->toString(Nano::db()));
     self::assertEquals('select * from t limit 0, 5', sql::select(sql::ALL)->from('t')->limitPage(1, 5)->toString(Nano::db()));
     self::assertEquals('select * from t limit 5, 5', sql::select(sql::ALL)->from('t')->limitPage(2, 5)->toString(Nano::db()));
     self::assertEquals('select * from t limit 10, 5', sql::select(sql::ALL)->from('t')->limitPage(3, 5)->toString(Nano::db()));
 }
コード例 #11
0
ファイル: Date.php プロジェクト: studio-v/nano
 /**
  * @return string
  * @param $type
  */
 public function toSql($type = null)
 {
     if (null === $type) {
         $type = Nano::db()->getType();
     }
     $format = 'Date::FORMAT_' . strToUpper($type);
     return $this->format(constant($format));
 }
コード例 #12
0
ファイル: Nano.php プロジェクト: 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');
 }
コード例 #13
0
ファイル: SubdomainTest.php プロジェクト: studio-v/nano
 public function testParameters()
 {
     $route = new Nano_Route_Subdomain('(?P<p1>some)', '(?P<p2>some)');
     $_SERVER['HTTP_HOST'] = 'some.' . Nano::config('web')->domain;
     self::assertTrue($route->match('some'));
     self::assertArrayHasKey('p1', $route->matches());
     self::assertArrayHasKey('p2', $route->matches());
 }
コード例 #14
0
ファイル: Subdomain.php プロジェクト: visor/nano
 /**
  * @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;
 }
コード例 #15
0
ファイル: Category.php プロジェクト: studio-v/nano
 protected static function loadCache()
 {
     $result = array();
     $rows = self::fetchThis(sql::select('*')->from(self::NAME)->order(Nano::db()->quoteName('order')));
     foreach ($rows as $row) {
         $result[$row->name] = $row;
     }
     return $result;
 }
コード例 #16
0
ファイル: ControlPanelAssets.php プロジェクト: studio-v/nano
 /**
  * @return void
  * @param Nano_C $controller
  */
 public function init(Nano_C $controller)
 {
     if ('control-panel' !== $controller->layout) {
         return;
     }
     Nano::message()->load('control-panel');
     Assets::style()->variable('images', WEB_URL . '/resources/images')->append(WEB_ROOT . '/resources/styles/960.css')->append(WEB_ROOT . '/resources/styles/reset.css')->append(WEB_ROOT . '/resources/styles/text.css')->append(WEB_ROOT . '/resources/styles/default.css')->append(WEB_ROOT . '/resources/styles/blue.css')->append(WEB_ROOT . '/resources/styles/smoothness-ui.css');
     Assets::script()->append(WEB_ROOT . '/resources/scripts/jquery.min.js')->append(WEB_ROOT . '/resources/scripts/jquery.blend.js')->append(WEB_ROOT . '/resources/scripts/ui.core.js')->append(WEB_ROOT . '/resources/scripts/ui.sortable.js')->append(WEB_ROOT . '/resources/scripts/ui.dialog.js')->append(WEB_ROOT . '/resources/scripts/ui.datepicker.js')->append(WEB_ROOT . '/resources/scripts/effects.js')->append(WEB_ROOT . '/resources/scripts/cp.js');
 }
コード例 #17
0
ファイル: App.php プロジェクト: visor/nano
 public function restore()
 {
     if (null === $this->backup) {
         return;
     }
     \Nano::setApplication(null);
     \Nano::setApplication($this->backup);
     $this->backup = null;
 }
コード例 #18
0
ファイル: Message.php プロジェクト: studio-v/nano
 /**
  * @return Nano_Message
  * @param boolean $reset
  */
 public static function instance($reset = false)
 {
     if (null == self::$instance || true === $reset) {
         self::$instance = new self();
         if (isset(Nano::config('web')->lang)) {
             self::$instance->lang(Nano::config('web')->lang);
         }
     }
     return self::$instance;
 }
コード例 #19
0
ファイル: HelperBroker.php プロジェクト: visor/nano
 /**
  * @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();
 }
コード例 #20
0
ファイル: DispatcherTest.php プロジェクト: visor/nano
 public function testDetectingContextBySuffix()
 {
     Nano::setApplication(null);
     $application = new \Nano\Application();
     $application->withConfigurationFormat('php')->withRootDir($this->files->get($this, ''))->configure();
     $application->dispatcher->setResponse(new \Nano\Controller\Response\Test($application));
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $routes = new \Nano\Routes();
     $routes->suffix('~(\\.(?P<context>xml|rss))?')->get('index', 'test', 'index');
     self::assertInstanceOf('Nano\\Route\\RegExp', $application->dispatcher->getRoute($routes, 'index.xml'));
     $application->dispatcher->run($application->dispatcher->getRoute($routes, 'index.xml'));
     self::assertEquals('xml', $application->dispatcher->controllerInstance()->context);
 }
コード例 #21
0
ファイル: NanoDbObjectTest.php プロジェクト: studio-v/nano
 public function testDelete()
 {
     Nano::db()->insert(TestDbTable1::NAME, array('field1' => 3, 'field2' => 3, 'field3' => 'value 3 1', 'field4' => 'value 3 1'));
     $object1 = new TestDbTable1(array('field1' => 3, 'field2' => 3));
     $this->assertFalse($object1->isNew());
     $this->assertEquals('value 3 1', $object1->field3);
     $this->assertEquals('value 3 1', $object1->field4);
     $object1->delete();
     $object2 = new TestDbTable1(array('field1' => 3, 'field2' => 3));
     $this->assertTrue($object2->isNew());
     $row = Nano::db()->getRow('select * from ' . TestDbTable1::NAME . ' where ' . Nano::db()->buildWhere(array('field1' => 3, 'field2' => 3)));
     $this->assertFalse($row);
 }
コード例 #22
0
ファイル: Render.php プロジェクト: studio-v/nano
 public static function file($fileName, array $variables = array(), $throw = true)
 {
     if (!file_exists($fileName)) {
         if ($throw) {
             throw new Exception('View ' . $fileName . ' not exists');
         }
         return null;
     }
     extract($variables);
     $helper = Nano::helper();
     ob_start();
     include $fileName;
     $result = ob_get_contents();
     ob_end_clean();
     return $result;
 }
コード例 #23
0
ファイル: Dictionary.php プロジェクト: visor/nano
 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;
 }
コード例 #24
0
ファイル: Manager.php プロジェクト: visor/nano
 /**
  * @return \Nano\Event
  * @param string|\Nano\Event $eventOrType
  * @param array $arguments
  */
 public function trigger($eventOrType, array $arguments = array())
 {
     $this->loadEvents();
     $event = $eventOrType instanceof \Nano\Event ? $eventOrType : new \Nano\Event($eventOrType);
     foreach ($arguments as $name => $value) {
         $event->setArgument($name, $value);
     }
     $methodName = 'on' . \Nano::stringToName($event->getType());
     foreach ($this->handlers as $instance) {
         if (method_exists($instance, $methodName)) {
             call_user_func(array($instance, $methodName), $event);
         }
     }
     if ($this->callbackExists($eventOrType)) {
         foreach ($this->callbacks->offsetGet($event->getType()) as $handler) {
             $handler($event);
         }
     }
     return $event;
 }
コード例 #25
0
ファイル: expr.php プロジェクト: studio-v/nano
 /**
  * @return string
  * @param Nano_Db $db
  */
 public function toString(Nano_Db $db = null)
 {
     if (null === $db) {
         $db = Nano::db();
     }
     $result = '';
     foreach ($this->parts as $part) {
         if ($part['type'] !== sql::SQL_NONE) {
             $result .= ' ' . $part['type'] . ' ';
         }
         $result .= '(';
         if (null !== $part['operation'] && null !== $part['right']) {
             $result .= $this->operand($db, $part['left'], true) . ' ' . $part['operation'] . ' ' . $this->operand($db, $part['right'], false);
         } elseif (null !== $part['operation']) {
             $result .= $this->operand($db, $part['left'], true) . ' ' . $part['operation'];
         } else {
             $result .= $this->operand($db, $part['left'], true);
         }
         $result .= ')';
     }
     return $result;
 }
コード例 #26
0
ファイル: Db.php プロジェクト: studio-v/nano
 protected static function getTypeClass()
 {
     $result = 'Nano_Db_' . Nano::db()->getType();
     if (!class_exists($result, false)) {
         require LIB . '/Nano/Db/' . Nano::db()->getType() . '.php';
     }
     return $result;
 }
コード例 #27
0
ファイル: SqlExprTest.php プロジェクト: studio-v/nano
 public function testNestedExpr()
 {
     $expected = "((a = 'b') and (c = 'd')) or ((e = 'f') and (g = 'h'))";
     $expr = sql::expr(sql::expr('a', '=', 'b')->addAnd('c', '=', 'd'))->addOr(sql::expr('e', '=', 'f')->addAnd('g', '=', 'h'));
     self::assertEquals($expected, $expr->toString(Nano::db()));
 }
コード例 #28
0
ファイル: SettingHelper.php プロジェクト: studio-v/nano
 protected function htmlField(Setting $setting, $name, $value)
 {
     return Nano::helper()->ui()->textareaField($name, $setting->title, $value, self::CSS, $setting->description);
 }
コード例 #29
0
ファイル: queries.php プロジェクト: studio-v/nano
<?php

$sql = array();
$sql[] = 'insert into migration_test(id, comment) values (200, ' . Nano::db()->quote('second migration') . ')';
コード例 #30
0
ファイル: _bootstrap.php プロジェクト: studio-v/nano
<?php

error_reporting(E_ALL);
ini_set('error_log', dirName(__FILE__) . '/reports/error.log');
define('TESTING', true);
require dirName(__FILE__) . '/../library/Nano.php';
Nano::instance();
Nano::config('selenium');
Nano_Db::setDefault('test');