Recommend this page to a friend! |
Download .zip |
Info | View files (13) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2011-08-12 (5 years ago) | Not enough user ratings | Total: 346 | All time: 6,644 This week: 935 |
Version | License | PHP version | Categories | |||
php-mixin 0.1 | GNU Lesser Genera... | 5.0 | PHP 5, Language, Code Generation |
Description | Author | ||||||||||||||
This class can extend classes by using several mixin classes. Innovation Award |
|
The Issue === Let's say you have a core class in your system that you reference in many places. But you want to allow people to write extensions to it. You want to be able to add multiple extensions to the same class and you want each one to use the same syntax. ### Your Base Class // extend me! class BaseClass { public $iambase = 1; } ### Extension #1 // John writes a cool new feature class JohnsCoolFeature extends BaseClass { public $iamjohn = 1; public $extended = 1; } ### Extension #1 // Jane writes a cool new feature class JanesCoolFeature extends BaseClass { public $iamjane = 1; public $extended = 2; } In this case, John and Jane couldn't both write extensions to the original object and have them implemented. They would have to manually extend each other and that makes it very difficult to maintain and manage. Moreover when you implement the code in your system. This will be the result $foo = new BaseClass; echo $foo->extended; // null echo $foo->iambase; // 1 echo $foo->iamjohn; // null echo $foo->iamjane; // null The Solution === This mixin utility takes all the different objects and restacks them in a special cache file. Once it has been restacked. You can easily include this file and bingo, it's ready to rock. Now this works! $foo = new BaseClass; echo $foo->extended; // 2 echo $foo->iambase; // 1 echo $foo->iamjohn; // 1 echo $foo->iamjane; // 1 How To Use === _You must never have more than one class in each file._ You can't properly include the original file as it will hijack the classname we want to adjust. So classes you want to make sure are stacked, you include like this. e_MixinUtil::load($file); All you need to do is make sure the extending classes are built like: myClass extends BaseClass { } The base class may be a completely standalone class or it may extend other objects. These other objects will not be touched. |
Files |
File | Role | Description | ||
---|---|---|---|---|
stacks (4 files) | ||||
tests (4 files) | ||||
mixin.php | Class | Class source | ||
readme.markdown | Doc. | Documentation | ||
setup.markdown | Doc. | Documentation | ||
stackindex.cache | Output | Sample output | ||
test.php | Example | Unit test script |
Files | / | stacks |
File | Role | Description |
---|---|---|
31c226b21bb94f8daf0715bf913f77ce.php | Output | Sample output |
a87fe4d445124a6a14240eba6f7e185b.php | Output | Sample output |
cca4a4b222dc407169a3397fa0097c11.php | Output | Sample output |
index.php | Aux. | Auxiliary script |
Files | / | tests |
File | Role | Description |
---|---|---|
base.php | Example | Unit test script |
extend.php | Example | Unit test script |
extend2.php | Example | Unit test script |
extend3.php | Example | Unit test script |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.