Symfony\Component\PropertyAccess\PropertyAccessor::isWritable PHP Method

isWritable() public method

public isWritable ( $objectOrArray, $propertyPath )
    public function isWritable($objectOrArray, $propertyPath)
    {
        $propertyPath = $this->getPropertyPath($propertyPath);

        try {
            $zval = array(
                self::VALUE => $objectOrArray,
            );
            $propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength() - 1);

            for ($i = count($propertyValues) - 1; 0 <= $i; --$i) {
                $zval = $propertyValues[$i];
                unset($propertyValues[$i]);

                if ($propertyPath->isIndex($i)) {
                    if (!$zval[self::VALUE] instanceof \ArrayAccess && !is_array($zval[self::VALUE])) {
                        return false;
                    }
                } else {
                    if (!$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
                        return false;
                    }
                }

                if (is_object($zval[self::VALUE])) {
                    return true;
                }
            }

            return true;
        } catch (AccessException $e) {
            return false;
        } catch (UnexpectedTypeException $e) {
            return false;
        }
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function isWritable($node, $singlePath)
 {
     if (!$singlePath) {
         return false;
     }
     return $this->propertyAccess->isWritable($node, $singlePath);
 }
All Usage Examples Of Symfony\Component\PropertyAccess\PropertyAccessor::isWritable