Created
January 21, 2014 15:35
-
-
Save waaadim/8542320 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
isEnabled() (example): | |
let's pretend that you have a folder "web_root/module" and in that folder the following files: | |
Model1.php | |
Model2.php | |
Model3.php | |
Model4.php | |
Usually you'd have to create a table in your database (tbl_modules: {id,module_name,is_enabled}) | |
and when the `disable` button is clicked you'd do: | |
1. select from tbl_modules where ... | |
2. update ... | |
============================ | |
with this thing you could do it like this: | |
*/ | |
$cg = new CodeGenerator('modules/Module1.php'); | |
$cg->removeFunction('isEnabled'); | |
$params = array( | |
'tokens' => array( | |
'%visibility%' => 'public', | |
'%functionName%' => 'isEnabled', | |
'%params%' => '', | |
'%code%' => 'return false;', // or true if you want to enable it | |
) | |
); | |
$saved = $cg->createFunction($template = 'function', $params)->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment