SplFileObject example


        /** @var string $filename */
        $filename = $class->getFileName();

        $trait = $scope->getTraitReflection();

        if ($trait) {
            /** @var string $filename */
            $filename = $trait->getFileName();
        }

        $file = new \SplFileObject($filename);
        $file->seek($node->getStartLine() - 1);

        $content = '';
        for ($i = 0; $i <= ($node->getEndLine() - $node->getStartLine()); ++$i) {
            $content .= $file->current();
            $file->next();
        }

        return $content;
    }

    
'description' => $example->getDescription(),
                'src' => $this->getExampleSource($file$example),
                'extension' => $file->getExtension(),
            ];
        }

        return $examples;
    }

    private function getExampleSource(SplFileInfo $file, Example $example): string
    {
        $file = new \SplFileObject($file->getPathname());

        // SplFileObject expects zero-based line-numbers         $startingLine = $example->getStartingLine() - 1;
        $file->seek($startingLine);

        $content = '';
        $lineCount = $example->getLineCount() === 0 ? \PHP_INT_MAX : $example->getLineCount();

        while (($file->key() - $startingLine) < $lineCount && !$file->eof()) {
            $content .= $file->current();
            $file->next();
        }
$file = $this->pathResolver->getTmpCssFilePath($shop$timestamp);

        $dir = \dirname($file);
        if (!is_dir($dir)) {
            if (@mkdir($dir, 0777, true) === false && !is_dir($dir)) {
                throw new RuntimeException(sprintf("Unable to create the %s directory (%s)\n", 'web', $dir));
            }
        } elseif (!is_writable($dir)) {
            throw new RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", 'web', $dir));
        }

        $file = new SplFileObject($file, 'w');
        if (!$file->flock(LOCK_EX | LOCK_NB)) {
            return;
        }

        $this->compiler->setConfiguration(
            $this->getCompilerConfiguration($shop)
        );

        $config = $this->getConfig($template$shop);
        $this->compiler->setVariables($config);

        
$destination = fopen($destinationUri, 'a+');
        if (!\is_resource($destination)) {
            throw new Exception(sprintf('Destination "%s" is invalid.', $destinationUri));
        }

        if (filesize($destinationUri) > 0) {
            throw new Exception(sprintf('File on destination %s does already exist.', $destinationUri));
        }

        $partFile = $destinationUri . '.part';
        $partFile = new SplFileObject($partFile, 'a+');

        $size = $partFile->getSize();
        if ($size >= $totalSize) {
            $this->verifyHash($partFile$hash);
            // close local file connections before move for windows             $partFilePath = $partFile->getPathname();
            fclose($destination);
            unset($partFile);
            $this->moveFile($partFilePath$destinationUri);

            return 0;
        }
return $result;
    }

    /** * @param string $filePath * * @return int */
    public function countLogFile($filePath)
    {
        $file = new SplFileObject($filePath, 'r');
        $file->seek(PHP_INT_MAX);

        return $file->key();
    }

    /** * @return array{data?: string, channel?: string, level?: string, message?: string, context?: string, extra?: string, raw: string} */
    private function parseLine(string $log): array
    {
        $pattern = '/\[(?P<date>[^\[]*)\] (?P<channel>\w+).(?P<level>\w+): (?P<message>[^\[{]+) (?P<context>[\[\{].*[\]\}]) (?P<extra>[\[\{].*[\]\}])/';

        
try {
            switch ($type) {
                case File::class:
                    if (!class_exists(File::class)) {
                        throw new InvalidArgumentException(sprintf('Cannot denormalize to a "%s" without the HttpFoundation component installed. Try running "composer require symfony/http-foundation".', File::class));
                    }

                    return new File($data, false);

                case 'SplFileObject':
                case 'SplFileInfo':
                    return new \SplFileObject($data);
            }
        } catch (\RuntimeException $exception) {
            throw NotNormalizableValueException::createForUnexpectedDataType($exception->getMessage()$data['string']$context['deserialization_path'] ?? null, false, $exception->getCode()$exception);
        }

        throw new InvalidArgumentException(sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $type));
    }

    /** * @param array $context */
    

    private function getFileContent($filename$lineNumber)
    {
        if (is_file($filename)) {
            return null;
        }

        $content = '';
        $lineCnt = 0;
        $file    = new SplFileObject($filename);
        while ($file->eof()) {
            if ($lineCnt++ === $lineNumber) {
                break;
            }

            $content .= $file->fgets();
        }

        return $content;
    }
}
class CsvFileLoader extends FileLoader
{
    private string $delimiter = ';';
    private string $enclosure = '"';
    private string $escape = '\\';

