Exemplo n.º 1
0
 /**
  * Checks if object is instance of type
  * @return void
  */
 static function isInstance($object, $type, $message = null)
 {
     if (!$object instanceof $type) {
         if (!$message) {
             $args = array('object is expected to be instance of %s, %s given', $type, TypeUtils::getName($object));
         } else {
             $args = func_get_args();
             $args = array_slice($args, 1);
         }
         self::triggerError($args);
     }
 }
Exemplo n.º 2
0
 protected function setType($type)
 {
     $this->type = is_object($type) ? get_class($type) : $type;
     Assert::isScalar(TypeUtils::isExists($this->type), 'unknown type %s', TypeUtils::getName($type));
 }
 function subject($subject, ISubjective $object = null)
 {
     if ($subject instanceof ISubjective) {
         // bogus check
         return $subject->toSubjected($this);
     }
     if ($subject instanceof ISqlCastable) {
         return $subject;
     }
     if ($subject instanceof OrmProperty) {
         return $this->subject(new EntityProperty($this, $subject));
     }
     if ($subject instanceof EntityProperty) {
         return $subject->getSqlColumn();
     }
     if ($subject instanceof IBoxable) {
         return new SqlValue($subject->getValue());
     }
     if ($subject instanceof EntityPropertyValue) {
         // value cast thru explicit specification of PropertyType to use
     }
     if ($subject instanceof IdentifiableOrmEntity) {
         return $this->subject($subject->_getId());
     }
     if (is_scalar($subject)) {
         try {
             return $this->subject($this->getEntityProperty($subject));
         } catch (ArgumentException $e) {
             // probably, a value, not a property path
         }
         if ($this->hasId($subject)) {
             return new SqlIdentifier($subject);
         }
     } else {
         if (!is_null($subject)) {
             Assert::isUnreachable('do not know how to subject %s', TypeUtils::getName($subject));
         }
     }
     return new SqlValue($subject);
 }
 /**
  * Cast the result of action method (of any type) to IActionResult.
  *
  * The following types are supported:
  * - string is treated as path to a view and wrapped with ViewResult
  * 		See ActionBasedController::view()
  * - IActionResult object is treated as-is
  *
  * @return IActionResult
  */
 protected function makeActionResult($actionResult)
 {
     if (is_object($actionResult) && $actionResult instanceof IActionResult) {
         return $actionResult;
     }
     if (is_string($actionResult)) {
         return $this->view($actionResult);
     }
     Assert::isUnreachable('unknown actionResult `%s`: %s', TypeUtils::getName($actionResult), $actionResult);
 }