Pagekit\Database\ORM\MetadataManager::get PHP Method

get() public method

Gets the metadata for the given class.
public get ( object | string $class ) : Pagekit\Database\ORM\Metadata
$class object | string
return Pagekit\Database\ORM\Metadata
    public function get($class)
    {
        $class = new \ReflectionClass($class);
        $name = $class->getName();
        if (!isset($this->metadata[$name])) {
            if ($this->cache) {
                $hash = filemtime($class->getFileName());
                foreach ($class->getTraits() as $trait) {
                    $hash += filemtime($trait->getFileName());
                }
                $current = $class;
                while ($parent = $current->getParentClass()) {
                    $hash += filemtime($parent->getFileName());
                    $current = $parent;
                }
                $id = sprintf('%s%s.%s', $this->prefix, $hash, $name);
                if ($config = $this->cache->fetch($id)) {
                    $this->metadata[$name] = new Metadata($this, $name, $config);
                } else {
                    $this->cache->save($id, $this->load($class)->getConfig());
                }
            } else {
                $this->load($class);
            }
            $this->subscribe($this->metadata[$name]);
        }
        return $this->metadata[$name];
    }

Usage Example

 /**
  * Gets the metadata object of an entity class.
  *
  * @param  mixed $class
  * @return Metadata
  */
 public function getMetadata($class)
 {
     return $this->metadata->get($class);
 }