Пример #1
0
 /**
  * @param string    $message
  * @param mixed     $detail
  * @param Exception $previous
  * @param int       $code
  */
 public final function __construct($variable, $expected_type_list)
 {
     if (FALSE === is_array($expected_type_list)) {
         $expected_type_list = [$expected_type_list];
     }
     foreach ($expected_type_list as $expected_type) {
         if (FALSE === Kit::isValidType($expected_type)) {
             throw new UserException('Invalid type.', $expected_type);
         }
     }
     $this->variable = $variable;
     $variable_type = $this->variableType = Kit::type($variable, TRUE);
     $this->expectedTypeList = $expected_type_list;
     $expected_type_string = Kit::join(' or ', $expected_type_list);
     $message = "Invalid type({$variable_type}), {$expected_type_string} is expected.";
     $detail = ['variable' => $variable, 'variable_type' => $variable_type, 'expected_type_list' => $expected_type_list];
     parent::__construct($message, $detail);
 }
Пример #2
0
 /**
  * eg. 'Collection/Content/ResourceCollection' => 'Content/Resource'
  * eg. 'Entity/Content/ResourceEntity'         => 'Content/Resource'
  */
 public static final function getModelPath($model_class_name, $delimiter = '\\')
 {
     Kit::ensureString($model_class_name);
     Kit::ensureString($delimiter);
     $handler_prefix = self::getHandlerPrefixFromPath($model_class_name);
     // 'Resource'
     $word_list = Kit::split($delimiter, $model_class_name);
     while (Kit::len($word_list) > 0 and 'Model' !== $word_list[0]) {
         $word_list = Kit::slice($word_list, 1);
     }
     $word_list = Kit::slice($word_list, 2);
     // [ 'Content', 'ResourceCollection' ]
     Kit::popList($word_list);
     // [ 'Content' ]
     $word_list[] = $handler_prefix;
     // [ 'Content', 'Resource' ]
     return Kit::join('/', $word_list);
     // 'Content/Resource'
 }