Example #1
0
 /**
  * @param array $argv
  * @return Pflow_CommandInterface
  * @throws BadMethodCallException
  */
 public function dispatch(array $argv)
 {
     for ($i = count($argv); $i > 1; $i--) {
         $command = sprintf('Pflow_Command_%s', implode('_', array_map('ucfirst', array_slice($argv, 1, $i - 1))));
         if (class_exists($command)) {
             $reflectionClass = new ReflectionClass($command);
             if ($reflectionClass->IsInstantiable() && $reflectionClass->implementsInterface('Pflow_CommandInterface')) {
                 return new $command($this->git, $this->output, $this->input, $this->history);
             }
         }
     }
     throw new BadMethodCallException(sprintf('Could not find command in "%s"', implode(' ', $argv)));
 }
Example #2
0
 /**
  * cast() - casts generic object to Et-Specific object
  *
  * @param stdClass $obj    - standard php object
  * @param string   $class  - Et-class
  * @param EtClient $client
  *
  * @return <typeOf $class>
  *
  */
 public function cast($obj, $class, $client = null)
 {
     $reflectionClass = new \ReflectionClass($class);
     if (!$reflectionClass->IsInstantiable()) {
         throw new \Exception($class . " is not instantiable!");
     }
     if ($obj instanceof $class) {
         return $obj;
         // nothing to do.
     }
     // lets instantiate the new object
     $tmpObject = null;
     try {
         $r = new \ReflectionMethod($class, '__construct');
         $params = $r->getParameters();
         if (count($params)) {
             $tmpObject = $reflectionClass->newInstance($client);
         }
     } catch (\ReflectionException $e) {
         // do nothing
     }
     if ($tmpObject === null) {
         $tmpObject = $reflectionClass->newInstance();
     }
     $properties = array();
     foreach ($reflectionClass->getProperties() as $property) {
         $properties[$property->getName()] = $property;
     }
     // we'll take all the properties from the fathers as well
     // overwriting the old properties from the son as well if needed.
     $parentClass = $reflectionClass;
     // loop init
     while ($parentClass = $parentClass->getParentClass()) {
         foreach ($parentClass->getProperties() as $property) {
             $properties[$property->getName()] = $property;
         }
     }
     // now lets see what we have set in $obj and transfer that to the new object
     $vars = get_object_vars($obj);
     foreach ($vars as $varName => $varValue) {
         if (array_key_exists($varName, $properties)) {
             $prop = $properties[$varName];
             if (!$prop->isPublic()) {
                 $prop->setAccessible(true);
             }
             $prop->setValue($tmpObject, $varValue);
         }
     }
     return $tmpObject;
 }
Example #3
0
 /**
  * Loader
  *
  * @param ClassLoader $loader Loader
  *
  * @return array
  */
 public static function load(ClassLoader $loader)
 {
     $modules = array();
     $classmap = $loader->getClassMap();
     foreach ($classmap as $class => $file) {
         // The following is required as class_exists, is_subclass_of and ReflectionClass will throw a fatal error if class extends a non-existent class
         // @todo allow custom namespaces
         if (!preg_match('/^main|phpforge|module/i', $class) && !preg_match('/^' . str_replace('/', '\\/', self::getModDir()) . '/i', $file)) {
             continue;
         }
         if (class_exists($class)) {
             if (is_subclass_of($class, 'Forge\\Application\\Module')) {
                 $ref = new \ReflectionClass($class);
                 if ($ref->IsInstantiable()) {
                     $mod = $ref->newInstanceWithoutConstructor();
                     $acls = array();
                     if (method_exists($mod, 'acl')) {
                         $acls = $mod->acl();
                     }
                     $routemap = array();
                     $methods = $ref->getMethods(\ReflectionMethod::IS_PUBLIC);
                     foreach ($methods as $method) {
                         if (preg_match('/Post|Get|Put|Delete$/', $method->name)) {
                             $methodName = preg_replace('/Post|Get|Put|Delete$/', '', $method->name);
                             $methodType = strtoupper(preg_replace('/.*(Post|Get|Put|Delete)$/', '$1', $method->name));
                             $urls = array();
                             if (strtolower($methodName) == strtolower($ref->getShortName())) {
                                 if (strtolower($method->class) == strtolower(self::$defaultModule) && $methodType == 'GET') {
                                     $urls[] = '/';
                                 }
                                 $urls[] = '/' . strtolower(preg_replace('/\\\\/', '/', $class));
                             } else {
                                 $urls[] = '/' . strtolower(preg_replace('/\\\\/', '/', $class) . '/' . $methodName);
                             }
                             $route = new Route();
                             $route->setClass($class)->setMethod($method->name)->setRequestMethod($methodType)->setUrls($urls);
                             if (key_exists($method->name, $acls)) {
                                 $route->setAcls($acls[$method->name]);
                             }
                             $routemap[] = $route;
                         }
                     }
                     $mod->setRoutes($routemap);
                     $modules[] = $mod;
                 }
             }
         }
     }
     return $modules;
 }
