Example #1
0
 protected function toString($ident = 1, $name = '')
 {
     $lines = [];
     //$lines[] = get_class($this->getRule());
     if ($this->getRule()->hasName()) {
         $name = ($name ? $name . '.' : '') . $this->getRule()->getName();
         $lines[] = $name;
     }
     if (false !== ($children = $this->getChildren())) {
         foreach ($children as $child) {
             $lines[] = $child->toString($ident + 1, $name);
         }
     } elseif (false !== ($related = $this->getRelated())) {
         $lines[] = $related->toString($ident + 1, $name);
     } else {
         $lines[] = 'Message: ' . $this->getRule()->getMessage($this->getInfo(), $this->getInput());
         $lines[] = 'Input: ' . \Nora\Nora::dump($this->getInput(), true);
     }
     $text = '';
     foreach ($lines as $line) {
         if ($line[0] === ">") {
             $text .= $line . PHP_EOL;
         } else {
             $text .= str_repeat(">", $ident) . ($ident != 0 ? ' ' : '') . $line . PHP_EOL;
         }
     }
     return $text;
 }
Example #2
0
 public function testMain()
 {
     // セットアップ
     Nora::Configure(TEST_DIR, 'dev', ['config' => 'config/test']);
     Nora::getService('logger')->err('エラーだよ');
     $this->assertEquals(spl_object_hash(Nora::getService('logger')), spl_object_hash(Nora::getService('logger')));
     // 既存クラスをサービスにする
     Nora::setService('mysql', ['class' => 'PDO', 'params' => ['dsn' => 'mysql:dbname=test;host=127.0.0.1']]);
     // サービスを読み込む
     Nora::setService('hoge', ['callback' => function ($db) {
         return $db;
     }, 'params' => ['db' => '@mysql']]);
     var_Dump(Nora::getService('hoge')->prepare('SHOW TABLES;')->fetch());
 }
Example #3
0
 /**
  * ロガーをビルドアップする
  */
 public static function build($options)
 {
     $options = Hash::create($options, Hash::OPT_ALLOW_UNDEFINED_KEY_GET);
     $logger = self::create($options->getVal('name', 'Nora'));
     foreach ($options->getVal('handlers', []) as $h) {
         $logger->addHandler(Handler::create($h));
     }
     if ($options->getVal('withPHPError', false)) {
         // ハンドラ系の登録
         set_error_handler([$logger, 'phpErrorHandler']);
         set_exception_handler([$logger, 'phpExceptionHandler']);
         register_shutdown_function([$logger, 'phpShutdownHandler']);
     }
     if ($options->getVal('asMainLogger', false)) {
         Nora::setLogger($logger);
     }
     return $logger;
 }
Example #4
0
File: Web.php Project: hossy78/nora
 public function start()
 {
     // LOGを作成する
     Nora::info(['msg' => 'Access', 'uri' => $this->_context->request()]);
     // ルータを取得
     $routers = [$this->router()];
     $request = $this->context()->request();
     while (true) {
         // ルーティングを終了させる処理
         if (!$routers[0]->hasNext()) {
             if (count($routers) > 1) {
                 array_shift($routers);
                 continue;
             }
             break;
         }
         // ルーティングをする
         if ($route = $routers[0]->route($request)) {
             // ルーティングインデックスを進める
             $routers[0]->next();
             try {
                 // 実行
                 $result = $this->dispatch($route->getSpec());
                 // 戻り値がルータであれば、切り替える
                 if ($result instanceof RouterIF) {
                     array_unshift($routers, $result);
                     continue;
                 }
             } catch (Exception\ControllerNotFoundException $e) {
                 $this->logNotice($e->getMessage());
                 $result = false;
             }
             // 戻り値がfalse以外であればディスパッチ終了
             if ($result !== false) {
                 $dispatched = true;
                 break;
             }
         }
         // 再ルート用にインデックスをすすめる
         $routers[0]->next();
     }
 }
Example #5
0
 public function create($name, array $arguments = [])
 {
     if (is_object($name)) {
         return $name;
     }
     $log = [];
     foreach ($this->getClassPrefixList() as list($prefix, $sufix)) {
         $className = $prefix . ucfirst($name) . $sufix;
         array_push($log, $className);
         if (!class_exists($className)) {
             continue;
         }
         $ref = new ReflectionClass($className);
         if (!$this->checkClass($ref)) {
             $this->reportError(Nora::Message("'%s' は呼び出せないクラスです", [$name]));
         }
         return $ref->newInstanceArgs($arguments);
     }
     $this->reportError(Nora::Message("'%s' は対応するクラスがありません %s", [$name, var_export($log, true)]));
 }
Example #6
0
 public function getMessage($code, $input)
 {
     if (isset($this->_messages[$code])) {
         $msg = $this->_messages[$code];
     } else {
         $msg = $this->_messages['DEFAULT'];
     }
     return preg_replace_callback('/%\\(([^\\)]+)\\)/', function ($m) use($input, $code) {
         if ($m[1] === 'input') {
             return trim(\Nora\Nora::dump($input, true));
         }
         if ($m[1] === 'code') {
             return $code;
         }
         if ($this->hasParam($m[1])) {
             return $this->getParam($m[1]);
         }
         return $m[0];
     }, $msg);
 }
Example #7
0
<?php

//die('a');
//echo 'a';
use Nora\Nora;
require_once realpath(__DIR__ . '/../script/autoload.php');
// Webを起動する
Nora::getService('web')->route('/({controller:*}/)*', function ($context) {
    // バリデータを取得
    $v = $context->getService('validator');
    // マッチしたパターンを取得
    $matched = $context->getMatched($v->offset('controller', $v->string('index', true)));
    return $context->getService('web')->getController($ctrl_name = $matched['controller'], $url_mask = '/' . $matched['controller']);
})->start();
Example #8
0
 public function testMain()
 {
     Nora::dump(Nora::getService('config'));
 }
Example #9
0
<?php

use Nora\Nora;
# NoraのAutoLoaderを呼び出す
#require_once realpath(__DIR__.'/../../lib/nora/script/autoload.php');
require_once realpath(__DIR__ . '/../../vendor/autoload.php');
# 環境名
$env = 'devel';
# ルートディレクトリ
$root = __DIR__ . '/..';
# 起動オプション
$bootConfig = ['cache' => 'tmp/cache', 'config' => 'config', 'debug' => true];
# 起動
Nora::Configure($root, $env, $bootConfig);