memio / memio
A highly opinionated PHP code generator library
Installs: 303 564
Dependents: 16
Suggesters: 0
Security: 0
Stars: 337
Watchers: 14
Forks: 23
Open Issues: 7
Requires
- php: ^7.2 || ^8.0
- memio/linter: ^3.0
- memio/model: ^3.0.1
- memio/pretty-printer: ^3.0
- memio/twig-template-engine: ^3.0
- memio/validator: ^3.0.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^8.5
- dev-main
- v3.0.0
- v2.0.1
- v2.0.0
- v2.0.0-alpha3
- v2.0.0-alpha2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v1.0.0-rc14
- v1.0.0-rc13
- v1.0.0-rc12
- v1.0.0-rc11
- v1.0.0-rc10
- v1.0.0-rc9
- v1.0.0-rc8
- v1.0.0-rc7
- v1.0.0-rc6
- v1.0.0-rc5
- v1.0.0-rc3
- v1.0.0-rc2
- v1.0.0-rc1
- v1.0.0-beta4
- v1.0.0-beta3
- v1.0.0-beta2
- v1.0.0-beta1
- v1.0.0-alpha18
- v1.0.0-alpha17
- v1.0.0-alpha16
- v1.0.0-alpha15
- v1.0.0-alpha14
- v1.0.0-alpha13
- v1.0.0-alpha12
- v1.0.0-alpha11
- v1.0.0-alpha10
- v1.0.0-alpha9
- v1.0.0-alpha8
- v1.0.0-alpha7
- v1.0.0-alpha6
- v1.0.0-alpha5
- v1.0.0-alpha4
- v1.0.0-alpha3
- v1.0.0-alpha2
- v1.0.0-alpha1
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.0
This package is auto-updated.
Last update: 2024-12-14 22:11:54 UTC
README
Memio is a library, it allows you to describe PHP code by building "Model" classes
(e.g. new Method('__construct')
) and then to generate it using a PrettyPrinter
!
Note: The actual generation logic is held in Twig templates. If the coding style provided doesn't appeal to you, you can overwrite those templates easily.
Installation
Install using Composer:
$ composer require memio/memio:^3.0
Full example
We're going to generate a class with a constructor and two attributes:
<?php require __DIR__.'/vendor/autoload.php'; use Memio\Memio\Config\Build; use Memio\Model\File; use Memio\Model\Object; use Memio\Model\Property; use Memio\Model\Method; use Memio\Model\Argument; // Describe the code you want to generate using "Models" $file = (new File('src/Vendor/Project/MyService.php')) ->setStructure( (new Object('Vendor\Project\MyService')) ->addProperty(new Property('createdAt')) ->addProperty(new Property('filename')) ->addMethod( (new Method('__construct')) ->addArgument(new Argument('DateTime', 'createdAt')) ->addArgument(new Argument('string', 'filename')) ) ) ; // Generate the code and display in the console $prettyPrinter = Build::prettyPrinter(); $generatedCode = $prettyPrinter->generateCode($file); echo $generatedCode; // Or display it in a browser // echo '<pre>'.htmlspecialchars($prettyPrinter->generateCode($file)).'</pre>';
With this simple example, we get the following output:
<?php namespace Vendor\Project; class MyService { private $createdAt; private $filename; public function __construct(DateTime $createdAt, string $filename) { } }
Want to know more?
Memio can be quite powerful, discover how by reading the docs:
You can see the current and past versions using one of the following:
- the
git tag
command - the releases page on Github
- the file listing the changes between versions
And finally some meta documentation:
Roadmap
- commands (e.g. add use statement, add PHPdoc, injecting dependency, etc)
- parsing existing code (using nikic's PHP-Parser)