예제 #1
0
 private final function execute($method_name, $arg_list, $call_parent = FALSE)
 {
     $execution_record = [];
     $execution_id = Debug::addExecutionRecord($execution_record);
     Debug::pushExecutionId($execution_id);
     try {
         $execution_record = $this->prepareExecutionRecord($method_name, $arg_list, $call_parent);
         $class_name = $execution_record['class'];
         $declaring_class_name = $execution_record['declaring_class'];
         $method_accessibility = $execution_record['method_accessibility'];
         $handler_prefix = $execution_record['handler_prefix'];
         $handler_suffix = $execution_record['handler_suffix'];
         Debug::updateExecutionRecord($execution_id, $execution_record);
         if (($count = Debug::countExecutionRecord()) > 3000000) {
             throw new UserException('Abnormal execution record count.', $count);
         }
         if (FALSE === $method_accessibility) {
             throw new UserException("Handler({$declaring_class_name} :: {$method_name}) is not accessible.", $execution_record);
         }
         $config_model_name = $this->loadConfig(Loader::getModelPath($declaring_class_name));
         // Method validateModelPrivilege should throw exception if the validation fails.
         $execution_record['validateModelPrivilege'] = $this->{$config_model_name}->validateModelPrivilege($handler_suffix, $method_name);
         $data_model_name = $this->loadData(Loader::getModelPath($declaring_class_name));
         // Method validateArgs should throw exception if the validation fails,
         // and it should load the config model and fetch the config info itself.
         $args_validation_result = $execution_record['validateArgs'] = $this->{$data_model_name}->validateArgs($handler_suffix, $method_name, $arg_list);
         // Now the validation passed.
         // Method sanitizeArgs should load the config model and fetch the config info itself.
         $args_sanitization_result = $execution_record['sanitizeArgs'] = $this->{$data_model_name}->sanitizeArgs($handler_suffix, $method_name, $arg_list, $args_validation_result);
         // @TODO: check it, can be called with context info?
         // so that XCollection will work correctly.
         // $method = new ReflectionMethod($declaring_class_name, $method_name);
         // $method->setAccessible(TRUE);
         $result = $execution_record['result'] = call_user_func_array([$declaring_class_name, $method_name], $args_sanitization_result);
         // Method validateResult should throw exception if the validation fails,
         // and it should load the config model and fetch the config info itself.
         $result_validation_result = $execution_record['validateResult'] = $this->{$data_model_name}->validateResult($handler_suffix, $method_name, $result);
         // Now the validation passed.
         // Method sanitizeResult should load the config model and fetch the config info itself.
         $result_sanitization_result = $execution_record['sanitizeResult'] = $this->{$data_model_name}->sanitizeResult($handler_suffix, $method_name, $result, $result_validation_result);
         $execution_record['success'] = TRUE;
         Debug::updateExecutionRecord($execution_id, $execution_record);
         Debug::popExecutionId($execution_id);
         return $result;
     } catch (Exception $e) {
         $execution_record['success'] = FALSE;
         Debug::updateExecutionRecord($execution_id, $execution_record);
         Debug::popExecutionId($execution_id);
         throw new UserException('Model execution failed.', $execution_record, $e);
     }
 }
예제 #2
0
 /**
  * @param string $APPPATH
  * @param string $RUNTIMEPATH
  * @param string $APPNAME
  */
 public static function initialize($APPPATH, $RUNTIMEPATH, $APPNAME)
 {
     $APPPATH = Kit::getRealPath($APPPATH);
     $ILEXPATH = Kit::getRealPath(__DIR__ . '/Base/');
     $RUNTIMEPATH = Kit::getRealPath($RUNTIMEPATH);
     /**
      * Loader::initialize() should be called before Constant::initialize(), 
      * because Loader::APPPATH() is called in Constant::initialize()
      */
     session_cache_expire(240);
     date_default_timezone_set('UTC');
     Loader::initialize($ILEXPATH, $APPPATH, $RUNTIMEPATH, $APPNAME);
     Constant::initialize();
     Debug::initialize();
 }