Example #4
0
 private function getPluginInstance($pluginPath, $pluginFqcn)
 {
     require_once $pluginPath;
     if (!class_exists($pluginFqcn)) {
         throw new RuntimeException("Class '{$pluginFqcn}' not found in '{$pluginPath}'.", self::NON_EXISTENT_BUNDLE_CLASS);
     }
     $reflectionClass = new \ReflectionClass($pluginFqcn);
     if (!$reflectionClass->IsInstantiable()) {
         throw new RuntimeException("Class '{$pluginFqcn}' is not instantiable.", self::NON_INSTANTIABLE_BUNDLE_CLASS);
     }
     if (!$reflectionClass->isSubclassOf('Claroline\\CoreBundle\\Library\\PluginBundle')) {
         throw new RuntimeException("Class '{$pluginFqcn}' doesn't extend Claroline 'PluginBundle' class.", self::UNEXPECTED_BUNDLE_TYPE);
     }
     return new $pluginFqcn();
 }
Example #5
0
 protected function getDefaultCommands()
 {
     $commands = parent::getDefaultCommands();
     $finder = new Finder();
     $finder->files()->name('*.php')->depth('0')->in(__DIR__ . '/Commands/')->sortByName();
     foreach ($finder as $file) {
         $fileName = $file->getFilename();
         $class = substr($fileName, 0, strlen($fileName) - 4);
         $fullClassName = '\\Spark\\Commands\\' . $class;
         $reflectionClass = new \ReflectionClass($fullClassName);
         if ($reflectionClass->IsInstantiable()) {
             $commands[] = new $fullClassName();
         }
     }
     return $commands;
 }
Example #6
0
 /**
  * Loader
  *
  * @param ClassLoader $loader Loader
  *
  * @return array
  */
 public static function load(ClassLoader $loader)
 {
     $modules = array();
     $classmap = $loader->getClassMap();
     foreach ($classmap as $class => $file) {
         if (preg_match('/^phpforge|forge|devforge|module/i', $class) || preg_match('/^' . str_replace('/', '\\/', self::getModDir()) . '/i', $file)) {
             if (class_exists($class)) {
                 $ref = new \ReflectionClass($class);
                 if ($ref->IsInstantiable()) {
                     $mod = $ref->newInstanceWithoutConstructor();
                     if ($mod instanceof Module) {
                         $routemap = array();
                         $methods = $ref->getMethods(\ReflectionMethod::IS_PUBLIC);
                         foreach ($methods as $method) {
                             if (preg_match('/Post|Get|Put|Delete$/', $method->name)) {
                                 $methodName = preg_replace('/Post|Get|Put|Delete$/', '', $method->name);
                                 $methodType = strtoupper(preg_replace('/.*(Post|Get|Put|Delete)$/', '$1', $method->name));
                                 $urls = array();
                                 if (strtolower($methodName) == strtolower($ref->getShortName())) {
                                     if (strtolower($method->class) == strtolower(self::$defaultModule) && $methodType == 'GET') {
                                         $urls[] = '/';
                                     }
                                     $urls[] = '/' . strtolower(preg_replace('/\\\\/', '/', $class));
                                 } else {
                                     $urls[] = '/' . strtolower(preg_replace('/\\\\/', '/', $class) . '/' . $methodName);
                                 }
                                 if (!preg_match('/^(event|global|hook)/', $methodName)) {
                                     $route = new Route();
                                     $route->setClass($class)->setMethod($method->name)->setRequestMethod($methodType)->setUrls($urls);
                                     $routemap[] = $route;
                                 }
                             }
                         }
                         $mod->setRoutes($routemap);
                         $modules[] = $mod;
                     }
                 }
             }
         }
     }
     return $modules;
 }
