public function import($scope)
 {
     $savedRaw = null;
     if (isset($scope[$this->name]) && $scope[$this->name]) {
         $savedRaw = $scope[$this->name];
         $this->customError = null;
         try {
             list($class, $id) = explode(self::DELIMITER, $savedRaw, 2);
         } catch (BaseException $e) {
             $this->customError = self::WRONG_CID_FORMAT;
         }
         if (!$this->customError && !ClassUtils::isInstanceOf($class, $this->baseClassName)) {
             $this->customError = self::WRONG_CLASS;
         }
         if (!$this->customError) {
             parent::of($class);
             $scope[$this->name] = $id;
         }
     } else {
         // we need some class in any case
         parent::of($this->baseClassName);
     }
     if (!$this->customError) {
         $result = parent::import($scope);
     } else {
         $this->value = null;
         $result = false;
     }
     if ($savedRaw) {
         $this->raw = $savedRaw;
     }
     return $result;
 }
 public function __construct($class)
 {
     Assert::isTrue(ClassUtils::isInstanceOf($class, 'Prototyped'));
     if (is_object($class)) {
         $this->className = get_class($class);
     } else {
         $this->className = $class;
     }
 }
 private function fetchHelpers($className)
 {
     if (isset(self::$protos[$className], self::$daos[$className])) {
         return;
     }
     self::$protos[$className] = call_user_func(array($className, 'proto'));
     self::$daos[$className] = ClassUtils::isInstanceOf($className, 'DAOConnected') ? call_user_func(array($className, 'dao')) : null;
     Assert::isTrue(self::$protos[$className] instanceof AbstractProtoClass && (self::$daos[$className] instanceof ProtoDAO || self::$daos[$className] === null));
 }
 public function import($scope)
 {
     if (!($result = parent::import($scope))) {
         return $result;
     }
     if (!ClassUtils::isClassName($scope[$this->name]) || !$this->classExists($scope[$this->name]) || $this->ofClassName && !ClassUtils::isInstanceOf($scope[$this->name], $this->ofClassName)) {
         $this->value = null;
         return false;
     }
     return true;
 }
 public function testInstanceOf()
 {
     try {
         $this->assertFalse(ClassUtils::isInstanceOf('2007-07-14&genre', 'Date'));
     } catch (WrongArgumentException $e) {
         /* pass */
     }
     $this->assertTrue(ClassUtils::isInstanceOf('ClassUtilsTestClassChild', 'ClassUtilsTestClass'));
     $this->assertFalse(ClassUtils::isInstanceOf('ClassUtilsTestClass', 'ClassUtilsTestClassChild'));
     $this->assertTrue(ClassUtils::isInstanceOf('ClassUtilsTestClassChild', 'ClassUtilsTestInterface'));
     $this->assertTrue(ClassUtils::isInstanceOf('ClassUtilsTestClass', 'ClassUtilsTestInterface'));
     $this->assertTrue(ClassUtils::isInstanceOf('ClassUtilsTestAbstract', 'ClassUtilsTestInterface'));
     $this->assertTrue(ClassUtils::isInstanceOf('ClassUtilsTestAbstract', 'ClassUtilsTestClass'));
     $this->assertFalse(ClassUtils::isInstanceOf('ClassUtilsTestAbstract', 'ClassUtilsTestClassChild'));
     $base = new ClassUtilsTestClass();
     $this->assertTrue(ClassUtils::isInstanceOf($base, $base));
     $this->assertTrue(ClassUtils::isInstanceOf('ClassUtilsTestAbstract', $base));
     $this->assertFalse(ClassUtils::isInstanceOf($base, 'ClassUtilsTestAbstract'));
     $child = new ClassUtilsTestClassChild();
     $this->assertFalse(ClassUtils::isInstanceOf($base, $child));
     $this->assertTrue(ClassUtils::isInstanceOf($child, $base));
     $this->assertFalse(ClassUtils::isInstanceOf($base, 'ClassUtilsTestClassChild'));
     $this->assertTrue(ClassUtils::isInstanceOf($child, 'ClassUtilsTestClass'));
 }
 /**
  * Also try using plain limitedPropertiesList instead of limited
  * hierarchy recursing.
  **/
 public function make($object, $recursive = true)
 {
     // FIXME: make entityProto() non-static, problem with forms here
     if ($object instanceof PrototypedEntity || $object instanceof Form) {
         $proto = $this->proto;
         if ($object instanceof Form) {
             $objectProto = $object->getProto();
         } else {
             $objectProto = $object->entityProto();
         }
         if ($objectProto && !ClassUtils::isInstanceOf($proto, $objectProto)) {
             if (!$objectProto->isInstanceOf($proto)) {
                 throw new WrongArgumentException('target proto ' . get_class($objectProto) . ' is not a child of ' . get_class($proto));
             }
             $proto = $objectProto;
             return $this->cloneBuilder($proto)->make($object);
         }
     }
     if ($this->proto->isAbstract()) {
         throw new WrongArgumentException('cannot make from abstract proto ' . get_class($this->proto));
     }
     return $this->compile($object, $recursive);
 }
Example #7
0
 public static function isInstance($first, $second, $message = null)
 {
     if (!ClassUtils::isInstanceOf($first, $second)) {
         throw new WrongArgumentException($message . ', ' . self::dumpOppositeArguments($first, $second));
     }
 }
 private function checkType($object)
 {
     if ($this->className) {
         Assert::isTrue(ClassUtils::isInstanceOf($object, $this->className));
     } else {
         Assert::isTrue(ClassUtils::isInstanceOf($object, $this->getObjectName()));
     }
 }
 protected function checkType($value)
 {
     Assert::isTrue(ClassUtils::isInstanceOf($value, $this->getObjectName()));
 }
 protected function actualExportValue($value)
 {
     if (!ClassUtils::isInstanceOf($value, $this->className)) {
         return null;
     }
     if (is_callable($this->extractMethod)) {
         return call_user_func($this->extractMethod, $value);
     } elseif (strpos($this->extractMethod, '::') === false) {
         return $value->{$this->extractMethod}($value);
     } else {
         ClassUtils::callStaticMethod($this->extractMethod, $value);
     }
 }
 public function isInstanceOf(EntityProto $proto)
 {
     return ClassUtils::isInstanceOf($this->className(), $proto->className());
 }
 private function fromState()
 {
     if ($this->checkKeyword($this->tokenizer->peek(), 'from')) {
         $this->tokenizer->next();
         $class = $this->tokenizer->next();
         $className = $this->getTokenValue($class, true);
         if (!$this->checkIdentifier($class) || !ClassUtils::isClassName($className)) {
             $this->error('invalid class name:', $className);
         }
         if (!class_exists($className, true)) {
             $this->error('class does not exists:', $className);
         }
         if (!ClassUtils::isInstanceOf($className, 'DAOConnected')) {
             $this->error('class must implement DAOConnected interface:', $className);
         }
         $this->oqlObject->setDao(call_user_func(array($className, 'dao')));
     } else {
         $this->error("expecting 'from' clause");
     }
     return self::WHERE_STATE;
 }