예제 #3
0
<?php

namespace Ilex\Test;

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
ini_set('display_errors', 1);
ini_set('html_errors', 0);
session_cache_expire(240);
require_once __DIR__ . '/../../../autoload.php';
require_once __DIR__ . '/ValidatorTester.php';
use Exception;
use Ilex\Tester;
use Ilex\Core\Debug;
use Ilex\Lib\Kit;
use Ilex\Test\ValidatorTester as VT;
try {
    Tester::boot(__DIR__ . '/app', __DIR__ . '/runtime', 'app');
    // VT::test('countCollection');
    // echo 'Validator Test Passed.' . PHP_EOL;
} catch (Exception $e) {
    echo Kit::j(Debug::extractException($e));
}
예제 #4
0
 /**
  * @TODO: check efficiency
  */
 public final function addRequestLog($class_name, $method_name, $input, $code, $operation_status)
 {
     $content = ['Data' => ['Class' => $class_name, 'Method' => $method_name, 'Input' => $input, 'Code' => $code, 'OperationStatus' => $operation_status], 'Info' => ['RequestInfo' => ['RequestMethod' => $_SERVER['REQUEST_METHOD'], 'RequestURI' => $_SERVER['REQUEST_URI'], 'RequestTime' => $_SERVER['REQUEST_TIME'], 'QueryString' => $_SERVER['QUERY_STRING'], 'RemoteIP' => $_SERVER['REMOTE_ADDR'], 'RemotePort' => $_SERVER['REMOTE_PORT'], 'ServerPort' => $_SERVER['SERVER_PORT']], 'OperationInfo' => ['TimeUsed' => Debug::getTimeUsed(Debug::T_MICROSECOND, FALSE), 'MemoryUsed' => Debug::getMemoryUsed(Debug::M_BYTE, FALSE), 'ExecutionRecordCount' => Debug::countExecutionRecord()], 'SystemVersion' => SYS_VERSION]];
     $this->loadCollection('Log');
     return $this->LogCollection->addRequestLog($content);
 }
예제 #5
0
 /**
  * @param int     $execution_id
  * @param array   $execution_record
  * @param int     $status_code
  * @param boolean $close_cgi_only
  */
 private final function respond($execution_id, $execution_record, $status_code, $close_cgi_only = FALSE)
 {
     if (FALSE === $close_cgi_only) {
         $this->result['database'] = [];
         if (2 !== $this->getCode()) {
             $this->result['database']['rollbacked'] = MDBC::rollback();
         } else {
             $this->result['database']['rollbacked'] = FALSE;
         }
         $this->result['database']['changed'] = MDBC::isChanged();
         Debug::updateExecutionRecord($execution_id, $execution_record);
         Debug::popExecutionId($execution_id);
     }
     if (FALSE === is_null($error = error_get_last()) and TRUE === Debug::isErrorCared($error)) {
         Debug::handleFatalError($error);
     }
     header('Content-Type : application/json', TRUE, $status_code);
     if (FALSE === Debug::isProduction()) {
         $this->result['monitor'] = Debug::getMonitor();
         $this->result += Debug::getDebugInfo();
         $this->result += ['size' => sprintf('%.2fKB', Kit::len(json_encode($this->result)) / 1024)];
         if (TRUE === is_null($this->result['mainException'])) {
             unset($this->result['mainException']);
         }
         if (TRUE === is_null($this->result['monitor'])) {
             unset($this->result['monitor']);
         }
     } else {
         unset($this->result['mainException']);
         unset($this->result['monitor']);
         unset($this->result['database']);
         unset($this->result['process']);
     }
     Http::json($this->result);
     if (TRUE === $close_cgi_only) {
         fastcgi_finish_request();
         // DO NOT exit in order to run the subsequent scripts.
     } else {
         exit;
     }
 }