1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @file DbUpdatesFeedOpts.php |
||
5 | * @brief This file contains the DbUpdatesFeedOpts class. |
||
6 | * @details |
||
7 | * @author Filippo F. Fadda |
||
8 | */ |
||
9 | |||
10 | |||
11 | namespace EoC\Opt; |
||
12 | |||
13 | |||
14 | /** |
||
15 | * @brief To change the feed type, set a different timeout, etc, you can create a DbUpdatesFeedOpts instance and pass |
||
16 | * it as parameter to the Couch::getDbUpdates() method. |
||
17 | * @nosubgrouping |
||
18 | * @see http://docs.couchdb.org/en/latest/changes.html#changes |
||
19 | */ |
||
20 | class DbUpdatesFeedOpts extends AbstractOpts { |
||
21 | |||
22 | //! Period in seconds to wait for a change before the response is sent, even if there are no results. |
||
23 | const DEFAULT_TIMEOUT = 60; |
||
24 | |||
25 | /** @name Feed Types */ |
||
26 | //!@{ |
||
0 ignored issues
–
show
|
|||
27 | |||
28 | /** |
||
29 | * @brief Long polling mode. |
||
30 | * @details The longpoll feed (probably most useful used from a browser) is a more efficient form of polling that waits |
||
31 | * for a change to occur before the response is sent. Longpoll avoids the need to frequently poll CouchDB to discover |
||
32 | * nothing has changed. |
||
33 | */ |
||
34 | const LONGPOLL_TYPE = "longpoll"; |
||
35 | |||
36 | /** |
||
37 | * @brief Continuous (non-polling) mode. |
||
38 | * @details Polling the CouchDB server is not a good thing to do. Setting up new HTTP connections just to tell the |
||
39 | * client that nothing happened puts unnecessary strain on CouchDB. |
||
40 | * A continuous feed stays open and connected to the database until explicitly closed and changes are sent to the |
||
41 | * client as they happen, i.e. in near real-time. |
||
42 | */ |
||
43 | const CONTINUOUS_TYPE = "continuous"; |
||
44 | |||
45 | /** |
||
46 | * @brief The eventsource feed provides push notifications that can be consumed in the form of DOM events in the browser. |
||
47 | * @see http://www.w3.org/TR/eventsource/ |
||
48 | */ |
||
49 | const EVENTSOURCE_TYPE = "eventsource"; |
||
50 | |||
51 | //!@} |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
100% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
52 | |||
53 | |||
54 | private static $supportedTypes = array( // Cannot use [] syntax otherwise Doxygen generates a warning. |
||
55 | self::LONGPOLL_TYPE => NULL, |
||
56 | self::CONTINUOUS_TYPE => NULL, |
||
57 | self::EVENTSOURCE_TYPE => NULL |
||
58 | ); |
||
59 | |||
60 | |||
61 | /** |
||
62 | * @brief Sets the type of feed. |
||
63 | * @param string $type Type of feed. |
||
64 | */ |
||
65 | public function setFeedType($type) { |
||
66 | if (array_key_exists($type, self::$supportedTypes)) |
||
67 | $this->options["feed"] = $type; |
||
68 | else |
||
69 | throw new \InvalidArgumentException("Invalid feed type."); |
||
70 | |||
71 | return $this; |
||
72 | } |
||
73 | |||
74 | |||
75 | /** |
||
76 | * @brief Maximum period in seconds to wait for a change before the response is sent, even if there are no results. |
||
77 | * @details Note that 60 is also the default maximum timeout to prevent undetected dead connections. |
||
78 | * @param integer $timeout Maximum period to wait before the response is sent. Must be a positive integer. |
||
79 | * @warning Only applicable for `continuous` feeds. |
||
80 | */ |
||
81 | public function setTimeout($timeout = self::DEFAULT_TIMEOUT) { |
||
82 | $feed = $this->options['feed']; |
||
83 | |||
84 | if ($feed == self::CONTINUOUS_TYPE) |
||
85 | if (is_int($timeout) && ($timeout > 0)) |
||
86 | $this->options["timeout"] = $timeout; |
||
87 | else |
||
88 | throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
||
89 | |||
90 | return $this; |
||
91 | } |
||
92 | |||
93 | |||
94 | /** |
||
95 | * @brief An empty line is emitted, by default, when the timeout occurs to maintain the connection active. Using this |
||
96 | * option the connection ends on timeout. |
||
97 | */ |
||
98 | public function doNotKeepAlive() { |
||
99 | $this->options["heartbeat"] = 'false'; |
||
100 | return $this; |
||
101 | } |
||
102 | |||
103 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.