eZ\Publish\Core\Limitation\ContentTypeLimitationType::evaluate PHP Method

evaluate() public method

Evaluate permission against content & target(placement/parent/assignment).
public evaluate ( eZ\Publish\API\Repository\Values\User\Limitation $value, eZ\Publish\API\Repository\Values\User\UserReference $currentUser, eZ\Publish\API\Repository\Values\ValueObject $object, array $targets = null ) : boolean
$value eZ\Publish\API\Repository\Values\User\Limitation
$currentUser eZ\Publish\API\Repository\Values\User\UserReference
$object eZ\Publish\API\Repository\Values\ValueObject
$targets array The context of the $object, like Location of Content, if null none where provided by caller
return boolean
    public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
    {
        if (!$value instanceof APIContentTypeLimitation) {
            throw new InvalidArgumentException('$value', 'Must be of type: APIContentTypeLimitation');
        }
        if ($object instanceof Content) {
            $object = $object->getVersionInfo()->getContentInfo();
        } elseif ($object instanceof VersionInfo) {
            $object = $object->getContentInfo();
        } elseif (!$object instanceof ContentInfo && !$object instanceof ContentCreateStruct) {
            throw new InvalidArgumentException('$object', 'Must be of type: ContentCreateStruct, Content, VersionInfo or ContentInfo');
        }
        if (empty($value->limitationValues)) {
            return false;
        }
        if ($object instanceof ContentCreateStruct) {
            return in_array($object->contentType->id, $value->limitationValues);
        }
        /*
         * @var $object ContentInfo
         */
        return in_array($object->contentTypeId, $value->limitationValues);
    }