Example #7
0
 /**
  * @return array
  */
 public function getCommandClasses()
 {
     $classes = array();
     foreach ($this->libDirs as $libDir) {
         $commandDir = $libDir . '/Pflow/Command/';
         $ite = new RecursiveDirectoryIterator($commandDir);
         foreach (new RecursiveIteratorIterator($ite) as $fileName => $splFile) {
             if ($splFile->isDir()) {
                 continue;
             }
             $className = str_replace('/', '_', substr($fileName, strlen($libDir . '/'), -4));
             // Trigger autoload
             class_exists($className);
             $reflectionClass = new ReflectionClass($className);
             if ($reflectionClass->IsInstantiable() && $reflectionClass->implementsInterface('Pflow_CommandInterface')) {
                 $classes[] = $className;
             }
         }
     }
     sort($classes);
     return $classes;
 }
}
class privateCtorNew
{
    private function __construct()
    {
    }
}
class publicCtorOld
{
    public function publicCtorOld()
    {
    }
}
class protectedCtorOld
{
    protected function protectedCtorOld()
    {
    }
}
class privateCtorOld
{
    private function privateCtorOld()
    {
    }
}
$classes = array("noCtor", "publicCtorNew", "protectedCtorNew", "privateCtorNew", "publicCtorOld", "protectedCtorOld", "privateCtorOld");
foreach ($classes as $class) {
    $reflectionClass = new ReflectionClass($class);
    echo "Is {$class} instantiable?  ";
    var_dump($reflectionClass->IsInstantiable());
}
Example #9
0
 /**
  * Checks if a bridge is an instantiable bridge.
  * @param string $nameBridge name of the bridge that you want to use
  * @return true if it is an instantiable bridge, false otherwise.
  */
 public static function isInstantiable($nameBridge)
 {
     $re = new ReflectionClass($nameBridge);
     return $re->IsInstantiable();
 }
 protected function generateDocs($loadModels, $ignore = '')
 {
     $output = "<?php\n/**\n * An helper file for your Eloquent Models\n * Copy the phpDocs from this file to the correct Model,\n * And remove them from this file, to prevent double declarations.\n *\n * @author Barry vd. Heuvel <*****@*****.**>\n */\n\n\n";
     if (empty($loadModels)) {
         $models = $this->loadModels();
     } else {
         $models = array();
         foreach ($loadModels as $model) {
             $models = array_merge($models, explode(',', $model));
         }
     }
     $ignore = explode(',', $ignore);
     foreach ($models as $name) {
         if (in_array($name, $ignore)) {
             $this->comment("Ignoring model '{$name}'");
             continue;
         } else {
             $this->comment("Loading model '{$name}'");
         }
         $this->properties = array();
         $this->methods = array();
         if (class_exists($name)) {
             try {
                 // handle abstract classes, interfaces, ...
                 $reflectionClass = new \ReflectionClass($name);
                 if (!$reflectionClass->IsInstantiable()) {
                     throw new \Exception($name . ' is not instanciable.');
                 } elseif (!$reflectionClass->isSubclassOf('Illuminate\\Database\\Eloquent\\Model')) {
                     $this->comment("Class '{$name}' is not a model");
                     continue;
                 }
                 $model = new $name();
                 $this->getPropertiesFromTable($model);
                 $this->getPropertiesFromMethods($model);
                 $output .= $this->createPhpDocs($name);
             } catch (\Exception $e) {
                 $this->error("Exception: " . $e->getMessage() . "\nCould not analyze class {$name}.");
             }
         } else {
             $this->error("Class {$name} does not exist");
         }
     }
     return $output;
 }
Example #11
0
 private function checkInstantiable($class)
 {
     $reflectionClass = new \ReflectionClass($class);
     if (!$reflectionClass->IsInstantiable()) {
         $this->addError('Controller error!', "Class: <b>\"{$class}\"</b> is can not initialize!", 404);
         $this->checkError();
     }
 }
