Services::load

@param string      $className
@param string|null $offset
328161
public function load($className, $offset = null)
    {
        if (is_string($className)) {
            $className = str_replace([
                'O2System\Framework\\',
                'O2System\Reactor\\',
                'O2System\Kernel\\',
                'App\\',
            ], '',
                ltrim($className, '\\')
            );

            if (class_exists($className)) {
                $service = new SplServiceRegistry($className);
            } else {
                if (is_object(kernel()->modules)) {
                    if ($module = kernel()->modules->top()) {
                        if (class_exists($serviceClassName = $module->getNamespace() . $className)) {
                            $service = new SplServiceRegistry($serviceClassName);
                        }
                    }
                }

                if (empty($service)) {
                    if (class_exists($serviceClassName = 'App\\' . $className)) {
                        $service = new SplServiceRegistry($serviceClassName);
                    } elseif (class_exists($serviceClassName = 'O2System\Framework\\' . $className)) {
                        $service = new SplServiceRegistry($serviceClassName);
                    } elseif (class_exists($serviceClassName = 'O2System\Reactor\\' . $className)) {
                        $service = new SplServiceRegistry($serviceClassName);
                    } elseif (class_exists($serviceClassName = 'O2System\Kernel\\' . $className)) {
                        $service = new SplServiceRegistry($serviceClassName);
                    } elseif(class_exists($className)) {
                        $service = new SplServiceRegistry($serviceClassName);
                    }
                }
            }
        }

        if (isset($service)) {
            if ($service instanceof SplServiceRegistry) {
                if (profiler() !== false) {
                    profiler()->watch('Load New Service: ' . $service->getClassName());
                }

                $this->register($service, $offset);
            }
        }
    }
396689
public function load($className) {
        //如果内存缓存里有
        if (isset($this->metadataMap[$className])) {
            return $this->metadataMap[$className];
        }

        //如果没有就加载
        $classMetadata = $this->doLoad($className);

        //存入内存缓存
        $this->metadataMap[$className] = $classMetadata;

        return $classMetadata;
    }
977404
final public static function autoload($className)
    {
        if (\Phar::running() && defined('PHAR_SWAGGER_VALIDATOR_ROOT_PATH')) {
            $baseDir = PHAR_SWAGGER_VALIDATOR_ROOT_PATH;
        }
        elseif (\Phar::running()) {
            $baseDir = null;
        }
        else {
            $baseDir = __DIR__ . DIRECTORY_SEPARATOR;
        }

        $thisClass = 'SwaggerValidator';

        $namespace = explode('\\', $className);
        $className = array_pop($namespace);
        $rootPath  = array_shift($namespace);

        if ($rootPath == $thisClass) {
            $namespace = $baseDir . trim(implode(DIRECTORY_SEPARATOR, $namespace), DIRECTORY_SEPARATOR);
        }
        else {
            $namespace = $baseDir . trim($rootPath . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $namespace), DIRECTORY_SEPARATOR);
        }

        if (substr($namespace, -1, 1) != DIRECTORY_SEPARATOR) {
            $namespace .= DIRECTORY_SEPARATOR;
        }

        if ($namespace == DIRECTORY_SEPARATOR) {
            $namespace = "";
        }

        $fileName = $namespace . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

        if (file_exists($fileName)) {
            require_once $fileName;
        }
    }
333195
public function load($className)
    {
        $class = ltrim($className, '\\');

        if (strpos($class, $this->namespace) !== 0) {
            return false;
        }

        $nsparts   = explode('\\', $class);
        $class     = array_pop($nsparts);
        $nsparts[] = '';
        $path      = $this->path . implode(DIRECTORY_SEPARATOR, $nsparts);
        $path     .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';

        if (!is_readable($path)) {
            return false;
        }

        require $path;

        return class_exists($className,false);
    }
750811
public function add($service, $offset = null)
    {
        if (is_object($service)) {
            if ( ! $service instanceof SplServiceRegistry) {
                $service = new SplServiceRegistry($service);
            }
        }

        if (profiler() !== false) {
            profiler()->watch('Add New Service: ' . $service->getClassName());
        }

        $this->register($service, $offset);
    }
570621
protected function loadClass($className)
    {
        if (strpos($className, NS) !== false) {
            $className = str_replace(NS, DS, ltrim($className, NS));
        }

        $filename = str_replace('_', DS, $className) . '.php';

        if (array_key_exists($className, $this->includePaths)) {
            @require_once $this->includePaths[$className];

            if (class_exists('\\' . trim("$className", '\\'))) {
                return true;
            }
        }

        foreach ($this->includePaths as $namespace => $includePath) {
            if (file_exists($includePath . $filename)) {
                require_once $includePath . $filename;

                return true;
            }
        }

        return false;
    }
