Exemplo n.º 1
0
 /**
  * Correct (if needed) class doc block comment. Works for one element from the queue
  *
  * @param \Includes\Decorator\DataStructure\Graph\Classes $node Current node
  *
  * @return void
  */
 protected function correctTagsOnElement(\Includes\Decorator\DataStructure\Graph\Classes $node)
 {
     $path = LC_DIR_CACHE_CLASSES . $node->getPath();
     \Includes\Utils\FileManager::write($path, \Includes\Decorator\Utils\Tokenizer::getSourceCode($path, null, null, null, call_user_func_array(array($node, 'addLinesToDocBlock'), $this->getTagsToAdd($node)), $node->isDecorator() ? 'abstract' : null));
 }
Exemplo n.º 2
0
 /**
  * Parse PHP files and return plain array with the class descriptors
  *
  * @return array
  */
 protected static function getClassesTreeIndex()
 {
     $index = array();
     // Iterate over all directories with PHP class files
     foreach (static::getClassFileIterator()->getIterator() as $path => $data) {
         // Use PHP Tokenizer to search class declaration
         if (($class = \Includes\Decorator\Utils\Tokenizer::getFullClassName($path)) && \Includes\Utils\Operator::checkIfLCClass($class)) {
             // File contains a class declaration: create node (descriptor)
             $node = new \Includes\Decorator\DataStructure\Graph\Classes($class);
             // Check parent class (so called optional dependencies for modules)
             $dependencies = $node->getTag('lc_dependencies', true);
             if (empty($dependencies) || \Includes\Utils\ModulesManager::areActiveModules($dependencies)) {
                 // Node is valid: add to the index
                 $index[$class] = $node;
             } else {
                 // The unused class file must be removed from the cache file structure
                 \Includes\Utils\FileManager::deleteFile($node->getFile());
             }
         }
     }
     return $index;
 }
