Download the PHP package offworks/classgen without Composer
On this page you can find all versions of the php package offworks/classgen. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download offworks/classgen
More information about offworks/classgen
Files in offworks/classgen
Package classgen
Short Description A simple, dynamic and programmatically fluent PHP class generator.
License MIT
Informations about the package classgen
classgen
A simple, dynamic and programmatically fluent PHP class generator.
Installation
Through composer
Usage
Class creation manipulation
Create a class
Add property
Add method
And it'll print the class on casting the object to string.
Class's method manipulation
Generate a stub from \Closure
Through the initialize($mixed) method, the stub will automatically generate the method's params, if \Closure is passed.
This code might generate a method stub something like this :
Generate the stub directly from string
Generate a method stub something like this :
More nested code block
Generate a method stub something like this :
Saving the class to the desired path
file_put_contents
Most straight forward way
With generator
PSR-4 based generator
The generator has it's own sort of Collection of classes. Adding a class is simply by passing class name (it'll create a new), or add existing instance.
And generate once you're done.
It will generator a structure and file (since we have only one class) similar to this :
Flat based generator
Generate classes in a single directory
And generate
API
\Classgen\Stub\ClassStub
- inherits(string $parentClass) : self
- interfaces(array $interfaces) : self
- addMethod(string $name, mixed $initialCode) : \Classgen\Stub\MethodStub'
- getName() : string
- getNamespace() : string
- getShortClassname() : string
- addProperty(string $name, string $type = null) : \Classgen\Stub\PropertyStub
- addStaticProperty(string $name, string $type = null) : Classgen\Stub\PropertyStub
- addMethod(string $name, mixed $code = null) : \Classgen\Stub\MethodStub
- addStaticMethod(string $name, mixed $code = null) : \Classgen\Stub\MethodStub
\Classgen\Stub\PropertyStub
- value(string $value, bool $asString = false) : self
- setAsStatic(bool $static = true) : self
- visibility(string $string) : self
\Classgen\Stub\MethodStub
- initialize(mixed $code) : self
- returnAs(string $type) : self
- visibility(string $visibility) : self
- code(\Closure $handler) : self
- getCode() : \Classgen\Stub\CodeStub
- setAsStatic() : self
- setAsAbstract() : self
\Classgen\Stub\CodeStub
- replace(string $find, string $replace) : self
- filter(\Closure $handler) : self
- write(string|\Closure $code) : self
- prepend(string|\Closure $code) : self
- each(\Closure $handler) : self
- addBlock($header, \Closure $handler = null) : \Classgen\Stub\BlockStub
- addContinuedBlock($header, \Closure $handler = null) : \Classgen\Stub\Blockstub
License
See MIT License
Thank you!
Hope you like it!