Differences Between: [Versions 310 and 311] [Versions 39 and 311]
1 <?php 2 3 /** 4 * This file is part of FPDI 5 * 6 * @package setasign\Fpdi 7 * @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com) 8 * @license http://opensource.org/licenses/mit-license The MIT License 9 */ 10 11 namespace setasign\Fpdi\PdfParser\Type; 12 13 use setasign\Fpdi\PdfParser\PdfParser; 14 use setasign\Fpdi\PdfParser\Tokenizer; 15 16 /** 17 * Class representing a PDF array object 18 * 19 * @property array $value The value of the PDF type. 20 */ 21 class PdfArray extends PdfType 22 { 23 /** 24 * Parses an array of the passed tokenizer and parser. 25 * 26 * @param Tokenizer $tokenizer 27 * @param PdfParser $parser 28 * @return bool|self 29 * @throws PdfTypeException 30 */ 31 public static function parse(Tokenizer $tokenizer, PdfParser $parser) 32 { 33 $result = []; 34 35 // Recurse into this function until we reach the end of the array. 36 while (($token = $tokenizer->getNextToken()) !== ']') { 37 if ($token === false || ($value = $parser->readValue($token)) === false) { 38 return false; 39 } 40 41 $result[] = $value; 42 } 43 44 $v = new self(); 45 $v->value = $result; 46 47 return $v; 48 } 49 50 /** 51 * Helper method to create an instance. 52 * 53 * @param PdfType[] $values 54 * @return self 55 */ 56 public static function create(array $values = []) 57 { 58 $v = new self(); 59 $v->value = $values; 60 61 return $v; 62 } 63 64 /** 65 * Ensures that the passed array is a PdfArray instance with a (optional) specific size. 66 * 67 * @param mixed $array 68 * @param null|int $size 69 * @return self 70 * @throws PdfTypeException 71 */ 72 public static function ensure($array, $size = null) 73 { 74 $result = PdfType::ensureType(self::class, $array, 'Array value expected.'); 75 76 if ($size !== null && \count($array->value) !== $size) { 77 throw new PdfTypeException( 78 \sprintf('Array with %s entries expected.', $size), 79 PdfTypeException::INVALID_DATA_SIZE 80 ); 81 } 82 83 return $result; 84 } 85 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body