本文整理汇总了PHP中stream_resolve_include_path函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_resolve_include_path函数的具体用法?PHP stream_resolve_include_path怎么用?PHP stream_resolve_include_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_resolve_include_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: autoload
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';
}
}
}
}
示例2: getLink
/**
* 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;
}
示例3: setAdapter
/**
* 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;
}
示例4: autoload
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;
}
}
示例5: route
/**
* 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}();
}
示例6: isValid
/**
* 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);
}
示例7: execute
/**
* {@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>');
}
示例8: testGetGlobalFileNamespace
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);
}
示例9: get
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);
}
}
示例10: load
/**
* 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;
}
示例11: autoload
public static function autoload($class)
{
$file = str_replace(array('\\', '_'), '/', $class) . '.php';
if (stream_resolve_include_path($file)) {
require_once $file;
}
}
示例12: findFile
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;
}
}
示例13: testGetReturnTypeMethod
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());
}
}
}
}
示例14: isIncludeable
/**
* @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;
}
示例15: resolveClass
/**
* 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;
}
}