|
| 1 | +<templateSet group="PHP"> |
| 2 | + <template name="vo_string" value="private $$$PROP_NAME$; public static function fromString(string $$$PROP_NAME$): self { return new self($$$PROP_NAME$); } private function __construct(string $$$PROP_NAME$) { $this->$PROP_NAME$ = $$$PROP_NAME$; } public function toString(): string { return $this->$PROP_NAME$; } public function equals($other): bool { if(!$other instanceof self) { return false; } return $this->$PROP_NAME$ === $other->$PROP_NAME$; } public function __toString(): string { return $this->$PROP_NAME$; } " shortcut="SPACE" description="String value object" toReformat="false" toShortenFQNames="true"> |
| 3 | + <variable name="PROP_NAME" expression="" defaultValue="" alwaysStopAt="true" /> |
| 4 | + <context> |
| 5 | + <option name="PHP" value="true" /> |
| 6 | + </context> |
| 7 | + </template> |
| 8 | + <template name="vo_int" value="private $$$PROP_NAME$; public static function fromInt(int $$$PROP_NAME$): self { return new self($$$PROP_NAME$); } private function __construct(int $$$PROP_NAME$) { $this->$PROP_NAME$ = $$$PROP_NAME$; } public function toInt(): int { return $this->$PROP_NAME$; } public function equals($other): bool { if(!$other instanceof self) { return false; } return $this->$PROP_NAME$ === $other->$PROP_NAME$; } public function __toString(): string { return (string)$this->$PROP_NAME$; } " shortcut="SPACE" description="Int value object" toReformat="false" toShortenFQNames="true"> |
| 9 | + <variable name="PROP_NAME" expression="" defaultValue="" alwaysStopAt="true" /> |
| 10 | + <context> |
| 11 | + <option name="PHP" value="true" /> |
| 12 | + </context> |
| 13 | + </template> |
| 14 | + <template name="vo_float" value="private $$$PROP_NAME$; public static function fromFloat(float $$$PROP_NAME$): self { return new self($$$PROP_NAME$); } private function __construct(float $$$PROP_NAME$) { $this->$PROP_NAME$ = $$$PROP_NAME$; } public function toFloat(): float { return $this->$PROP_NAME$; } public function equals($other): bool { if(!$other instanceof self) { return false; } return $this->$PROP_NAME$ === $other->$PROP_NAME$; } public function __toString(): string { return (string)$this->$PROP_NAME$; } " shortcut="SPACE" description="Float value object" toReformat="false" toShortenFQNames="true"> |
| 15 | + <variable name="PROP_NAME" expression="" defaultValue="" alwaysStopAt="true" /> |
| 16 | + <context> |
| 17 | + <option name="PHP" value="true" /> |
| 18 | + </context> |
| 19 | + </template> |
| 20 | + <template name="vo_bool" value="private $$$PROP_NAME$; public static function fromBool(bool $$$PROP_NAME$): self { return new self($$$PROP_NAME$); } private function __construct(bool $$$PROP_NAME$) { $this->$PROP_NAME$ = $$$PROP_NAME$; } public function toBool(): bool { return $this->$PROP_NAME$; } public function equals($other): bool { if(!$other instanceof self) { return false; } return $this->$PROP_NAME$ === $other->$PROP_NAME$; } public function __toString(): string { return $this->$PROP_NAME$ ? 'TRUE' : 'FALSE'; } " shortcut="SPACE" description="Bool value object" toReformat="false" toShortenFQNames="true"> |
| 21 | + <variable name="PROP_NAME" expression="" defaultValue="" alwaysStopAt="true" /> |
| 22 | + <context> |
| 23 | + <option name="PHP" value="true" /> |
| 24 | + </context> |
| 25 | + </template> |
| 26 | + <template name="vo_array" value="public static function fromArray(array $data): self { $END$ return new self(); } private function __construct() { /* Map data to private props */ } public function toArray(): array { return [ ]; } public function equals($other): bool { if(!$other instanceof self) { return false; } return $this->toArray() === $other->toArray(); } public function __toString(): string { return json_encode($this->toArray()); } " shortcut="SPACE" description="Array value object" toReformat="false" toShortenFQNames="true"> |
| 27 | + <context> |
| 28 | + <option name="PHP" value="true" /> |
| 29 | + </context> |
| 30 | + </template> |
| 31 | + <template name="vo_uuid" value="private $$$PROP_NAME$; public static function generate(): self { return new self(Uuid::uuid4()); } public static function fromString(string $$$PROP_NAME$): self { return new self(Uuid::fromString($$$PROP_NAME$)); } private function __construct(UuidInterface $$$PROP_NAME$) { $this->$PROP_NAME$ = $$$PROP_NAME$; } public function toString(): string { return $this->$PROP_NAME$->toString(); } public function equals($other): bool { if(!$other instanceof self) { return false; } return $this->$PROP_NAME$->equals($other->$PROP_NAME$); } public function __toString(): string { return $this->$PROP_NAME$->toString(); } " shortcut="SPACE" description="UUID value object" toReformat="true" toShortenFQNames="true"> |
| 32 | + <variable name="PROP_NAME" expression="" defaultValue="" alwaysStopAt="true" /> |
| 33 | + <context> |
| 34 | + <option name="PHP" value="true" /> |
| 35 | + </context> |
| 36 | + </template> |
| 37 | + <template name="use_uuid" value="use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface;" shortcut="SPACE" description="use statments for UUID" toReformat="true" toShortenFQNames="true"> |
| 38 | + <context> |
| 39 | + <option name="PHP" value="true" /> |
| 40 | + </context> |
| 41 | + </template> |
| 42 | + <template name="record_field" value="public const $CONSTANT$ = '$FIELD_NAME$';$END$ /** * @var $TYPE$ */ private $$$FIELD_NAME$;" description="Add a constant + private field to an immutable record" toReformat="false" toShortenFQNames="true"> |
| 43 | + <variable name="FIELD_NAME" expression="" defaultValue="" alwaysStopAt="true" /> |
| 44 | + <variable name="CONSTANT" expression="capitalizeAndUnderscore(FIELD_NAME)" defaultValue="" alwaysStopAt="false" /> |
| 45 | + <variable name="TYPE" expression="" defaultValue="" alwaysStopAt="true" /> |
| 46 | + <context> |
| 47 | + <option name="PHP" value="true" /> |
| 48 | + <option name="PHP Comment" value="false" /> |
| 49 | + <option name="PHP String Literal" value="false" /> |
| 50 | + </context> |
| 51 | + </template> |
| 52 | + <template name="vo_datetime" value="public const FORMAT = 'Y-m-d\TH:i:s.u'; /** * @var \DateTimeImmutable */ private $$$PROP_NAME$; public static function fromDateTime(\DateTimeImmutable $$$PROP_NAME$): self { $$$PROP_NAME$ = self::ensureUTC($$$PROP_NAME$); return new self($$$PROP_NAME$); } public static function fromString(string $$$PROP_NAME$): self { if (\strlen($$$PROP_NAME$) === 19) { $$$PROP_NAME$ = $$$PROP_NAME$ . '.000'; } $$$PROP_NAME$ = \DateTimeImmutable::createFromFormat( self::FORMAT, $$$PROP_NAME$, new \DateTimeZone('UTC') ); $$$PROP_NAME$ = self::ensureUTC($$$PROP_NAME$); return new self($$$PROP_NAME$); } private function __construct(\DateTimeImmutable $$$PROP_NAME$) { $this->$PROP_NAME$ = $$$PROP_NAME$; } public function toString(): string { return $this->$PROP_NAME$->format(self::FORMAT); } public function dateTime(): \DateTimeImmutable { return $this->$PROP_NAME$; } public function add(\DateInterval $interval): self { return new self($this->$PROP_NAME$->add($interval)); } public function sub(\DateInterval $interval): self { return new self($this->$PROP_NAME$->sub($interval)); } public function __toString(): string { return $this->toString(); } private static function ensureUTC(\DateTimeImmutable $$$PROP_NAME$): \DateTimeImmutable { if ($$$PROP_NAME$->getTimezone()->getName() !== 'UTC') { $$$PROP_NAME$ = $$$PROP_NAME$->setTimezone(new \DateTimeZone('UTC')); } return $$$PROP_NAME$; }" description="DateTimeImmutable value object" toReformat="true" toShortenFQNames="true"> |
| 53 | + <variable name="PROP_NAME" expression="" defaultValue="" alwaysStopAt="true" /> |
| 54 | + <context> |
| 55 | + <option name="PHP" value="true" /> |
| 56 | + <option name="PHP Comment" value="false" /> |
| 57 | + <option name="PHP String Literal" value="false" /> |
| 58 | + </context> |
| 59 | + </template> |
| 60 | + <template name="fl_hint" value="[FlavourHint$END$::class, $CLASS_NAME$]" description="EE Flavour Hint" toReformat="false" toShortenFQNames="true"> |
| 61 | + <variable name="CLASS_NAME" expression="" defaultValue="" alwaysStopAt="true" /> |
| 62 | + <context> |
| 63 | + <option name="PHP" value="true" /> |
| 64 | + <option name="PHP Class Member" value="false" /> |
| 65 | + <option name="PHP Comment" value="false" /> |
| 66 | + <option name="PHP Statement" value="false" /> |
| 67 | + <option name="PHP String Literal" value="false" /> |
| 68 | + </context> |
| 69 | + </template> |
| 70 | + <template name="vo_collection" value="/** * @var $ITEM_CLASS$[] */ private $items; public static function fromArray(array $items): self { return new self(...array_map(function ($TYPE$ $item) { return $ITEM_CLASS$::from$TYPE_METHOD$($item); }, $items)); } public static function fromItems($ITEM_CLASS$ ...$items): self { return new self(...$items); } public static function emptyList(): self { return new self([]); } private function __construct($ITEM_CLASS$ ...$items) { $this->items = $items; } public function push($ITEM_CLASS$ $item): self { $copy = clone $this; $copy->items[] = $item; return $copy; } public function pop(): self { $copy = clone $this; \array_pop($copy->items); return $copy; } public function first(): ?$ITEM_CLASS$ { return $this->items[0] ?? null; } public function last(): ?$ITEM_CLASS$ { if(count($this->items) === 0) { return null; } return $this->items[count($this->items) - 1]; } public function contains($ITEM_CLASS$ $item): bool { foreach($this->items as $existingItem) { if($existingItem->equals($item)) { return true; } } return false; } /** * @return $ITEM_CLASS$[] */ public function items(): array { return $this->items; } public function toArray(): array { return \array_map(function ($ITEM_CLASS$ $item) { return $item->to$TYPE_METHOD$(); }, $this->items); } public function equals($other): bool { if(!$other instanceof self) { return false; } return $this->toArray() === $other->toArray(); } public function __toString(): string { return \json_encode($this->toArray()); }" description="Collection value object" toReformat="true" toShortenFQNames="true"> |
| 71 | + <variable name="ITEM_CLASS" expression="classNameComplete()" defaultValue="" alwaysStopAt="true" /> |
| 72 | + <variable name="TYPE" expression=""raw_type"" defaultValue="" alwaysStopAt="true" /> |
| 73 | + <variable name="TYPE_METHOD" expression="capitalize(TYPE)" defaultValue="" alwaysStopAt="false" /> |
| 74 | + <context> |
| 75 | + <option name="PHP" value="true" /> |
| 76 | + <option name="PHP Comment" value="false" /> |
| 77 | + <option name="PHP Expression" value="false" /> |
| 78 | + <option name="PHP Statement" value="false" /> |
| 79 | + <option name="PHP String Literal" value="false" /> |
| 80 | + </context> |
| 81 | + </template> |
| 82 | +</templateSet> |
0 commit comments