Skip to content

Commit

Permalink
Allow handle to be passed in make()
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Feb 8, 2024
1 parent cad3395 commit e9efb77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Fields/BlueprintRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ public function make($handle = null)
$blueprint = new Blueprint;

if ($handle) {
$handle = explode('::', $handle);

if (count($handle) > 1) {
$namespace = array_shift($handle);
$blueprint->setNamespace($namespace);
}

$handle = implode('::', $handle);

$blueprint->setHandle($handle);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Fields/BlueprintRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,13 @@ public function it_returns_empty_collection_if_directory_doesnt_exist()
$this->assertInstanceOf(Collection::class, $all);
$this->assertCount(0, $all);
}

/** @test */
public function it_sets_the_namespace_when_passed_when_making()
{
$blueprint = $this->repo->make('test::handle');

$this->assertSame($blueprint->namespace(), 'test');
$this->assertSame($blueprint->handle(), 'handle');
}
}

0 comments on commit e9efb77

Please sign in to comment.