Returns object mapping.

Loads from cache if it's already loaded.

@param string $className
@param string $directory Name of the directory where the Document is

@return array
543590
private function getObjectMapping($className, $directory)
    {
        $namespace = $this->finder->getNamespace($className, $directory);

        if (array_key_exists($namespace, $this->objects)) {
            return $this->objects[$namespace];
        }

        $reflectionClass = new \ReflectionClass($namespace);

        switch (true) {
            case $this->reader->getClassAnnotation($reflectionClass, self::OBJECT_ANNOTATION):
                $type = 'object';
                break;
            case $this->reader->getClassAnnotation($reflectionClass, self::NESTED_ANNOTATION):
                $type = 'nested';
                break;
            default:
                throw new \LogicException(
                    sprintf(
                        '%s should have @ObjectType or @Nested annotation to be used as embeddable object.',
                        $className
                    )
                );
        }

        $this->objects[$namespace] = [
            'type' => $type,
            'properties' => $this->getProperties($reflectionClass),
        ];

        return $this->objects[$namespace];
    }
200153
protected function searchForClassFile($className, $directory) {
        if(is_dir($directory) && is_readable($directory)) {
            $d = dir($directory);
            while($f = $d->read()) {
                $subPath = realpath($directory . DIRECTORY_SEPARATOR . $f);
                //echo "Looking in $subPath for $className{$this->classFileSuffix}\n";
                if(is_dir($subPath)) {
                    // Found a subdirectory
                    if(!preg_match($this->excludeFolderNames, $f)) {
                        if($filePath = $this->searchForClassFile($className, $subPath . '/')) {
                            return $filePath;
                        }
                    }
                }
                else { // it's a file... so does the name match ?
                    if($f == $className . $this->classFileSuffix) {
                        return $subPath;
                    }
                }
            }
        }
        return false;
    }
1159705
public function getDiRequirements($className)
    {
        if (!isset($this->classCache[$className])) {
            $reflectionClass = new \ReflectionClass($className);
            $injects = [];
            // get all defined properties
            $props = $reflectionClass->getProperties();
            foreach ($props as $prop) {
                $inject = $this->annotationReader->getPropertyAnnotation(
                    $prop,
                    'Slender\Core\DependencyInjector\Annotation\Inject'
                );
                if ($inject) {

                    // Get the DI identifier
                    $identifier = $inject->getIdentifier();
                    if (!$identifier) {
                        $identifier = Util::hyphenCase($prop->getName());
                    }

                    $data = array(
                        'identifier' => $identifier,
                        'isPublic' => $prop->isPublic(),
                        'setter' => false
                    );

                    // Is there a setter method (cos its still faster andrew...)
                    if (!$prop->isPublic()) {
                        $setter = Util::setterMethodName($prop->getName());
                        if (method_exists($className, $setter)) {
                            $data['hasSetter'] = $setter;
                        };
                    };

                    $injects[$prop->getName()] = $data;
                }
            }
            $this->classCache[$className] = $injects;
        }
        return $this->classCache[$className];
    }
541286
protected static function getObject($className)
    {
        if (!isset(self::$instances[$className])) {
            self::$instances[$className] = self::createObject($className);
        }

        return self::$instances[$className];
    }
1076873
public function getByClassname(string $classname)
    {
        foreach ($this->container as $value) {
            if (is_object($value) && $value instanceof $classname) {
                return $value;
            }
        }

        return null;
    }
902304
public static function fromClass(string $className) : Mapping
    {
        /* @var ApiMapping $instance */
        $className = '\\'.ltrim($className, '\\');
        if (!class_exists($className, true)) {
            throw new MappingException(
                \sprintf('Provided class %s could not be loaded.', $className)
            );
        }
        $instance = new $className();

        if (!in_array(ApiMapping::class, \class_implements($instance, true))) {
            throw new MappingException(
                \sprintf('Class %s must implement %s.', \ltrim($className, '\\'), ApiMapping::class)
            );
        }

        $mappedClass = [
            static::CLASS_KEY => $instance->getClass(),
            static::ALIAS_KEY => $instance->getAlias(),
            static::ALIASED_PROPERTIES_KEY => $instance->getAliasedProperties(),
            static::HIDE_PROPERTIES_KEY => $instance->getHideProperties(),
            static::ID_PROPERTIES_KEY => $instance->getIdProperties(),
            static::URLS_KEY => $instance->getUrls(),
        ];

        if (\in_array(HalMapping::class, \class_implements($instance, true))) {
            $mappedClass[static::CURIES_KEY] = $instance->getCuries();
        }

        if (\in_array(JsonApiMapping::class, \class_implements($instance, true))) {
            $mappedClass[static::RELATIONSHIPS_KEY] = $instance->getRelationships();
        }

        return static::fromArray($mappedClass);
    }
1146802
public static function loadClass($className)
  {
    if (!class_exists($className)) {
      $path = self::getPath($className);

      $realPath = stream_resolve_include_path($path);

      if (file_exists($realPath)) {
        require_once($realPath);

        return class_exists($className);
      }
      return false;
    } else {
      return true;
    }
  }
