Check if current file.xml is shared stimulus

@param $relativePath
@return bool
@throws FileUploadException
335113
public function isApplicable($relativePath)
    {
        $xincluded = array();
        /** @var Element $xincludeElement */
        foreach ($this->getQtiModel()->getComposingElements('oat\taoQtiItem\model\qti\Xinclude') as $xincludeElement) {
            $xincluded[] = $xincludeElement->attr('href');
            \common_Logger::i("Xinclude component found in resource '" .
                $this->getQtiModel()->getIdentifier() . "' with href '" . $xincludeElement->attr('href') . "'.");
        }

        return (!empty($this->sharedStorage) && in_array($relativePath, $xincluded));
    }
1042955
public function delete($filePath)
    {
        $relativePath = $this->fs->makePathRelative($filePath, $this->root);
        if (preg_match('!(^|/)\.\.!', $relativePath)) {
            throw new \RuntimeException("{$relativePath} does not seem to be managed by the filemanager");
        }
        if ($this->fs->exists($filePath)) {
            $this->fs->remove($filePath);
            $this->dispatchEvent(ResourceEvent::DELETED, $filePath);
            return true;
        }
        return false;
    }
368461
public function uploadFile(string $dirPath, string $fileName): bool
    {
        try {
            if (!$this->filesystem->createDir($dirPath)) {
                return false;
            }

            $targetFilePath = $dirPath . DIRECTORY_SEPARATOR . $fileName;

            if ($this->filesystem->has($targetFilePath)) {
                $this->addError('', "File by path `{$targetFilePath}` already exists.");

                return false;
            }

            $contentResource = $this->getFileContent();
            if ($contentResource === null) {
                return false;
            }

            return $this->filesystem->writeStream($targetFilePath, $contentResource);
        } catch (\Exception $e) {
            return false;
        }
    }
208860
public function registerAutoload($basePath, $prefix = '', $relative = true)
    {
        $path = $relative ? $this->basePath . '/' . $basePath : $basePath;

        Autoloader::getInstance()->registerAutoload($path, $prefix);
    }
1076823
public function getFile($relativePath)
    {
        $fileKey = $this->getFileKey($this->getAbsolutePath($relativePath));

        return new File($fileKey, $this);
    }
962776
protected function checkFilePath($filePath)
	{
	    $filePath = rtrim($filePath, '/\\');
	    if (!is_dir($filePath)) {
			mkdir($filePath, 0755, true);
		}
        
		if (!is_writable($filePath)) {
			throw new \RuntimeException(sprintf('The base cache path `%s` is not writable.', $filePath));
		}

		return true;
	}
863323
public function getRelativeAsset (string $relativePath) : ?self
    {
        $filePath = new FilePath();

        return new self(
            $this->getNamespace(),
            $filePath->resolvePath($this->getFilePath(), $relativePath)
        );
    }
250026
public function uploadImage($filePath)
    {
        $result = $this->wechat->httpPost(self::WECHAT_IMG_UPLOAD_PREFIX, [
            'buffer' => class_exists('\CURLFile') ? new \CURLFile($filePath) : '@' . $filePath
        ], [
            'access_token' => $this->wechat->getAccessToken()
        ]);

        return isset($result['url']) ? $result['url'] : false;
    }
236939
public function readFileStream($containerName, $fileName, $relativePath)
    {
        $fullFileName = $this->getFullFileName($containerName, $fileName, $relativePath);

        return $this->filesystem->readStream($fullFileName);
    }
1264451
public function isApplicable($relativePath)
    {
        $xincluded = array();
        /** @var Element $xincludeElement */
        foreach ($this->getQtiItem()->getComposingElements('oat\taoQtiItem\model\qti\Xinclude') as $xincludeElement) {
            $xincluded[] = $xincludeElement->attr('href');
            \common_Logger::i("Xinclude component found in resource '" .
                $this->getQtiItem()->getIdentifier() . "' with href '" . $xincludeElement->attr('href') . "'.");
        }

        return in_array($relativePath, $xincluded);
    }
