"Fossies" - the Fresh Open Source Software Archive

Member "drupal-9.4.5/vendor/laminas/laminas-feed/src/Writer/AbstractFeed.php" (24 Mar 2022, 24385 Bytes) of package /linux/www/drupal-9.4.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 
    3 namespace Laminas\Feed\Writer;
    4 
    5 use DateTime;
    6 use DateTimeImmutable;
    7 use DateTimeInterface;
    8 use Laminas\Feed\Uri;
    9 use Laminas\Validator;
   10 
   11 use function array_key_exists;
   12 use function date;
   13 use function in_array;
   14 use function is_array;
   15 use function is_int;
   16 use function is_numeric;
   17 use function is_string;
   18 use function preg_match;
   19 use function sprintf;
   20 use function strlen;
   21 use function strtolower;
   22 use function strtotime;
   23 
   24 class AbstractFeed
   25 {
   26     /**
   27      * Contains all Feed level date to append in feed output
   28      *
   29      * @var array
   30      */
   31     protected $data = [];
   32 
   33     /**
   34      * Holds the value "atom" or "rss" depending on the feed type set when
   35      * when last exported.
   36      *
   37      * @var string
   38      */
   39     protected $type;
   40 
   41     /** @var Extension\RendererInterface[] */
   42     protected $extensions;
   43 
   44     /**
   45      * Constructor: Primarily triggers the registration of core extensions and
   46      * loads those appropriate to this data container.
   47      */
   48     public function __construct()
   49     {
   50         Writer::registerCoreExtensions();
   51         $this->_loadExtensions();
   52     }
   53 
   54     /**
   55      * Set a single author
   56      *
   57      * The following option keys are supported:
   58      * 'name'  => (string) The name
   59      * 'email' => (string) An optional email
   60      * 'uri'   => (string) An optional and valid URI
   61      *
   62      * @return $this
   63      * @throws Exception\InvalidArgumentException If any value of $author not follow the format.
   64      */
   65     public function addAuthor(array $author)
   66     {
   67         // Check array values
   68         if (
   69             ! array_key_exists('name', $author)
   70             || empty($author['name'])
   71             || ! is_string($author['name'])
   72         ) {
   73             throw new Exception\InvalidArgumentException(
   74                 'Invalid parameter: author array must include a "name" key with a non-empty string value'
   75             );
   76         }
   77 
   78         if (isset($author['email'])) {
   79             if (empty($author['email']) || ! is_string($author['email'])) {
   80                 throw new Exception\InvalidArgumentException(
   81                     'Invalid parameter: "email" array value must be a non-empty string'
   82                 );
   83             }
   84         }
   85         if (isset($author['uri'])) {
   86             if (
   87                 empty($author['uri'])
   88                 || ! is_string($author['uri'])
   89                 || ! Uri::factory($author['uri'])->isValid()
   90             ) {
   91                 throw new Exception\InvalidArgumentException(
   92                     'Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI'
   93                 );
   94             }
   95         }
   96 
   97         $this->data['authors'][] = $author;
   98 
   99         return $this;
  100     }
  101 
  102     /**
  103      * Set an array with feed authors
  104      *
  105      * @see addAuthor
  106      *
  107      * @return $this
  108      */
  109     public function addAuthors(array $authors)
  110     {
  111         foreach ($authors as $author) {
  112             $this->addAuthor($author);
  113         }
  114 
  115         return $this;
  116     }
  117 
  118     /**
  119      * Set the copyright entry
  120      *
  121      * @param  string $copyright
  122      * @return $this
  123      * @throws Exception\InvalidArgumentException
  124      */
  125     public function setCopyright($copyright)
  126     {
  127         if (empty($copyright) || ! is_string($copyright)) {
  128             throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
  129         }
  130         $this->data['copyright'] = $copyright;
  131 
  132         return $this;
  133     }
  134 
  135     /**
  136      * Set the feed creation date
  137      *
  138      * @param DateTime|DateTimeImmutable|int|null|string $date
  139      * @return self
  140      * @throws Exception\InvalidArgumentException
  141      */
  142     public function setDateCreated($date = null)
  143     {
  144         if ($date === null) {
  145             $date = new DateTime();
  146         }
  147         if (is_int($date)) {
  148             $date = new DateTime('@' . $date);
  149         }
  150         if (! $date instanceof DateTimeInterface) {
  151             throw new Exception\InvalidArgumentException(
  152                 'Invalid DateTime object or UNIX Timestamp passed as parameter'
  153             );
  154         }
  155         $this->data['dateCreated'] = $date;
  156 
  157         return $this;
  158     }
  159 
  160     /**
  161      * Set the feed modification date
  162      *
  163      * @param DateTime|DateTimeImmutable|int|null|string $date
  164      * @return self
  165      * @throws Exception\InvalidArgumentException
  166      */
  167     public function setDateModified($date = null)
  168     {
  169         if ($date === null) {
  170             $date = new DateTime();
  171         }
  172         if (is_int($date)) {
  173             $date = new DateTime('@' . $date);
  174         }
  175         if (! $date instanceof DateTimeInterface) {
  176             throw new Exception\InvalidArgumentException(
  177                 'Invalid DateTime object or UNIX Timestamp passed as parameter'
  178             );
  179         }
  180         $this->data['dateModified'] = $date;
  181 
  182         return $this;
  183     }
  184 
  185     /**
  186      * Set the feed last-build date. Ignored for Atom 1.0.
  187      *
  188      * @param DateTime|DateTimeImmutable|int|null|string $date
  189      * @return self
  190      * @throws Exception\InvalidArgumentException
  191      */
  192     public function setLastBuildDate($date = null)
  193     {
  194         if ($date === null) {
  195             $date = new DateTime();
  196         }
  197         if (is_int($date)) {
  198             $date = new DateTime('@' . $date);
  199         }
  200         if (! $date instanceof DateTimeInterface) {
  201             throw new Exception\InvalidArgumentException(
  202                 'Invalid DateTime object or UNIX Timestamp passed as parameter'
  203             );
  204         }
  205         $this->data['lastBuildDate'] = $date;
  206 
  207         return $this;
  208     }
  209 
  210     /**
  211      * Set the feed description
  212      *
  213      * @param  string $description
  214      * @return $this
  215      * @throws Exception\InvalidArgumentException
  216      */
  217     public function setDescription($description)
  218     {
  219         if (empty($description) || ! is_string($description)) {
  220             throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
  221         }
  222         $this->data['description'] = $description;
  223 
  224         return $this;
  225     }
  226 
  227     /**
  228      * Set the feed generator entry
  229      *
  230      * @param  array|string $name
  231      * @param  null|string $version
  232      * @param  null|string $uri
  233      * @return $this
  234      * @throws Exception\InvalidArgumentException
  235      */
  236     public function setGenerator($name, $version = null, $uri = null)
  237     {
  238         if (is_array($name)) {
  239             $data = $name;
  240             if (empty($data['name']) || ! is_string($data['name'])) {
  241                 throw new Exception\InvalidArgumentException('Invalid parameter: "name" must be a non-empty string');
  242             }
  243             $generator = ['name' => $data['name']];
  244             if (isset($data['version'])) {
  245                 if (empty($data['version']) || ! is_string($data['version'])) {
  246                     throw new Exception\InvalidArgumentException(
  247                         'Invalid parameter: "version" must be a non-empty string'
  248                     );
  249                 }
  250                 $generator['version'] = $data['version'];
  251             }
  252             if (isset($data['uri'])) {
  253                 if (empty($data['uri']) || ! is_string($data['uri']) || ! Uri::factory($data['uri'])->isValid()) {
  254                     throw new Exception\InvalidArgumentException(
  255                         'Invalid parameter: "uri" must be a non-empty string and a valid URI/IRI'
  256                     );
  257                 }
  258                 $generator['uri'] = $data['uri'];
  259             }
  260         } else {
  261             if (empty($name) || ! is_string($name)) {
  262                 throw new Exception\InvalidArgumentException('Invalid parameter: "name" must be a non-empty string');
  263             }
  264             $generator = ['name' => $name];
  265             if (isset($version)) {
  266                 if (empty($version) || ! is_string($version)) {
  267                     throw new Exception\InvalidArgumentException(
  268                         'Invalid parameter: "version" must be a non-empty string'
  269                     );
  270                 }
  271                 $generator['version'] = $version;
  272             }
  273             if (isset($uri)) {
  274                 if (empty($uri) || ! is_string($uri) || ! Uri::factory($uri)->isValid()) {
  275                     throw new Exception\InvalidArgumentException(
  276                         'Invalid parameter: "uri" must be a non-empty string and a valid URI/IRI'
  277                     );
  278                 }
  279                 $generator['uri'] = $uri;
  280             }
  281         }
  282         $this->data['generator'] = $generator;
  283 
  284         return $this;
  285     }
  286 
  287     /**
  288      * Set the feed ID - URI or URN (via PCRE pattern) supported
  289      *
  290      * @param  string $id
  291      * @return $this
  292      * @throws Exception\InvalidArgumentException
  293      */
  294     public function setId($id)
  295     {
  296         // phpcs:disable Generic.Files.LineLength.TooLong
  297         if (
  298             (empty($id) || ! is_string($id) || ! Uri::factory($id)->isValid())
  299             && ! preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", $id)
  300             && ! $this->_validateTagUri($id)
  301         ) {
  302             throw new Exception\InvalidArgumentException(
  303                 'Invalid parameter: parameter must be a non-empty string and valid URI/IRI'
  304             );
  305         }
  306         // phpcs:enable Generic.Files.LineLength.TooLong
  307 
  308         $this->data['id'] = $id;
  309 
  310         return $this;
  311     }
  312 
  313     /**
  314      * Set a feed image (URI at minimum). Parameter is a single array with the
  315      * required key 'uri'. When rendering as RSS, the required keys are 'uri',
  316      * 'title' and 'link'. RSS also specifies three optional parameters 'width',
  317      * 'height' and 'description'. Only 'uri' is required and used for Atom rendering.
  318      *
  319      * @return $this
  320      * @throws Exception\InvalidArgumentException
  321      */
  322     public function setImage(array $data)
  323     {
  324         if (
  325             empty($data['uri']) || ! is_string($data['uri'])
  326             || ! Uri::factory($data['uri'])->isValid()
  327         ) {
  328             throw new Exception\InvalidArgumentException(
  329                 'Invalid parameter: parameter \'uri\' must be a non-empty string and valid URI/IRI'
  330             );
  331         }
  332         $this->data['image'] = $data;
  333 
  334         return $this;
  335     }
  336 
  337     /**
  338      * Set the feed language
  339      *
  340      * @param  string $language
  341      * @return $this
  342      * @throws Exception\InvalidArgumentException
  343      */
  344     public function setLanguage($language)
  345     {
  346         if (empty($language) || ! is_string($language)) {
  347             throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
  348         }
  349         $this->data['language'] = $language;
  350 
  351         return $this;
  352     }
  353 
  354     /**
  355      * Set a link to the HTML source
  356      *
  357      * @param  string $link
  358      * @return $this
  359      * @throws Exception\InvalidArgumentException
  360      */
  361     public function setLink($link)
  362     {
  363         if (empty($link) || ! is_string($link) || ! Uri::factory($link)->isValid()) {
  364             throw new Exception\InvalidArgumentException(
  365                 'Invalid parameter: parameter must be a non-empty string and valid URI/IRI'
  366             );
  367         }
  368         $this->data['link'] = $link;
  369 
  370         return $this;
  371     }
  372 
  373     /**
  374      * Set a link to an XML feed for any feed type/version
  375      *
  376      * @param  string $link
  377      * @param  string $type
  378      * @return $this
  379      * @throws Exception\InvalidArgumentException
  380      */
  381     public function setFeedLink($link, $type)
  382     {
  383         if (empty($link) || ! is_string($link) || ! Uri::factory($link)->isValid()) {
  384             throw new Exception\InvalidArgumentException(
  385                 'Invalid parameter: "link"" must be a non-empty string and valid URI/IRI'
  386             );
  387         }
  388         if (! in_array(strtolower($type), ['rss', 'rdf', 'atom'])) {
  389             throw new Exception\InvalidArgumentException(
  390                 'Invalid parameter: "type"; You must declare the type of feed the link points to, i.e. RSS, RDF or Atom'
  391             );
  392         }
  393         $this->data['feedLinks'][strtolower($type)] = $link;
  394 
  395         return $this;
  396     }
  397 
  398     /**
  399      * Set the feed title
  400      *
  401      * @param  string $title
  402      * @return $this
  403      * @throws Exception\InvalidArgumentException
  404      */
  405     public function setTitle($title)
  406     {
  407         if ((empty($title) && ! is_numeric($title)) || ! is_string($title)) {
  408             throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
  409         }
  410         $this->data['title'] = $title;
  411 
  412         return $this;
  413     }
  414 
  415     /**
  416      * Set the feed character encoding
  417      *
  418      * @param  string $encoding
  419      * @return $this
  420      * @throws Exception\InvalidArgumentException
  421      */
  422     public function setEncoding($encoding)
  423     {
  424         if (empty($encoding) || ! is_string($encoding)) {
  425             throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
  426         }
  427         $this->data['encoding'] = $encoding;
  428 
  429         return $this;
  430     }
  431 
  432     /**
  433      * Set the feed's base URL
  434      *
  435      * @param  string $url
  436      * @return $this
  437      * @throws Exception\InvalidArgumentException
  438      */
  439     public function setBaseUrl($url)
  440     {
  441         if (empty($url) || ! is_string($url) || ! Uri::factory($url)->isValid()) {
  442             throw new Exception\InvalidArgumentException(
  443                 'Invalid parameter: "url" array value must be a non-empty string and valid URI/IRI'
  444             );
  445         }
  446         $this->data['baseUrl'] = $url;
  447 
  448         return $this;
  449     }
  450 
  451     /**
  452      * Add a Pubsubhubbub hub endpoint URL
  453      *
  454      * @param  string $url
  455      * @return $this
  456      * @throws Exception\InvalidArgumentException
  457      */
  458     public function addHub($url)
  459     {
  460         if (empty($url) || ! is_string($url) || ! Uri::factory($url)->isValid()) {
  461             throw new Exception\InvalidArgumentException(
  462                 'Invalid parameter: "url" array value must be a non-empty string and valid URI/IRI'
  463             );
  464         }
  465         if (! isset($this->data['hubs'])) {
  466             $this->data['hubs'] = [];
  467         }
  468         $this->data['hubs'][] = $url;
  469 
  470         return $this;
  471     }
  472 
  473     /**
  474      * Add Pubsubhubbub hub endpoint URLs
  475      *
  476      * @return $this
  477      */
  478     public function addHubs(array $urls)
  479     {
  480         foreach ($urls as $url) {
  481             $this->addHub($url);
  482         }
  483 
  484         return $this;
  485     }
  486 
  487     /**
  488      * Add a feed category
  489      *
  490      * @return $this
  491      * @throws Exception\InvalidArgumentException
  492      */
  493     public function addCategory(array $category)
  494     {
  495         if (! isset($category['term'])) {
  496             throw new Exception\InvalidArgumentException(
  497                 'Each category must be an array and contain at least a "term" element'
  498                 . ' containing the machine readable category name'
  499             );
  500         }
  501         if (isset($category['scheme'])) {
  502             if (
  503                 empty($category['scheme'])
  504                 || ! is_string($category['scheme'])
  505                 || ! Uri::factory($category['scheme'])->isValid()
  506             ) {
  507                 throw new Exception\InvalidArgumentException(
  508                     'The Atom scheme or RSS domain of a category must be a valid URI'
  509                 );
  510             }
  511         }
  512         if (! isset($this->data['categories'])) {
  513             $this->data['categories'] = [];
  514         }
  515         $this->data['categories'][] = $category;
  516 
  517         return $this;
  518     }
  519 
  520     /**
  521      * Set an array of feed categories
  522      *
  523      * @return $this
  524      */
  525     public function addCategories(array $categories)
  526     {
  527         foreach ($categories as $category) {
  528             $this->addCategory($category);
  529         }
  530 
  531         return $this;
  532     }
  533 
  534     /**
  535      * Get a single author
  536      *
  537      * @param  int $index
  538      * @return null|string
  539      */
  540     public function getAuthor($index = 0)
  541     {
  542         if (isset($this->data['authors'][$index])) {
  543             return $this->data['authors'][$index];
  544         }
  545 
  546         return null;
  547     }
  548 
  549     /**
  550      * Get an array with feed authors
  551      *
  552      * @return null|array
  553      */
  554     public function getAuthors()
  555     {
  556         if (! array_key_exists('authors', $this->data)) {
  557             return null;
  558         }
  559 
  560         return $this->data['authors'];
  561     }
  562 
  563     /**
  564      * Get the copyright entry
  565      *
  566      * @return null|string
  567      */
  568     public function getCopyright()
  569     {
  570         if (! array_key_exists('copyright', $this->data)) {
  571             return null;
  572         }
  573 
  574         return $this->data['copyright'];
  575     }
  576 
  577     /**
  578      * Get the feed creation date
  579      *
  580      * @return null|string
  581      */
  582     public function getDateCreated()
  583     {
  584         if (! array_key_exists('dateCreated', $this->data)) {
  585             return null;
  586         }
  587 
  588         return $this->data['dateCreated'];
  589     }
  590 
  591     /**
  592      * Get the feed modification date
  593      *
  594      * @return null|string
  595      */
  596     public function getDateModified()
  597     {
  598         if (! array_key_exists('dateModified', $this->data)) {
  599             return null;
  600         }
  601 
  602         return $this->data['dateModified'];
  603     }
  604 
  605     /**
  606      * Get the feed last-build date
  607      *
  608      * @return null|string
  609      */
  610     public function getLastBuildDate()
  611     {
  612         if (! array_key_exists('lastBuildDate', $this->data)) {
  613             return null;
  614         }
  615 
  616         return $this->data['lastBuildDate'];
  617     }
  618 
  619     /**
  620      * Get the feed description
  621      *
  622      * @return null|string
  623      */
  624     public function getDescription()
  625     {
  626         if (! array_key_exists('description', $this->data)) {
  627             return null;
  628         }
  629 
  630         return $this->data['description'];
  631     }
  632 
  633     /**
  634      * Get the feed generator entry
  635      *
  636      * @return null|string
  637      */
  638     public function getGenerator()
  639     {
  640         if (! array_key_exists('generator', $this->data)) {
  641             return null;
  642         }
  643 
  644         return $this->data['generator'];
  645     }
  646 
  647     /**
  648      * Get the feed ID
  649      *
  650      * @return null|string
  651      */
  652     public function getId()
  653     {
  654         if (! array_key_exists('id', $this->data)) {
  655             return null;
  656         }
  657 
  658         return $this->data['id'];
  659     }
  660 
  661     /**
  662      * Get the feed image URI
  663      *
  664      * @return null|array
  665      */
  666     public function getImage()
  667     {
  668         if (! array_key_exists('image', $this->data)) {
  669             return null;
  670         }
  671 
  672         return $this->data['image'];
  673     }
  674 
  675     /**
  676      * Get the feed language
  677      *
  678      * @return null|string
  679      */
  680     public function getLanguage()
  681     {
  682         if (! array_key_exists('language', $this->data)) {
  683             return null;
  684         }
  685 
  686         return $this->data['language'];
  687     }
  688 
  689     /**
  690      * Get a link to the HTML source
  691      *
  692      * @return null|string
  693      */
  694     public function getLink()
  695     {
  696         if (! array_key_exists('link', $this->data)) {
  697             return null;
  698         }
  699 
  700         return $this->data['link'];
  701     }
  702 
  703     /**
  704      * Get a link to the XML feed
  705      *
  706      * @return null|string
  707      */
  708     public function getFeedLinks()
  709     {
  710         if (! array_key_exists('feedLinks', $this->data)) {
  711             return null;
  712         }
  713         return $this->data['feedLinks'];
  714     }
  715 
  716     /**
  717      * Get the feed title
  718      *
  719      * @return null|string
  720      */
  721     public function getTitle()
  722     {
  723         if (! array_key_exists('title', $this->data)) {
  724             return null;
  725         }
  726 
  727         return $this->data['title'];
  728     }
  729 
  730     /**
  731      * Get the feed character encoding
  732      *
  733      * @return null|string
  734      */
  735     public function getEncoding()
  736     {
  737         if (! array_key_exists('encoding', $this->data)) {
  738             return 'UTF-8';
  739         }
  740 
  741         return $this->data['encoding'];
  742     }
  743 
  744     /**
  745      * Get the feed's base url
  746      *
  747      * @return null|string
  748      */
  749     public function getBaseUrl()
  750     {
  751         if (! array_key_exists('baseUrl', $this->data)) {
  752             return null;
  753         }
  754 
  755         return $this->data['baseUrl'];
  756     }
  757 
  758     /**
  759      * Get the URLs used as Pubsubhubbub hubs endpoints
  760      *
  761      * @return null|string
  762      */
  763     public function getHubs()
  764     {
  765         if (! array_key_exists('hubs', $this->data)) {
  766             return null;
  767         }
  768 
  769         return $this->data['hubs'];
  770     }
  771 
  772     /**
  773      * Get the feed categories
  774      *
  775      * @return null|string
  776      */
  777     public function getCategories()
  778     {
  779         if (! array_key_exists('categories', $this->data)) {
  780             return null;
  781         }
  782 
  783         return $this->data['categories'];
  784     }
  785 
  786     /**
  787      * Resets the instance and deletes all data
  788      *
  789      * @return void
  790      */
  791     public function reset()
  792     {
  793         $this->data = [];
  794     }
  795 
  796     /**
  797      * Set the current feed type being exported to "rss" or "atom". This allows
  798      * other objects to gracefully choose whether to execute or not, depending
  799      * on their appropriateness for the current type, e.g. renderers.
  800      *
  801      * @param  string $type
  802      * @return $this
  803      */
  804     public function setType($type)
  805     {
  806         $this->type = $type;
  807         return $this;
  808     }
  809 
  810     /**
  811      * Retrieve the current or last feed type exported.
  812      *
  813      * @return string Value will be "rss" or "atom"
  814      */
  815     public function getType()
  816     {
  817         return $this->type;
  818     }
  819 
  820     /**
  821      * Unset a specific data point
  822      *
  823      * @param  string $name
  824      * @return $this
  825      */
  826     public function remove($name)
  827     {
  828         if (isset($this->data[$name])) {
  829             unset($this->data[$name]);
  830         }
  831         return $this;
  832     }
  833 
  834     /**
  835      * Method overloading: call given method on first extension implementing it
  836      *
  837      * @param  string $method
  838      * @param  array $args
  839      * @return mixed
  840      * @throws Exception\BadMethodCallException If no extensions implements the method.
  841      */
  842     public function __call($method, $args)
  843     {
  844         foreach ($this->extensions as $extension) {
  845             try {
  846                 $callback = [$extension, $method];
  847                 return $callback(...$args);
  848             } catch (Exception\BadMethodCallException $e) {
  849             }
  850         }
  851         throw new Exception\BadMethodCallException(
  852             'Method: ' . $method . ' does not exist and could not be located on a registered Extension'
  853         );
  854     }
  855 
  856     // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
  857 
  858     /**
  859      * Validate a URI using the tag scheme (RFC 4151)
  860      *
  861      * @param  string $id
  862      * @return bool
  863      */
  864     protected function _validateTagUri($id)
  865     {
  866         if (
  867             preg_match(
  868                 '/^tag:(?P<name>.*),(?P<date>\d{4}-?\d{0,2}-?\d{0,2}):(?P<specific>.*)(.*:)*$/',
  869                 $id,
  870                 $matches
  871             )
  872         ) {
  873             $dvalid = false;
  874             $date   = $matches['date'];
  875             $d6     = strtotime($date);
  876             if ((strlen($date) === 4) && $date <= date('Y')) {
  877                 $dvalid = true;
  878             } elseif ((strlen($date) === 7) && ($d6 < strtotime('now'))) {
  879                 $dvalid = true;
  880             } elseif ((strlen($date) === 10) && ($d6 < strtotime('now'))) {
  881                 $dvalid = true;
  882             }
  883             $validator = new Validator\EmailAddress();
  884             if ($validator->isValid($matches['name'])) {
  885                 $nvalid = true;
  886             } else {
  887                 $nvalid = $validator->isValid('info@' . $matches['name']);
  888             }
  889             return $dvalid && $nvalid;
  890         }
  891         return false;
  892     }
  893 
  894     /**
  895      * Load extensions from Laminas\Feed\Writer\Writer
  896      *
  897      * @throws Exception\RuntimeException
  898      * @return void
  899      */
  900     protected function _loadExtensions()
  901     {
  902         $all     = Writer::getExtensions();
  903         $manager = Writer::getExtensionManager();
  904         $exts    = $all['feed'];
  905         foreach ($exts as $ext) {
  906             if (! $manager->has($ext)) {
  907                 throw new Exception\RuntimeException(
  908                     sprintf('Unable to load extension "%s"; could not resolve to class', $ext)
  909                 );
  910             }
  911             $this->extensions[$ext] = $manager->get($ext);
  912             $this->extensions[$ext]->setEncoding($this->getEncoding());
  913         }
  914     }
  915 
  916     // phpcs:enable PSR2.Methods.MethodDeclaration.Underscore
  917 }