Returns the registered cache file built from the given $resource.

@param AbstractResourceFile $resource
@return File
431474
public function getCacheBuilt(AbstractResourceFile $resource) {
        if (isset($this->cacheMap[$resource->getMemberId()])) {
            return $this->cacheMap[$resource->getMemberId()];
        } else {
            return null;
        }
    }
1039917
public function get($resource)
    {
        $path = $this->getSourcePath($resource);

        if (!file_exists($path)) {
            throw new \RuntimeException('There is no cached value for '.$resource);
        }

        return include $path;
    }
1130025
protected function getPartFiles(ResourceInterface $resource)
    {
        $files = [];

        $originalFile = $resource->getFile();
        $regex = sprintf('/^%s\.part(\d+)$/', preg_quote($originalFile->getBasename(), '/'));
        $finder = new \DirectoryIterator($originalFile->getPath());

        /** @var $file \SplFileInfo */
        foreach ($finder as $file) {
            if ($file->isFile() && preg_match($regex, $file->getBaseName(), $matches)) {
                $files[(int) $matches[1]] = $file->getPathname();
            }
        }

        ksort($files);

        return $files;
    }
26997
public static File getResourceAsFile(final String resource) {
        final ClassLoader classLoader = FileUtils.class.getClassLoader();
        final String path = classLoader != null
                ? classLoader.getResource(resource).getFile()
                : ClassLoader.getSystemResource(resource).getFile();

        if (path == null) {
            return new File(resource);
        }
        return new File(path);
    }
1162319
public function load(string $resource, string $type = null) : RepositoryInterface
    {
        $resourceContent = $resource;

        if (empty($type)) {
            $file = $this->getLocation($resource);
            $resourceContent = $this->readFile($file);
        }

        $parsedResource = $this->parseJson($resourceContent);
        $errorMsg = $this->getLastErrorMessage(json_last_error());

        if ($errorMsg) {
            $msg = $type ? sprintf('JSON parse error: %s.', $errorMsg) : sprintf('JSON parse error: %s at %s', $errorMsg, $resource);

            throw new \RuntimeException($msg);
        }

        $repository = new Repository($parsedResource ?? []);

        return $this->parseImports($repository, $resource);
    }
876376
public function resolvePath($resource)
    {
        // Skip blank resources
        if (empty($resource)) {
            return null;
        }
        $resourceObj = $this->resolveResource($resource);
        if ($resourceObj instanceof ModuleResource) {
            return $resourceObj->getRelativePath();
        }
        return $resource;
    }
56611
public function getIcon(AbstractResource $resource, Workspace $workspace = null)
    {
        $node = $resource->getResourceNode();
        $mimeElements = explode('/', $node->getMimeType());
        $ds = DIRECTORY_SEPARATOR;
        // if video or img => generate the thumbnail, otherwise find an existing one.
        if (($mimeElements[0] === 'video' || $mimeElements[0] === 'image')) {
            $this->om->startFlushSuite();
            $thumbnailPath = $this->createFromFile(
                $this->fileDir. $ds . $resource->getHashName(),
                $mimeElements[0],
                $workspace
            );

            if ($thumbnailPath !== null) {
                $thumbnailName = pathinfo($thumbnailPath, PATHINFO_BASENAME);

                if (is_null($workspace)) {
                    $relativeUrl = $this->basepath . "/{$thumbnailName}";
                } else {
                    $relativeUrl = $this->basepath .
                        $ds .
                        $workspace->getCode() .
                        $ds .
                        $thumbnailName;
                }
                $icon = $this->om->factory('Claroline\CoreBundle\Entity\Resource\ResourceIcon');
                $icon->setMimeType('custom');
                $icon->setRelativeUrl($relativeUrl);
                $icon->setShortcut(false);
                $this->om->persist($icon);
                $this->createShortcutIcon($icon, $workspace);
                $this->om->endFlushSuite();

                return $icon;
            }
            $this->om->endFlushSuite();
        }

        //default & fallback
        return $this->searchIcon($node->getMimeType());
    }
934257
public function registerResource(AbstractResourceFile $resource) {
        if (!isset($this->resources[md5($resource->getRealPath())])) {
            $this->resources[md5($resource->getRealPath())] = $resource;
        }
    }
