예제 #1
0
파일: Module.php 프로젝트: nadar/ifw
 public function runController($controllerName, $controllerNamespace)
 {
     \ifw::trace("run controller {$controllerName} in namespace {$controllerNamespace}");
     $className = $this->getClassNamespace() . '\\' . $controllerNamespace . '\\' . $controllerName . 'Controller';
     $this->dispatchEvent(self::EVENT_BEFORE_CONTROLLER);
     $this->response = \ifw::createObject($className, ['module' => $this, 'id' => $controllerName]);
     $this->dispatchEvent(self::EVENT_AFTER_CONTROLLER);
     return $this->response;
 }
예제 #2
0
파일: ActiveQuery.php 프로젝트: nadar/ifw
 private function createModel($row)
 {
     if ($this->_asArray) {
         return $row;
     }
     $obj = \ifw::createObject($this->modelClass);
     $obj->setAsUpdateRecord();
     $obj->attributes = $row;
     return $obj;
 }
예제 #3
0
파일: Controller.php 프로젝트: nadar/ifw
 public function runAction($action)
 {
     Ifw::trace("run action '{$action}'");
     $request = Ifw::$app->request;
     $this->dispatchEvent(self::EVENT_BEFORE_ACTION);
     $actions = $this->actions();
     if (array_key_exists($action, $actions)) {
         $obj = \ifw::createObject($actions[$action], ['controller' => $this, 'id' => $action]);
         if (!$obj instanceof \ifw\core\Action) {
             throw new \ifw\core\Exception("The requested action class must be an instance of ifw\\core\\Action.");
         }
         $this->response = $obj->run();
     } else {
         $actionName = 'action' . ucfirst($action);
         if (!$this->hasMethod($actionName)) {
             throw new \Exception("The requested action {$actionName} does not exists.");
         }
         $params = [];
         // @todo should implement the request of data inside the specific controller (cli/web)
         if (!$request->isCli()) {
             $actionTypes = $this->actionTypes();
             $dataType = array_key_exists($action, $actionTypes) ? $actionTypes[$action] : $request::TYPE_GET;
             $data = $request->getData($dataType);
         } else {
             $data = $request->getParams();
         }
         foreach ($this->getMethodArguments($actionName) as $arg) {
             if (array_key_exists($arg->name, $data)) {
                 $value = $data[$arg->name];
                 if ($arg->isArray) {
                     if (!is_array($value)) {
                         throw new Exception("The paremeter '{$arg->name}' for action '{$actionName}' must be an array!");
                     }
                 }
             } else {
                 if (!$arg->isOptional) {
                     throw new Exception("The action '{$actionName}' requires the {$dataType} parameter '{$arg->name}'.");
                 }
                 $value = $arg->defaultValue;
             }
             $params[] = $value;
         }
         $this->response = call_user_func_array([$this, $actionName], $params);
     }
     $this->dispatchEvent(self::EVENT_AFTER_ACTION);
     return $this->response;
 }
예제 #4
0
파일: index.php 프로젝트: nadar/ifw
<?php

error_reporting(E_ALL);
require_once '../../vendor/autoload.php';
require_once '../../framework/ifw.php';
try {
    $config = new \ifw\Config(dirname(__DIR__), 'test');
    $config->module('test', '\\app\\modules\\test\\Module');
    $config->component('db', ['dsn' => 'mysql:host=localhost;dbname=ifw', 'user' => 'root', 'password' => 'root']);
    ifw::init($config->get());
    echo ifw::$app->run();
    //print_r(ifw::getTrace());
} catch (Exception $e) {
    echo "<pre>";
    print_r($e);
    echo "</pre>";
}
예제 #5
0
파일: Component.php 프로젝트: nadar/ifw
 private function callHandler($handler, $context)
 {
     if (is_object($handler) && !$handler instanceof \Closure) {
         return $handler->handler($context);
     }
     if (is_callable($handler)) {
         return $handler($context);
     }
     if (is_array($handler) && isset($handler[0]) && is_object($handler[0]) && isset($handler[1]) && is_string($handler[1])) {
         return call_user_func_array([$handler[0], $handler[1]], []);
     }
     if (is_string($handler)) {
         $object = \ifw::createObject($handler);
         if ($object instanceof \ifw\core\Event) {
             $object->setContext($context);
             return $object->handler();
         }
         return $object->handler($context);
     }
     throw new \Exception('The registered event handler is not valid.');
 }