LazyRecord\Schema\SchemaCollection::evaluate PHP Method

evaluate() public method

public evaluate ( )
    public function evaluate()
    {
        return new self(array_map(function ($a) {
            if (is_string($a)) {
                return new $a();
            } elseif (is_object($a)) {
                return $a;
            } else {
                throw new InvalidArgumentException('Invalid schema class argument');
            }
            return $a;
        }, $this->schemas));
    }

Usage Example

 public function testEvaluate()
 {
     $c = new SchemaCollection(['\\TestApp\\Model\\UserSchema', '\\TestApp\\Model\\IDNumberSchema', '\\TestApp\\Model\\NameSchema', '\\AuthorBooks\\Model\\AddressSchema', '\\AuthorBooks\\Model\\BookSchema', '\\AuthorBooks\\Model\\AuthorSchema', '\\AuthorBooks\\Model\\AuthorBookSchema', '\\AuthorBooks\\Model\\PublisherSchema']);
     foreach ($c->getSchemas() as $s) {
         $this->assertInternalType('string', $s);
     }
     $ec = $c->evaluate();
     foreach ($ec->getSchemas() as $s) {
         $this->assertInstanceOf('LazyRecord\\Schema\\DeclareSchema', $s);
     }
 }