function autoload($className) { $baseDir = __DIR__; $realClassName = ltrim($className, '\\'); $realClassName = str_replace('\\', DIRECTORY_SEPARATOR, $realClassName); $fileName = ''; $includePaths = $baseDir . DIRECTORY_SEPARATOR . $realClassName . '.php'; if ($file = stream_resolve_include_path($includePaths)) { if (file_exists($file)) { require $file; } } elseif (preg_match('/^\\\\?test/', $className)) { $fileName = preg_replace('/^\\\\?test\\\\/', '', $fileName); $fileName = 'test' . DIRECTORY_SEPARATOR . $fileName; include $fileName; } else { $classNameArray = explode('_', $className); $includePath = get_include_path(); set_include_path($includePath); if (!empty($classNameArray) && sizeof($classNameArray) > 1) { if (!class_exists('com\\checkout\\packages\\Autoloader')) { include 'com' . DIRECTORY_SEPARATOR . 'checkout' . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'Autoloader.php'; } } } }
/** * Loop through the files and get the max * modification date which is then used as part * of the url we send out. When any of the files * is modified, the mod date changes and this will * invalidate the cached version of the browser * @param $type (js|css) * @param $memo array Store any files specified in dir format * @return string */ protected function getLink($type, array &$memo) { $arr = array_unique($this->{$type}); foreach ($arr as $file) { if (substr($file, -1) == '*') { $relativePath = stream_resolve_include_path(substr($file, 0, -2)); if ($relativePath) { $files = glob($relativePath . "/*"); foreach ($files as $fname) { $memo[$fname] = filemtime($fname); } } } else { $path = stream_resolve_include_path($file); if ($path) { $memo[$path] = filemtime($path); } } } $modified = (string) max(array_values($memo)); $key = md5($modified . serialize($memo)); $file = sprintf("%s_%s.%s", $modified, $key, $type); $link = Edge::app()->router->createLink("Edge\\Controllers\\Asset", $type, [':file' => $file]); $this->cache($file, $type); return $link; }
/** * Sets new encryption options * * @param string|array $options (Optional) Encryption options * @return Encrypt * @throws Exception\InvalidArgumentException */ public function setAdapter($options = null) { if (is_string($options)) { $adapter = $options; } elseif (isset($options['adapter'])) { $adapter = $options['adapter']; unset($options['adapter']); } else { $adapter = 'BlockCipher'; } if (!is_array($options)) { $options = array(); } if (stream_resolve_include_path('Zend/Filter/Encrypt/' . ucfirst($adapter) . '.php')) { $adapter = 'Zend\\Filter\\Encrypt\\' . ucfirst($adapter); } if (!class_exists($adapter)) { throw new Exception\DomainException(sprintf('%s expects a valid registry class name; received "%s", which did not resolve', __METHOD__, $adapter)); } $this->adapter = new $adapter($options); if (!$this->adapter instanceof Encrypt\EncryptionAlgorithmInterface) { throw new Exception\InvalidArgumentException("Encoding adapter '" . $adapter . "' does not implement Zend\\Filter\\Encrypt\\EncryptionAlgorithmInterface"); } return $this; }
public static function autoload($sClassName) { if (isset(self::$CLASS_MAPPING[$sClassName])) { if (self::$CLASS_MAPPING[$sClassName] === null) { return; } require_once self::$CLASS_MAPPING[$sClassName]; return; } foreach (self::getClassFinders() as $sClassFinder) { $sIncludeFilePath = self::$sClassFinder($sClassName); if ($sIncludeFilePath) { $sIncludeFilePath = stream_resolve_include_path($sIncludeFilePath); if ($sIncludeFilePath === false) { $sIncludeFilePath = null; continue; } break; } } self::$CLASS_MAPPING[$sClassName] = $sIncludeFilePath; self::$MAPPING_HAS_BEEN_MODIFIED = true; if ($sIncludeFilePath) { require_once $sIncludeFilePath; } }
/** * Routing function * * @param string $route The given route to map */ function route($route) { $path = explode('/', $route); $method = array_pop($path); $controller = ucfirst(array_pop($path)) . 'Controller'; $deep = count($path); $currentDeep = 0; $route = __DIR__ . DIRECTORY_SEPARATOR . 'controllers'; while ($currentDeep < $deep) { $route .= DIRECTORY_SEPARATOR . $path[$currentDeep++]; if (!is_dir($route)) { header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request', true, 400); die; } } $route .= DIRECTORY_SEPARATOR . $controller . '.php'; if (stream_resolve_include_path($route) === false) { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404); die(file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR . '404NotFound.html')); } include_once $route; Ini::setIniFileName(Ini::INI_CONF_FILE); // If the print SQL debug mode is on start a buffer if (Ini::getParam('Console', 'printSql')) { ob_start(); } $controllerPath = 'controllers\\' . $controller; $controllerInstance = new $controllerPath(); $controllerInstance->{$method}(); }
/** * Returns true if and only if the file extension of $value is not included in the * set extension list * * @param string $value Real file to check for extension * @param array $file File data from \Zend\File\Transfer\Transfer * @return bool */ public function isValid($value, $file = null) { if ($file === null) { $file = array('name' => basename($value)); } // Is file readable ? if (false === stream_resolve_include_path($value)) { return $this->throwError($file, self::NOT_FOUND); } if ($file !== null) { $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1); } else { $info = pathinfo($value); } $extensions = $this->getExtension(); if ($this->getCase() && !in_array($info['extension'], $extensions)) { return true; } elseif (!$this->getCase()) { $found = false; foreach ($extensions as $extension) { if (strtolower($extension) == strtolower($info['extension'])) { $found = true; } } if (!$found) { return true; } } return $this->throwError($file, self::FALSE_EXTENSION); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Start up application with supplied config...'); $config = $input->getArgument('applicationConfig'); $path = stream_resolve_include_path($config); if (!is_readable($path)) { throw new \InvalidArgumentException("Invalid loader path: {$config}"); } // Init the application once using given config // This way the late static binding on the AspectKernel // will be on the goaop-zf2-module kernel \Zend\Mvc\Application::init(include $path); if (!class_exists(AspectKernel::class, false)) { $message = "Kernel was not initialized yet. Maybe missing module Go\\ZF2\\GoAopModule in config {$path}"; throw new \InvalidArgumentException($message); } $kernel = AspectKernel::getInstance(); $options = $kernel->getOptions(); if (empty($options['cacheDir'])) { throw new \InvalidArgumentException('Cache warmer require the `cacheDir` options to be configured'); } $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $iterator = $enumerator->enumerate(); $totalFiles = iterator_count($iterator); $output->writeln("Total <info>{$totalFiles}</info> files to process."); $iterator->rewind(); set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); }); $index = 0; $errors = []; foreach ($iterator as $file) { if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Processing file <info>{$file->getRealPath()}</info>"); } $isSuccess = null; try { // This will trigger creation of cache file_get_contents(FilterInjectorTransformer::PHP_FILTER_READ . SourceTransformingLoader::FILTER_IDENTIFIER . '/resource=' . $file->getRealPath()); $isSuccess = true; } catch (\Exception $e) { $isSuccess = false; $errors[$file->getRealPath()] = $e; } if ($output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { $output->write($isSuccess ? '.' : '<error>E</error>'); if (++$index % 50 == 0) { $output->writeln("({$index}/{$totalFiles})"); } } } restore_error_handler(); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { foreach ($errors as $file => $error) { $message = "File {$file} is not processed correctly due to exception: {$error->getMessage()}"; $output->writeln($message); } } $output->writeln('<info>Done</info>'); }
public function testGetGlobalFileNamespace() { $fileName = stream_resolve_include_path(__DIR__ . self::STUB_GLOBAL_FILE); $reflectionFile = new ReflectionFile($fileName); $reflectionFileNamespace = $reflectionFile->getFileNamespace('\\'); $this->assertInstanceOf('Go\\ParserReflection\\ReflectionFileNamespace', $reflectionFileNamespace); }
public static function get($file, $decode = TRUE) { //var $e, $config, $error; if (FALSE !== $decode) { $decode = TRUE; } $f = stream_resolve_include_path($file); if ($f) { $config = file_get_contents($f); if (TRUE === $decode) { $config = json_decode($config, TRUE); if (json_last_error()) { $caller = debug_backtrace()[0]; trigger_error(json_last_error_msg() . ": " . $file . " in " . $caller['file'] . ' on line ' . $caller['line'] . ' and defined ', E_USER_ERROR); } else { return $config; } } else { return $config; } } else { $caller = debug_backtrace()[0]; trigger_error("file does not exists: " . $file . " in " . $caller['file'] . ' on line ' . $caller['line'] . ' and defined ', E_USER_ERROR); } }
/** * load(): defined by FileLoaderInterface. * * @see FileLoaderInterface::load() * @param string $locale * @param string $filename * @return TextDomain|null * @throws Exception\InvalidArgumentException */ public function load($locale, $filename) { $resolvedIncludePath = stream_resolve_include_path($filename); $fromIncludePath = $resolvedIncludePath !== false ? $resolvedIncludePath : $filename; if (!$fromIncludePath || !is_file($fromIncludePath) || !is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf('Could not find or open file %s for reading', $filename)); } $messages = []; $iniReader = new IniReader(); $messagesNamespaced = $iniReader->fromFile($fromIncludePath); $list = $messagesNamespaced; if (isset($messagesNamespaced['translation'])) { $list = $messagesNamespaced['translation']; } foreach ($list as $message) { if (!is_array($message) || count($message) < 2) { throw new Exception\InvalidArgumentException('Each INI row must be an array with message and translation'); } if (isset($message['message']) && isset($message['translation'])) { $messages[$message['message']] = $message['translation']; continue; } $messages[array_shift($message)] = array_shift($message); } if (!is_array($messages)) { throw new Exception\InvalidArgumentException(sprintf('Expected an array, but received %s', gettype($messages))); } $textDomain = new TextDomain($messages); if (array_key_exists('plural', $messagesNamespaced) && isset($messagesNamespaced['plural']['plural_forms'])) { $textDomain->setPluralRule(PluralRule::fromString($messagesNamespaced['plural']['plural_forms'])); } return $textDomain; }
public static function autoload($class) { $file = str_replace(array('\\', '_'), '/', $class) . '.php'; if (stream_resolve_include_path($file)) { require_once $file; } }
public function findFile($class) { if ('\\' == $class[0]) { $class = substr($class, 1); } if (false !== ($pos = strrpos($class, '\\'))) { $classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR; $className = substr($class, $pos + 1); } else { $classPath = null; $className = $class; } $classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; foreach ($this->prefixes as $prefix => $dirs) { foreach ($dirs as $dir) { if (0 === strpos($class, $prefix)) { if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) { return $dir . DIRECTORY_SEPARATOR . $classPath; } } } } foreach ($this->fallbackDirs as $dir) { if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) { return $dir . DIRECTORY_SEPARATOR . $classPath; } } if ($this->useIncludePath && ($file = stream_resolve_include_path($classPath))) { return $file; } }
public function testGetReturnTypeMethod() { if (PHP_VERSION_ID < 70000) { $this->markTestSkipped('Test available only for PHP7.0 and newer'); } $fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE70); $reflectionFile = new ReflectionFile($fileName); include $fileName; foreach ($reflectionFile->getFileNamespaces() as $fileNamespace) { foreach ($fileNamespace->getFunctions() as $refFunction) { $functionName = $refFunction->getName(); $originalRefFunction = new \ReflectionFunction($functionName); $hasReturnType = $refFunction->hasReturnType(); $this->assertSame($originalRefFunction->hasReturnType(), $hasReturnType, "Presence of return type for function {$functionName} should be equal"); if ($hasReturnType) { $parsedReturnType = $refFunction->getReturnType(); $originalReturnType = $originalRefFunction->getReturnType(); $this->assertSame($originalReturnType->allowsNull(), $parsedReturnType->allowsNull()); $this->assertSame($originalReturnType->isBuiltin(), $parsedReturnType->isBuiltin()); $this->assertSame($originalReturnType->__toString(), $parsedReturnType->__toString()); } else { $this->assertSame($originalRefFunction->getReturnType(), $refFunction->getReturnType()); } } } }
/** * @static * @param $filename * @return bool */ public static function isIncludeable($filename) { if (array_key_exists($filename, self::$isIncludeableCache)) { return self::$isIncludeableCache[$filename]; } $isIncludeAble = false; // use stream_resolve_include_path if PHP is >= 5.3.2 because the performance is better if (function_exists("stream_resolve_include_path")) { if ($include = stream_resolve_include_path($filename)) { if (@is_readable($include)) { $isIncludeAble = true; } } } else { // this is the fallback for PHP < 5.3.2 $include_paths = explode(PATH_SEPARATOR, get_include_path()); foreach ($include_paths as $path) { $include = $path . DIRECTORY_SEPARATOR . $filename; if (@is_file($include) && @is_readable($include)) { $isIncludeAble = true; break; } } } // add to store self::$isIncludeableCache[$filename] = $isIncludeAble; return $isIncludeAble; }
/** * find class file path * * @param string $fullclass */ public function resolveClass($fullclass) { $fullclass = ltrim($fullclass, '\\'); # echo "Fullclass: " . $fullclass . "\n"; $subpath = null; if (($r = strrpos($fullclass, '\\')) !== false) { $namespace = substr($fullclass, 0, $r); $classname = substr($fullclass, $r + 1); $subpath = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $classname) . '.php'; # echo "namespace: $ns in $namespace\n"; foreach ($this->paths as $d) { $path = $d . DIRECTORY_SEPARATOR . $subpath; if (file_exists($path)) { return $path; } } } else { // use prefix to load class (pear style), convert _ to DIRECTORY_SEPARATOR. $subpath = str_replace('_', DIRECTORY_SEPARATOR, $fullclass) . '.php'; foreach ($this->paths as $dir) { $file = $dir . DIRECTORY_SEPARATOR . $subpath; if (file_exists($file)) { return $file; } } } if ($this->useIncludePath && ($file = stream_resolve_include_path($subpath))) { return $file; } }
public static function main() { if (stream_resolve_include_path('PHPUnit/TextUI/TestRunner.php')) { include_once 'PHPUnit/TextUI/TestRunner.php'; } PHPUnit_TextUI_TestRunner::run(new PHPUnit_Framework_TestSuite('HTML_Page2_GetBodyContent_Test')); }
public function onMove($typeProgress, $module, $name, $copy = FALSE) { $imgs = $this->getConfig('img'); foreach ($imgs as $img) { $oldPath = $img['name']; $imagePath = substr(strstr($oldPath, '/files/'), 7); $newPath = $module . '/files/' . $imagePath; if ($oldPath !== $newPath) { if (stream_resolve_include_path($newPath) !== FALSE) { /* check if an image with this path already exists in profile */ $fileInfo = pathinfo($imagePath); $extension = strtolower($fileInfo['extension']); $filename = $fileInfo['filename']; /* allow to not overload filename with name_0_3_2_0 ... */ $generatedPart = strrchr($filename, '_'); if ($generatedPart !== FALSE && is_numeric(substr($generatedPart, 1))) { $filename = substr($fileInfo['filename'], 0, -strlen($generatedPart)); } $nbn = 0; while (stream_resolve_include_path($newPath)) { $imagePath = $filename . '_' . $nbn . '.' . $extension; $newPath = $module . '/files/' . $imagePath; $nbn++; } } $this->setConfig('imgPath', $newPath); \tools::file_put_contents(PROFILE_PATH . $newPath, file_get_contents($oldPath, FILE_USE_INCLUDE_PATH)); } } }
/** * Load the given class * * @param string $class Class name * * @return void */ public function load($class) { $file = strtr($class, '_\\', '//') . '.php'; if (stream_resolve_include_path($file)) { include $file; } }
/** * Return full file path from PHP include_path * * @param string[] $dirs * @param string $file * @param \Smarty $smarty * * @return bool|string full filepath or false * */ public static function getIncludePath($dirs, $file, Smarty $smarty) { static $_include_path = null; static $_has_stream_include = null; if ($_include_path === null) { $_include_path = (array) explode(PATH_SEPARATOR, get_include_path()); foreach ($_include_path as $key => $_path) { $_include_path[$key] = rtrim($_path, '/\\'); } $_has_stream_include = function_exists('stream_resolve_include_path'); } // try PHP include_path foreach ($dirs as $dir) { if ($dir[0] != '/' && $dir[1] != ':') { $_d_path = $dir . isset($file) ? $file : ''; if ($_has_stream_include) { // available since PHP 5.3.2 $path = stream_resolve_include_path($_d_path); if ($path !== false && is_file($path)) { return $smarty->_realpath($path); } } foreach ($_include_path as $_i_path) { if (is_file($_i_path . DS . $_d_path)) { return $smarty->_realpath($_i_path . DS . $_d_path); } } } } return false; }
public static function instanceCell($cellUri) { if (is_array($cellUri)) { return self::_cell($cellUri); } if (isset(self::$_aliases[$cellUri])) { $cellUri = self::$_aliases[$cellUri]; } $className = str_replace("/", "\\", $cellUri); if (class_exists($className)) { $reflection = new \ReflectionClass($className); $constructor = $reflection->getConstructor(); if ($constructor) { $cell = $reflection->newInstanceArgs(); } else { $cell = $reflection->newInstanceWithoutConstructor(); } $fileConfig = str_replace('.php', '.yml', $reflection->getFileName()); if (file_exists($fileConfig)) { $data = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($fileConfig)); $cell->setData($data); } } else { $fileConfig = stream_resolve_include_path(str_replace("\\", "/", trim($cellUri, "/")) . '.yml'); if ($fileConfig !== FALSE) { $data = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($fileConfig)); $cell = self::_cell($data); } else { $cell = new \Nucleus\Cell(); } } $cell->setCellUri($cellUri); return $cell; }
protected static function loadClass($class) { $file = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; if ($file = stream_resolve_include_path($file)) { require $file; } }
/** * @param string $tplFile * @param TemplateCacheEntry|null $currentCacheEntry * @param string $compiledTemplateContent * * @throws TemplateEngineException * @return TemplateCacheEntry */ public function addCachedTplFile($tplFile, $currentCacheEntry, $compiledTemplateContent) { // NEW HERE $cacheFileName = $currentCacheEntry !== null ? $currentCacheEntry->path : uniqid() . self::CACHE_SUFFIX; $cacheFilePath = $this->cachePath . $cacheFileName; if (stream_resolve_include_path($cacheFilePath) === true && is_writable($cacheFilePath) === false) { throw new TemplateEngineException('Cache file is not writable: ' . $cacheFilePath); } $fp = @fopen($cacheFilePath, 'w'); if ($fp !== false) { fwrite($fp, $compiledTemplateContent); fclose($fp); $this->saveOnDestruct = true; } else { throw new TemplateEngineException('Could not cache template-file: ' . $cacheFilePath); } $fileSize = @filesize($tplFile); if (($changeTime = @filemtime($tplFile)) === false) { $changeTime = @filectime($tplFile); } $tplCacheEntry = new TemplateCacheEntry(); $tplCacheEntry->path = $cacheFileName; $tplCacheEntry->size = $fileSize; $tplCacheEntry->changeTime = $changeTime; $this->registry[$tplFile] = $tplCacheEntry; //new TemplateCacheEntry($tplFile, $id, $size, $changeTime); $this->cacheChanged = true; return $tplCacheEntry; }
/** * Uses the class name to locate the file by converting _ or namespace \ * characters in the name to the system directory separator * * @param string $class */ public function loader($class) { $filename = str_replace(array('\\', '_'), DIRECTORY_SEPARATOR, $class); if (stream_resolve_include_path($filename . $this->classExtension)) { include $filename . $this->classExtension; } return false; }
/** * Resolve a translation file via the include_path * * @param string $filename * @return string|false */ protected function resolveViaIncludePath($filename) { $resolvedIncludePath = stream_resolve_include_path($filename); if (!$resolvedIncludePath || !is_file($resolvedIncludePath) || !is_readable($resolvedIncludePath)) { return false; } return $resolvedIncludePath; }
protected function parseRequire($data, $path) { return preg_replace_callback('/\\/\\/= require (.*)$/m', function ($m) use($path) { $file = trim($m[1], '"\''); $file = stream_resolve_include_path($file); return $this->parseRequire($this->loadFile($file), $file); }, $data); }
protected function setUp() { $fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE); $fileNode = ReflectionEngine::parseFile($fileName); $reflectionFile = new ReflectionFile($fileName, $fileNode); $this->parsedRefFile = $reflectionFile; include_once $fileName; }
/** * Get the email template by its name * * @param string $templateName The email template name * * @throws \Exception if the template is not found * * @return string The email template */ public static function getEmailTemplate(string $templateName) : string { $templatePath = dirname(__FILE__, 3) . DIRECTORY_SEPARATOR . Ini::getParam('Web', 'emailsPath') . DIRECTORY_SEPARATOR . $templateName . '.php'; if (stream_resolve_include_path($templatePath) === false) { throw new \Exception('"' . $templatePath . '" not find in email templates path'); } return file_get_contents($templatePath); }
/** * Find a file in include path * * @param string $class * @return string|bool */ public static function getFile($class) { if (strpos($class, self::NS_SEPARATOR) !== false) { $class = ltrim(str_replace(self::NS_SEPARATOR, '_', $class), '_'); } $relativePath = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; return stream_resolve_include_path($relativePath); }
/** * AutoLoader * * @param string $class */ public static function load($class) { $file = preg_replace('/\\\\|_(?!.+\\\\)/', DIRECTORY_SEPARATOR, $class) . '.php'; if (false !== ($full_path = stream_resolve_include_path($file))) { /** @noinspection PhpIncludeInspection */ require $full_path; } }
/** * Sets file path for template of a method * * @param string $file Path to the template * * @throws \InvalidArgumentException If the file cannot be read */ public function setTemplate($file) { $path = stream_resolve_include_path($file); if (!is_readable($path)) { throw new \InvalidArgumentException('Template file not found'); } $this->template = $file; }