996352
public function loadClass($className)
    {
        $fileName = "";
        if (false !== ($lastNsPos = strripos($className, self::NAMESPACE_SEPARATOR))) {
            $namespace = substr($className, 0, $lastNsPos);
            $className = substr($className, $lastNsPos + 1);
            $fileName = str_replace(self::NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
        }
        $fileName .= str_replace("_", DIRECTORY_SEPARATOR, $className) . self::FILE_EXTENSION;

        foreach ($this->paths as $path) {
            $filePath = $path . DIRECTORY_SEPARATOR . $fileName;
            if (file_exists($filePath)) {
                require_once $filePath;
            }
        }
    }
124014
public static function autoload(string $className): void
    {
        $classPath = str_replace('\\', DS, $className);
        $path = $classPath . '.php';

        if ((@include $path) === false) {
            // if we fail to include a file, let's throw an exception so we can see where it happened - it'll speed up troubleshooting
            $includePath = get_include_path();
            throw new ApplicationException("Unable to load class {$className} in current include path={$includePath}");
        }
    }
892870
public function loadMetadataForClass(
        string $className,
        Mapping\ClassMetadata $metadata,
        Mapping\ClassMetadataBuildingContext $metadataBuildingContext
    ) : Mapping\ClassMetadata {
        $reflectionClass = $metadata->getReflectionClass();

        if (! $reflectionClass) {
            // this happens when running annotation driver in combination with
            // static reflection services. This is not the nicest fix
            $reflectionClass = new ReflectionClass($metadata->getClassName());
        }

        $classAnnotations = $this->getClassAnnotations($reflectionClass);
        $classMetadata    = $this->convertClassAnnotationsToClassMetadata(
            $reflectionClass,
            $classAnnotations,
            $metadata,
            $metadataBuildingContext
        );

        // Evaluate @Cache annotation
        if (isset($classAnnotations[Annotation\Cache::class])) {
            $cacheAnnot = $classAnnotations[Annotation\Cache::class];
            $cache      = $this->convertCacheAnnotationToCacheMetadata($cacheAnnot, $metadata);

            $classMetadata->setCache($cache);
        }

        // Evaluate annotations on properties/fields
        /** @var ReflectionProperty $reflProperty */
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            if ($reflectionProperty->getDeclaringClass()->getName() !== $reflectionClass->getName()) {
                continue;
            }

            $propertyAnnotations = $this->getPropertyAnnotations($reflectionProperty);
            $property            = $this->convertPropertyAnnotationsToProperty(
                $propertyAnnotations,
                $reflectionProperty,
                $classMetadata,
                $metadataBuildingContext
            );

            if (! $property) {
                continue;
            }

            $metadata->addProperty($property);
        }

        $this->attachPropertyOverrides($classAnnotations, $reflectionClass, $metadata, $metadataBuildingContext);

        return $classMetadata;
    }
1359353
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
    {
        $this->metadata = $metadata;
        $this->loadMappingFile($this->findMappingFile($className));
    }
736900
protected function load($className, $code)
    {
        if (class_exists($this->getFullClassName($className), false)) {
            return;
        }

        eval('?>'.$code);
    }
1249016
public function autoload($className)
    {
        if (0 === strpos($className, $this->prefix)) {
            $parts = explode('\\', substr($className, $this->prefixLength));
            $filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php';

            if (is_file($filepath)) {
                require $filepath;
            }
        }
    }
1206213
public function loadClass($className)
    {
        $className = ltrim($className, '\\');

        $namespaceParts = explode('\\', $className);
        // Workaround for Doctrine's annotation parser which does a class_exists() for annotations like "@param" and so on:
        if (isset($this->ignoredClassNames[$className]) || isset($this->ignoredClassNames[end($namespaceParts)])) {
            return false;
        }

        // Loads any known proxied class:
        if ($this->classesCache !== null && ($this->availableProxyClasses === null || isset($this->availableProxyClasses[implode('_', $namespaceParts)])) && $this->classesCache->requireOnce(implode('_', $namespaceParts)) !== false) {
            return true;
        }

        return false;
    }
1230021
public function loadClass($className)
    {
        if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
            $fileName = '';
            $namespace = '';
            if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
                $namespace = substr($className, 0, $lastNsPos);
                $className = substr($className, $lastNsPos + 1);
                $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
            }
            $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
            $filePath = ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;

            if (file_exists($filePath)) {
                require $filePath;
            }
        }
    }
18330
public static function load($context = '')
    {
        if (empty($context)) {
            $context = self::$defaultContext;
        }
        if ($context[0] !== '\\') {
            // Short context name (must be formatted into class name).
            $context = self::$contextPrefix . $context;
        }
        if (! class_exists($context)) {
            throw @new LoaderException(
                'Specified context ("' . $context . '") does not exist.',
                $context
            );
        }
        self::$loadedContext = $context;
        self::$KEYWORDS = $context::$KEYWORDS;
    }
64029
public function load(): void
    {
        $refl = new \ReflectionClass(GeneralUtility::class);

        $this->loadClassNameCache($refl);
        $this->loadInstanceCache($refl);
    }
170338
public function read( $offset = NULL, $limit = NULL )
	{
		return $this->load( $this->fileName, $offset, $limit );
	}