Exemplo n.º 3
0
 /**
  * Generated and write entity class to disk for the given ClassMetadataInfo instance
  *
  * @param ClassMetadataInfo $metadata
  * @param string $outputDirectory
  * @return void
  */
 public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
 {
     $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->_extension;
     $dir = dirname($path);
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     $this->_isNew = !file_exists($path) || file_exists($path) && $this->_regenerateEntityIfExists;
     if (!$this->_isNew) {
         $this->_parseTokensInEntityFile(file_get_contents($path));
         $this->_staticReflection[$metadata->name]['parent'] = \Includes\Decorator\Utils\Tokenizer::getParentClassName($path);
     } else {
         $this->_staticReflection[$metadata->name] = array('properties' => array(), 'methods' => array());
     }
     if ($this->_backupExisting && file_exists($path)) {
         $backupPath = dirname($path) . DIRECTORY_SEPARATOR . basename($path) . "~";
         if (!copy($path, $backupPath)) {
             throw new \RuntimeException("Attempt to backup overwritten entity file but copy operation failed.");
         }
     }
     // If entity doesn't exist or we're re-generating the entities entirely
     if ($this->_isNew) {
         file_put_contents($path, $this->generateEntityClass($metadata));
         // If entity exists and we're allowed to update the entity class
     } else {
         if (!$this->_isNew && $this->_updateEntityIfExists) {
             file_put_contents($path, $this->generateUpdatedEntityClass($metadata, $path));
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Get structures to save when module is disabled
  *
  * @param string $author Module author
  * @param string $name   Module name
  *
  * @return array
  */
 public static function getModuleProtectedStructures($author, $name)
 {
     $tables = array();
     $columns = array();
     $path = static::getAbsoluteDir($author, $name) . 'Model';
     if (\Includes\Utils\FileManager::isExists($path)) {
         $filter = new \Includes\Utils\FileFilter($path, '/.*\\.php$/Si');
         foreach ($filter->getIterator() as $path => $data) {
             // DO NOT call "getInterfaces()" after the "getFullClassName()"
             // DO NOT use reflection to get interfaces
             $interfaces = \Includes\Decorator\Utils\Tokenizer::getInterfaces($path);
             $class = \Includes\Decorator\Utils\Tokenizer::getFullClassName($path);
             // Do 'autoload' checking first since the class_exists tries to use autoloader
             // but fails into "cannot include file" warning when model class is not set to use (LC_Dependencies issue)
             if (\Includes\Autoloader::checkAutoload($class) && class_exists($class)) {
                 // $reflectionClass = new \ReflectionClass($class);
                 if ($class && is_subclass_of($class, '\\XLite\\Model\\AEntity')) {
                     $class = ltrim($class, '\\');
                     $len = strlen(\Includes\Utils\Database::getTablesPrefix());
                     // DO NOT remove leading backslash in interface name
                     if (in_array('\\XLite\\Base\\IDecorator', $interfaces)) {
                         $parent = \Includes\Decorator\Utils\Tokenizer::getParentClassName($path);
                         $parent = ltrim($parent, '\\');
                         $metadata = \XLite\Core\Database::getEM()->getClassMetadata($parent);
                         $table = substr($metadata->getTableName(), $len);
                         $tool = new \Doctrine\ORM\Tools\SchemaTool(\XLite\Core\Database::getEM());
                         $schema = $tool->getCreateSchemaSql(array($metadata));
                         foreach ((array) $metadata->reflFields as $field => $reflection) {
                             $pattern = '/(?:, |\\()(' . $field . ' .+)(?:, [A-Za-z]|\\) ENGINE)/USsi';
                             if ($reflection->class === $class && !empty($metadata->fieldMappings[$field]) && preg_match($pattern, $schema[0], $matches)) {
                                 $columns[$table][$field] = $matches[1];
                             }
                         }
                         foreach ($metadata->associationMappings as $mapping) {
                             if ($metadata->reflFields[$mapping['fieldName']]->class === $class) {
                                 if (isset($mapping['joinTable']) && $mapping['joinTable']) {
                                     $tables[] = substr($mapping['joinTable']['name'], $len);
                                 } elseif (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
                                     foreach ($mapping['joinColumns'] as $col) {
                                         $pattern = '/(?:, |\\()(' . $col['name'] . ' .+)(?:, [A-Za-z]|\\) ENGINE)/USsi';
                                         if (preg_match($pattern, $schema[0], $matches)) {
                                             $columns[$table][$col['name']] = $matches[1];
                                         }
                                     }
                                 }
                             }
                         }
                     } elseif (\XLite\Core\Database::getRepo($class)->canDisableTable()) {
                         $tables[] = substr(\XLite\Core\Database::getEM()->getClassMetadata($class)->getTableName(), $len);
                         $metadata = \XLite\Core\Database::getEM()->getClassMetadata($class);
                         foreach ($metadata->associationMappings as $mapping) {
                             if (isset($mapping['joinTable']) && $mapping['joinTable']) {
                                 $tables[] = substr($mapping['joinTable']['name'], $len);
                             }
                         }
                     }
                 }
             }
         }
     }
     return array('tables' => $tables, 'columns' => $columns);
 }
Exemplo n.º 5
0
 /**
  * Actualize and return source code for node
  *
  * @param self $parent Parent node OPTIONAL
  *
  * @return string
  */
 protected function getActualSource(self $parent = null)
 {
     return \Includes\Decorator\Utils\Tokenizer::getSourceCode($this->getFile(), $this->getActualNamespace(), $this->getClassBaseName(), $this->getActualParentClassName($parent), $this->removeLinesFromDocBlock(array('ListChild')), $this->isLowLevelNode() || $this->isDecorator() ? 'abstract' : null);
 }
Exemplo n.º 6
0
 /**
  * Put prepared code into the files
  *
  * @return void
  */
 protected function writeData()
 {
     foreach ($this->replacements as $file => $code) {
         \Includes\Utils\FileManager::write($file = \Includes\Decorator\ADecorator::getCacheClassesDir() . $file, \Includes\Decorator\Utils\Tokenizer::addCodeToClassBody($file, $code));
     }
 }
Exemplo n.º 7
0
Arquivo: Main.php Projeto: kingsj/core
 /**
  * Put prepared code into the files
  *
  * @return void
  */
 protected function writeData()
 {
     foreach ($this->replacements as $file => $code) {
         \Includes\Utils\FileManager::write($file = LC_DIR_CACHE_CLASSES . $file, \Includes\Decorator\Utils\Tokenizer::addCodeToClassBody($file, $code));
     }
 }