2017 © Pedro PelĆ”ez
 

library model

Memio's models, used to describe the code to generate

image

memio/model

Memio's models, used to describe the code to generate

  • Wednesday, June 13, 2018
  • by gnupat
  • Repository
  • 1 Watchers
  • 4 Stars
  • 118,858 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 21 Versions
  • 9 % Grown

The README.md

Memio's Models

Describe PHP code (classes/interfaces with their constants, properties, methods, method arguments and even PHPdoc) by constructing "Model" objects., (*1)

Note: This package is part of Memio, a highly opinionated PHP code generator. Have a look at the main repository., (*2)

Installation

Install it using Composer:, (*3)

composer require memio/model:^3.0

Example

Let's say we want to describe the following method:, (*4)

    /**
     * @api
     */
    public function doSomething(ValueObject $valueObject, int $type = self::TYPE_ONE, bool $option = true);

In order to do so, we'd need to write the following:, (*5)

<?php

require __DIR__.'/vendor/autoload.php';

use Memio\Model\Argument;
use Memio\Model\Method;
use Memio\Model\Phpdoc\ApiTag;
use Memio\Model\Phpdoc\MethodPhpdoc;
use Memio\Model\Phpdoc\ParameterTag;

$method = (new Method('doSomething'))
    ->setPhpdoc((new MethodPhpdoc())
        ->addParameterTag(new ParameterTag('Vendor\Project\ValueObject', 'valueObject'))
        ->addParameterTag(new ParameterTag('int', 'type'))
        ->addParameterTag(new ParameterTag('bool', 'option'))

        ->addApiTag(new ApiTag())
    )
    ->addArgument(new Argument('Vendor\Project\ValueObject', 'valueObject'))
    ->addArgument((new Argument('int', 'type'))
        ->setDefaultValue('self::TYPE_ONE')
    )
    ->addArgument((new Argument('bool', 'option'))
        ->setDefaultValue('true')
    )
;

Usually models aren't described manually like this, they would be built dynamically:, (*6)

// Let's say we've received the following two parameters:
$methodName = 'doSomething';
$arguments = [new \Vendor\Project\ValueObject(), ValueObject::TYPE_ONE, true];

$method = new Method($methodName);
$phpdoc = (new MethodPhpdoc())->setApiTag(new ApiTag());
$index = 1;
foreach ($arguments as $rawArgument) {
    $type = is_object($rawArgument) ? get_class($argument) : gettype($rawArgument);
    $name = 'argument'.$index++;
    $argument = new Argument($type, $name);

    $method->addArgument($argument);
    $phpdoc->addParameterTag(new ParameterTag($type, $name));
}
$method->setPhpdoc($phpdoc);

We can build dynamically the models using a configuration file, user input, existing source code... Possibilities are endless!, (*7)

Once built these models can be further tweaked, and converted to another format: an array, source code, etc... Again, the possibilities are endless!, (*8)

Have a look at the main respository to discover the full power of Medio., (*9)

Want to know more?

Memio uses phpspec, which means the tests also provide the documentation. Not convinced? Then clone this repository and run the following commands:, (*10)

composer install
./vendor/bin/phpspec run -n -f pretty

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

And finally some meta documentation:, (*12)

Roadmap

  • get rid of Type
  • extract Import (use statement) from FullyQualifiedName
  • get rid of FullyQualifiedName
  • support more PHPdoc stuff
  • support annotations

The Versions

13/06 2018

dev-master

9999999-dev http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

13/06 2018

2.0.4

2.0.4.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

02/03 2018

2.0.3

2.0.3.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

02/03 2018

dev-version-2

dev-version-2 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

02/01 2018

v2.0.1

2.0.1.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

03/10 2016

v2.0.0-alpha3

2.0.0.0-alpha3 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

03/10 2016

v2.0.0

2.0.0.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

27/09 2016

v2.0.0-alpha2

2.0.0.0-alpha2 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

21/09 2016

v2.0.0-alpha1

2.0.0.0-alpha1 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php code generator

01/12 2015

v1.4.1

1.4.1.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

php code generator

01/12 2015

v1.4.0

1.4.0.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

php code generator

03/08 2015

v1.3.5

1.3.5.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

31/07 2015

v1.3.4

1.3.4.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

04/06 2015

v1.3.3

1.3.3.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

04/06 2015

v1.3.2

1.3.2.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

14/05 2015

v1.3.1

1.3.1.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

14/05 2015

v1.3.0

1.3.0.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

13/05 2015

v1.2.0

1.2.0.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

08/05 2015

v1.1.0

1.1.0.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

20/04 2015

v1.0.1

1.0.1.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator

02/04 2015

v1.0.0

1.0.0.0 http://memio.github.io/memio

Memio's models, used to describe the code to generate

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php code generator