Skip to content

Instantly share code, notes, and snippets.

@waaadim
Created January 21, 2014 15:35
Show Gist options
  • Save waaadim/8542320 to your computer and use it in GitHub Desktop.
Save waaadim/8542320 to your computer and use it in GitHub Desktop.
<?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