Overview

Namespaces

  • FastFeed
    • Aggregator
    • Cache
    • Exception
    • Logger
    • Parser
    • Processor
  • PHP

Classes

  • ImageProcessor
  • ImagesProcessor
  • LimitProcessor
  • PathProcessor
  • RemoveStylesProcessor
  • SanitizerProcessor
  • SortByDateProcessor
  • StripTagsProcessor

Interfaces

  • ProcessorInterface
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * This file is part of the FastFeed package.
 4:  *
 5:  * (c) Daniel González <daniel@desarrolla2.com>
 6:  *
 7:  * For the full copyright and license information, please view the LICENSE
 8:  * file that was distributed with this source code.
 9:  */
10: namespace FastFeed\Processor;
11: 
12: /**
13:  * LimitProcessor
14:  * Set the max number of items in result set
15:  */
16: class LimitProcessor implements ProcessorInterface
17: {
18:     /**
19:      * @var int
20:      */
21:     protected $limit;
22: 
23:     /**
24:      * @param int $limit
25:      */
26:     public function __construct($limit)
27:     {
28:         $this->setLimit($limit);
29:     }
30: 
31:     /**
32:      * Set the max number of items in result set
33:      *
34:      * @param int $limit
35:      */
36:     public function setLimit($limit)
37:     {
38:         $this->limit = (int) $limit;
39:     }
40: 
41:     /**
42:      * @param array $items
43:      *
44:      * @return array
45:      */
46:     public function process(array $items)
47:     {
48:         if (!$this->limit) {
49:             return $items;
50:         }
51:         $total = count($items);
52:         if ($this->limit > $total) {
53:             return $items;
54:         }
55:         for ($i = $this->limit; $i < $total; $i++) {
56:             if (isset($items[$i])) {
57:                 unset ($items[$i]);
58:             }
59:         }
60: 
61:         return $items;
62:     }
63: }
64: 
API documentation generated by ApiGen 2.8.0