-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from sitegeist/feature/useCases
FEATURE: Add `useCases` for styleguide prototypes
- Loading branch information
Showing
34 changed files
with
780 additions
and
88 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
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,63 @@ | ||
<?php declare(strict_types=1); | ||
namespace Sitegeist\Monocle\Domain\PrototypeDetails\UseCases; | ||
|
||
/** | ||
* This file is part of the Sitegeist.Monocle package | ||
* | ||
* (c) 2020 | ||
* Martin Ficzel <[email protected]> | ||
* Wilhelm Behncke <[email protected]> | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @Flow\Proxy(false) | ||
*/ | ||
final class UseCase implements \JsonSerializable | ||
{ | ||
/** | ||
* @var UseCaseName | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var UseCaseTitle | ||
*/ | ||
private $title; | ||
|
||
/** | ||
* @var array<string,PropValue> | ||
*/ | ||
private $overrides; | ||
|
||
/** | ||
* @param UseCaseName $name | ||
* @param array $overrides | ||
*/ | ||
public function __construct( | ||
UseCaseName $name, | ||
UseCaseTitle $title, | ||
array $overrides | ||
) { | ||
$this->name = $name; | ||
$this->title = $title; | ||
$this->overrides = $overrides; | ||
} | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return [ | ||
'name' => $this->name, | ||
'title' => $this->title, | ||
'overrides' => $this->overrides | ||
]; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
Classes/Domain/PrototypeDetails/UseCases/UseCaseCollection.php
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,80 @@ | ||
<?php declare(strict_types=1); | ||
namespace Sitegeist\Monocle\Domain\PrototypeDetails\UseCases; | ||
|
||
/** | ||
* This file is part of the Sitegeist.Monocle package | ||
* | ||
* (c) 2020 | ||
* Martin Ficzel <[email protected]> | ||
* Wilhelm Behncke <[email protected]> | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Sitegeist\Monocle\Domain\Fusion\Prototype; | ||
use Sitegeist\Monocle\Domain\PrototypeDetails\Props\PropValue; | ||
|
||
/** | ||
* @Flow\Proxy(false) | ||
*/ | ||
final class UseCaseCollection implements \JsonSerializable | ||
{ | ||
/** | ||
* @var array|UseCase[] | ||
*/ | ||
private $useCases; | ||
|
||
/** | ||
* @param UseCase ...$useCases | ||
*/ | ||
private function __construct(UseCase ...$useCases) | ||
{ | ||
$this->useCases = $useCases; | ||
} | ||
|
||
/** | ||
* @param Prototype $prototype | ||
* @return self | ||
*/ | ||
public static function fromPrototype(Prototype $prototype): self | ||
{ | ||
$ast = $prototype->getAst(); | ||
$useCases = []; | ||
|
||
if (isset($ast['__meta']['styleguide']['useCases'])) { | ||
foreach ($ast['__meta']['styleguide']['useCases'] as $useCaseNameAsString => $useCaseAst) { | ||
$useCaseName = UseCaseName::fromString((string)$useCaseNameAsString); | ||
$useCaseTitle = UseCaseTitle::fromString((string)($useCaseAst['title'] ?? $useCaseNameAsString)); | ||
$values = $prototype->evaluate(sprintf( | ||
'/__meta/styleguide/useCases/%s/props<Neos.Fusion:DataStructure>', | ||
$useCaseName | ||
)); | ||
$overrides = []; | ||
|
||
if (is_array($values)) { | ||
foreach ($values as $name => $value) { | ||
if (PropValue::isValid($value)) { | ||
$overrides[(string) $name] = | ||
PropValue::fromAny($value); | ||
} | ||
} | ||
} | ||
|
||
$useCases[] = new UseCase($useCaseName, $useCaseTitle, $overrides); | ||
} | ||
} | ||
|
||
return new self(...$useCases); | ||
} | ||
|
||
/** | ||
* @return array|UseCases[] | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->useCases; | ||
} | ||
} |
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,60 @@ | ||
<?php declare(strict_types=1); | ||
namespace Sitegeist\Monocle\Domain\PrototypeDetails\UseCases; | ||
|
||
/** | ||
* This file is part of the Sitegeist.Monocle package | ||
* | ||
* (c) 2020 | ||
* Martin Ficzel <[email protected]> | ||
* Wilhelm Behncke <[email protected]> | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @Flow\Proxy(false) | ||
*/ | ||
final class UseCaseName implements \JsonSerializable | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* @param string $value | ||
*/ | ||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @param string $string | ||
* @return self | ||
*/ | ||
public static function fromString(string $string): self | ||
{ | ||
return new self($string); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
Oops, something went wrong.