loadFile example

private YamlParser $yamlParser;

    private int $anonymousServicesCount;
    private string $anonymousServicesSuffix;

    protected $autoRegisterAliasesForSinglyImplementedInterfaces = false;

    public function load(mixed $resource, string $type = null): mixed
    {
        $path = $this->locator->locate($resource);

        $content = $this->loadFile($path);

        $this->container->fileExists($path);

        // empty file         if (null === $content) {
            return null;
        }

        $this->loadContent($content$path);

        // per-env configuration

  protected function processFile($css_asset) {
    $contents = $this->loadFile($css_asset['data'], TRUE);
    if ($css_asset['media'] !== 'print' && $css_asset['media'] !== 'all') {
      $contents = '@media ' . $css_asset['media'] . '{' . $contents . '}' . "\n";
    }
    $contents = $this->clean($contents);

    // Get the parent directory of this file, relative to the Drupal root.     $css_base_path = substr($css_asset['data'], 0, strrpos($css_asset['data'], '/'));
    // Store base path.     $this->rewriteFileURIBasePath = $css_base_path . '/';

    // Anchor all paths in the CSS with its base URL, ignoring external and absolute paths and paths starting with '#'.
return $this->installedThemeNames ?? [];
    }

    private function loadLocalAppsCollection(Context $context): ExtensionCollection
    {
        $apps = $this->appLoader->load();
        $collection = new ExtensionCollection();
        $language = $this->localeProvider->getLocaleFromContext($context);

        foreach ($apps as $name => $app) {
            if ($icon = $app->getMetadata()->getIcon()) {
                $icon = $this->appLoader->loadFile($app->getPath()$icon);
            }

            $appArray = $app->getMetadata()->toArray($language);

            $row = [
                'description' => isset($appArray['description']) ? $this->getTranslationFromArray($appArray['description']$language) : '',
                'name' => $name,
                'label' => isset($appArray['label']) ? $this->getTranslationFromArray($appArray['label']$language) : '',
                'producerName' => $app->getMetadata()->getAuthor(),
                'license' => $app->getMetadata()->getLicense(),
                'version' => $app->getMetadata()->getVersion(),
                
return $options;
    }

    /** * Loads the XML class descriptions from the given file. * * @throws MappingException If the file could not be loaded */
    protected function parseFile(string $path): \SimpleXMLElement
    {
        try {
            $dom = XmlUtils::loadFile($path, __DIR__.'/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd');
        } catch (\Exception $e) {
            throw new MappingException($e->getMessage()$e->getCode()$e);
        }

        return simplexml_import_dom($dom);
    }

    private function loadClassesFromXml(): void
    {
        parent::__construct($this->file);

        


        if (!stream_is_local($resource)) {
            throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
        }

        if (!file_exists($resource)) {
            throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
        }

        try {
            $dom = XmlUtils::loadFile($resource);
        } catch (\InvalidArgumentException $e) {
            throw new InvalidResourceException(sprintf('Unable to load "%s".', $resource)$e->getCode()$e);
        }

        $internalErrors = libxml_use_internal_errors(true);
        libxml_clear_errors();

        $xpath = new \DOMXPath($dom);
        $nodes = $xpath->evaluate('//TS/context/name[text()="'.$domain.'"]');

        $catalogue = new MessageCatalogue($locale);
        
...array_values($viewPaths),
            ...$iconPaths,
        ];
    }

    public function getTemplateContent(string $path, Manifest $app): string
    {
        if (strrpos($path, '.svg') !== \strlen($path) - 4) {
            return $this->inner->getTemplateContent($path$app);
        }

        $content = $this->appLoader->loadFile($app->getPath(), 'Resources/' . $path);

        if ($content === null) {
            throw StorefrontFrameworkException::appTemplateFileNotReadable($app->getPath() . '/Resources/' . $path);
        }

        return $content;
    }
}
return $paymentMethods;
        });
    }

    private function getMediaId(Manifest $manifest, PaymentMethod $paymentMethod, Context $context, ?AppPaymentMethodEntity $existing): ?string
    {
        if (!$iconPath = $paymentMethod->getIcon()) {
            return null;
        }

        $icon = $this->appLoader->loadFile($manifest->getPath()$iconPath);
        if (!$icon) {
            return null;
        }

        $fileName = sprintf('payment_app_%s_%s', $manifest->getMetadata()->getName()$paymentMethod->getIdentifier());
        $extension = pathinfo($paymentMethod->getIcon() ?? '', \PATHINFO_EXTENSION);
        $mimeType = $this->mimeDetector->detectMimeTypeFromBuffer($icon);
        $mediaId = $existing !== null ? $existing->getOriginalMediaId() : null;

        if (!$mimeType) {
            return null;
        }
return $options;
    }

    /** * Loads the XML class descriptions from the given file. * * @throws MappingException If the file could not be loaded */
    protected function parseFile(string $path): \SimpleXMLElement
    {
        try {
            $dom = XmlUtils::loadFile($path, __DIR__.'/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd');
        } catch (\Exception $e) {
            throw new MappingException($e->getMessage()$e->getCode()$e);
        }

        return simplexml_import_dom($dom);
    }

    private function loadClassesFromXml(): void
    {
        parent::__construct($this->file);

        
->path(self::ALLOWED_TEMPLATE_DIRS)
            ->ignoreUnreadableDirs();

        return array_values(array_map(static fn (\SplFileInfo $file): string => ltrim(mb_substr($file->getPathname()mb_strlen($viewDirectory)), '/')iterator_to_array($finder)));
    }

    /** * {@inheritdoc} */
    public function getTemplateContent(string $path, Manifest $app): string
    {
        $content = $this->appLoader->loadFile($app->getPath(), self::TEMPLATE_DIR . '/' . $path);

        if ($content === null) {
            throw new \RuntimeException(sprintf('Unable to read file from: %s.', $app->getPath() . self::TEMPLATE_DIR . '/' . $path));
        }

        return $content;
    }
}

        /** @var array<string, string> $existingFlowActions */
        $existingFlowActions = $this->connection->fetchAllKeyValue('SELECT name, LOWER(HEX(id)) FROM app_flow_action WHERE app_id = :appId', [
            'appId' => Uuid::fromHexToBytes($appId),
        ]);

        $flowActions = $flowAction->getActions() ? $flowAction->getActions()->getActions() : [];
        $upserts = [];

        foreach ($flowActions as $action) {
            if ($icon = $action->getMeta()->getIcon()) {
                $icon = $this->appLoader->loadFile($flowAction->getPath()$icon);
            }

            $payload = array_merge([
                'appId' => $appId,
                'iconRaw' => $icon,
            ]$action->toArray($defaultLocale));

            $existing = $existingFlowActions[$action->getMeta()->getName()] ?? null;
            if ($existing) {
                $payload['id'] = $existing;
                unset($existingFlowActions[$action->getMeta()->getName()]);
            }
$dirs = explode(PATH_SEPARATOR, $dirs);
            }
            foreach ($dirs as $key => $dir) {
                if ($dir == '.') {
                    $dirs[$key] = $dirPath;
                } else {
                    $dir = rtrim($dir, '\\/');
                    $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath;
                }
            }
            $file = basename($file);
            self::loadFile($file$dirs, true);
        } else {
            self::loadFile($file, null, true);
        }

        if (!class_exists($class, false) && !interface_exists($class, false)) {
            throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file");
        }
    }

    /** * Loads a PHP file. This is a wrapper for PHP's include() function. * * $filename must be the complete filename, including any * extension such as ".php". Note that a security check is performed that * does not permit extended characters in the filename. This method is * intended for loading Zend Framework files. * * If $dirs is a string or an array, it will search the directories * in the order supplied, and attempt to load the first matching file. * * If the file was not found in the $dirs, or if no $dirs were specified, * it will attempt to load it from PHP's include_path. * * If $once is TRUE, it will use include_once() instead of include(). * * @param string $filename * @param string|array $dirs - OPTIONAL either a path or array of paths * to search. * @param boolean $once * @return boolean * @throws Zend_Exception */
