-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
244 additions
and
42 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
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,33 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\base; | ||
|
||
use markhuot\keystone\validators\Required; | ||
use markhuot\keystone\validators\Safe; | ||
|
||
class Model extends \craft\base\Model | ||
{ | ||
public function safeAttributes() | ||
{ | ||
$reflect = new \ReflectionClass($this); | ||
$properties = collect($reflect->getProperties(\ReflectionProperty::IS_PUBLIC)) | ||
->filter(fn (\ReflectionProperty $property) => $property->getAttributes(Safe::class)) | ||
->map(fn (\ReflectionProperty $property) => $property->getName()) | ||
->all(); | ||
|
||
return array_merge(parent::safeAttributes(), $properties); | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
$reflect = new \ReflectionClass($this); | ||
$required = collect($reflect->getProperties(\ReflectionProperty::IS_PUBLIC)) | ||
->filter(fn (\ReflectionProperty $property) => $property->getAttributes(Required::class)) | ||
->map(fn (\ReflectionProperty $property) => $property->getName()) | ||
->all(); | ||
|
||
return [ | ||
[$required, 'required'], | ||
]; | ||
} | ||
} |
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
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,11 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\models\http; | ||
|
||
use markhuot\keystone\base\Model; | ||
use markhuot\keystone\models\Component; | ||
|
||
class EditComponentRequest extends Model | ||
{ | ||
public Component $component; | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\models\http; | ||
|
||
use craft\base\ElementInterface; | ||
use craft\base\FieldInterface; | ||
use markhuot\keystone\base\Model; | ||
use markhuot\keystone\validators\Required; | ||
use markhuot\keystone\validators\Safe; | ||
|
||
class StoreComponentRequest extends Model | ||
{ | ||
#[Required] | ||
public ElementInterface $element; | ||
|
||
#[Required] | ||
public FieldInterface $field; | ||
|
||
#[Safe] | ||
public ?string $path=null; | ||
|
||
#[Safe] | ||
public ?string $slot=null; | ||
|
||
#[Required] | ||
public int $sortOrder; | ||
|
||
#[Required] | ||
public string $type; | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\validators; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_PROPERTY)] | ||
class Required | ||
{ | ||
|
||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\validators; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_PROPERTY)] | ||
class Safe | ||
{ | ||
|
||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\tests\models; | ||
|
||
use craft\base\ElementInterface; | ||
use craft\base\Model; | ||
|
||
class ElementToElementIdTest extends Model | ||
{ | ||
public ElementInterface $element; | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
[['element'], 'required'], | ||
]; | ||
} | ||
} |
Oops, something went wrong.