示例#1
0
<?php

namespace Rubicon\Collection;

use Rubicon\Collection\Constraint\IsInstanceOf;
require dirname(__DIR__) . '/vendor/autoload.php';
$validation = new IsInstanceOf([\ArrayObject::class, \stdClass::class]);
$collection = new MutableCollection([], $validation);
$collection->add(new \ArrayObject());
$collection->add(new \stdClass());
print_r($collection->toImmutable());
 public function testReplaceElementsNonStrict()
 {
     $result = $this->instance->add(1)->add('1')->replace(1, 2, false)->toArray();
     $this->assertSame([2, 2], $result);
 }
示例#3
0
<?php

namespace Rubicon\Collection;

use Rubicon\Collection\Constraint\CompositeConstraint;
use Rubicon\Collection\Constraint\IsGreaterThan;
use Rubicon\Collection\Constraint\IsTypeOf;
use Rubicon\Collection\Constraint\Regex;
require dirname(__DIR__) . '/vendor/autoload.php';
$constraint = new CompositeConstraint([new IsTypeOf('integer'), new IsGreaterThan(2)], CompositeConstraint::CONSTRAINT_AND);
try {
    new MutableCollection([1, 2, 3], $constraint);
} catch (\Exception $exception) {
    echo $exception->getMessage() . PHP_EOL;
}
$collection = new MutableCollection([], new Regex('^api/.*$'));
$collection->add('api/result');