/** * Implements the loading of the class object * @throws Exception if the class is already generated(not null) */ protected function generateClass() { if ($this->class != null) { throw new Exception("The class has already been generated"); } $config = Generator::getInstance()->getConfig(); $class = new PhpClass($this->phpIdentifier, $config->getClassExists()); $constructorComment = new PhpDocComment(); $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess()); $constructorSource = ''; $constructorParameters = ''; $accessors = array(); // Add member variables foreach ($this->members as $member) { $type = ''; try { $type = Validator::validateType($member->getType()); } catch (ValidationException $e) { $type .= 'Custom'; } $name = Validator::validateNamingConvention($member->getName()); $comment = new PhpDocComment(); $comment->setVar(PhpDocElementFactory::getVar($type, $name, '')); $comment->setAccess(PhpDocElementFactory::getPublicAccess()); $var = new PhpVariable('public', $name, 'null', $comment); $class->addVariable($var); if (!$member->getNillable()) { $constructorSource .= ' $this->' . $name . ' = $' . $name . ';' . PHP_EOL; $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, '')); $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess()); $constructorParameters .= ', $' . $name; if ($config->getConstructorParamsDefaultToNull()) { $constructorParameters .= ' = null'; } if ($config->getCreateAccessors()) { $getterComment = new PhpDocComment(); $getterComment->setReturn(PhpDocElementFactory::getReturn($type, '')); $getter = new PhpFunction('public', 'get' . ucfirst($name), '', ' return $this->' . $name . ';' . PHP_EOL, $getterComment); $accessors[] = $getter; $setterComment = new PhpDocComment(); $setterComment->addParam(PhpDocElementFactory::getParam($type, $name, '')); $setter = new PhpFunction('public', 'set' . ucfirst($name), '$' . $name, ' $this->' . $name . ' = $' . $name . ';' . PHP_EOL, $setterComment); $accessors[] = $setter; } } } $constructorParameters = substr($constructorParameters, 2); // Remove first comma $function = new PhpFunction('public', '__construct', $constructorParameters, $constructorSource, $constructorComment); // Only add the constructor if type constructor is selected if ($config->getNoTypeConstructor() == false) { $class->addFunction($function); } foreach ($accessors as $accessor) { $class->addFunction($accessor); } $this->class = $class; }
/** * ensure method has no body * @see \WsdlToPhp\PhpGenerator\Element\AbstractElement::addChild() * @param mixed */ public function addChild($child) { if ($child instanceof PhpMethod) { $child->setHasBody(false); } return parent::addChild($child); }
public function writeCache(\Symforce\AdminBundle\Compiler\Generator\PhpWriter $lazy_writer, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer) { $default_value = $this->getDefaultValue(); if ($this->_lazy) { $lazy_writer->writeln('$this->' . $this->getName() . ' = ' . $this->_class->propertyEncode($default_value) . ' ; '); $default_value = null; } $writer->write("\n"); if ($this->getDocblock()) { $writer->writeln($this->getDocblock()); } $writer->write($this->getVisibility())->write(' $')->write($this->getName())->write(' = ')->write($this->_class->propertyEncode($default_value))->writeln(" ;"); if ($this->_get) { $this->genGetter(); } }
public function startVisitingClass(PhpClass $class) { if ($namespace = $class->getNamespace()) { $this->writer->write('namespace ' . $namespace . ';' . "\n\n"); } if ($files = $class->getRequiredFiles()) { foreach ($files as $file) { $this->writer->writeln('require_once ' . var_export($file, true) . ';'); } $this->writer->write("\n"); } if ($useStatements = $class->getUseStatements()) { foreach ($useStatements as $alias => $namespace) { $this->writer->write('use ' . $namespace); if (substr($namespace, strrpos($namespace, '\\') + 1) !== $alias) { $this->writer->write(' as ' . $alias); } $this->writer->write(";\n"); } $this->writer->write("\n"); } if ($docblock = $class->getDocblock()) { $this->writer->write($docblock); } $this->writer->write('class ' . $class->getShortName()); if ($parentClassName = $class->getParentClassName()) { $this->writer->write(' extends ' . ('\\' === $parentClassName[0] ? $parentClassName : '\\' . $parentClassName)); } $interfaceNames = $class->getInterfaceNames(); if (!empty($interfaceNames)) { $interfaceNames = array_unique($interfaceNames); $interfaceNames = array_map(function ($name) { if ('\\' === $name[0]) { return $name; } return '\\' . $name; }, $interfaceNames); $this->writer->write(' implements ' . implode(', ', $interfaceNames)); } $this->writer->write("\n{\n")->indent(); }
public function writeCache(\Symforce\CoreBundle\PhpHelper\PhpWriter $writer) { $default_value = $this->getDefaultValue(); if ($this->_lazy) { $this->_class->getLazyWriter()->writeln('$this->' . $this->getName() . ' = ' . PhpHelper::compilePropertyValue($default_value) . ' ; '); $default_value = null; } $writer->write("\n"); if ($this->getDocblock()) { $writer->writeln($this->getDocblock()); } $writer->write($this->getVisibility())->write(' $')->write($this->getName()); if (null !== $default_value) { $writer->write(' = ')->write(PhpHelper::compilePropertyValue($default_value)); } $writer->writeln(";"); if ($this->_get) { $this->genGetter(); } }
/** * Checks if the class is approved * Removes the prefix and suffix for namechecking * * @param PhpClass $class * @return bool Returns true if the class is ok to add to file */ private function isValidClass(PhpClass $class) { $suffix = strlen($this->config->getSuffix()); if ($suffix > 0) { $nSuf = 0 - $suffix; $className = substr($class->getIdentifier(), strlen($this->config->getPrefix()), $nSuf); } else { $className = substr($class->getIdentifier(), strlen($this->config->getPrefix())); } if (count($this->classesToSave) == 0 || count($this->classesToSave) > 0 && in_array($className, $this->classesToSave)) { return true; } return false; }
public function add($use, $as = null) { if (in_array($use, $this->use)) { return; } $this->use[] = $use; $this->aliases[$as ?: PhpClass::extractName($use)] = $use; }
* You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * This program incorporates work covered by the following copyright and * permission notices: * * DropsizeMVCf is (c) 2013, 2015 * Isaac Trenado - isaac.trenado@codigolimpio.com - * http://www.codigolimpio.com * * Wherever third party code has been used, credit has been given in the code's comments. * * DropsizeMVCf is released under the GPL * */ /** * Main drop * * @package com.dropsizemvcf * @author Isaac Trenado * @since 1.0.0 */ error_reporting(E_ALL); ini_set("display_errors", 1); define('_DSEXEC', 1); define('FPATH_BASE', dirname(__FILE__)); require_once FPATH_BASE . '/utils/PhpClass.php'; PhpClass::import(FPATH_BASE . "/utils/legacy/defines"); PhpClass::import(FPATH_LIBRARIES . "/legacy/framework");
/** * Cria os métodos para manipulação dos atributos do nó. * @param \PhpClass $class * @param \DOMElement $node */ public function createAttributeMethods(\PhpClass &$class, \DOMElement $node) { $methodName = $node->getAttribute('name'); $returnType = in_array($node->getAttribute('type'), array('string')) ? null : $class->getFullName(); $class->addMethod($this->createAttributeGetMethod($methodName)); $class->addMethod($this->createAttributeSetMethod($methodName, $returnType)); if ($node->hasAttribute('use') and $node->getAttribute('use') == 'optional') { $class->addMethod($this->createAttributeIsSetMethod($methodName)); $class->addMethod($this->createAttributeUnsetMethod($methodName)); } }
public function startVisitingClass(PhpClass $class) { if ($namespace = $class->getNamespace()) { $this->writer->write('namespace ' . $namespace . ';' . "\n\n"); } if ($files = $class->getRequiredFiles()) { foreach ($files as $file) { if ($file instanceof RelativePath) { $this->writer->writeln('require_once __DIR__ . ' . var_export('/' . $file->getRelativePath(), true) . ';'); continue; } $this->writer->writeln('require_once ' . var_export($file, true) . ';'); } $this->writer->write("\n"); } if ($useStatements = $class->getUseStatements()) { foreach ($useStatements as $alias => $namespace) { $this->writer->write('use ' . $namespace); if (substr($namespace, strrpos($namespace, '\\') + 1) !== $alias) { $this->writer->write(' as ' . $alias); } $this->writer->write(";\n"); } $this->writer->write("\n"); } if ($docblock = $class->getDocblock()) { $this->writer->write($docblock); } if ($class->isAbstract()) { $this->writer->write('abstract '); } if ($class->isFinal()) { $this->writer->write('final '); } // TODO: Interfaces should be modeled as separate classes. $this->isInterface = $class->getAttributeOrElse('interface', false); $this->writer->write($this->isInterface ? 'interface ' : 'class '); $this->writer->write($class->getShortName()); if (!$this->isInterface) { if ($parentClassName = $class->getParentClassName()) { $this->writer->write(' extends ' . ('\\' === $parentClassName[0] ? $parentClassName : '\\' . $parentClassName)); } } $interfaceNames = $class->getInterfaceNames(); if (!empty($interfaceNames)) { $interfaceNames = array_unique($interfaceNames); $interfaceNames = array_map(function ($name) { if ('\\' === $name[0]) { return $name; } return '\\' . $name; }, $interfaceNames); $this->writer->write($this->isInterface ? ' extends ' : ' implements '); $this->writer->write(implode(', ', $interfaceNames)); } $this->writer->write("\n{\n")->indent(); }
/** * Adds a class to the file * * @param PhpClass $class The class to add * @throws Exception If the class already exists */ public function addClass(PhpClass $class) { if ($this->classExists($class->getIdentifier())) { throw new Exception('A class of the name (' . $class->getIdentifier() . ') does already exist.'); } $this->classes[$class->getIdentifier()] = $class; }
<?php require 'config.php'; require 'phpSource/PhpClass.php'; $db = mysql_connect($host, $user, $pass); mysql_select_db($db); $tables = mysql_query('show tables'); while ($table = mysql_fetch_row($tables)) { $classd = new PhpClass($table[0] . "Data"); $classfw = new PhpClass('DB' . $table[0]); $primary_key = array(); $const_params = array(); $const_params_def = array(); $const_source = array(); $fields = mysql_query("explain {$table[0]}"); while ($field = mysql_fetch_assoc($fields)) { $type = preg_replace('/^([a-z]*).*/', '$1', $field['Type']); $default = null; if ($field['Default'] != NULL) { $type = preg_replace('/^([a-z]*).*/', '$1', $field['Type']); switch ($type) { case "int": case "tinyint": case "decimal": $default = "{$field['Default']}"; break; default: $default = "\"{$field['Default']}\""; } } $variable = new PhpVariable('public', $field['Field'], $default);
public static function fnAutoLoad($controller, $action) { if (class_exists($controller . "Dependence")) { $lstClaseDependence = $controller . "Dependence"; $lobClassDependece = new $lstClaseDependence(); if (!method_exists($lobClassDependece, $action)) { throw new Exception("Acción no definida 8"); } else { $larDependencias = call_user_func_array(array($lobClassDependece, $action), array()); } } else { throw new Exception("Dependencia no identificada 6"); } // Buscamos en cada ruta los archivos while (list($k, $v) = each($larDependencias['Archivos'])) { foreach ($v as $path) { PhpClass::import($path); } } }
* * This program incorporates work covered by the following copyright and * permission notices: * * DropsizeMVCf is (c) 2013, 2015 * Isaac Trenado - isaac.trenado@codigolimpio.com - * http://www.codigolimpio.com * * Wherever third party code has been used, credit has been given in the code's comments. * * DropsizeMVCf is released under the GPL * */ /** * Import and Run APP invoke all BO CO MO DE. * here goes all library for default too can use path_library PHP * * @package com.dropsizemvcf.utils.legacy.framework * @author Isaac Trenado * @since 1.0.0 */ defined('_DSEXEC') or die; PhpClass::import(FPATH_LIBRARIES . DIRECTORY_SEPARATOR . "Slim" . DIRECTORY_SEPARATOR . "Slim"); PhpClass::import(FPATH_LIBRARIES . DIRECTORY_SEPARATOR . "Slim" . DIRECTORY_SEPARATOR . "LogWriter"); PhpClass::import(FPATH_LIBRARIES . DIRECTORY_SEPARATOR . "Slim" . DIRECTORY_SEPARATOR . "Log"); PhpClass::import(FPATH_LIBRARIES . DIRECTORY_SEPARATOR . "Model"); PhpClass::import(FPATH_LIBRARIES . DIRECTORY_SEPARATOR . "Controller"); PhpClass::import(FPATH_LIBRARIES . DIRECTORY_SEPARATOR . "legacy" . DIRECTORY_SEPARATOR . "aplicacion"); $hostname = "log"; $app = FDropSize::Instance($hostname); $app->run();