function exec_ogp_module()
{
    ?>
	<h2>XML Config Creator</h2>
	 <table BORDER=1>
	 <tr>
	 <td>
	  Query protocol
	 </td> 
	 <form action="" method="POST">
	 <td>
	   <select name="protocol" onchange="this.form.submit()">
		<option value="">None</option>
		<option value="lgsl" <?php 
    if (isset($_POST['protocol']) && $_POST['protocol'] == "lgsl") {
        echo 'selected="selected"';
    }
    ?>
>LGSL</option>
		<option value="gameq" <?php 
    if (isset($_POST['protocol']) && $_POST['protocol'] == "gameq") {
        echo 'selected="selected"';
    }
    ?>
>GameQ</option>
	   </select>
	 </td>
	 </form>
	</tr>
	<form action='home.php?m=config_games&p=cli-params&type=cleared' method='POST' name='xml_creator'>
	<?php 
    if (isset($_POST['protocol'])) {
        echo "\n\t<tr>\n\t <td>\n\t  <input type='hidden' name='protocol' value='" . $_POST['protocol'] . "'/>\n\t";
        if ($_POST['protocol'] == "lgsl") {
            echo "LGSL Query Name</td><td><select name='query_name'>";
            require 'protocol/lgsl/lgsl_protocol.php';
            $lgsl_type_list = lgsl_type_list();
            asort($lgsl_type_list);
            foreach ($lgsl_type_list as $type => $description) {
                echo "<option value='{$type}'>{$description}</option>";
            }
        } elseif ($_POST['protocol'] == "gameq") {
            require 'protocol/GameQ/GameQ.php';
            // Define the protocols path
            $protocols_path = "protocol/GameQ/gameq/protocols/";
            // Grab the dir with all the classes available
            $dir = dir($protocols_path);
            $protocols = array();
            // Now lets loop the directories
            while (false !== ($entry = $dir->read())) {
                if (!is_file($protocols_path . $entry)) {
                    continue;
                }
                // Figure out the class name
                $class_name = 'GameQ_Protocols_' . ucfirst(pathinfo($entry, PATHINFO_FILENAME));
                // Lets get some info on the class
                $reflection = new ReflectionClass($class_name);
                // Check to make sure we can actually load the class
                if (!$reflection->IsInstantiable()) {
                    continue;
                }
                // Load up the class so we can get info
                $class = new $class_name();
                // Add it to the list
                $protocols[$class->name()] = array('name' => $class->name_long(), 'port' => $class->port(), 'state' => $class->state());
                // Unset the class
                unset($class);
            }
            // Close the directory
            unset($dir);
            ksort($protocols);
            echo "GameQ Query Name</td><td><select name='query_name'>";
            foreach ($protocols as $gameq => $info) {
                echo "<option value='" . $gameq . "'>" . htmlentities($info['name']) . "</option>";
            }
        }
        echo "\n\t  </select>\n\t </td>\n\t</tr>";
    } else {
    }
    ?>
	<tr>
	 <td>
	  OS:
	 </td>
	 <td>
	  <select name="os">
	   <option value="linux">Linux</option>
	   <option value="win">Windows</option>
	  </select>
	 </td>
	</tr>
	<tr>
	 <td>
	  Architecture
	 </td>
	 <td>
	  <select name="arch">
	   <option value="32">32bit</option>
	   <option value="64">64bit</option>
	  </select>
	 </td>
	</tr>
	<tr>
	 <td>
	  Installer
	 </td>
	 <td>
	  <select name="installer">
	   <option value="">None</option>
	   <option value="steam">HLDSUpdateTool</option>
	  </select>
	 </td>
	</tr>
	<tr>
	 <td>
	 <input name="main" type="submit"/>
	 </form>
	 </td>
	</tr>
	</table>
<?php 
}
Example #13
0
 $protocols_path = GAMEQ_BASE . 'gameq/protocols/';
 // Grab the dir with all the classes available
 $dir = dir($protocols_path);
 $protocols = array();
 // Now lets loop the directories
 while (false !== ($entry = $dir->read())) {
     if (!is_file($protocols_path . $entry)) {
         continue;
     }
     // Figure out the class name
     $class_name = 'GameQ_Protocols_' . ucfirst(pathinfo($entry, PATHINFO_FILENAME));
     // Lets get some info on the class
     $reflection = new ReflectionClass($class_name);
     // Check to make sure we can actually load the class
     try {
         if (!$reflection->IsInstantiable()) {
             continue;
         }
         // Load up the class so we can get info
         $class = new $class_name();
         // Add it to the list
         $protocols[$class->name()] = $class->name_long();
         // Unset the class
         unset($class);
     } catch (ReflectionException $e) {
         $errors['reflection'] = $e->getMessage();
     }
 }
 // Close the directory
 unset($dir);
 ksort($protocols);
 protected final function Instantiate($classname)
 {
     $classname = ucfirst(strtolower(trim($classname)));
     $classfile = PANEL_BASE_PATH . '/server/modules/comp/' . $classname . '.class.php';
     if (is_file($classfile)) {
         require_once $classfile;
     }
     if (!class_exists($classname, false)) {
         exit('ERROR: ' . $classname . ' is not defined as a Class');
     }
     $class = new ReflectionClass($classname);
     if (!$class->isSubclassOf('PanelCommon')) {
         exit("ERROR: {$classname} must extends PanelCommon");
     }
     if (!$class->isUserDefined()) {
         exit("ERROR: {$classname} must be user defined and not internal to PHP");
     }
     if (!$class->IsInstantiable()) {
         exit("ERROR: {$classname} must be instantiable and not an Interface or Abstract class");
     }
     if (!$class->hasMethod('home')) {
         exit("ERROR: {$classname} lacks required method/function home()");
     }
     if (!$class->hasProperty('menu')) {
         exit("ERROR: {$classname} lacks \$menu as a class property");
     }
     return new $classname();
 }
