-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Importer command and implement getBlueprints method
- Loading branch information
Showing
7 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Tdwesten\StatamicBuilder\Contracts; | ||
|
||
use Tdwesten\StatamicBuilder\Enums\OperatorOption; | ||
|
||
trait ConditionalLogic | ||
{ | ||
protected $if; | ||
|
||
protected $if_any; | ||
|
||
protected $unless; | ||
|
||
protected $unless_any; | ||
|
||
public function if(string $key, OperatorOption $oparator, $value) | ||
{ | ||
if ($this->if === null) { | ||
$this->if = collect(); | ||
} | ||
|
||
$this->if->put($key, "{$oparator->value} {$value}"); | ||
|
||
return $this; | ||
} | ||
|
||
public function ifCustom(string $custom) | ||
{ | ||
if ($this->if === null) { | ||
$this->if = collect(); | ||
} | ||
|
||
$this->if->put('custom', $custom); | ||
|
||
return $this; | ||
} | ||
|
||
public function ifAny(string $key, OperatorOption $oparator, $value) | ||
{ | ||
if ($this->if_any === null) { | ||
$this->if_any = collect(); | ||
} | ||
|
||
$this->if_any->put($key, "{$oparator->value} {$value}"); | ||
|
||
return $this; | ||
} | ||
|
||
public function ifAnyCustom(string $custom) | ||
{ | ||
if ($this->if_any === null) { | ||
$this->if_any = collect(); | ||
} | ||
|
||
$this->if_any->put('custom', $custom); | ||
|
||
return $this; | ||
} | ||
|
||
public function unless(string $key, OperatorOption $oparator, $value) | ||
{ | ||
if ($this->unless === null) { | ||
$this->unless = collect(); | ||
} | ||
|
||
$this->unless->put($key, "{$oparator->value} {$value}"); | ||
|
||
return $this; | ||
} | ||
|
||
public function unlessCustom(string $custom) | ||
{ | ||
if ($this->unless === null) { | ||
$this->unless = collect(); | ||
} | ||
|
||
$this->unless->put('custom', $custom); | ||
|
||
return $this; | ||
} | ||
|
||
public function conditionalLogicToArray() | ||
{ | ||
return [ | ||
'if' => $this->if?->toArray(), | ||
'if_any' => $this->if_any?->toArray(), | ||
'unless' => $this->unless?->toArray(), | ||
'unless_any' => $this->unless_any?->toArray(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Tdwesten\StatamicBuilder\Enums; | ||
|
||
enum OperatorOption: string | ||
{ | ||
case Equals = 'equals'; | ||
case Not = 'not'; | ||
case Contains = 'contains'; | ||
case ContainsAny = 'contains_any'; | ||
case IsIdentical = '==='; | ||
case IsNotIdentical = '!=='; | ||
case GreaterThan = '>'; | ||
case GreaterThanOrEqual = '>='; | ||
case LessThan = '<'; | ||
case LessThanOrEqual = '<='; | ||
case Custom = 'custom'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +0,0 @@ | ||
<?php | ||
|
||
namespace Tdwesten\StatamicBuilder; | ||
|
||
class Importer | ||
{ | ||
|
||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
use Tdwesten\StatamicBuilder\Enums\OperatorOption; | ||
|
||
test('Can set conditional logic if', function () { | ||
$field = new \Tdwesten\StatamicBuilder\FieldTypes\Field('title'); | ||
$field | ||
->type('text') | ||
->if('title', OperatorOption::Equals, 'red'); | ||
|
||
expect($field->toArray()['field']['if'])->toBe([ | ||
'title' => 'equals red', | ||
]); | ||
}); | ||
|
||
test('Can set conditional logic if with multiple conditions', function () { | ||
$field = new \Tdwesten\StatamicBuilder\FieldTypes\Field('title'); | ||
$field | ||
->type('text') | ||
->if('title', OperatorOption::Equals, 'red') | ||
->if('short_title', OperatorOption::IsIdentical, 'blue'); | ||
|
||
expect($field->toArray()['field']['if'])->toBe([ | ||
'title' => 'equals red', | ||
'short_title' => '=== blue', | ||
]); | ||
}); | ||
|
||
test('Can set conditional logic if any', function () { | ||
$field = new \Tdwesten\StatamicBuilder\FieldTypes\Field('title'); | ||
$field | ||
->type('text') | ||
->ifAny('title', OperatorOption::Equals, 'red'); | ||
|
||
expect($field->toArray()['field']['if_any'])->toBe([ | ||
'title' => 'equals red', | ||
]); | ||
}); |