public function import($scope) { if (!$this->className) { throw new WrongStateException("no class defined for PrimitiveEnumeration '{$this->name}'"); } if (isset($scope[$this->name])) { $scopedValue = urldecode($scope[$this->name]); $anyId = ClassUtils::callStaticMethod($this->className . '::getAnyId'); $object = new $this->className($anyId); $names = $object->getNameList(); foreach ($names as $key => $value) { if ($value == $scopedValue) { try { $this->value = new $this->className($key); } catch (MissingElementException $e) { $this->value = null; return false; } return true; } } return false; } return null; }
protected function uncacheClassName($className, SegmentHandler $handler) { $handler->drop(); $dao = ClassUtils::callStaticMethod($className . '::dao'); /* @var $dao StorableDAO */ return Cache::worker($dao)->uncacheByQuery($dao->makeSelectHead()); }
/** * @return Controller */ protected function makeControllerChain() { $this->controllerName = self::DEFAULT_CONTROLLER; if ($this->request->hasAttachedVar('area') && $this->request->getAttachedVar('area') && ClassUtils::isClassName($this->request->getAttachedVar('area'))) { $this->controllerName = $this->request->getAttachedVar('area'); } return new $this->controllerName(); }
/** * @return ModelAndView **/ public function run(Prototyped $subject, Form $form, HttpRequest $request) { if (!$form->getErrors()) { ClassUtils::copyProperties($form->getValue('id'), $subject); FormUtils::form2object($form, $subject, false); return parent::run($subject, $form, $request); } return new ModelAndView(); }
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 uncache() { foreach ($this->classNameMap as $className => $tags) { $dao = ClassUtils::callStaticMethod("{$className}::dao"); /* @var $dao StorableDAO */ $worker = Cache::worker($dao); Assert::isInstance($worker, TaggableDaoWorker::class); $worker->expireTags($tags); } }
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 getList() { if ($this->value) { return ClassUtils::callStaticMethod(get_class($this->value) . '::getList'); } elseif ($this->default) { return ClassUtils::callStaticMethod(get_class($this->default) . '::getList'); } else { $object = new $this->className(ClassUtils::callStaticMethod($this->className . '::getAnyId')); return $object->getObjectList(); } }
public function uncache() { foreach ($this->classNameMap as $className => $uncaches) { list($idKeys, $tags) = $uncaches; $dao = ClassUtils::callStaticMethod("{$className}::dao"); /* @var $dao StorableDAO */ $worker = Cache::worker($dao); Assert::isInstance($worker, TaggableDaoWorker::class); $worker->expireTags($tags); foreach ($idKeys as $key) { Cache::me()->mark($className)->delete($key); } $dao->uncacheLists(); } }
private function checkEnumerationReferentialIntegrity($enumeration, $tableName) { Assert::isTrue($enumeration instanceof Enumeration || $enumeration instanceof Enum || $enumeration instanceof Registry, 'argument enumeation must be instacne of Enumeration or Enum! gived, "' . gettype($enumeration) . '"'); $updateQueries = null; $db = DBPool::me()->getLink(); $class = get_class($enumeration); $ids = []; if ($enumeration instanceof Enumeration) { $list = $enumeration->getList(); } elseif ($enumeration instanceof Enum) { $list = ClassUtils::callStaticMethod($class . '::getList'); } elseif ($enumeration instanceof Registry) { $list = ClassUtils::callStaticMethod($class . '::getList'); } foreach ($list as $enumerationObject) { $ids[$enumerationObject->getId()] = $enumerationObject->getName(); } $rows = $db->querySet(OSQL::select()->from($tableName)->multiGet('id', 'name')); echo "\n"; foreach ($rows as $row) { if (!isset($ids[$row['id']])) { echo "Class '{$class}', strange id: {$row['id']} found. \n"; } else { if ($ids[$row['id']] != $row['name']) { echo "Class '{$class}',id: {$row['id']} sync names. \n"; $updateQueries .= OSQL::update($tableName)->set('name', $ids[$row['id']])->where(Expression::eq('id', $row['id']))->toDialectString($db->getDialect()) . ";\n"; } unset($ids[$row['id']]); } } foreach ($ids as $id => $name) { echo "Class '{$class}', id: {$id} not present in database. \n"; } echo $updateQueries; return $this; }
/** * 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 getPropertiesByClassName($className) { $proto = ClassUtils::callStaticMethod($className . '::proto'); return $proto->getPropertyList(); }
exit; } if ($metaOnlyContainers) { $meta->buildContainers(); } else { $meta->buildClasses()->buildContainers(); if (!$metaNoSchema) { $meta->buildSchema(); } if (!$metaNoSchemaCheck) { $meta->buildSchemaChanges(); } } $meta->checkForStaleFiles($metaDropStaleFiles); $out->newLine()->info('Trying to compile all known classes... '); \Hesper\Main\Util\ClassUtils::preloadAllClasses(); $out->infoLine('done.'); if ($metaCheckEnumerationRefIntegrity) { $meta->setWithEnumerationRefIntegrityCheck(true); } if (!$metaNoIntegrityCheck) { $meta->checkIntegrity(); } } catch (\Hesper\Core\Exception\BaseException $e) { $out->newLine()->errorLine($e->getMessage(), true)->newLine()->logLine($e->getTraceAsString()); } } else { $out->getOutput()->resetAll()->newLine(); stop('Can not continue.'); } $out->getOutput()->resetAll();
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)); } }
protected function actualImportValue($value) { if (is_callable($this->methodName)) { return call_user_func($this->methodName, $value); } elseif (strpos($this->methodName, '::') === false) { return $this->dao()->{$this->methodName}($value); } else { return ClassUtils::callStaticMethod($this->methodName, $value); } }
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); } }
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())); } }