eZ\Publish\Core\Limitation\ParentDepthLimitationType::acceptValue PHP Method

acceptValue() public method

Makes sure LimitationValue object and ->limitationValues is of correct type.
public acceptValue ( eZ\Publish\API\Repository\Values\User\Limitation $limitationValue )
$limitationValue eZ\Publish\API\Repository\Values\User\Limitation
    public function acceptValue(APILimitationValue $limitationValue)
    {
        if (!$limitationValue instanceof APIParentDepthLimitation) {
            throw new InvalidArgumentType('$limitationValue', 'APIParentDepthLimitation', $limitationValue);
        } elseif (!is_array($limitationValue->limitationValues)) {
            throw new InvalidArgumentType('$limitationValue->limitationValues', 'array', $limitationValue->limitationValues);
        }
        foreach ($limitationValue->limitationValues as $key => $value) {
            // Cast integers passed as string to int
            if (is_string($value) && ctype_digit($value)) {
                $limitationValue->limitationValues[$key] = (int) $value;
            } elseif (!is_int($value)) {
                throw new InvalidArgumentType("\$limitationValue->limitationValues[{$key}]", 'int', $value);
            }
        }
    }

Usage Example

 /**
  * @dataProvider providerForTestAcceptValueException
  * @depends testConstruct
  * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  *
  * @param \eZ\Publish\API\Repository\Values\User\Limitation $limitation
  * @param \eZ\Publish\Core\Limitation\ParentDepthLimitationType $limitationType
  */
 public function testAcceptValueException(Limitation $limitation, ParentDepthLimitationType $limitationType)
 {
     $limitationType->acceptValue($limitation);
 }