本文整理汇总了PHP中Symfony\Component\PropertyAccess\PropertyAccessor::isWritable方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyAccessor::isWritable方法的具体用法?PHP PropertyAccessor::isWritable怎么用?PHP PropertyAccessor::isWritable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\PropertyAccess\PropertyAccessor
的用法示例。
在下文中一共展示了PropertyAccessor::isWritable方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isWritable
/**
* {@inheritdoc}
*/
public function isWritable($node, $singlePath)
{
if (!$singlePath) {
return false;
}
return $this->propertyAccess->isWritable($node, $singlePath);
}
示例2: populate
/**
* @param mixed $entity
* @param array $entityData
*
* @return mixed
*/
protected function populate($entity, array $entityData)
{
foreach ($entityData as $key => $value) {
if ($this->propertyAccessor->isWritable($entity, $key)) {
$this->propertyAccessor->setValue($entity, $key, $value);
}
}
return $entity;
}
示例3: connect
/**
* {@inheritDoc}
*/
public function connect(UserInterface $user, UserResponseInterface $response)
{
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Expected an instance of FOS\\UserBundle\\Model\\User, but got "%s".', get_class($user)));
}
$property = $this->getProperty($response);
if (!$this->accessor->isWritable($user, $property)) {
throw new \RuntimeException(sprintf("Class '%s' must have defined setter method for property: '%s'.", get_class($user), $property));
}
$username = $response->getUsername();
if (null !== ($previousUser = $this->userManager->findUserBy(array($property => $username)))) {
$this->accessor->setValue($previousUser, $property, null);
$this->userManager->updateUser($previousUser);
}
$this->accessor->setValue($user, $property, $username);
$this->userManager->updateUser($user);
}
示例4: add
/**
* @param $object
* @param $data
* @param ObjectManager $manager For persistence
* @param string $referenceName
*
* @return $object
*/
protected function add($object, $data, ObjectManager $manager = null, $referenceName = null)
{
$accessor = new PropertyAccessor();
foreach ($data as $key => $value) {
if ($accessor->isWritable($object, $key)) {
$accessor->setValue($object, $key, $value);
}
}
if (null !== $manager) {
$manager->persist($object);
$manager->flush();
}
if (null !== $referenceName) {
$this->addReference($referenceName, $object);
}
return $object;
}
示例5: save
/**
* @param \Doctrine\ORM\Mapping\ClassMetadata $meta
* @param \Nette\ComponentModel\Component $component
* @param mixed $entity
* @return boolean
*/
public function save(ClassMetadata $meta, Component $component, $entity)
{
if (!$component instanceof BaseControl) {
return false;
}
$name = $component->getOption(self::FIELD_NAME, $component->getName());
$value = $component->getValue();
if ($this->accessor->isWritable($entity, $name) && !$meta->hasAssociation($name)) {
try {
$this->accessor->setValue($entity, $name, $value);
return true;
} catch (\Kdyby\Doctrine\MemberAccessException $e) {
}
}
if (!$meta->hasAssociation($name)) {
return false;
}
$value = $component->getValue();
$entityClass = $this->relatedMetadata($entity, $name)->getName();
$repository = $this->entityManager->getRepository($entityClass);
if ($meta->isCollectionValuedAssociation($name)) {
$property = \Doctrine\Common\Util\Inflector::singularize($name);
foreach ($repository->findAll() as $associatedEntity) {
if (in_array($associatedEntity->id, $value)) {
$hasMethod = 'has' . ucfirst($property);
if (!$entity->{$hasMethod}($associatedEntity)) {
$addMethod = 'add' . ucfirst($property);
$entity->{$addMethod}($associatedEntity);
}
} else {
$removeMethod = 'remove' . ucfirst($property);
$entity->{$removeMethod}($associatedEntity);
}
}
} elseif ($value === null || ($value = $repository->find($value))) {
if ($this->accessor->isWritable($entity, $name)) {
try {
$this->accessor->setValue($entity, $name, $value);
} catch (\Kdyby\Doctrine\MemberAccessException $e) {
return false;
}
}
}
return true;
}
示例6: testIsWritableForReferenceChainIssue
/**
* @dataProvider getReferenceChainObjectsForIsWritable
*/
public function testIsWritableForReferenceChainIssue($object, $path, $value)
{
$this->assertEquals($value, $this->propertyAccessor->isWritable($object, $path));
}
示例7: testEmptyIsNotWritable
public function testEmptyIsNotWritable()
{
$this->assertFalse($this->propertyAccessor->isWritable('', 'foobar'));
}
示例8: testIsWritableReturnsFalseIfNotObjectOrArray
/**
* @dataProvider getPathsWithUnexpectedType
*/
public function testIsWritableReturnsFalseIfNotObjectOrArray($objectOrArray, $path)
{
$this->assertFalse($this->propertyAccessor->isWritable($objectOrArray, $path));
}
示例9: testIsWritable
/**
* @dataProvider getValidPropertyPaths
*/
public function testIsWritable($collection, $path)
{
$this->assertTrue($this->propertyAccessor->isWritable($collection, $path, 'Updated'));
}
示例10: testIsWritableThrowsExceptionIfEmpty
public function testIsWritableThrowsExceptionIfEmpty()
{
$this->assertFalse($this->propertyAccessor->isWritable('', 'foobar', 'Updated'));
}
示例11: isWritable
/**
* {@inheritdoc}
*/
public function isWritable($object, $propertyPath)
{
return $this->accessor->isWritable($object, $propertyPath);
}