353349
protected static function getBindingsForApp(string $className): array
    {
        $bindings   = parent::getBindingsForApp($className);
        $bindings[] = function(Binder $binder)
        {
            $binder->bind(InputStream::class)
                   ->named('stdin')
                   ->toInstance(ConsoleInputStream::forIn());
            $binder->bind(OutputStream::class)
                   ->named('stdout')
                   ->toInstance(ConsoleOutputStream::forOut());
            $binder->bind(OutputStream::class)
                   ->named('stderr')
                   ->toInstance(ConsoleOutputStream::forError());
        };
        return $bindings;
    }
74759
public function fetchAllClass(string $classname) : array
    {
        $this->stmt->setFetchMode(\PDO::FETCH_CLASS, $classname);
        return $this->stmt->fetchAll();
    }
637461
public function items($directory)
    {
        $directory = trim($directory, '/') . '/';

        $options = array(
            'return_prefixes' => true,
            'sort_results' => true
        );

        $objectIterator = $this->clientS3->getIterator('ListObjects', array(
            'Bucket'    => $this->bucket,
            'Prefix'    => $directory,
            'Delimiter' => '/',
        ), $options);

        $iterator = new CallbackFilterIterator($objectIterator, function($object){
            return (isset($object['Key']) || isset($object['Prefix']));
        });

        $files = array();

        foreach ($iterator as $object)
        {
            $files[] = isset($object['Key']) ? $object['Key'] : $object['Prefix'];
        }

        return $files;
    }
172424
public function getClassMetadata($className)
    {
        if (!$this->initialized) {
            $this->initialize();
        }
        if (array_key_exists($className, $this->metadata)) {
            return $this->metadata[$className];
        }

        return false;
    }
28301
public function loadClass($className)
    {
        if ($this->namespace !== null && strpos($className, $this->namespace.$this->namespaceSeparator) !== 0) {
            return false;
        }

        require ($this->includePath !== null ? $this->includePath . DIRECTORY_SEPARATOR : '')
               . str_replace($this->namespaceSeparator, DIRECTORY_SEPARATOR, $className)
               . $this->fileExtension;

        return true;
    }
1218373
private function _read($filename, $directory = null)
    {
        $cache_path = $this->config->get('cache_path');

        if (is_null($directory)) {
            $path = $cache_path.$this->config->get('object_dir').$filename.'.cache';
        } else {
            $path = $cache_path.$directory.$filename.'.cache';
        }

        // nope. not here.
        if ( ! file_exists($path)) return null;

        $fh = @fopen($path, 'rb');
        flock($fh, LOCK_SH);

        // read out the expiration date
        $use_before_date = fread($fh, 10);

        // still a valid cache object or is it stale?
        if ($use_before_date < time()) return null;

        $data = fread($fh, filesize($path));

        flock($fh, LOCK_UN);
        fclose($fh);

        return $data;
    }
324182
public static function getClassContentClassnamesFromDir($directory)
    {
        if (!is_dir($directory)) {
            return [];
        }

        return array_map(
            function ($path) use ($directory) {
                return str_replace(
                    [DIRECTORY_SEPARATOR, '\\\\'],
                    [NAMESPACE_SEPARATOR, NAMESPACE_SEPARATOR],
                    AbstractClassContent::CLASSCONTENT_BASE_NAMESPACE.str_replace([$directory, '.yml'], ['', ''], $path)
                );
            },
            File::getFilesRecursivelyByExtension($directory, 'yml')
        );
    }
158347
public function getMetadataFor($className)
    {
        if (!$this->isService($className)) {
            throw Exception::classIsNotMappedService($className);
        }

        if (!isset($this->loadedMetadata[$className])) {
            $this->loadMetadata($className);
        }

        if ($this->cache) {
            $cacheId = $this->cachePrefix . $className . $this->cacheSuffix;

            if (($cached = $this->cache->fetch($cacheId)) !== false) {
                $this->loadedMetadata[$className] = $cached;
            } else {
                $this->loadMetadata($className);
                $this->cache->save($cacheId, $this->loadedMetadata[$className], null);
            }
        } else {
            $this->loadMetadata($className);
        }

        return $this->loadedMetadata[$className];
    }
810981
public function listFiles($directory)
    {
        if (!file_exists($directory)) {
            return collect([]);
        }

        return $this->scanDir($directory)->reject(function ($item) {
            return !$this->isAllowedDirectory($item) && !$this->isYamlFile($item);
        })->mapWithKeys(function ($item) {
            if (is_dir($item)) {
                return [basename($item) => $this->listFiles($item)->toArray()];
            }

            return [$this->cleanKey($item) => $item];
        });
    }
526320
public function getDocumentCollection(string $className) : Collection
    {
        $className = $this->classNameResolver->getRealClass($className);

        /** @var ClassMetadata $metadata */
        $metadata = $this->metadataFactory->getMetadataFor($className);
        assert($metadata instanceof ClassMetadata);
        if ($metadata->isFile) {
            return $this->getDocumentBucket($className)->getFilesCollection();
        }

        $collectionName = $metadata->getCollection();

        if (! $collectionName) {
            throw MongoDBException::documentNotMappedToCollection($className);
        }

        if (! isset($this->documentCollections[$className])) {
            $db = $this->getDocumentDatabase($className);

            $options = [];
            if ($metadata->readPreference !== null) {
                $options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
            }

            $this->documentCollections[$className] = $db->selectCollection($collectionName, $options);
        }

        return $this->documentCollections[$className];
    }