:getStubFileIndex(); if (!$this->dumpFile($stubFilename, $contentStub)) { Tools::error_log('Cannot write temporary file '.$stubFilename); } $namespacedStubFilename = PrestaShopAutoload::getNamespacedStubFileIndex(); if (!$this->dumpFile($namespacedStubFilename, $contentNamespacedStub)) { Tools::error_log('Cannot write temporary file '.$namespacedStubFilename); } $this->index = $classes; } /** * @param string $filename * @param string $content * * @return bool * * @see http://api.symfony.com/3.0/Symfony/Component/Filesystem/Filesystem.html#method_dumpFile */ public function dumpFile($filename, $content) { $dir = dirname($filename); // Will create a temp file with 0600 access rights // when the filesystem supports chmod. $tmpFile = tempnam($dir, basename($filename)); if (false === @file_put_contents($tmpFile, $content)) { return false; } // Ignore for filesystems that do not support umask @chmod($tmpFile, 0666); rename($tmpFile, $filename); return true; } /** * Retrieve recursively all classes in a directory and its subdirectories * * @param string $path Relativ path from root to the directory * * @return array */ protected function getClassesFromDir($path, $hostMode = false) { $classes = array(); $rootDir = $hostMode ? $this->normalizeDirectory(_PS_ROOT_DIR_) : $this->root_dir; foreach (scandir($rootDir.$path) as $file) { if ($file[0] != '.') { if (is_dir($rootDir.$path.$file)) { $classes = array_merge($classes, $this->getClassesFromDir($path.$file.'/', $hostMode)); } elseif (substr($file, -4) == '.php') { $content = file_get_contents($rootDir.$path.$file); $namespacePattern = '[\\a-z0-9_]*[\\]'; $pattern = '#\W((abstract\s+)?class|interface)\s+(?P'.basename($file, '.php').'(?:Core)?)' .'(?:\s+extends\s+'.$namespacePattern.'[a-z][a-z0-9_]*)?(?:\s+implements\s+'.$namespacePattern.'[a-z][\\a-z0-9_]*(?:\s*,\s*'.$namespacePattern.'[a-z][\\a-z0-9_]*)*)?\s*\{#i'; //DONT LOAD CLASS WITH NAMESPACE - PSR4 autoloaded from composer $usesNamespace = false; foreach (token_get_all($content) as $token) { if ($token[0] === T_NAMESPACE) { $usesNamespace = true; break; } } if (!$usesNamespace && preg_match($pattern, $content, $m)) { $classes[$m['classname']] = array( 'path' => $path.$file, 'type' => trim($m[1]), 'override' => $hostMode, ); if (substr($m['classname'], -4) == 'Core') { $classes[substr($m['classname'], 0, -4)] = array( 'path' => '', 'type' => $classes[$m['classname']]['type'], 'override' => $hostMode, ); } } } } } return $classes; } /** * Get Class path * * @param string $classname * * @return null */ public function getClassPath($classname) { return (isset($this->index[$classname]) && isset($this->index[$classname]['path'])) ? $this->index[$classname]['path'] : null; } /** * Normalize directory * * @param string $directory * * @return string */ private function normalizeDirectory($directory) { return rtrim($directory, '/\\').DIRECTORY_SEPARATOR; } } spl_autoload_register(array(PrestaShopAutoload::getInstance(), 'load'));