public function __construct($class) { Assert::isTrue(ClassUtils::isInstanceOf($class, Prototyped::class)); if (is_object($class)) { $this->className = get_class($class); } else { $this->className = $class; } }
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; }
/** * 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); }
public function isInstanceOf(EntityProto $proto) { return ClassUtils::isInstanceOf($this->className(), $proto->className()); }
protected function checkType($value) { Assert::isTrue(ClassUtils::isInstanceOf($value, $this->getObjectName())); }
protected function getTableByClassName($className) { if (ClassUtils::isInstanceOf($className, 'DAOConnected')) { return ClassUtils::callStaticMethod("{$className}::dao")->getTable(); } else { return $className . '|className|'; } }
private function fetchHelpers($className) { if (isset(self::$protos[$className], self::$daos[$className])) { return; } self::$protos[$className] = call_user_func([$className, 'proto']); self::$daos[$className] = ClassUtils::isInstanceOf($className, DAOConnected::class) ? call_user_func([$className, 'dao']) : null; Assert::isTrue(self::$protos[$className] instanceof AbstractProtoClass && (self::$daos[$className] instanceof ProtoDAO || self::$daos[$className] === null)); }
private function checkType($object) { if ($this->className) { Assert::isTrue(ClassUtils::isInstanceOf($object, $this->className)); } else { Assert::isTrue(ClassUtils::isInstanceOf($object, $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); } }
protected final function prepareTrigger($input, $triggerName) { $objName = $this->getObjectName(); if (!$this->triggersAllowed || !ClassUtils::isInstanceOf($objName, $triggerName)) { return function () { }; } $method = explode('\\', $triggerName); $method = lcfirst(end($method)); $check = function ($obj) use($objName) { if (!$obj instanceof $objName) { $obj = $this->getById($obj); } return $obj; }; if (is_array($input)) { $input = array_map($check, $input); } else { $input = array($check($input)); } return function () use(&$input, $method) { foreach ($input as $obj) { call_user_func(array($obj, $method)); } }; }
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 static function isInstance($first, $second, $message = null) { if (!ClassUtils::isInstanceOf($first, $second)) { throw new WrongArgumentException($message . ', ' . self::dumpOppositeArguments($first, $second)); } }