/** * Modify class source * * @param \Includes\Decorator\DataStructure\Graph\Classes $node Current node * * @return void */ protected function writeCallToSourceFile(\Includes\Decorator\DataStructure\Graph\Classes $node) { $path = \Includes\Decorator\ADecorator::getCacheClassesDir() . $node->getPath(); $content = \Includes\Utils\FileManager::read($path); $content .= PHP_EOL . '// Call static constructor' . PHP_EOL; $content .= '\\' . $node->getClass() . '::' . static::STATIC_CONSTRUCTOR_METHOD . '();'; \Includes\Utils\FileManager::write($path, $content); }
/** * Get allowed commands * * @return array */ public function getAllowedCommands() { $dsQuoted = preg_quote(LC_DS, '/'); $path = \Includes\Decorator\ADecorator::getCacheClassesDir() . 'XLite' . LC_DS . 'Controller' . LC_DS . 'Console' . LC_DS . '*.php'; $commands = array(); $list = glob($path); if ($list) { foreach ($list as $f) { if (!preg_match('/Abstract.php$/Ss', $f) && !preg_match('/' . $dsQuoted . 'A[A-Z]/Ss', $f)) { $commands[] = strtolower(substr(basename($f), 0, -4)); } } } return $commands; }
/** * Check if proxy classes are already generated * * @return boolean */ protected function areProxiesExist() { return \Includes\Utils\FileManager::isDirReadable(\Includes\Decorator\ADecorator::getCacheModelProxiesDir()); }
/** * Write PHP class to the files * * @param \Includes\Decorator\DataStructure\Graph\Classes $node Current class node * @param \Includes\Decorator\DataStructure\Graph\Classes $parent Parent class node * * @return void */ public static function writeClassFile(\Includes\Decorator\DataStructure\Graph\Classes $node, \Includes\Decorator\DataStructure\Graph\Classes $parent = null) { \Includes\Utils\FileManager::write(\Includes\Decorator\ADecorator::getCacheClassesDir() . $node->getPath(), $node->getSource($parent)); }
/** * 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 = \Includes\Decorator\ADecorator::getCacheClassesDir() . $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)); }
/** * Check if class exists * * @param string $name Name of class to check * * @return boolean */ public static function isClassExists($name) { return class_exists($name, false) || file_exists(\Includes\Decorator\ADecorator::getCacheClassesDir() . str_replace('\\', LC_DS, $name) . '.php'); }
/** * Return the Doctrine config object * * @return \Doctrine\ORM\Configuration */ protected static function getConfig() { $config = new \Doctrine\ORM\Configuration(); $config->setAutoGenerateProxyClasses(false); static::setMetadataDriver($config); // Set proxy settings $config->setProxyDir(rtrim(\Includes\Decorator\ADecorator::getCacheModelProxiesDir(), LC_DS)); $config->setProxyNamespace(LC_MODEL_PROXY_NS); $cache = new \Doctrine\Common\Cache\ArrayCache(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); return $config; }
/** * Get list of dependent modules as Doctrine entities * * @return array */ public function getDependentModules() { $result = array(); $current = \Includes\Decorator\ADecorator::getModulesGraph()->find($this->getActualName()); if ($current) { foreach ($current->getChildren() as $node) { $class = $node->getActualName(); $result[$class] = $this->getRepository()->findOneBy(array_combine(array('author', 'name'), explode('\\', $class)), array('installed' => 'DESC')); } } return array_filter($result); }
/** * Return list of relative module paths * * @return array */ protected static function getModuleQuotedPaths() { if (!isset(static::$quotedPaths)) { static::$quotedPaths = array(); \Includes\Decorator\ADecorator::getModulesGraph()->walkThrough(array(get_called_class(), 'getModuleQuotedPathsCallback')); } return static::$quotedPaths; }
/** * Get compress file path * * @return string */ protected function getPath() { return \Includes\Decorator\ADecorator::getCacheClassesDir() . 'core.php'; }
/** * 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)); } }
/** * 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) { \Includes\Utils\FileManager::replace(\Includes\Decorator\ADecorator::getCacheClassesDir() . $node->getPath(), '@$1 ' . $this->getRepositoryCustomClassParameter($node), \Includes\Decorator\Utils\Operator::getTagPattern(array('Entity', 'MappedSuperClass'))); }
/** * Name of the origin class file * * @param string $class Class name OPTIONAL * @param string $dir Dir to file OPTIONAL * * @return string */ public function getFile($class = null, $dir = null) { $dir = $dir ?: \Includes\Decorator\ADecorator::getCacheClassesDir(); return $dir . $this->getPath($class); }
/** * Initialize classes directory * * @return void */ protected static function initializeClassesDir() { static::$lcAutoloadDir = \Includes\Decorator\ADecorator::getCacheClassesDir(); }
/** * Connect and set-up Doctrine * * @return void */ public function connect() { $this->configuration = new \Doctrine\ORM\Configuration(); // Setup cache $this->setDoctrineCache(); // Set metadata driver $chain = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain(); $chain->addDriver($this->createAnnotationDriver(\Includes\Decorator\ADecorator::getCacheModelsDir()), 'XLite\\Model'); $iterator = new \RecursiveDirectoryIterator(\Includes\Decorator\ADecorator::getCacheClassesDir() . 'XLite' . LC_DS . 'Module', \FilesystemIterator::SKIP_DOTS); foreach ($iterator as $dir) { if (\Includes\Utils\FileManager::isDir($dir->getPathName())) { $iterator2 = new \RecursiveDirectoryIterator($dir->getPathName(), \FilesystemIterator::SKIP_DOTS); foreach ($iterator2 as $dir2) { if (\Includes\Utils\FileManager::isDir($dir2->getPathName()) && \Includes\Utils\FileManager::isDir($dir2->getPathName() . LC_DS . 'Model')) { $chain->addDriver($this->createAnnotationDriver($dir2->getPathName() . LC_DS . 'Model'), 'XLite\\Module\\' . $dir->getBaseName() . '\\' . $dir2->getBaseName() . '\\Model'); } } } } $this->configuration->setMetadataDriverImpl($chain); // Set proxy settings $this->configuration->setProxyDir(rtrim(\Includes\Decorator\ADecorator::getCacheModelProxiesDir(), LC_DS)); $this->configuration->setProxyNamespace(LC_MODEL_PROXY_NS); $this->configuration->setAutoGenerateProxyClasses(false); // Register custom functions $this->configuration->addCustomStringFunction('if', '\\XLite\\Core\\Doctrine\\IfFunction'); $this->configuration->addCustomStringFunction('IFNULL', '\\XLite\\Core\\Doctrine\\IfnullFunction'); $this->configuration->addCustomStringFunction('relevance', '\\XLite\\Core\\Doctrine\\RelevanceFunction'); $this->configuration->addCustomNumericFunction('intval', '\\XLite\\Core\\Doctrine\\IntvalFunction'); $this->configuration->addCustomStringFunction('findInSet', '\\XLite\\Core\\Doctrine\\FindInSetFunction'); $this->configuration->addCustomStringFunction('castChar', '\\XLite\\Core\\Doctrine\\CastCharFunction'); $this->configuration->addCustomStringFunction('collate', '\\XLite\\Core\\Doctrine\\CollateFunction'); $this->tablePrefix = trim(\XLite::getInstance()->getOptions(array('database_details', 'table_prefix'))); // Initialize DB connection and entity manager $this->startEntityManager(); }