本文整理汇总了PHP中Symfony\Component\PropertyAccess\PropertyAccessor::isReadable方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyAccessor::isReadable方法的具体用法?PHP PropertyAccessor::isReadable怎么用?PHP PropertyAccessor::isReadable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\PropertyAccess\PropertyAccessor
的用法示例。
在下文中一共展示了PropertyAccessor::isReadable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isReadable
/**
* {@inheritdoc}
*/
public function isReadable($node, $singlePath)
{
if (!$singlePath) {
return false;
}
return $this->propertyAccess->isReadable($node, $singlePath);
}
示例2: formAttributes
/**
* @param FormView $formView
* @param array $data
*
* @return FormView
*/
public function formAttributes(FormView $formView, array $data)
{
$formView = clone $formView;
foreach ($data as $key => $value) {
$path = 'children[' . str_replace('.', '].children[', $key) . ']';
if (false === $this->accessor->isReadable($formView, $path)) {
continue;
}
/** @var FormView $field */
$field = $this->accessor->getValue($formView, $path);
if (false === $field instanceof FormView) {
throw new \RuntimeException("Cannot set form attribute: {$key} is not a FormView instance");
}
if (is_string($value)) {
$value = ["class" => " {$value}"];
}
if (false === isset($field->vars['attr'])) {
$field->vars['attr'] = [];
}
foreach ($value as $name => $attribute) {
if (isset($field->vars['attr'][$name]) && " " === substr($attribute, 0, 1)) {
$attribute = $field->vars['attr'][$name] . $attribute;
}
$field->vars['attr'][$name] = trim($attribute);
}
}
return $formView;
}
示例3: transform
/**
* Applies the given mapping on a given object or array.
*
* @param object|array $raw The input object or array
* @param array $mapping The mapping
* @param object|array $transformed The output object or array.
* @return array
*/
public function transform($raw, array $mapping, $transformed = [])
{
foreach ($mapping as $destination => $source) {
$value = $this->propertyAccessor->isReadable($raw, $source) ? $this->propertyAccessor->getValue($raw, $source) : null;
$this->propertyAccessor->setValue($transformed, $destination, $value);
}
return $transformed;
}
示例4: supportsParameter
/**
* Supports anything that's mapped or readable directly.
*
* {@inheritdoc}
*/
public function supportsParameter($name, $object)
{
if (!is_object($object)) {
return false;
}
$class = get_class($object);
return isset($this->mapping[$class][$name]) || isset($this->mapping[$class]['_fallback']) || is_string($name) && $this->propertyAccessor->isReadable($object, $name);
}
示例5: preUpdate
/**
* preUpdate
*
* @param LifecycleEventArgs $event
*/
public function preUpdate(LifecycleEventArgs $event)
{
if ($this->accessor->isReadable($this->context, $this->property) && $event->getObject() == $this->accessor->getValue($this->context, $this->property)) {
if (($resource = $event->getObject()) && $resource instanceof ResourceObjectInterface) {
$this->loader->load($this->context, $this->property, $this->file);
}
}
}
示例6: createDataProviderPath
private function createDataProviderPath(ColumnInterface $column, $data, $customPath) : PropertyPath
{
try {
if (null === $customPath) {
$name = $column->getName();
if (!$this->propertyAccessor->isReadable($data, $path = new PropertyPath(sprintf('[%s]', $name))) && !$this->propertyAccessor->isReadable($data, $path = new PropertyPath($name))) {
throw DataProviderException::autoAccessorUnableToGetValue($name);
}
return $path;
}
if (!$this->propertyAccessor->isReadable($data, $path = new PropertyPath($customPath))) {
throw DataProviderException::pathAccessorUnableToGetValue($column->getName(), $path);
}
return $path;
} catch (InvalidPropertyPathException $e) {
throw DataProviderException::invalidPropertyPath($column->getName(), $e);
}
}
示例7: hasPropertyFunction
/**
* @param $object
* @param $path
*
* @return bool
*/
public function hasPropertyFunction($object, $path)
{
if (null == $this->accessor) {
$this->accessor = new PropertyAccessor();
}
static $hasIsReadableMethod = null;
if (null === $hasIsReadableMethod) {
$hasIsReadableMethod = method_exists($this->accessor, 'isReadable');
}
if ($hasIsReadableMethod) {
return $this->accessor->isReadable($object, $path);
} else {
try {
$this->accessor->getValue($object, $path);
return true;
} catch (\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException $ex) {
return false;
}
}
}
示例8: buildResponse
/**
* {@inheritdoc}
*/
public function buildResponse(AutocompleteResults $results, AutocompleteContextInterface $context)
{
$array = [];
$property = $context->getParameter('autocomplete');
$accessor = new PropertyAccessor();
foreach ($results as $id => $result) {
if ($accessor->isReadable($result, $property)) {
$array[] = $accessor->getValue($result, $property);
}
}
return new JsonResponse($array);
}
示例9: mapMessagesToElement
/**
* Sets errors on element
*
* @param array $messages
* @param ElementInterface $element
*/
protected function mapMessagesToElement(array $messages, ElementInterface $element)
{
if ($element->hasPropertyPath()) {
$propertyPathParts = explode('.', $element->getPropertyPath(false));
$propertyPath = $this->buildPath($propertyPathParts);
if ($this->propertyAccessor->isReadable($messages, $propertyPath)) {
$errors = $this->propertyAccessor->getValue($messages, $propertyPath);
$element->setError($errors);
}
}
$children = $element->getChildren();
if ($children->count()) {
$this->mapMessagesToElementCollection($messages, $children);
}
}
示例10: buildResponse
/**
* {@inheritdoc}
*/
public function buildResponse(AutocompleteResults $results, AutocompleteContextInterface $context)
{
$accessor = new PropertyAccessor();
$data['results'] = [];
$property = $context->getParameter('autocomplete');
foreach ($results as $id => $result) {
if ($accessor->isReadable($result, $property)) {
$value = $accessor->getValue($result, $property);
$data['results'][] = ['id' => $value, 'text' => $value];
}
}
if ($max = $context->getParameter('max_results', false)) {
$data['pagination'] = ['more' => $results->count() == $max];
}
return new JsonResponse($data);
}
示例11: refreshUser
/**
* {@inheritDoc}
*/
public function refreshUser(UserInterface $user)
{
// Compatibility with FOSUserBundle < 2.0
if (class_exists('FOS\\UserBundle\\Form\\Handler\\RegistrationFormHandler')) {
return $this->userManager->refreshUser($user);
}
$identifier = $this->properties['identifier'];
if (!$user instanceof User || !$this->accessor->isReadable($user, $identifier)) {
throw new UnsupportedUserException(sprintf('Expected an instance of FOS\\UserBundle\\Model\\User, but got "%s".', get_class($user)));
}
$userId = $this->accessor->getValue($user, $identifier);
if (null === ($user = $this->userManager->findUserBy(array($identifier => $userId)))) {
throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $userId));
}
return $user;
}
示例12: testIsReadableReturnsFalseIfNotObjectOrArray
/**
* @dataProvider getPathsWithUnexpectedType
*/
public function testIsReadableReturnsFalseIfNotObjectOrArray($objectOrArray, $path)
{
$this->assertFalse($this->propertyAccessor->isReadable($objectOrArray, $path));
}
示例13: theCertificateForTheDomainShouldContains
/**
* @Then the certificate for the domain :domain should contains:
*/
public function theCertificateForTheDomainShouldContains($domain, PyStringNode $content)
{
$certFile = $this->storageDir . '/domains/' . $domain . '/cert.pem';
$parser = new CertificateParser();
$certificateMetadata = $parser->parse(file_get_contents($certFile));
$accessor = new PropertyAccessor();
$yaml = new Yaml();
$expected = $yaml->parse($content->getRaw());
foreach ($expected as $key => $value) {
PHPUnit_Framework_Assert::assertTrue($accessor->isReadable($certificateMetadata, $key));
$formattedValue = $accessor->getValue($certificateMetadata, $key);
if (is_array($value) && is_array($formattedValue)) {
sort($value);
sort($formattedValue);
}
PHPUnit_Framework_Assert::assertSame($value, $formattedValue);
}
}
示例14: testIsReadableThrowsExceptionIfEmpty
public function testIsReadableThrowsExceptionIfEmpty()
{
$this->assertFalse($this->propertyAccessor->isReadable('', 'foobar'));
}
示例15: parseName
/**
* parse name and replace tokens with context properties, ej. logo_{id} --> logo_1
*
* @param $name
* @param object $context
* @param object $defaultName
*
* @return mixed
*/
protected function parseName($name, $context, $defaultName = null)
{
if ($context) {
preg_match_all('/\\{([\\w\\.]+)\\}/', $name, $matches);
$accessor = new PropertyAccessor();
if (isset($matches[1])) {
foreach ($matches[1] as $token) {
if ($accessor->isReadable($context, $token)) {
$value = str_replace(' ', '_', $accessor->getValue($context, $token));
$name = str_replace("{{$token}}", $value, $name);
}
}
}
//render default file name into {}
$defaultName = str_replace(' ', '_', Inflector::tableize($defaultName));
$name = str_replace('{}', $defaultName, $name);
//unique id for each token {*}
while (strpos($name, '{*}') !== false) {
$name = preg_replace('/\\{\\*\\}/', substr(sha1(uniqid(mt_rand())), 0, 8), $name, 1);
}
}
return $name;
}