Пример #1
0
 private final function getInitiatorNameAndType($method_name, $declaring_class)
 {
     $backtrace = Kit::columns(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20), ['class', 'function'], FALSE);
     $initiator_name = NULL;
     foreach ($backtrace as $record) {
         if (TRUE === is_null($record['class']) or TRUE === Kit::in($record['class'], ['Ilex\\Base\\Base', 'Ilex\\Base\\Controller\\Service\\BaseService', 'Ilex\\Base\\Model\\BaseModel'])) {
             continue;
         }
         if ($method_name !== $record['function']) {
             $initiator_name = $record['class'];
             break;
         }
     }
     if (TRUE === is_null($initiator_name)) {
         $result = [$initiator_name, self::T_OTHER];
     } else {
         $initiator = new ReflectionClass($initiator_name);
         $declaring_class_name = $declaring_class->getName();
         if ($initiator_name === $declaring_class_name) {
             $result = [$initiator_name, self::T_SELF];
         } elseif (TRUE === $initiator->isSubclassOf($declaring_class_name)) {
             $result = [$initiator_name, self::T_DESCENDANT];
         } else {
             $result = [$initiator_name, self::T_OTHER];
         }
     }
     // var_dump([$method_name, $declaring_class, $initiator_name]);
     // var_dump($result);
     // var_dump($backtrace);
     return $result;
 }
Пример #2
0
 /**
  * @param string $name
  * @param array  $data
  * @return boolean
  */
 public static final function merge($name, $data)
 {
     if (TRUE === Kit::in($name, ['get', 'post', 'input'])) {
         $name .= 'Data';
         self::${$name}->merge($data);
         /* 
         CAUTION: 
             The + operator returns the right-hand array appended to the left-hand array;
             for keys that exist in both arrays, the elements from the left-hand array will be used,
             and the matching elements from the right-hand array will be ignored.
         
             array_merge — Merge one or more arrays
             array array_merge ( array $array1 [, array $... ] )
             Merges the elements of one or more arrays together so that the values of one
             are appended to the end of the previous one. It returns the resulting array.
             If the input arrays have the same string keys, then the later value for that key will 
             overwrite the previous one. If, however, the arrays contain numeric keys,
             the later value will not overwrite the original value, but will be appended.
             Values in the input array with numeric keys will be renumbered with
             incrementing keys starting from zero in the result array.
         */
         if ($name !== 'input') {
             self::$inputData->merge(self::get());
             self::$inputData->merge(self::post());
         }
         return TRUE;
     } else {
         throw new UserException("Invalid \$name({$name}).");
     }
 }
Пример #3
0
 /**
  * Set code from NULL/1/2 to 0.
  * @param int       $execution_id
  * @param array     $execution_record
  * @param Exception $exception
  */
 private final function failRequest($execution_id, $execution_record, Exception $exception)
 {
     $code = $this->getCode();
     if (FALSE === is_null($code) and FALSE === Kit::in($code, [1, 2])) {
         throw new UserException('Can not fail the request because of invalid code.', $code, $exception);
     }
     // Now code must be NULL or 1 or 2.
     $this->setCode(0);
     if (FALSE === Debug::isProduction()) {
         $this->result['exception'] = Debug::extractException($exception);
         $this->result['mainException'] = Debug::extractMainException($this->result['exception']);
     }
     $execution_record['success'] = FALSE;
     $this->respond($execution_id, $execution_record, 200);
     // @TODO: change code
 }
Пример #4
0
 private final function getDocument($root_field_name, $field_name, $ensure_existence = TRUE, $default = NULL)
 {
     if (FALSE === Kit::in($root_field_name, self::$rootFieldNameList)) {
         throw new UserException('Invalid $root_field_name.', $root_field_name);
     }
     Kit::ensureString($field_name, TRUE);
     $root_field_value = $this->get($root_field_name);
     if (TRUE === is_null($field_name)) {
         return $root_field_value;
     }
     if (FALSE === isset($root_field_value[$field_name])) {
         if (TRUE === $ensure_existence) {
             $msg = "Field({$field_name}) does not exist in root field({$root_field_name}).";
             throw new UserException($msg, $root_field_value);
         } else {
             return $default;
         }
     } else {
         return $root_field_value[$field_name];
     }
 }
Пример #5
0
 /**
  * Extracts handler suffix name from path.
  * eg. 'Service/AdminServiceController'           => 'Service'
  * eg. 'Collection/Content/ResourceCollectionModel' => 'Collection'
  * eg. 'Collection/LogCollection'                   => 'Collection'
  * eg. 'Entity/ResourceEntity'                    => 'Entity'
  * @param string $path
  * @param string $delimiter
  * @return string
  */
 public static final function getHandlerSuffixFromPath($path, $delimiter = '\\')
 {
     Kit::ensureString($path);
     Kit::ensureString($delimiter);
     $handler = self::getHandlerFromPath($path, $delimiter);
     $title_word_list = Kit::separateTitleWords($handler);
     if (Kit::len($title_word_list) > 0) {
         if (TRUE === Kit::in($last_word = Kit::last($title_word_list), self::$handler_suffix_list)) {
             return $last_word;
         }
     }
     throw new UserException("Get handler suffix of \$handler({$handler}) failed.");
 }