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
0 parents
commit c65e34c
Showing
21 changed files
with
1,761 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/.settings | ||
/.project | ||
/.buildpath | ||
/vendor | ||
/build | ||
.idea | ||
.php_cs.cache | ||
nbproject | ||
composer.lock | ||
|
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,27 @@ | ||
Copyright (c) 2018, Sascha-Oliver Prolic | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the prooph software GmbH nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,84 @@ | ||
# FPP | ||
|
||
## Functional PHP Preprocessor | ||
|
||
### What it this? | ||
|
||
This library can generate php code bases on fpp definitions, the syntax is inspired by Haskell. | ||
|
||
### So what really is it? | ||
|
||
Create a file and put this in it: | ||
|
||
```console | ||
namespace Model\Foo; | ||
|
||
data Person = {string $name, ?int $age} deriving (ValueObject) | ||
``` | ||
|
||
Then generate php code. Now you can do this: | ||
|
||
```php | ||
$p = \Model\Foo\Person\Person('sasa', 36); | ||
|
||
echo \Model\Foo\Person\name($p); // sasa | ||
echo \Model\Foo\Person\age($p); // 36 | ||
|
||
$p2 = \Model\Foo\Person\setAge($p, 37); | ||
|
||
echo \Model\Foo\Person\age($p2); // 36 | ||
|
||
var_dump($p === $p2); // false | ||
``` | ||
|
||
### Derivings | ||
|
||
There are 4 deriving types for now: | ||
|
||
- Show (not yet implemented) | ||
- StringConverter | ||
- ArrayConverter | ||
- ValueObject | ||
|
||
Deriving ValueObject + ArrayConverter | ||
|
||
```console | ||
namespace Model\Foo; | ||
|
||
data Person = {string $name, ?int $age} deriving (ArrayConveter, ValueObject) | ||
``` | ||
|
||
Now you can do this: | ||
|
||
```php | ||
$p = Person::fromArray(['name' => 'sasa', 'age' => 36]); | ||
var_dump($p->toArray()); // ['name' => 'sasa', 'age' => 36] | ||
$p->sameAs($p) // true | ||
``` | ||
|
||
### Usage | ||
|
||
`php bin/fpp.php <source dir> <target file>` | ||
|
||
### Demo | ||
|
||
``` | ||
git clone https://github.com/prolic/fpp | ||
cd fpp | ||
composer install | ||
php bin/fpp.php demo demo/generated.php | ||
``` | ||
|
||
### Features | ||
|
||
- [x] Create immutable data types with ease | ||
- [x] Strict types always | ||
- [x] Functional accessors and setters | ||
- [x] Generate prooph commands | ||
- [ ] Generate prooph events | ||
- [ ] Generate prooph queries | ||
- [ ] Generate prooph aggregate changed events | ||
- [ ] Allow creating of or-types (f.e. data Color = Red | Blue | Green) | ||
- [ ] Show deriving feature | ||
- [ ] Make parser more robust | ||
- [ ] More to come |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fpp; | ||
|
||
if (! isset($argv[1])) { | ||
echo "Missing input directory argument"; | ||
exit(1); | ||
} | ||
|
||
if (! isset($argv[2])) { | ||
echo "Missing output file argument"; | ||
exit(1); | ||
} | ||
|
||
$path = $argv[1]; | ||
$output = $argv[2]; | ||
|
||
if (! is_readable($path)) { | ||
echo "$path is not readable"; | ||
exit(1); | ||
} | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$scanner = new Scanner($path); | ||
$parser = new Parser(); | ||
$collection = new DefinitionCollection(); | ||
|
||
foreach ($scanner as $file) { | ||
/* @var \SplFileInfo $file */ | ||
$definition = $parser->parse(file_get_contents($file->getRealPath())); | ||
$collection = $collection->merge($definition); | ||
} | ||
|
||
$dumper = new Dumper(); | ||
$php = $dumper->dump($collection); | ||
|
||
file_put_contents($output, $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,24 @@ | ||
{ | ||
"name": "prolic/fpp", | ||
"description": "Functional PHP Preprocessor", | ||
"authors": [ | ||
{ | ||
"name": "Sascha-Oliver Prolic", | ||
"email": "saschaprolic@googlemail.com" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.1", | ||
"marc-mabe/php-enum": "^3.0", | ||
"nikic/php-parser": "^3.1.4" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^7.0", | ||
"prooph/php-cs-fixer-config": "^0.2.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Fpp\\": "src/" | ||
} | ||
} | ||
} |
Oops, something went wrong.