2017 © Pedro PelĆ”ez
 

library memio

A highly opinionated PHP code generator library

image

memio/memio

A highly opinionated PHP code generator library

  • Monday, October 3, 2016
  • by gnupat
  • Repository
  • 17 Watchers
  • 341 Stars
  • 118,037 Installations
  • PHP
  • 20 Dependents
  • 0 Suggesters
  • 18 Forks
  • 7 Open issues
  • 48 Versions
  • 9 % Grown

The README.md

Memio

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!, (*1)

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., (*2)

Installation

Install using Composer:, (*3)

$ composer require memio/memio:^3.0

Full example

We're going to generate a class with a constructor and two attributes:, (*4)

<?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 '

'.htmlspecialchars($prettyPrinter->generateCode($file)).'
';

With this simple example, we get the following output:, (*5)

<?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:, (*6)

You can see the current and past versions using one of the following:, (*7)

And finally some meta documentation:, (*8)

Roadmap

  • commands (e.g. add use statement, add PHPdoc, injecting dependency, etc)
  • parsing existing code (using nikic's PHP-Parser)

The Versions

21/09 2016
11/02 2015

v1.0.0-alpha2

1.0.0.0-alpha2

A highly opinionated PHP code generator library

  Sources   Download

MIT

The Requires

 

The Development Requires

php code generator

10/02 2015

v1.0.0-alpha1

1.0.0.0-alpha1

A highly opinionated PHP code generator library

  Sources   Download

MIT

The Requires

 

The Development Requires

php code generator

03/02 2015

v0.4.0

0.4.0.0

A highly opinionated PHP code generator library

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

26/01 2015

v0.3.0

0.3.0.0

A highly opinionated PHP code generator library

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

17/10 2014

v0.2.0

0.2.0.0

Helps you with your PHP code

  Sources   Download

MIT

The Requires

 

The Development Requires

php helper ide

12/10 2014

v0.1.0

0.1.0.0

Helps you with your PHP code

  Sources   Download

MIT

The Requires

 

The Development Requires

php helper ide