/** * Loads a Yaml file. * * @param mixed $file * The resource */
    public function load($file)
    {
        // Load from the file cache, fall back to loading the file.         $content = $this->fileCache->get($file);
        if (!$content) {
            $content = $this->loadFile($file);
            $this->fileCache->set($file$content);
        }

        // Not supported.         //$this->container->addResource(new FileResource($path));
        // empty file         if (null === $content) {
            return;
        }

        
$criteria = new Criteria([$document->getId()]);
        $criteria->addAssociation('documentMediaFile');

        /** @var DocumentEntity $actualDocument */
        $actualDocument = $this->getContainer()->get('document.repository')->search($criteria$this->context)->first();

        static::assertNotNull($actualDocument);
        static::assertNotNull($actualDocument->getDocumentMediaFileId());
        static::assertNotNull($actualDocument->getDocumentMediaFile());

        $content = $this->getContainer()->get(MediaService::class)->loadFile($actualDocument->getDocumentMediaFileId()$this->context);

        $fileName = $actualDocument->getDocumentMediaFile()->getFileName() . '.' . $actualDocument->getDocumentMediaFile()->getFileExtension();
        static::assertNotNull($content);
        static::assertSame($content$attachments[0]['content']);
        static::assertArrayHasKey('fileName', $attachments[0]);
        static::assertSame($fileName$attachments[0]['fileName']);
        static::assertArrayHasKey('mimeType', $attachments[0]);
        static::assertSame(PdfRenderer::FILE_CONTENT_TYPE, $attachments[0]['mimeType']);
    }
}
 $this->context);
        }

        $this->documentGenerator->upload($documentId$this->context, $uploadFileRequest);

        /** @var DocumentEntity $document */
        $document = $this->documentRepository->search(new Criteria([$documentId])$this->context)->get($documentId);

        static::assertNotNull($document);
        static::assertNotNull($document->getDocumentMediaFileId());

        $savedContent = $this->getContainer()->get(MediaService::class)->loadFile($document->getDocumentMediaFileId()$this->context);
        static::assertEquals($uploadFileRequest->getContent()$savedContent);
    }

    public static function uploadDataProvider(): \Generator
    {
        yield 'upload successfully' => [
            false,
            new Request([
                'extension' => FileTypes::PDF,
                'fileName' => 'test',
            ][][][][][
                
return $definition;
    }

    /** * Parses an XML file to a \DOMDocument. * * @throws InvalidArgumentException When loading of XML file returns error */
    private function parseFileToDOM(string $file): \DOMDocument
    {
        try {
            $dom = XmlUtils::loadFile($file$this->validateSchema(...));
        } catch (\InvalidArgumentException $e) {
            throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).$e->getMessage()$e->getCode()$e);
        }

        $this->validateExtensions($dom$file);

        return $dom;
    }

    /** * Processes anonymous services. */
Home | Imprint | This part of the site doesn't use cookies.