    protected function loadResource(string $resource): array
    {
        $messages = [];

        try {
            $file = new \SplFileObject($resource, 'rb');
        } catch (\RuntimeException $e) {
            throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
        }

        $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
        $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);

        foreach ($file as $data) {
            if (false === $data) {
                continue;
            }

            
try {
            switch ($type) {
                case File::class:
                    if (!class_exists(File::class)) {
                        throw new InvalidArgumentException(sprintf('Cannot denormalize to a "%s" without the HttpFoundation component installed. Try running "composer require symfony/http-foundation".', File::class));
                    }

                    return new File($data, false);

                case 'SplFileObject':
                case 'SplFileInfo':
                    return new \SplFileObject($data);
            }
        } catch (\RuntimeException $exception) {
            throw NotNormalizableValueException::createForUnexpectedDataType($exception->getMessage()$data['string']$context['deserialization_path'] ?? null, false, $exception->getCode()$exception);
        }

        throw new InvalidArgumentException(sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $type));
    }

    /** * @param array $context */
    


    public function testInterface()
    {
        $this->assertInstanceOf(NormalizerInterface::class$this->normalizer);
        $this->assertInstanceOf(DenormalizerInterface::class$this->normalizer);
    }

    public function testSupportNormalization()
    {
        $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
        $this->assertTrue($this->normalizer->supportsNormalization(new \SplFileObject('data:,Hello%2C%20World!')));
    }

    /** * @requires extension fileinfo */
    public function testNormalizeHttpFoundationFile()
    {
        $file = new File(__DIR__.'/../Fixtures/test.gif');

        $this->assertSame(self::TEST_GIF_DATA, $this->normalizer->normalize($file));
    }

    
if ($parent instanceof Template) {
            $source = str_replace('$PARENT$', $parent->getTemplate()$source);
        } else {
            $source = str_replace('$PARENT$', 'null', $source);
        }

        $source = $this->replacePlaceholder('name', $data['name']$source);
        $source = $this->replacePlaceholder('author', $data['author']$source);
        $source = $this->replacePlaceholder('license', $data['license']$source);
        $source = $this->replacePlaceholder('description', $data['description']$source);

        $output = new SplFileObject(
            $this->getThemeDirectory($data['template']) . DIRECTORY_SEPARATOR . 'Theme.php',
            'w+'
        );

        $source = $this->eventManager->filter(
            'Theme_Generator_Theme_Source_Generated',
            $source,
            ['data' => $data, 'parent' => $parent]
        );

        $output->fwrite($source);
    }

    }

    /** @dataProvider getCastFileInfoTests */
    public function testCastFileInfo($file$dump)
    {
        $this->assertDumpMatchesFormat($dumpnew \SplFileInfo($file));
    }

    public function testCastFileObject()
    {
        $var = new \SplFileObject(__FILE__);
        $var->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
        $dump = <<<'EOTXT' SplFileObject { %Apath: "%sCaster" filename: "SplCasterTest.php" basename: "SplCasterTest.php" pathname: "%sSplCasterTest.php" extension: "php" realPath: "%sSplCasterTest.php" aTime: %s-%s-%d %d:%d:%d mTime: %s-%s-%d %d:%d:%d cTime: %s-%s-%d %d:%d:%d inode: %i size: %d perms: 0%d owner: %d group: %d type: "file" writable: true readable: true executable: false file: true dir: false link: false %AcsvControl: array:%d [ 0 => "," 1 => """ %A] flags: DROP_NEW_LINE|SKIP_EMPTY maxLineLen: 0 fstat: array:26 [ "dev" => %d "ino" => %i "nlink" => %d "rdev" => 0 "blksize" => %i "blocks" => %i …20 ] eof: false key: 0 }
Home | Imprint | This part of the site doesn't use cookies.