Example #15
0
 /**
  * Check and Add/delete controller Methods
  *
  * @param string $className The classname to check
  * @param string $controllerName The controller name
  * @param array $node The node to check.
  * @param string $pluginPath The plugin path to use.
  * @return void
  */
 protected function _checkMethods($className, $controllerName, $node, $pluginPath = false)
 {
     $excludes = $this->_getCallbacks($className, $pluginPath);
     $baseMethods = get_class_methods(new Controller());
     $namespace = $this->_getNamespace($className, $pluginPath);
     $reflectionClass = new \ReflectionClass($namespace);
     $actions = null;
     if ($reflectionClass->IsInstantiable()) {
         $methods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
         foreach ($methods as $method) {
             $actions[] = $method->getName();
         }
     }
     $prefix = $this->_getPrefix($namespace, $pluginPath);
     if ($actions == null) {
         $this->err(__d('cake_acl', 'Unable to get methods for {0}', $className));
         return false;
     }
     $methods = array_diff($actions, $baseMethods);
     $methods = array_diff($methods, $excludes);
     foreach ($methods as $key => $action) {
         if (strpos($action, '_', 0) === 0) {
             continue;
         }
         $path = $this->rootNode . '/' . $pluginPath . $controllerName . '/' . $prefix . $action;
         $this->_checkNode($path, $prefix . $action, $node->id);
         $methods[$key] = $prefix . $action;
     }
     if ($this->_clean) {
         $actionNodes = $this->Aco->find('children', ['for' => $node->id]);
         $methodFlip = array_flip($methods);
         foreach ($actionNodes as $action) {
             if (!isset($methodFlip[$action->alias])) {
                 $entity = $this->Aco->get($action->id);
                 if ($this->Aco->delete($entity)) {
                     $path = $this->rootNode . '/' . $controllerName . '/' . $action->alias;
                     $this->out(__d('cake_acl', 'Deleted Aco node: <warning>{0}</warning>', $path));
                 }
             }
         }
     }
     return true;
 }
