Download the PHP package popphp/pop-code without Composer
On this page you can find all versions of the php package popphp/pop-code. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popphp/pop-code
More information about popphp/pop-code
Files in popphp/pop-code
Package pop-code
Short Description Pop Code Component for Pop PHP Framework
License BSD-3-Clause
Homepage http://www.popphp.org/
Informations about the package pop-code
pop-code
- Overview
- Install
- Quickstart
- Generate Code
- Parse Code
Overview
pop-code
provides the ability to dynamically generate PHP code on the fly
as well as parse and modify existing PHP code.
pop-code
is a component of the Pop PHP Framework.
Top
Install
Install pop-code
using Composer.
composer require popphp/pop-code
Or, require it in your composer.json file
"require": {
"popphp/pop-view" : "^5.0.0"
}
Top
Quickstart
Create a simple function
In this example, a function is created and rendered to a string:
Create a simple class
In this example, a class is created and saved to a file:
The contents of the file will be:
Top
Generate Code
There are a number of individual code generators available to manage the creation and output of various types of code blocks. Code generators are available for the following type of code:
- Classes
- Interfaces
- Traits
- Methods
- Functions
- Constants
- Properties
- Namespaces
- Docblocks
- Bodies (general blocks of code)
Create a file with some functions
The above code will produce a file called functions.php
with the following
code in it:
Top
Parse Code
This pop-code
component also provides the ability to parse existing code, which is useful
to obtain information about the code or to even modify and save new code.
In this example, we use the class that we created above. The reflection object provides you with a code generator object like the one above so that you can add or remove things from the parsed code.
And the modified class will look like, complete with the new hasFoo()
method:
Top