AbstractPurger.php
175 lines
| 1 | <?php //@phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase |
| 2 | /** |
| 3 | * ArubaHiSpeedCacheWpPurger |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category Wordpress-plugin |
| 7 | * @package Aruba-HiSpeed-Cache |
| 8 | * @author Aruba Developer <hispeedcache.developer@aruba.it> |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link \ArubaHiSpeedCache\Run_Aruba_Hispeed_cache() |
| 11 | * @since 1.1.3 |
| 12 | */ |
| 13 | |
| 14 | namespace ArubaSPA\HiSpeedCache\Purger; |
| 15 | |
| 16 | if ( ! \class_exists( __NAMESPACE__ . 'AbstractPurger' ) ) { |
| 17 | // phpcs:disable WordPress.NamingConventions |
| 18 | /** |
| 19 | * AbstracPurger. |
| 20 | */ |
| 21 | abstract class AbstractPurger { |
| 22 | /** |
| 23 | * $servr_host for the requst |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | protected $serverHost; |
| 28 | |
| 29 | /** |
| 30 | * $server_port for the request |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | protected $serverPort; |
| 35 | |
| 36 | /** |
| 37 | * $time_out of request |
| 38 | * |
| 39 | * @var integer |
| 40 | */ |
| 41 | protected $timeOut; |
| 42 | |
| 43 | /** |
| 44 | * Purge the cache of a single page |
| 45 | * |
| 46 | * @param string $url The url to purge. |
| 47 | * @return void |
| 48 | */ |
| 49 | abstract public function purgeUrl( $url ); |
| 50 | |
| 51 | /** |
| 52 | * Purge the cache of a list of pages |
| 53 | * |
| 54 | * @param array $urls The urls to purge. |
| 55 | * @return void |
| 56 | */ |
| 57 | abstract public function purgeUrls( $urls ); |
| 58 | |
| 59 | /** |
| 60 | * Purge the alla chace of site |
| 61 | * |
| 62 | * @return void |
| 63 | */ |
| 64 | abstract public function purgeAll(); |
| 65 | |
| 66 | /** |
| 67 | * DoRemoteGet |
| 68 | * |
| 69 | * @param string $target path to purge. |
| 70 | * |
| 71 | * @return void |
| 72 | */ |
| 73 | abstract public function doRemoteGet( $target = '/' ); |
| 74 | |
| 75 | /** |
| 76 | * PreparePurgeRequestUri |
| 77 | * |
| 78 | * @param string $url Url to prepare. |
| 79 | * |
| 80 | * @return string for the purge request. |
| 81 | */ |
| 82 | public function preparePurgeRequestUri( $url ) { |
| 83 | return \sprintf( |
| 84 | 'http://%s:%s/purge%s', |
| 85 | $this->getServerHost(), |
| 86 | $this->getServerPort(), |
| 87 | preg_replace( '|^(https?:)?//[^/]+(/?.*)|i', '$2', filter_var( $url, FILTER_SANITIZE_URL ) ) |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Set the purger. |
| 93 | * |
| 94 | * $config [ |
| 95 | * 'time_out' => int 5; |
| 96 | * 'server_host' => string '127.0.0.1' |
| 97 | * 'server_port' => string '8889' |
| 98 | * ]; |
| 99 | * |
| 100 | * @param array $configs The confi for the purger. |
| 101 | * @return void |
| 102 | */ |
| 103 | public function setPurger( $configs ) { |
| 104 | $this->setTimeOut( $configs['time_out'] ); |
| 105 | $this->setServerHost( $configs['server_host'] ); |
| 106 | $this->setServerPort( $configs['server_port'] ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Get undocumented variable |
| 111 | * |
| 112 | * @return integer |
| 113 | */ |
| 114 | public function getTimeOut() { |
| 115 | return $this->timeOut; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Set undocumented variable |
| 120 | * |
| 121 | * @param integer $timeOut Undocumented variable. |
| 122 | * |
| 123 | * @return self |
| 124 | */ |
| 125 | public function setTimeOut( $timeOut ) { |
| 126 | $this->timeOut = $timeOut; |
| 127 | |
| 128 | return $this; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Get undocumented variable |
| 133 | * |
| 134 | * @return string |
| 135 | */ |
| 136 | public function getServerPort() { |
| 137 | return $this->serverPort; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Set undocumented variable |
| 142 | * |
| 143 | * @param string $serverPort Undocumented variable. |
| 144 | * |
| 145 | * @return self |
| 146 | */ |
| 147 | public function setServerPort( $serverPort ) { |
| 148 | $this->serverPort = $serverPort; |
| 149 | return $this; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Get undocumented variable |
| 154 | * |
| 155 | * @return string |
| 156 | */ |
| 157 | public function getServerHost() { |
| 158 | return $this->serverHost; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Set undocumented variable |
| 163 | * |
| 164 | * @param string $serverHost Undocumented variable. |
| 165 | * |
| 166 | * @return self |
| 167 | */ |
| 168 | public function setServerHost( $serverHost ) { |
| 169 | $this->serverHost = $serverHost; |
| 170 | return $this; |
| 171 | } |
| 172 | } |
| 173 | // phpcs:enable |
| 174 | } |
| 175 |