Example #16
0
 /**
  * Load a module
  *
  * @param string $path path of module
  */
 public static function load($path)
 {
     $basePath = basename($path);
     if (!empty(self::$list[$basePath])) {
         return;
     }
     self::$list[$basePath] = $path;
     if (file_exists($path . '/boot.php')) {
         include $path . '/boot.php';
     }
     $files = self::getAllFiles($path . "/Controller");
     foreach ($files as $file) {
         self::$files[] = $file;
         require_once $file;
         $name_class = str_replace(PATH_SRC, "", $file);
         $name_class = str_replace("/", "\\", $name_class);
         $name_class = str_replace(".php", "", $name_class);
         if (is_subclass_of($name_class, Controller::class)) {
             $reflectionClass = new \ReflectionClass($name_class);
             if ($reflectionClass->IsInstantiable()) {
                 self::$controllers[] = new $name_class();
             }
         }
     }
     $files = self::getAllFiles($path . "/Command");
     foreach ($files as $file) {
         $ext = pathinfo($file, PATHINFO_EXTENSION);
         if ($ext == 'php') {
             self::$files[] = $file;
             require_once $file;
             $name_class = str_replace(PATH_SRC, "", $file);
             $name_class = str_replace("/", "\\", $name_class);
             $name_class = str_replace(".php", "", $name_class);
             if (is_subclass_of($name_class, Command::class)) {
                 Console::addCommand($name_class);
             }
         }
     }
     if (file_exists($path . "/Exceptions/Handler.php")) {
         $name_class = str_replace(PATH_SRC, "", $path . "/Exceptions/Handler.php");
         $name_class = str_replace("/", "\\", $name_class);
         $name_class = str_replace(".php", "", $name_class);
         if (is_subclass_of($name_class, \Kernel\Exceptions\ExceptionHandler::class)) {
             \Kernel\Exceptions\Handler::add($name_class);
         }
     }
     $files = self::getAllFiles($path . "/Service");
     foreach ($files as $file) {
         self::$files[] = $file;
         require_once $file;
         $name_class = str_replace(PATH_SRC, "", $file);
         $name_class = str_replace("/", "\\", $name_class);
         $name_class = str_replace(".php", "", $name_class);
         if (is_subclass_of($name_class, Service::class)) {
             $last_name = explode("\\", $name_class);
             $last_name = end($last_name);
             class_alias($name_class, $last_name);
         }
     }
     if (!file_exists(PATH . "/src/")) {
         mkdir(PATH . "/src", 0755);
     }
     # Create symlink to access
     if (!file_exists(PATH . "/src/" . $basePath)) {
         if (file_exists(PATH . "/../src/" . $basePath . "/Resources/public/")) {
             try {
                 symlink(PATH . "/../src/" . $basePath . "/Resources/public/", PATH . "/src/" . $basePath);
             } catch (\Exception $e) {
                 throw new \Exception($e);
             }
         }
     }
     # Set config
     foreach (glob($path . '/Resources/config/*') as $file) {
         $cfgs = (require_once $file);
         $base = basename($file, ".php");
         foreach ($cfgs as $cfg_name => $cfg_value) {
             Cfg::set($base . "." . $cfg_name, $cfg_value);
         }
     }
 }
<?php

class privateCtorOld
{
    private function privateCtorOld()
    {
    }
}
$reflectionClass = new ReflectionClass("privateCtorOld");
var_dump($reflectionClass->IsInstantiable('X'));
var_dump($reflectionClass->IsInstantiable(0, null));
Example #18
0
 private final function LoadModule($classname)
 {
     if (!$this->modules) {
         $this->SessionDestroy();
         $this->Login('ERROR: No modules defined.');
         exit;
     }
     $classes = explode(' ', $this->modules);
     if (!in_array($classname, $classes)) {
         exit('ERROR: LoadModule found unknown Class/Module');
     }
     $classfile = PANEL_BASE_PATH . '/server/modules/comp/' . $classname . '.class.php';
     if (is_file($classfile)) {
         require_once $classfile;
     }
     if (!class_exists($classname, false)) {
         exit('ERROR: ' . $classname . ' is not defined as a Class');
     }
     $class = new ReflectionClass($classname);
     if (!$class->isSubclassOf('PanelCommon')) {
         exit("ERROR: {$classname} must extends PanelCommon");
     }
     if (!$class->isUserDefined()) {
         exit("ERROR: {$classname} must be user defined and not internal to PHP");
     }
     if (!$class->IsInstantiable()) {
         exit("ERROR: {$classname} must be instantiable and not an Interface or Abstract class");
     }
     if (!$class->hasMethod('home')) {
         exit("ERROR: {$classname} lacks required method/function home()");
     }
     if (!$class->hasProperty('menu')) {
         exit("ERROR: {$classname} lacks \$menu as a class property");
     }
 }
Example #19
0
 function getGameQ2List()
 {
     $protocols = array();
     // Protocol list code taken from https://github.com/Austinb/GameQ/blob/v2/examples/list.php
     $protocols_path = GAMEQ_BASE . 'gameq/protocols/';
     // Grab the dir with all the classes available
     $dir = dir($protocols_path);
     // Now lets loop the directories
     while (false !== ($entry = $dir->read())) {
         if (!is_file($protocols_path . $entry)) {
             continue;
         }
         // Figure out the class name
         $class_name = 'GameQ_Protocols_' . ucfirst(pathinfo($entry, PATHINFO_FILENAME));
         // Lets get some info on the class
         $reflection = new ReflectionClass($class_name);
         // Check to make sure we can actually load the class
         try {
             if (!$reflection->IsInstantiable()) {
                 continue;
             }
             // Load up the class so we can get info
             $class = new $class_name();
             // Add it to the list
             if (!isset($protocols[$class->name()])) {
                 $protocols[$class->name()] = $class->name_long();
             }
             // Unset the class
             unset($class);
         } catch (ReflectionException $e) {
             $errors['reflection'] = $e->getMessage();
         }
     }
     // Close the directory
     unset($dir);
     return $protocols;
 }
