Git Product home page Git Product logo

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's Projects

linter icon linter

[sub] A set of constraints that check Models for syntax errors and the likes.

memio icon memio

[main] A highly opinionated PHP code generator library

model icon model

[sub] Describe PHP code by building Memio objects

php-printer icon php-printer

A Pretty Printer for PHP-Parser, powered by a template engine

spec-gen icon spec-gen

[standalone] A phpspec extension that improves its code generator

validator icon validator

[sub] A validator library to check Memio Models

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.