Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

memio

[main] A highly opinionated PHP code generator library

Subscribe to updates I use memio


Statistics on memio

Number of watchers on Github 341
Number of open issues 7
Average time to close an issue 28 days
Main language PHP
Average time to merge a PR about 9 hours
Open pull requests 1+
Closed pull requests 4+
Last commit about 3 years ago
Repo Created about 5 years ago
Repo Last Updated over 1 year ago
Size 1.31 MB
Homepage http://memio.gith...
Organization / Authormemio
Latest Releasev2.0.0
Contributors6
Page Updated
Do you use memio? Leave a review!
View open issues (7)
View memio activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating memio for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Memio SensioLabsInsight Travis CI

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:^1.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 = File::make('src/Vendor/Project/MyService.php')
    ->setStructure(
        Object::make('Vendor\Project\MyService')
            ->addProperty(new Property('createdAt'))
            ->addProperty(new Property('filename'))
            ->addMethod(
                Method::make('__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, $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:

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)
memio open issues Ask a question     (View All Issues)
  • almost 4 years Missing collection/object_collection.twig for array of objects
  • about 4 years Values are escaped in phpdocs
  • over 4 years Support Traits
  • over 4 years Allow removal of arguments/constants/methods/properties
memio open pull requests (View All Pulls)
  • Open-source development monetization
memio list of languages used
Other projects in PHP