Download the PHP package khalyomede/prototype without Composer
On this page you can find all versions of the php package khalyomede/prototype. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download khalyomede/prototype
More information about khalyomede/prototype
Files in khalyomede/prototype
Package prototype
Short Description Enable adding method to a class on the fly
License MIT
Informations about the package prototype
Prototype
Enable adding method to a class on the fly.
Summary
- Prerequisites
- Installation
- Examples of uses
- Methods definition
- MIT licence
Prerequisites
This project is bounded to the following requirements you should be aware of:
- PHP >= 7.0.0
- Each class extending
Prototype
should not define the following method:prototype()
- Each class extending
Prototype
should not define the following static method:prototypes()
Installation
On your project folder, open a command prompt and type:
Examples of uses
All these examples can be seen in /example
folder.
- Example 1: extending a class with a simple function
- Example 2: extending a class with a simple method
- Example 3: extending a class with a method with parameters
For all these examples, we will assume we have a function called Tableau
that simulate the behavior of PHP collections:
Example 1: extending a class with a simple function
Will display:
Example 2: extending a class with a simple method
Will print:
Example 3: extending a class with a method with parameters
Will echo:
Methods definition
- prototypes()
- prototype()
Prototypes()
List all the registered prototypes. The list is shared across all the instance of your prototyped object.
Prototype()
Register a new method for the object. This method can then be accessed across all your instances of the prototyped object.
Exceptions
InvalidArgumentException
:
- If the name of the function is already used by the prototyped object
- If the prototype has already been registered for this object
BadMethodCallException
:
- If the method (you thought you prototyped) has not been registered yet
Note
This function returns an instance of the current object.
MIT licence
Prototype
Copyright © 2018 Khalyomede
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.