1175360
protected function makeReleaseRelativePath(AbstractResourceFile $resource) {
        if (is_null($this->getReleaseDir())) {
            throw new FileWriteErrorException("The release dir configuration is missed for " . get_class($this));
        }
        return $resource->getRelativePath($this->getSourceDir());
    }
526488
public function checkResource($resource)
    {
        $resource =
            $resource instanceof Resource
                ? $resource
                : $this->getResourceBySlug($resource);

        $checked = $this->cache->remember($resource->slug, function () use (
            $resource
        ) {
            return $resource->check($this->getCurrentAction());
        });

        $resource->targets = $checked->targets;

        return $resource;
    }
92338
private function exportResource(AbstractResource $resource, $locale)
    {
        $resources = [];

        $event = $this->dispatchEvent($resource, $locale);
        $embedResources = $event->getEmbedResources();

        // Grab data from event
        $resources[$resource->getResourceNode()->getId()] = [
            'node' => $resource->getResourceNode(),
            'template' => $event->getTemplate(),
            'assets' => $event->getAssets(),
            'files' => $event->getFiles(),
            'translation_domains' => $event->getTranslationDomains(),
            'resources' => array_keys($embedResources), // We only need IDs
        ];

        if (!empty($embedResources)) {
            foreach ($embedResources as $embedResource) {
                if (empty($resources[$embedResource->getResourceNode()->getId()])) {
                    // Current resource has not been exported yet
                    $exported = $this->exportResource($embedResource, $locale);
                    $resources = array_merge($resources, $exported);
                }
            }
        }

        return $resources;
    }
1341555
public function getWebPathForResource(Resource $resource)
    {
        $relPath = Path::makeRelative($resource->getRepositoryPath(), $this->basePath);

        return '/'.trim($this->mapping->getWebPath().'/'.$relPath, '/');
    }
122504
private function generateResourceName($resource)
    {
        if (false === $this->pluralize) {
            return $resource;
        }

        return $this->inflector->pluralize($resource);
    }
481002
private function convertVideoToImage($resource)
    {
        $temporaryFilePath = $this->createTemporaryFile($resource);
        $this->videoThumbnail->generate($temporaryFilePath, '00:00:02:01', $temporaryFilePath);

        $extractedImage = file_get_contents($temporaryFilePath);
        unlink($temporaryFilePath);

        return $this->createTemporaryResource($extractedImage);
    }
55905
private function getResourceData($resource)
    {
        $data = false;
        if(!is_null($resource) && $resource->exists()) {
            $resourceTypes = array_keys($resource->getTypes());
            $data = [
                'uri'        => $resource->getUri(),
                'classUri'   => $resourceTypes[0],
                'label'      => $resource->getLabel(),
                'type'       => 'instance'
            ];
        }
        return $data;
    }
202306
public function load(string $resource, string $type = null) : RepositoryInterface
    {
        if (class_exists('Yosymfony\Toml\Toml') === false) {
            throw new \RuntimeException('"Yosymfony Toml" is required to read TOML files.');
        }

        $resourceContent = $resource;
        
        if (empty($type)) {
            $file = $this->getLocation($resource);
            $resourceContent = $this->readFile($file);
        }

        $parsedResource = Toml::parse($resourceContent);
        $repository = new Repository($parsedResource ?? []);

        return $this->parseImports($repository, $resource);
    }
210507
public function getMetadata(Resource $resource, $forceUpdate = false) {
		if ($this->metadata === null) {
			$this->initMetadata();
		}
		
		$path = $resource->getPath();
		
		if (! is_file($path)) {
			return false;
		}
		
		// Already exists for the resource
		if (! $forceUpdate && isset($this->metadata[$path])) {
			return $this->metadata[$path];
		}
		
		if ($resource->isLocal()) {
			$fileMtime = filemtime($path);
			
			if (isset($this->metadata[$path]) && $fileMtime === $this->metadata[$path]->mtime) {
				return $this->metadata[$path];
			}
		}
		
		$fileMeta = new stdClass();
		
		$fileMeta->mtime = isset($fileMtime) ? $fileMtime : false;
		$fileMeta->hash  = substr(md5_file($path), 24);
		
		$this->metadata[$path] = $fileMeta;
		$this->metadataChanged = true;
		
		return $fileMeta;
	}