61225
private function getSharedStimulusFile($filePath)
    {
        \helpers_TimeOutHelper::setTimeOutLimit(\helpers_TimeOutHelper::LONG);
        $extractPath = $this->extractArchive($filePath);
        \helpers_TimeOutHelper::reset();

        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($extractPath),
            \RecursiveIteratorIterator::LEAVES_ONLY);

        /** @var $file \SplFileInfo */
        foreach ($iterator as $file) {
            //check each file to see if it can be the shared stimulus file
            if ($file->isFile()) {
                if (preg_match('/^[\w]/', $file->getFilename()) === 1 && $file->getExtension() === 'xml') {
                    return $file->getRealPath();
                }
            }
        }

        throw new \common_Exception('XML not found in the package');
    }
1086810
public function isCacheExpired($cachePath, $path)
    {
        if (! $this->files->exists($cachePath)) {
            return true;
        }

        $lastModified = $this->files->lastModified($path);

        if ($lastModified >= $this->files->lastModified($cachePath)) {
            return true;
        }

        return false;
    }
1230296
public function restore($filepath)
	{
		if (!$this->getEnabled()) {
			return false;
		}

		if (!$this->getBackupFilesystemInstance()->checkFileExists($filepath)) {
			throw new BackupRestoreException('Unable to restore file "' . $filepath . '" as it doesn\'t exist.');
		}

		$this->setWorkingFilepath($filepath);

		if ($this->getBackupFilesystemInstance()->checkFileEmpty($filepath)) {
			$this->getBackupFilesystemInstance()->removeFile($filepath);

			return false;
		}

		if ($this->isCompressed($filepath)) {
			$filepath = $this->decompressFile($filepath);
		}

		$result = $this->getBackupEngineInstance()->restore($filepath);

		$this->removeTemporaryFiles($this->getWorkingFilepath());

		return $result;
	}
106292
public function hasFiles($onlySuccessful = true)
    {
        $context = $this->_context;

        /** @var $_FILES array */
        foreach ($context->_FILES as $file) {
            if (is_int($file['error'])) {
                $error = $file['error'];

                if (!$onlySuccessful || $error === UPLOAD_ERR_OK) {
                    return true;
                }
            } else {
                /** @noinspection ForeachSourceInspection */
                foreach ($file['error'] as $error) {
                    if (!$onlySuccessful || $error === UPLOAD_ERR_OK) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
157670
public function resolveRelativePath(string $basePath, string $relativePath) : string
    {
        if (strpos($relativePath, 'data://') === 0) {
            return $relativePath;
        }

        list($basePathStreamWrapper, $basePath) = $this->splitStreamWrapperAndPath($basePath);
        list($relativeStreamWrapper, $relativePathWithoutStreamWrapper) = $this->splitStreamWrapperAndPath($relativePath);

        $isAbsolutePath = $relativeStreamWrapper !== null;

        if ($isAbsolutePath) {
            return $relativePath;
        } else {
            $relativePath = $relativePathWithoutStreamWrapper;
        }

        $basePath     = str_replace('\\', '/', $basePath);
        $relativePath = str_replace('\\', '/', $relativePath);

        if (substr($basePath, -1) !== '/') {
            $basePath .= '/';
        }

        if (strpos($relativePath, '.') === false) {
            return ($basePathStreamWrapper ? $basePathStreamWrapper . '://' : '')
            . PathHelper::normalize(str_replace('//', '/', $basePath . '/' . $relativePath));
        }

        $parts          = explode('/', $basePath);
        $relativeParts  = explode('/', trim($relativePath, '/'));
        $isDrivePath    = substr($basePath, 1, 1) === ':';
        $precedingSlash = $basePathStreamWrapper || $isDrivePath ? '' : '/';
        $trailingSlash  = !$basePathStreamWrapper && substr($relativePath, -1) === '/' ? '/' : '';

        foreach ($parts as $key => $part) {
            if ($part === '') {
                unset($parts[$key]);
            }
        }

        foreach ($relativeParts as $part) {
            if ($part === '.') {
                continue;
            } elseif ($part === '..') {
                array_pop($parts);
            } elseif ($part !== '') {
                $parts[] = $part;
            }
        }

        return ($basePathStreamWrapper ? $basePathStreamWrapper . '://' : '')
        . PathHelper::normalize($precedingSlash . implode('/', $parts) . ($parts ? $trailingSlash : ''));
    }
171321
public function deleteFile($containerName, $fileName, $relativePath)
    {
        return $this->fileUploadFacade->deleteFile($containerName, $fileName, $relativePath);
    }
457170
public function fileExists($containerName, $fileName, $relativePath)
    {
        return $this->getFactory()
            ->createStorage($containerName)
            ->fileExists($containerName, $fileName, $relativePath);
    }