Skip to content

Commit bb9776e

Browse files
author
codeliner
committed
Initial commit
1 parent 1cf2a9d commit bb9776e

15 files changed

Lines changed: 727 additions & 26 deletions

.docheader

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This file is part of event-engine/php-data.
3+
* (c) 2018-%year% prooph software GmbH <contact@prooph.de>
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/

.env/PHPStorm/PHP.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<templateSet group="PHP">
2+
<template name="vo_string" value="private $$$PROP_NAME$;&#10;&#10;public static function fromString(string $$$PROP_NAME$): self&#10;{&#10; return new self($$$PROP_NAME$);&#10;}&#10;&#10;private function __construct(string $$$PROP_NAME$)&#10;{&#10; $this-&gt;$PROP_NAME$ = $$$PROP_NAME$;&#10;}&#10;&#10;public function toString(): string&#10;{&#10; return $this-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function equals($other): bool&#10;{&#10; if(!$other instanceof self) {&#10; return false;&#10; }&#10; &#10; return $this-&gt;$PROP_NAME$ === $other-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function __toString(): string&#10;{&#10; return $this-&gt;$PROP_NAME$;&#10;}&#10;" 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$;&#10;&#10;public static function fromInt(int $$$PROP_NAME$): self&#10;{&#10; return new self($$$PROP_NAME$);&#10;}&#10;&#10;private function __construct(int $$$PROP_NAME$)&#10;{&#10; $this-&gt;$PROP_NAME$ = $$$PROP_NAME$;&#10;}&#10;&#10;public function toInt(): int&#10;{&#10; return $this-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function equals($other): bool&#10;{&#10; if(!$other instanceof self) {&#10; return false;&#10; }&#10; &#10; return $this-&gt;$PROP_NAME$ === $other-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function __toString(): string&#10;{&#10; return (string)$this-&gt;$PROP_NAME$;&#10;}&#10;" 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$;&#10;&#10;public static function fromFloat(float $$$PROP_NAME$): self&#10;{&#10; return new self($$$PROP_NAME$);&#10;}&#10;&#10;private function __construct(float $$$PROP_NAME$)&#10;{&#10; $this-&gt;$PROP_NAME$ = $$$PROP_NAME$;&#10;}&#10;&#10;public function toFloat(): float&#10;{&#10; return $this-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function equals($other): bool&#10;{&#10; if(!$other instanceof self) {&#10; return false;&#10; }&#10; &#10; return $this-&gt;$PROP_NAME$ === $other-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function __toString(): string&#10;{&#10; return (string)$this-&gt;$PROP_NAME$;&#10;}&#10;" 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$;&#10;&#10;public static function fromBool(bool $$$PROP_NAME$): self&#10;{&#10; return new self($$$PROP_NAME$);&#10;}&#10;&#10;private function __construct(bool $$$PROP_NAME$)&#10;{&#10; $this-&gt;$PROP_NAME$ = $$$PROP_NAME$;&#10;}&#10;&#10;public function toBool(): bool&#10;{&#10; return $this-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function equals($other): bool&#10;{&#10; if(!$other instanceof self) {&#10; return false;&#10; }&#10; &#10; return $this-&gt;$PROP_NAME$ === $other-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function __toString(): string&#10;{&#10; return $this-&gt;$PROP_NAME$ ? 'TRUE' : 'FALSE';&#10;}&#10;" 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&#10;{&#10; $END$&#10; return new self();&#10;}&#10;&#10;private function __construct()&#10;{&#10; /* Map data to private props */&#10;}&#10;&#10;public function toArray(): array&#10;{&#10; return [&#10; &#10; ];&#10;}&#10;&#10;public function equals($other): bool&#10;{&#10; if(!$other instanceof self) {&#10; return false;&#10; }&#10; &#10; return $this-&gt;toArray() === $other-&gt;toArray();&#10;}&#10;&#10;public function __toString(): string&#10;{&#10; return json_encode($this-&gt;toArray());&#10;}&#10;" 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$;&#10;&#10;public static function generate(): self&#10;{&#10; return new self(Uuid::uuid4());&#10;}&#10;&#10;public static function fromString(string $$$PROP_NAME$): self&#10;{&#10; return new self(Uuid::fromString($$$PROP_NAME$));&#10;}&#10;&#10;private function __construct(UuidInterface $$$PROP_NAME$)&#10;{&#10; $this-&gt;$PROP_NAME$ = $$$PROP_NAME$;&#10;}&#10;&#10;public function toString(): string&#10;{&#10; return $this-&gt;$PROP_NAME$-&gt;toString();&#10;}&#10;&#10;public function equals($other): bool&#10;{&#10; if(!$other instanceof self) {&#10; return false;&#10; }&#10; &#10; return $this-&gt;$PROP_NAME$-&gt;equals($other-&gt;$PROP_NAME$);&#10;}&#10;&#10;public function __toString(): string&#10;{&#10; return $this-&gt;$PROP_NAME$-&gt;toString();&#10;}&#10;" 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;&#10;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$&#10;&#10;/**&#10; * @var $TYPE$&#10; */&#10;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';&#10;&#10;/**&#10; * @var \DateTimeImmutable&#10; */&#10;private $$$PROP_NAME$;&#10;&#10;public static function fromDateTime(\DateTimeImmutable $$$PROP_NAME$): self&#10;{&#10; $$$PROP_NAME$ = self::ensureUTC($$$PROP_NAME$);&#10;&#10; return new self($$$PROP_NAME$);&#10;}&#10;&#10;public static function fromString(string $$$PROP_NAME$): self&#10;{&#10; if (\strlen($$$PROP_NAME$) === 19) {&#10; $$$PROP_NAME$ = $$$PROP_NAME$ . '.000';&#10; }&#10;&#10; $$$PROP_NAME$ = \DateTimeImmutable::createFromFormat(&#10; self::FORMAT,&#10; $$$PROP_NAME$,&#10; new \DateTimeZone('UTC')&#10; );&#10; &#10; $$$PROP_NAME$ = self::ensureUTC($$$PROP_NAME$);&#10;&#10; return new self($$$PROP_NAME$);&#10;}&#10;&#10;private function __construct(\DateTimeImmutable $$$PROP_NAME$)&#10;{&#10; $this-&gt;$PROP_NAME$ = $$$PROP_NAME$;&#10;}&#10;&#10;public function toString(): string&#10;{&#10; return $this-&gt;$PROP_NAME$-&gt;format(self::FORMAT);&#10;}&#10;&#10;public function dateTime(): \DateTimeImmutable&#10;{&#10; return $this-&gt;$PROP_NAME$;&#10;}&#10;&#10;public function add(\DateInterval $interval): self&#10;{&#10; return new self($this-&gt;$PROP_NAME$-&gt;add($interval));&#10;}&#10;&#10;public function sub(\DateInterval $interval): self&#10;{&#10; return new self($this-&gt;$PROP_NAME$-&gt;sub($interval));&#10;}&#10;&#10;public function __toString(): string&#10;{&#10; return $this-&gt;toString();&#10;}&#10;&#10;private static function ensureUTC(\DateTimeImmutable $$$PROP_NAME$): \DateTimeImmutable&#10;{&#10; if ($$$PROP_NAME$-&gt;getTimezone()-&gt;getName() !== 'UTC') {&#10; $$$PROP_NAME$ = $$$PROP_NAME$-&gt;setTimezone(new \DateTimeZone('UTC'));&#10; }&#10;&#10; return $$$PROP_NAME$;&#10;}" 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="/**&#10; * @var $ITEM_CLASS$[]&#10; */&#10;private $items;&#10;&#10;public static function fromArray(array $items): self&#10;{&#10; return new self(...array_map(function ($TYPE$ $item) {&#10; return $ITEM_CLASS$::from$TYPE_METHOD$($item);&#10; }, $items));&#10;}&#10;&#10;public static function fromItems($ITEM_CLASS$ ...$items): self&#10;{&#10; return new self(...$items);&#10;}&#10;&#10;public static function emptyList(): self&#10;{&#10; return new self([]);&#10;}&#10;&#10;private function __construct($ITEM_CLASS$ ...$items)&#10;{&#10; $this-&gt;items = $items;&#10;}&#10;&#10;public function push($ITEM_CLASS$ $item): self&#10;{&#10; $copy = clone $this;&#10; $copy-&gt;items[] = $item;&#10; return $copy;&#10;}&#10;&#10;public function pop(): self&#10;{&#10; $copy = clone $this;&#10; \array_pop($copy-&gt;items);&#10; return $copy;&#10;}&#10;&#10;public function first(): ?$ITEM_CLASS$&#10;{&#10; return $this-&gt;items[0] ?? null;&#10;}&#10;&#10;public function last(): ?$ITEM_CLASS$&#10;{&#10; if(count($this-&gt;items) === 0) {&#10; return null;&#10; }&#10;&#10; return $this-&gt;items[count($this-&gt;items) - 1];&#10;}&#10;&#10;public function contains($ITEM_CLASS$ $item): bool&#10;{&#10; foreach($this-&gt;items as $existingItem) {&#10; if($existingItem-&gt;equals($item)) {&#10; return true;&#10; }&#10; }&#10; &#10; return false;&#10;}&#10;&#10;/**&#10; * @return $ITEM_CLASS$[]&#10; */&#10;public function items(): array&#10;{&#10; return $this-&gt;items;&#10;}&#10;&#10;public function toArray(): array&#10;{&#10; return \array_map(function ($ITEM_CLASS$ $item) {&#10; return $item-&gt;to$TYPE_METHOD$();&#10; }, $this-&gt;items);&#10;}&#10;&#10;public function equals($other): bool&#10;{&#10; if(!$other instanceof self) {&#10; return false;&#10; }&#10;&#10; return $this-&gt;toArray() === $other-&gt;toArray();&#10;}&#10;&#10;public function __toString(): string&#10;{&#10; return \json_encode($this-&gt;toArray());&#10;}" description="Collection value object" toReformat="true" toShortenFQNames="true">
71+
<variable name="ITEM_CLASS" expression="classNameComplete()" defaultValue="" alwaysStopAt="true" />
72+
<variable name="TYPE" expression="&quot;raw_type&quot;" 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>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
#if (${NAMESPACE})
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
use EventEngine\Data\ImmutableRecord;
9+
use EventEngine\Data\ImmutableRecordLogic;
10+
11+
final class ${NAME} implements ImmutableRecord
12+
{
13+
use ImmutableRecordLogic;
14+
15+
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @return ${TYPE_HINT}
3+
*/
4+
public ${STATIC} function ${FIELD_NAME}()#if(${RETURN_TYPE}): ${RETURN_TYPE}#else#end
5+
{
6+
#if (${STATIC} == "static")
7+
return self::$${FIELD_NAME};
8+
#else
9+
return $this->${FIELD_NAME};
10+
#end
11+
}

.env/PHPStorm/settings.zip

3.31 KB
Binary file not shown.

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
docs/ export-ignore
2+
template/ export-ignore
3+
examples/ export-ignore
4+
tests/ export-ignore
5+
.env/ export-ignore

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
composer.lock
3+
vendor

LICENSE

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
BSD 3-Clause License
1+
MIT License
22

3-
Copyright (c) 2019, event-engine
4-
All rights reserved.
3+
Copyright (c) 2018-2019 prooph software GmbH
54

6-
Redistribution and use in source and binary forms, with or without
7-
modification, are permitted provided that the following conditions are met:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
811

9-
* Redistributions of source code must retain the above copyright notice, this
10-
list of conditions and the following disclaimer.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1114

12-
* Redistributions in binary form must reproduce the above copyright notice,
13-
this list of conditions and the following disclaimer in the documentation
14-
and/or other materials provided with the distribution.
15-
16-
* Neither the name of the copyright holder nor the names of its
17-
contributors may be used to endorse or promote products derived from
18-
this software without specific prior written permission.
19-
20-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# php-data
2-
Immutable objects for PHP
2+
Immutable objects for Event Engine

composer.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "event-engine/php-data",
3+
"description": "Immutable objects for Event Engine",
4+
"homepage": "https://event-engine.io/",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Alexander Miertsch",
9+
"email": "contact@prooph.de",
10+
"homepage": "http://www.prooph.de"
11+
},
12+
{
13+
"name": "Sandro Keil",
14+
"email": "contact@prooph.de",
15+
"homepage": "http://prooph-software.com/"
16+
}
17+
],
18+
"require": {
19+
"php": "^7.2",
20+
"roave/security-advisories": "dev-master"
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "^7.0",
24+
"prooph/php-cs-fixer-config": "^0.3",
25+
"satooshi/php-coveralls": "^1.0",
26+
"malukenho/docheader": "^0.1.4"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"EventEngine\\Data\\": "src/"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"EventEngineTest\\": "tests/"
36+
}
37+
},
38+
"prefer-stable": true,
39+
"scripts": {
40+
"check": [
41+
"@cs",
42+
"@docheader",
43+
"@test"
44+
],
45+
"docheader": "vendor/bin/docheader check examples/ src/ tests/",
46+
"cs": "php-cs-fixer fix -v --diff --dry-run",
47+
"cs-fix": "php-cs-fixer fix -v --diff",
48+
"test": "vendor/bin/phpunit"
49+
}
50+
}

0 commit comments

Comments
 (0)