示例#1
0
 public function setup()
 {
     parent::setup();
     $this->controller = $this->prophesize("Ethna_Controller");
     $this->event_dispatcher = $this->prophesize('\\Symfony\\Component\\EventDispatcher\\EventDispatcher');
     $this->backend = $this->prophesize("Ethna_Backend");
     $this->i18n = $this->prophesize("Ethna_I18N");
     $this->action_error = $this->prophesize("Ethna_ActionError");
     $this->plugin = $this->prophesize("Ethna_Plugin");
     $this->logger = $this->prophesize("Ethna_Logger");
     $this->controller->getEventDispatcher()->willReturn($this->event_dispatcher);
     $this->event_dispatcher->dispatch(Argument::type('string'), Argument::any())->will(function ($args, $event) {
         $action_form = $args[1]->getActionForm();
         $target = null;
         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
             $target =& $_GET;
         } else {
             $target = $_POST;
         }
         foreach ($target as $key => $value) {
             $action_form->set($key, $value);
         }
     });
     $this->backend->getController()->willReturn($this->controller);
     $this->controller->getBackend()->willReturn($this->backend);
     $this->controller->getActionError()->willReturn($this->action_error);
     $this->controller->getI18N()->willReturn($this->i18n);
     $this->controller->getLogger()->willReturn($this->logger);
     $this->controller->getPlugin()->willReturn($this->plugin);
 }
示例#2
0
文件: Renderer.php 项目: t-f-m/ethna
 /**
  *  Ethna_Rendererクラスのコンストラクタ
  *
  *  @access public
  */
 public function __construct($controller)
 {
     $this->controller = $controller;
     $this->ctl = $this->controller;
     $this->engine = null;
     $this->template = null;
     $this->prop = array();
     $this->plugin_registry = array();
     $template_dir = $controller->getTemplatedir();
     $this->template_dir = $template_dir;
     // load configuration
     $config = $this->ctl->getConfig();
     $renderer_config = $config->get('renderer');
     $this->config = $this->mergeConfig($this->config_default, isset($renderer_config[$this->getName()]) ? $renderer_config[$this->getName()] : array());
     $this->logger = $this->controller->getBackend()->getLogger();
 }
示例#3
0
文件: Abstract.php 项目: t-f-m/ethna
 /**
  *  Constructor
  *
  *  @access public
  *  @param  object  Ethna_Controller    $controller    Controller Object
  */
 public function __construct($controller, $type = null, $name = null)
 {
     $this->controller = $controller;
     $this->ctl = $this->controller;
     $this->backend = $this->controller->getBackend();
     $this->logger = $controller->getLogger();
     $this->action_form = $controller->getActionForm();
     $this->af = $this->action_form;
     $this->session = $controller->getSession();
     // if constractor called without parameter $type or $name, auto detect type and name of self.
     if ($this->type === null) {
         $this->type = $this->_detectType($type);
     }
     if ($this->name === null) {
         $this->name = $this->_detectName($name);
     }
     // load config
     $this->_loadConfig();
     // load plugin hook
     $this->_load();
 }
示例#4
0
 public function setup()
 {
     parent::setup();
     $this->controller = $this->prophesize("Ethna_Controller");
     $this->backend = $this->prophesize("Ethna_Backend");
     $this->config = $this->prophesize("Ethna_Config");
     $this->i18n = $this->prophesize("Ethna_I18N");
     $this->action_error = $this->prophesize("Ethna_ActionError");
     $this->action_form = $this->prophesize("Ethna_ActionForm");
     $this->session = $this->prophesize("Ethna_Session");
     $this->plugin = $this->prophesize("Ethna_Plugin");
     $this->logger = $this->prophesize("Ethna_Logger");
     $this->backend->getLogger()->willReturn($this->logger);
     $this->backend->getPlugin()->willReturn($this->plugin);
     $this->backend->getSession()->willReturn($this->session);
     $this->backend->getActionForm()->willReturn($this->action_form);
     $this->backend->getActionError()->willReturn($this->action_error);
     $this->backend->getI18N()->willReturn($this->i18n);
     $this->backend->getConfig()->willReturn($this->config);
     $this->backend->getController()->willReturn($this->controller);
     $this->controller->getBackend()->willReturn($this->backend);
 }
示例#5
0
 /**
  *  クラスキーに対応するオブジェクトを返す/クラスキーが未定義の場合はAppObjectを探す
  *  クラスキーとは、[Appid]_Controller#class に定められたもの。
  *
  *  @access public
  *  @param  string  $key    [Appid]_Controller#class に定められたクラスキー
  *                          このキーは大文字小文字を区別する
  *                          (配列のキーとして使われているため)
  *  @param  bool    $ext    オブジェクトが未生成の場合の強制生成フラグ(default: false)
  *  @return object  生成されたオブジェクト(エラーならnull)
  */
 function getObject($key, $ext = false)
 {
     $object = null;
     $ext = to_array($ext);
     if (isset($this->class[$key]) == false) {
         // app object
         $class_name = $this->controller->getObjectClassName($key);
         $ext = array_pad($ext, 3, null);
         list($key_type, $key_value, $prop) = $ext;
     } else {
         // ethna classes
         $class_name = $this->class[$key];
         $ext = array_pad($ext, 1, null);
         list($weak) = $ext;
     }
     //  すでにincludeされていなければ、includeを試みる
     if (class_exists($class_name) == false) {
         if ($this->_include($class_name) == false) {
             return $object;
             //  include 失敗。返り値はnull
         }
     }
     //  AppObject をはじめに扱う
     //  AppObject はキャッシュされないことに注意
     if (isset($this->class[$key]) == false) {
         $backend = $this->controller->getBackend();
         $object = new $class_name($backend, $key_type, $key_value, $prop);
         return $object;
     }
     //  Ethna_Controllerで定義されたクラスキーの場合
     //  はメソッド情報を集める
     if (isset($this->method_list[$class_name]) == false) {
         $this->method_list[$class_name] = get_class_methods($class_name);
         for ($i = 0; $i < count($this->method_list[$class_name]); $i++) {
             $this->method_list[$class_name][$i] = strtolower($this->method_list[$class_name][$i]);
         }
     }
     //  以下のルールに従って、キャッシュが利用可能かを判定する
     //  利用可能と判断した場合、キャッシュされていればそれを返す
     //
     //  1. メソッドに getInstance があればキャッシュを利用可能と判断する
     //     この場合、シングルトンかどうかは getInstance 次第
     //  2. weak が true であれば、キャッシュは利用不能と判断してオブジェクトを再生成
     //  3. weak が false であれば、キャッシュは利用可能と判断する(デフォルト)
     if ($this->_isCacheAvailable($class_name, $this->method_list[$class_name], $weak)) {
         if (isset($this->object[$key]) && is_object($this->object[$key])) {
             return $this->object[$key];
         }
     }
     //  インスタンス化のヘルパがあればそれを使う
     $method = sprintf('_getObject_%s', ucfirst($key));
     if (method_exists($this, $method)) {
         $object = $this->{$method}($class_name);
     } else {
         if (in_array("getinstance", $this->method_list[$class_name])) {
             $object = call_user_func(array($class_name, 'getInstance'));
         } else {
             $object = new $class_name();
         }
     }
     //  クラスキーに定められたクラスのインスタンスは
     //  とりあえずキャッシュする
     if (isset($this->object[$key]) == false || is_object($this->object[$key]) == false) {
         $this->object[$key] = $object;
     }
     return $object;
 }