Example #20
0
 protected function generateDocs($loadModels, $ignore = '')
 {
     $output = "<?php\n/**\n * An helper file for your Eloquent Models\n * Copy the phpDocs from this file to the correct Model,\n * And remove them from this file, to prevent double declarations.\n *\n * @author Barry vd. Heuvel <*****@*****.**>\n */\n\n\n";
     $hasDoctrine = interface_exists('Doctrine\\DBAL\\Driver');
     if (empty($loadModels)) {
         $models = $this->loadModels();
     } else {
         $models = array();
         foreach ($loadModels as $model) {
             $models = array_merge($models, explode(',', $model));
         }
     }
     $ignore = explode(',', $ignore);
     foreach ($models as $name) {
         if (in_array($name, $ignore)) {
             $this->comment("Ignoring model '{$name}'");
             continue;
         }
         $this->properties = array();
         $this->methods = array();
         if (class_exists($name)) {
             try {
                 // handle abstract classes, interfaces, ...
                 $reflectionClass = new \ReflectionClass($name);
                 if (!$reflectionClass->isSubclassOf('Illuminate\\Database\\Eloquent\\Model')) {
                     continue;
                 }
                 $this->comment("Loading model '{$name}'");
                 if (!$reflectionClass->IsInstantiable()) {
                     throw new \Exception($name . ' is not instantiable.');
                 }
                 $model = $this->laravel->make($name);
                 if ($hasDoctrine) {
                     $this->getPropertiesFromTable($model);
                 }
                 $this->getPropertiesFromMethods($model);
                 $output .= $this->createPhpDocs($name);
             } catch (\Exception $e) {
                 $this->error("Exception: " . $e->getMessage() . "\nCould not analyze class {$name}.");
             }
         }
     }
     if (!$hasDoctrine) {
         $this->error('Warning: `"doctrine/dbal": "~2.3"` is required to load database information. Please require that in your composer.json and run `composer update`.');
     }
     return $output;
 }
 protected function generateFactories($loadModels, $ignore = '')
 {
     if (empty($loadModels)) {
         $models = $this->loadModels();
     } else {
         $models = array();
         foreach ($loadModels as $model) {
             $models = array_merge($models, explode(',', $model));
         }
     }
     $output = $this->reset || !$this->files->exists('database/factories/ModelFactory.php') ? '<?php' . "\n\n" : $this->existingFactories;
     $ignore = explode(',', $ignore);
     foreach ($models as $name) {
         if (in_array($name, $ignore)) {
             if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                 $this->comment("Ignoring model '{$name}'");
             }
             continue;
         }
         $this->properties = array();
         if (class_exists($name)) {
             try {
                 // handle abstract classes, interfaces, ...
                 $reflectionClass = new \ReflectionClass($name);
                 if (!$reflectionClass->isSubclassOf('Illuminate\\Database\\Eloquent\\Model')) {
                     continue;
                 }
                 if (!$this->reset && preg_match("/\\\$factory->define\\((.*?)" . preg_quote($reflectionClass->getName()) . "::class(.*?),/", $this->existingFactories)) {
                     if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                         $this->error("Model '{$name}' already has a factory");
                     }
                     continue;
                 }
                 if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                     $this->comment("Loading model '{$name}'");
                 }
                 if (!$reflectionClass->IsInstantiable()) {
                     // ignore abstract class or interface
                     continue;
                 }
                 $model = $this->laravel->make($name);
                 $this->getPropertiesFromTable($model);
                 $this->getPropertiesFromMethods($model);
                 $output .= $this->createFactory($name);
                 $ignore[] = $name;
             } catch (\Exception $e) {
                 $this->error("Exception: " . $e->getMessage() . "\nCould not analyze class {$name}.");
             }
         }
     }
     return $output;
 }