tonicospinelli/class-generation

Library to create Php Class files

2.2.1 2015-03-18 13:56 UTC

This package is auto-updated.

Last update: 2024-11-29 04:09:00 UTC


README

SensioLabsInsight Build Status Scrutinizer Code Quality Code Coverage

Latest Stable Version Total Downloads

Introduction

When I developed a specific project, I saw an opportunity to create a library to generate Php Class Files and this library was born.

Installation

I assume you know about Composer, if not look at Composer WebSite.

$ php composer.phar require tonicospinelli/class-generation:2.2.*

OR

{
    "tonicospinelli/class-generation" : "2.2.*"
}

QUICK START

ClassGeneration is simple to use. Here's a sample for creating a Php Class File.

<?php
require_once "../vendor/autoload.php";

use ClassGeneration\NamespaceClass;
use ClassGeneration\PhpClass;
use ClassGeneration\Property;
use ClassGeneration\Writer;

$code = new PhpClass();
$code
    ->setName('FirstClass')
    ->setNamespace(new NamespaceClass('MyNamespace'))
    ->setDescription('Class description')
    ->addProperty(new Property(array('name' => 'property')))
    ->generateGettersAndSettersFromProperties();

$writer = new Writer();
$writer
    ->setPhpClass($code)
    ->setPath('./src')
    ->write();

Result: ./src/MyNamespace/FirstClass.php

<?php

namespace MyNamespace;

/**
 * Class description
 * @name FirstClass
 */
class FirstClass
{

    public $property;

    public function getProperty()
    {
        return $this->property;
    }

    public function setProperty($property)
    {
        $this->property = $property;

        return $this;
    }
}

Version

2.2

MIT License

Free Software, Hell Yeah!