Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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\CrossReference\CrossReferenceException;
  14  use setasign\Fpdi\PdfParser\PdfParser;
  15  use setasign\Fpdi\PdfParser\PdfParserException;
  16  
  17  /**
  18   * A class defining a PDF data type
  19   */
  20  class PdfType
  21  {
  22      /**
  23       * Resolves a PdfType value to its value.
  24       *
  25       * This method is used to evaluate indirect and direct object references until a final value is reached.
  26       *
  27       * @param PdfType $value
  28       * @param PdfParser $parser
  29       * @param bool $stopAtIndirectObject
  30       * @return PdfType
  31       * @throws CrossReferenceException
  32       * @throws PdfParserException
  33       */
  34      public static function resolve(PdfType $value, PdfParser $parser, $stopAtIndirectObject = false)
  35      {
  36          if ($value instanceof PdfIndirectObject) {
  37              if ($stopAtIndirectObject === true) {
  38                  return $value;
  39              }
  40  
  41              return self::resolve($value->value, $parser, $stopAtIndirectObject);
  42          }
  43  
  44          if ($value instanceof PdfIndirectObjectReference) {
  45              return self::resolve($parser->getIndirectObject($value->value), $parser, $stopAtIndirectObject);
  46          }
  47  
  48          return $value;
  49      }
  50  
  51      /**
  52       * Ensure that a value is an instance of a specific PDF type.
  53       *
  54       * @param string $type
  55       * @param PdfType $value
  56       * @param string $errorMessage
  57       * @return mixed
  58       * @throws PdfTypeException
  59       */
  60      protected static function ensureType($type, $value, $errorMessage)
  61      {
  62          if (!($value instanceof $type)) {
  63              throw new PdfTypeException(
  64                  $errorMessage,
  65                  PdfTypeException::INVALID_DATA_TYPE
  66              );
  67          }
  68  
  69          return $value;
  70      }
  71  
  72      /**
  73       * The value of the PDF type.
  74       *
  75       * @var mixed
  76       */
  77      public $value;
  78  }