xylemical / code
An object modeling framework.
dev-master
2022-06-30 05:44 UTC
Requires
- php: >=8.0
Requires (Dev)
- xylemical/composer-dev-bundle: ^0.1.0
This package is auto-updated.
Last update: 2025-03-29 01:00:43 UTC
README
Simple class, interface and trait object modelling.
Install
The recommended way to install this library is through composer.
composer require xylemical/code
Usage
Creating a class representation:
<?php use Xylemical\Code\Expression; use Xylemical\Code\Definition\File; use Xylemical\Code\Definition\Method; use Xylemical\Code\Definition\Property; use Xylemical\Code\Definition\Structure; use Xylemical\Code\Definition\Contract; $file = File::create('test.php'); $class = Structure::create('Xylemical\\Code\\Representation', $file->getNameManager()) ->addContract(Contract::create('Xylemical\\Code\\RepresentationInterface')) ->addElement(Property::create('rep')) ->addMethod(Method::create('show')->setBody(Expression::create('return $this;')));
The model definition is equivalent to:
<?php namespace Xylemical\Code; class Representation implements \Xylemical\Code\RepresentationInterface { public $rep; public function show() { return $this; } }
Due to naming clashes, the class names are as follows:
- Structure represents a class,
- Contract represents an interface,
- Mixin represents a trait.
License
MIT, see LICENSE.