Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // aliases definitions, @ is a reserved word and should be escaped
- // since is used as regex delimiter
- $aliases = array(
- '^/?$' => 'Misc::home',
- '^/(.*)/(.*)/?$' => 'Profile::home',
- '^/(.*)/?$' => 'Profile::home'
- );
- foreach ($aliases as $alias => $dest) {
- // cycle through aliases to find a matching one
- $regex = '@' . $alias . '@';
- preg_match($regex, $argv[1], $values);
- if ($values) {
- // we have a match, remove first part (whole matching string)
- array_shift($values);
- // get class and method and instance
- list($className, $method) = explode('::', $dest);
- $class = new $className;
- // execute
- call_user_func_array(array($class, $method), $values);
- break;
- }
- }
- // only for testing purpose :)
- class Profile
- {
- public function home($userName, $section = 'home')
- {
- echo 'Perfil de ' . $userName . ', estas en ' . $section . "\n";
- }
- }
- class Misc
- {
- public function home()
- {
- echo 'Esto es / y no recibe parametros' . "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement