/** * Returns the ReflectionMethod for the given controller string. * * @param string $controller *Â @return \ReflectionMethod|null */ public function getReflectionMethod($controller) { if (false === strpos($controller, '::') && 2 === substr_count($controller, ':')) { $controller = $this->controllerNameParser->parse($controller); } if (preg_match('#(.+)::([\\w]+)#', $controller, $matches)) { $class = $matches[1]; $method = $matches[2]; } elseif (preg_match('#(.+):([\\w]+)#', $controller, $matches)) { $controller = $matches[1]; $method = $matches[2]; if ($this->container->has($controller)) { $this->container->enterScope('request'); $this->container->set('request', new Request(), 'request'); $class = ClassUtils::getRealClass(get_class($this->container->get($controller))); $this->container->leaveScope('request'); } } if (isset($class) && isset($method)) { try { return new \ReflectionMethod($class, $method); } catch (\ReflectionException $e) { } } return null; }
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; }
/** * {@inheritdoc} * * Expected input format : * { * 'attribute': 'maximum_print_size', * 'code': '210_x_1219_mm', * 'sort_order': 2, * 'labels': { * 'de_DE': '210 x 1219 mm', * 'en_US': '210 x 1219 mm', * 'fr_FR': '210 x 1219 mm' * } * } * * @throws BusinessValidationException */ public function update($attributeOption, array $data, array $options = []) { if (!$attributeOption instanceof AttributeOptionInterface) { throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\AttributeOptionInterface", "%s" provided.', ClassUtils::getClass($attributeOption))); } // TODO: ugly fix to workaround issue with "attribute.group.code: This value should not be blank." // in case of existing option, attribute is a proxy, attribute group too, the validated group code is null $attributeOption->getAttribute() !== null ? $attributeOption->getAttribute()->getGroup()->getCode() : null; $isNew = $attributeOption->getId() === null; $readOnlyFields = ['attribute', 'code']; $updateViolations = new ConstraintViolationList(); foreach ($data as $field => $data) { $isReadOnlyField = in_array($field, $readOnlyFields); if ($isNew || !$isReadOnlyField) { try { $this->setData($attributeOption, $field, $data); } catch (\InvalidArgumentException $e) { $setViolation = new ConstraintViolation($e->getMessage(), $e->getMessage(), [], $attributeOption, null, null); $updateViolations->add($setViolation); } } } $validatorViolations = $this->validator->validate($attributeOption); $updateViolations->addAll($validatorViolations); if ($updateViolations->count() > 0) { throw new BusinessValidationException($updateViolations); } return $this; }
protected function uncacheClassName($className, SegmentHandler $handler) { $handler->drop(); $dao = ClassUtils::callStaticMethod($className . '::dao'); /* @var $dao StorableDAO */ return Cache::worker($dao)->uncacheByQuery($dao->makeSelectHead()); }
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; }
/** * @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(); }
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 __construct($class) { Assert::isTrue(ClassUtils::isInstanceOf($class, 'Prototyped')); if (is_object($class)) { $this->className = get_class($class); } else { $this->className = $class; } }
/** * @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(); }
/** * {@inheritdoc} */ public function resolveTargetClassName($className, $sourceFile, $testDirectoryName) { $targetClassName = ClassUtils::resolveTargetClassName($className, $sourceFile, $testDirectoryName, $this->isTestCaseClass()); // replace the targetClassName by testCaseClassName $components = explode('\\', $targetClassName); array_pop($components); $components[] = $this->testCaseClassName; return implode('\\', $components); }
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(); } Assert::isUnreachable(); }
public function uncache() { foreach ($this->classNameMap as $className => $uncaches) { list($idKeys, $tags, $worker) = $uncaches; /* @var $worker TaggableDaoWorker */ $worker->expireTags($tags); foreach ($idKeys as $key) { Cache::me()->mark($className)->delete($idKey); } ClassUtils::callStaticMethod("{$className}::dao")->uncacheLists(); } }
/** * {@inheritdoc} * * Expected input format : * { * 'attribute': 'maximum_print_size', * 'code': '210_x_1219_mm', * 'sort_order': 2, * 'labels': { * 'de_DE': '210 x 1219 mm', * 'en_US': '210 x 1219 mm', * 'fr_FR': '210 x 1219 mm' * } * } */ public function update($attributeOption, array $data, array $options = []) { if (!$attributeOption instanceof AttributeOptionInterface) { throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Component\\Catalog\\Model\\AttributeOptionInterface", "%s" provided.', ClassUtils::getClass($attributeOption))); } $isNew = $attributeOption->getId() === null; $readOnlyFields = ['attribute', 'code']; foreach ($data as $field => $data) { $isReadOnlyField = in_array($field, $readOnlyFields); if ($isNew || !$isReadOnlyField) { $this->setData($attributeOption, $field, $data); } } return $this; }
public function testAnyId() { foreach (get_declared_classes() as $className) { if (is_subclass_of($className, 'Enumeration')) { try { $enum = new $className(call_user_func(array($className, 'getAnyId'))); /* pass */ } catch (MissingElementException $e) { $this->fail($className); } } elseif (is_subclass_of($className, 'Enum')) { try { $enum = new $className(ClassUtils::callStaticMethod($className . '::getAnyId')); /* pass */ } catch (MissingElementException $e) { $this->fail($className); } } } }
/** * 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); }
protected function actualImportValue($value) { return strpos($this->methodName, '::') === false ? $this->dao()->{$this->methodName}($value) : ClassUtils::callStaticMethod($this->methodName, $value); }
/** * Export * * @param mixed $var * @param int $maxDepth * @return mixed */ public static function export($var, $maxDepth) { $return = null; $isObj = is_object($var); if ($isObj && in_array('Doctrine\\Common\\Collections\\Collection', class_implements($var))) { $var = $var->toArray(); } if ($maxDepth) { if (is_array($var)) { $return = array(); foreach ($var as $k => $v) { $return[$k] = self::export($v, $maxDepth - 1); } } else { if ($isObj) { $return = new \stdclass(); if ($var instanceof \DateTime) { $return->__CLASS__ = "DateTime"; $return->date = $var->format('c'); $return->timezone = $var->getTimeZone()->getName(); } else { $reflClass = ClassUtils::newReflectionObject($var); $return->__CLASS__ = ClassUtils::getClass($var); if ($var instanceof \Doctrine\Common\Persistence\Proxy) { $return->__IS_PROXY__ = true; $return->__PROXY_INITIALIZED__ = $var->__isInitialized(); } foreach ($reflClass->getProperties() as $reflProperty) { $name = $reflProperty->getName(); $reflProperty->setAccessible(true); $return->{$name} = self::export($reflProperty->getValue($var), $maxDepth - 1); } } } else { $return = $var; } } } else { $return = is_object($var) ? get_class($var) : (is_array($var) ? 'Array(' . count($var) . ')' : $var); } return $return; }
/** * @param object $entity * * @return array */ private function getIdentifierValues($entity) { try { return $this->modelManager->getIdentifierValues($entity); } catch (\Exception $e) { throw new \InvalidArgumentException(sprintf('Unable to retrieve the identifier values for entity %s', ClassUtils::getClass($entity)), 0, $e); } }
public function __construct($tagOrElement, $slug = '', $role = '', $value = '') { if ($tagOrElement instanceof TagPartial || $tagOrElement instanceof Tag) { $this->fields = $tagOrElement->toArray(); return; } $this->fields = array_merge($this->fields, array('TagElement' => '', 'TagAspect' => '', 'TagSlug' => '', 'TagRole' => '', 'TagValue' => '')); if (is_array($tagOrElement)) { $this->fields = array_merge($this->fields, $tagOrElement); } else { if (is_string($tagOrElement)) { // assume first param is element if (!empty($slug) || !empty($role) || !empty($value)) { if (substr($tagOrElement, 0, 1) == '@') { $this->fields['TagAspect'] = substr($tagOrElement, 1); } else { $this->fields['TagElement'] = $tagOrElement; } $this->fields['TagSlug'] = $slug; $this->fields['TagRole'] = $role; $this->fields['TagValue'] = $value; // assume first param is tag string } else { $expressions = StringUtils::smartSplit($tagOrElement, ".", '"', '\\"', 2); if (preg_match("/^(((?P<ai>@)?(?P<el>[a-z0-9-]+))?(:(?P<s>[a-z0-9\\/\\-]+)?)?)?(#(?P<r>[a-z0-9-]+)?)?(=(?P<v>.+?))?\$/", array_shift($expressions), $m)) { if (!empty($m['ai'])) { $this->fields['TagAspect'] = !empty($m['el']) ? $m['el'] : ''; } else { $this->fields['TagElement'] = !empty($m['el']) ? $m['el'] : ''; } $this->fields['TagSlug'] = !empty($m['s']) ? $m['s'] : ''; $this->fields['TagRole'] = !empty($m['r']) ? $m['r'] : ''; $this->fields['TagValue'] = !empty($m['v']) ? $m['v'] : ''; if (!empty($expressions)) { // if(count($expressions) > 1) $this->fields['ChildPartials'] = current($expressions); // else // $this->fields['ChildPartial'] = $expressions[0]; } } } } else { throw new Exception('Invalid parameter to TagPartial: ' . ClassUtils::getQualifiedType($tagOrElement)); } } if (empty($this->fields['TagElement']) && empty($this->fields['TagAspect']) && empty($this->fields['TagRole'])) { throw new TagException('Invalid partial: No element, aspect, or role was specified [' . print_r($tagOrElement, true) . ']'); } if (!empty($this->fields['TagAspect'])) { // $this->fields['TagAspect'] = strtolower($this->fields['TagAspect']); if (!preg_match("/[a-z0-9-]+/", $this->fields['TagAspect'])) { throw new TagException('Invalid partial: Aspect "' . $this->fields['TagAspect'] . '" must contain only characters or dash'); } } if (!empty($this->fields['TagSlug'])) { $this->fields['TagSlug'] = strtolower($this->fields['TagSlug']); if (!SlugUtils::isSlug($this->fields['TagSlug'], true)) { throw new TagException('Invalid tag: "' . $this->fields['TagSlug'] . '" must be valid slug'); } } if (!empty($this->fields['TagRole']) && !SlugUtils::isSlug($this->fields['TagRole'])) { $this->fields['TagRole'] = SlugUtils::createSlug($this->fields['TagRole']); } if (!empty($this->fields['TagValue']) && !SlugUtils::isSlug($this->fields['TagValue'])) { $this->fields['TagValue'] = SlugUtils::createSlug($this->fields['TagValue']); } // lowercase all parts foreach (array('TagElement', 'TagAspect', 'TagSlug', 'TagRole', 'TagValue') as $name) { $this->fields[$name] = strtolower($this->fields[$name]); } }
public function testIsClassName() { $this->assertFalse(ClassUtils::isClassName(null)); $this->assertFalse(ClassUtils::isClassName('')); $this->assertFalse(ClassUtils::isClassName(0)); $this->assertFalse(ClassUtils::isClassName('0')); $this->assertTrue(ClassUtils::isClassName('A0')); $this->assertTrue(ClassUtils::isClassName('_')); $this->assertTrue(ClassUtils::isClassName('_1')); $this->assertTrue(ClassUtils::isClassName('Correct_Class1')); }
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); } }
/** * @param string $className * * @return string */ protected function getTestCaseNamespace($className) { $testCaseFullClassName = ClassUtils::resolveTestCaseClassName($className, $this->testCaseClassName, $this->testDirectoryName); $components = explode('\\', $testCaseFullClassName); array_pop($components); return implode('\\', $components); }
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); } }
/** * Returns all results as an array * * @return array an Array of all results, each one being an array */ public function getResultsAsArray() { $new = array(); foreach ((array) $this->results as $result) { if ($result instanceof Object) { $new[] = $result->toArray(); } else { if (is_array($result)) { return $this->results; } else { throw new Exception('Cannot convert to array: ' . ClassUtils::getQualifiedType($result)); } } } return $new; }
protected function checkType($value) { Assert::isTrue(ClassUtils::isInstanceOf($value, $this->getObjectName())); }
private function checkType($object) { if ($this->className) { Assert::isTrue(ClassUtils::isInstanceOf($object, $this->className)); } else { Assert::isTrue(ClassUtils::isInstanceOf($object, $this->getObjectName())); } }
private function checkEnumerationReferentialIntegrity($enumeration, $tableName) { Assert::isTrue($enumeration instanceof Enumeration || $enumeration instanceof Enum, 'argument enumeation must be instacne of Enumeration or Enum! gived, "' . gettype($enumeration) . '"'); $updateQueries = null; $db = DBPool::me()->getLink(); $class = get_class($enumeration); $ids = array(); if ($enumeration instanceof Enumeration) { $list = $enumeration->getList(); } elseif ($enumeration instanceof Enum) { $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; }
public function getClassName(\ReflectionClass $class) { $userClass = ClassUtils::getUserClass($class->name); return $this->prefix . '_' . sha1($class->name) . '\\' . self::SEPARATOR . '\\' . $userClass; }
public static function isInstance($first, $second, $message = null) { if (!ClassUtils::isInstanceOf($first, $second)) { throw new WrongArgumentException($message . ', ' . self::dumpOppositeArguments($first, $second)); } }