示例#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
 /**
  * @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
 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
 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
 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
 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
 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
 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
 /**
  * @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
 /**
  * @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
 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
 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
 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
 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
<?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');