Skip to content

Commit

Permalink
🚧 trying out fluent setter
Browse files Browse the repository at this point in the history
Signed-off-by: bnomei <[email protected]>
  • Loading branch information
bnomei committed Aug 25, 2023
1 parent 051824a commit 03b49d2
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 36 deletions.
4 changes: 2 additions & 2 deletions classes/Blueprints/Attributes/GenericAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Bnomei\Blueprints\Attributes;

use Bnomei\Blueprints\isArrayable;
use Bnomei\Blueprints\IsArrayable;

class GenericAttribute
{
use isArrayable;
use IsArrayable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use ReflectionMethod;
use ReflectionUnionType;

trait hasBlueprint
trait HasBlueprint
{
public static function registerBlueprintExtension()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bnomei\Blueprints;

trait isArrayable
trait IsArrayable
{
public function toArray(): array
{
Expand Down
11 changes: 9 additions & 2 deletions classes/Blueprints/Schema/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Bnomei\Blueprints\Schema;

use Bnomei\Blueprints\isArrayable;
use Bnomei\Blueprints\IsArrayable;

class Column
{
use isArrayable;
use IsArrayable;

/**
* @param array<Section> $sections
Expand All @@ -30,4 +30,11 @@ public function __construct(
public array $fields = [],
) {
}

public function width(float|string|null $width): Column
{
$this->width = $width;

return $this;
}
}
30 changes: 28 additions & 2 deletions classes/Blueprints/Schema/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public function toArray(): array
unset($data['properties']);
}

ray($data)->red();

ksort($data);

// empty() would catch 0 and false which is not what we want
Expand All @@ -55,4 +53,32 @@ public function jsonSerialize(): array
{
return $this->toArray();
}

public function label(array|string|null $label): Field
{
$this->label = $label;

return $this;
}

public function width(float|string|null $width): Field
{
$this->width = $width;

return $this;
}

public function properties(?array $properties): Field
{
$this->properties = $properties;

return $this;
}

public function property(string $key, mixed $value): Field
{
$this->properties[$key] = $value;

return $this;
}
}
4 changes: 2 additions & 2 deletions classes/Blueprints/Schema/Fields/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Bnomei\Blueprints\Schema\Fields;

use Bnomei\Blueprints\isArrayable;
use Bnomei\Blueprints\IsArrayable;
use JetBrains\PhpStorm\Deprecated;

#[
Deprecated
]
class Url
{
use isArrayable;
use IsArrayable;

/**
* @param string|array<string,string> $label
Expand Down
18 changes: 16 additions & 2 deletions classes/Blueprints/Schema/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Bnomei\Blueprints\Schema;

use Bnomei\Blueprints\isArrayable;
use Bnomei\Blueprints\IsArrayable;

class Page
{
use isArrayable;
use IsArrayable;

/**
* @param Page $page
Expand Down Expand Up @@ -45,4 +45,18 @@ public function __construct(
// public array $fields = [],
) {
}

public function tabs(array $tabs): Page
{
$this->tabs = $tabs;

return $this;
}

public function columns(array $columns): Page
{
$this->columns = $columns;

return $this;
}
}
27 changes: 24 additions & 3 deletions classes/Blueprints/Schema/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Bnomei\Blueprints\Schema;

use Bnomei\Blueprints\isArrayable;
use Bnomei\Blueprints\IsArrayable;

class Tab
{
use isArrayable;
use IsArrayable;

/**
* @param array<Column> $columns
Expand All @@ -30,11 +30,32 @@ public static function make(
* @return Page
*/
public function __construct(
public string $label = '',
public string|array $label = '',
public ?Icon $icon = null,
public array $columns = [],
// public array $section = [],
// public array $fields = [],
) {
}

public function label(string|array $label): Tab
{
$this->label = $label;

return $this;
}

public function icon(?Icon $icon): Tab
{
$this->icon = $icon;

return $this;
}

public function columns(array $columns): Tab
{
$this->columns = $columns;

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Bnomei\Blueprints\Schema\FieldTypes;
use Kirby\Content\Field;

trait hasDescriptionField
trait HasDescriptionField
{
#[
Type(FieldTypes::TEXTAREA),
Expand Down
33 changes: 13 additions & 20 deletions tests/site/plugins/test/models/ProductPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class ProductPage extends \Kirby\Cms\Page
{
// public static bool $cacheBlueprint = false;
use Bnomei\Blueprints\hasBlueprint;
use hasDescriptionField;
use Bnomei\Blueprints\HasBlueprint;
use HasDescriptionField;

#[
CustomType('qrcode'),
Expand Down Expand Up @@ -45,24 +45,14 @@ public static function blueprintFromMyCustomMethod(): array
public static function thisIsACustomBlueprint(): array
{
return Page::make(
// options: [],
// options: [],
tabs: [
Tab::make(
label: 'Shop',
icon: Icon::CART,
columns: [
Column::make(
width: 1 / 3,
// sections: [
// \Sections\Files::make(
// label: 'Gallery',
// template: 'cover',
// ),
// \MyCustomSection::make(
// callback: getenv('SOME_SECRET')
// ),
// ]
),
Column::make()
->width(1 / 3),
Column::make(
width: 2 / 3,
fields: [
Expand All @@ -76,7 +66,11 @@ public static function thisIsACustomBlueprint(): array
FieldProperties::SPELLCHECK->value => false,
FieldProperties::BUTTONS->value => false,
],
),
)
// ->property(FieldProperties::MAXLENGTH->value, 3000)
// ->property(FieldProperties::SPELLCHECK->value, false)
// ->property(FieldProperties::BUTTONS->value, false)
,
/*
* THIS WOULD MEAN CREATING A LOT OF CLASSES
// explicit field type
Expand All @@ -91,10 +85,9 @@ public static function thisIsACustomBlueprint(): array
),
],
),
Tab::make(
label: 'Settings',
icon: Icon::SETTINGS,
),
Tab::make()
->label('Settings')
->icon(Icon::SETTINGS),
],
)->toArray();
}
Expand Down

0 comments on commit 03b49d2

Please sign in to comment.