本文整理汇总了PHP中Composer\Autoload\ClassLoader::loadClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::loadClass方法的具体用法?PHP ClassLoader::loadClass怎么用?PHP ClassLoader::loadClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Autoload\ClassLoader
的用法示例。
在下文中一共展示了ClassLoader::loadClass方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadClass
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
*
* @return boolean|null True if loaded, null otherwise
*
* @since 3.4
*/
public function loadClass($class)
{
if ($result = $this->loader->loadClass($class)) {
JLoader::applyAliasFor($class);
}
return $result;
}
示例2: loadClass
/**
* @param string $class
*
* @return bool
*/
public function loadClass($class)
{
if (strpos(ltrim($class, '\\'), __NAMESPACE__) === 0) {
return $this->composer->loadClass($class);
} elseif ($file = $this->composer->findFile($class)) {
\Composer\Autoload\includeFile('php://filter/read=influence.reader/resource=' . $file);
return true;
}
return false;
}
示例3: testClassExists
/**
* Check if a required class exists, and if not, try to load it via composer and recheck.
* Can not use directly autoloader with class_exists. Sometimes it's behavior is non consistent
* with spl_autoload_register.
*
* @param string $className
* @return bool
*/
private function testClassExists($className)
{
if (class_exists($className, false)) {
return true;
}
return $this->composerInstance->loadClass($className) && class_exists($className, false);
}
示例4: tryLoadAllClasses
/**
* Check that the auto loading information is correct.
*
* @return bool
*/
public function tryLoadAllClasses()
{
$result = true;
// Trick Contao 2.11 into believing it is installed.
if (!defined('TL_ROOT')) {
define('TL_ROOT', '/tmp');
}
// Try hacking via Contao autoloader.
spl_autoload_register(function ($class) {
if (substr($class, 0, 7) !== 'Contao\\') {
spl_autoload_call('Contao\\' . $class);
if (class_exists('Contao\\' . $class, false) && !class_exists($class, false)) {
class_alias('Contao\\' . $class, $class);
}
}
});
// Now try to autoload all classes.
foreach ($this->classMap as $class => $file) {
if (!$this->isLoaded($class)) {
try {
if (!$this->loader->loadClass($class)) {
$this->output->writeln(sprintf('<error>The autoloader could not load %s (should be found from file %s).</error>', $class, $file));
$result = false;
}
} catch (\ErrorException $exception) {
$this->output->writeln(sprintf('<error>ERROR loading class %s: "%s".</error>', $class, $exception->getMessage()));
$result = false;
}
}
}
return $result;
}
开发者ID:contao-community-alliance,项目名称:build-system-tool-autoloading-validation,代码行数:37,代码来源:CheckAutoloading.php
示例5: loadClass
/**
* Load class with the option to respect case insensitivity
*
* @param string $className
* @return bool|null
*/
public function loadClass($className)
{
$classFound = $this->composerClassLoader->loadClass($className);
if (!$classFound && !$this->caseSensitiveClassLoading) {
$classFound = $this->composerClassLoader->loadClass(strtolower($className));
}
return $classFound;
}
示例6: loadClass
public function loadClass($class)
{
/* @var ClassLoader $loader */
if ($this->mainLoader->loadClass($class)) {
return true;
}
return false;
}
示例7: testLoadClass
/**
* Tests regular PSR-0 and PSR-4 class loading.
*
* @dataProvider getLoadClassTests
*
* @param string $class The fully-qualified class name to test, without preceding namespace separator.
*/
public function testLoadClass($class)
{
$loader = new ClassLoader();
$loader->add('Namespaced\\', __DIR__ . '/Fixtures');
$loader->add('Pearlike_', __DIR__ . '/Fixtures');
$loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures');
$loader->loadClass($class);
$this->assertTrue(class_exists($class, false), "->loadClass() loads '{$class}'");
}
示例8: loadClass
/**
* Load class with the option to respect case insensitivity
*
* @param string $className
* @return bool|null
*/
public function loadClass($className)
{
if (!$this->caseSensitiveClassLoading) {
$lowerCasedClassName = strtolower($className);
if ($this->composerClassLoader->findFile($lowerCasedClassName)) {
return $this->composerClassLoader->loadClass($lowerCasedClassName);
}
}
return $this->composerClassLoader->loadClass($className);
}
示例9: loadClass
/**
* Loads the given class or interface and invokes static constructor on it
*
* @param string $className The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($className)
{
$result = $this->loader->loadClass($className);
if ($result === true) {
//class loaded successfully
$this->callConstruct($className);
return true;
}
return null;
}
示例10: loadFactory
/**
* To load the factory of the stated class and check if it's implementing the good interface.
*
* @param string $factoryClassName
*
* @return bool
*/
private function loadFactory(string &$factoryClassName) : bool
{
if (!isset($this->factoryAvailabilityList[$factoryClassName])) {
if (true === \class_exists($factoryClassName, false) || true === $this->composerInstance->loadClass($factoryClassName)) {
$reflectionClassInstance = new \ReflectionClass($factoryClassName);
$this->factoryAvailabilityList[$factoryClassName] = $reflectionClassInstance->implementsInterface(FactoryInterface::class);
} else {
$this->factoryAvailabilityList[$factoryClassName] = false;
}
}
return $this->factoryAvailabilityList[$factoryClassName];
}
示例11: testLoadClass
/**
* Tests regular PSR-0 and PSR-4 class loading.
*
* @dataProvider getLoadClassTests
*
* @param string $class The fully-qualified class name to test, without preceding namespace separator.
* @param bool $prependSeparator Whether to call ->loadClass() with a class name with preceding
* namespace separator, as it happens in PHP 5.3.0 - 5.3.2. See https://bugs.php.net/50731
*/
public function testLoadClass($class, $prependSeparator = FALSE)
{
$loader = new ClassLoader();
$loader->add('Namespaced\\', __DIR__ . '/Fixtures');
$loader->add('Pearlike_', __DIR__ . '/Fixtures');
$loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures');
if ($prependSeparator) {
$prepend = '\\';
$message = "->loadClass() loads '{$class}'.";
} else {
$prepend = '';
$message = "->loadClass() loads '\\{$class}', as required in PHP 5.3.0 - 5.3.2.";
}
$loader->loadClass($prepend . $class);
$this->assertTrue(class_exists($class, false), $message);
}
示例12: loadClass
/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
public function loadClass($className)
{
return $this->autoloader->loadClass($className) === true;
}