Sleimanx2\Plastic\Map\Blueprint::toDSL PHP Method

toDSL() public method

Get the raw DSL statements for the blueprint.
public toDSL ( Grammar $grammar ) : array
$grammar Grammar
return array
    public function toDSL(Grammar $grammar)
    {
        $statements = [];
        // Each type of command has a corresponding compiler function on the schema
        // grammar which is used to build the necessary DSL statements to build
        // the blueprint element, so we'll just call that compilers function.
        foreach ($this->commands as $command) {
            $method = 'compile' . ucfirst($command->name);
            if (method_exists($grammar, $method)) {
                if (!is_null($dsl = $grammar->{$method}($this, $command))) {
                    $statements = array_merge($statements, (array) $dsl);
                }
            }
        }
        return $statements;
    }

Usage Example

Esempio n. 1
0
 /**
  * @test
  */
 public function it_adds_a_object_map()
 {
     $blueprint = new Blueprint('post');
     $blueprint->create();
     $blueprint->object('tags', function ($blueprint) {
         $blueprint->string('name');
     });
     $statement = $blueprint->toDSL($this->getGrammar());
     $this->assertEquals(['tags' => ['properties' => ['name' => ['type' => 'string']]]], $statement);
 }