@@ -34,97 +34,97 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class Search implements ISearch { |
| 36 | 36 | |
| 37 | - private $providers = array(); |
|
| 38 | - private $registeredProviders = array(); |
|
| 37 | + private $providers = array(); |
|
| 38 | + private $registeredProviders = array(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Search all providers for $query |
|
| 42 | - * @param string $query |
|
| 43 | - * @param string[] $inApps optionally limit results to the given apps |
|
| 44 | - * @return array An array of OC\Search\Result's |
|
| 45 | - */ |
|
| 46 | - public function search($query, array $inApps = array()) { |
|
| 47 | - // old apps might assume they get all results, so we set size 0 |
|
| 48 | - return $this->searchPaged($query, $inApps, 1, 0); |
|
| 49 | - } |
|
| 40 | + /** |
|
| 41 | + * Search all providers for $query |
|
| 42 | + * @param string $query |
|
| 43 | + * @param string[] $inApps optionally limit results to the given apps |
|
| 44 | + * @return array An array of OC\Search\Result's |
|
| 45 | + */ |
|
| 46 | + public function search($query, array $inApps = array()) { |
|
| 47 | + // old apps might assume they get all results, so we set size 0 |
|
| 48 | + return $this->searchPaged($query, $inApps, 1, 0); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Search all providers for $query |
|
| 53 | - * @param string $query |
|
| 54 | - * @param string[] $inApps optionally limit results to the given apps |
|
| 55 | - * @param int $page pages start at page 1 |
|
| 56 | - * @param int $size, 0 = all |
|
| 57 | - * @return array An array of OC\Search\Result's |
|
| 58 | - */ |
|
| 59 | - public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
|
| 60 | - $this->initProviders(); |
|
| 61 | - $results = array(); |
|
| 62 | - foreach($this->providers as $provider) { |
|
| 63 | - /** @var $provider Provider */ |
|
| 64 | - if ( ! $provider->providesResultsFor($inApps) ) { |
|
| 65 | - continue; |
|
| 66 | - } |
|
| 67 | - if ($provider instanceof PagedProvider) { |
|
| 68 | - $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
| 69 | - } else if ($provider instanceof Provider) { |
|
| 70 | - $providerResults = $provider->search($query); |
|
| 71 | - if ($size > 0) { |
|
| 72 | - $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
| 73 | - $results = array_merge($results, $slicedResults); |
|
| 74 | - } else { |
|
| 75 | - $results = array_merge($results, $providerResults); |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - return $results; |
|
| 82 | - } |
|
| 51 | + /** |
|
| 52 | + * Search all providers for $query |
|
| 53 | + * @param string $query |
|
| 54 | + * @param string[] $inApps optionally limit results to the given apps |
|
| 55 | + * @param int $page pages start at page 1 |
|
| 56 | + * @param int $size, 0 = all |
|
| 57 | + * @return array An array of OC\Search\Result's |
|
| 58 | + */ |
|
| 59 | + public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
|
| 60 | + $this->initProviders(); |
|
| 61 | + $results = array(); |
|
| 62 | + foreach($this->providers as $provider) { |
|
| 63 | + /** @var $provider Provider */ |
|
| 64 | + if ( ! $provider->providesResultsFor($inApps) ) { |
|
| 65 | + continue; |
|
| 66 | + } |
|
| 67 | + if ($provider instanceof PagedProvider) { |
|
| 68 | + $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
| 69 | + } else if ($provider instanceof Provider) { |
|
| 70 | + $providerResults = $provider->search($query); |
|
| 71 | + if ($size > 0) { |
|
| 72 | + $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
| 73 | + $results = array_merge($results, $slicedResults); |
|
| 74 | + } else { |
|
| 75 | + $results = array_merge($results, $providerResults); |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + return $results; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Remove all registered search providers |
|
| 86 | - */ |
|
| 87 | - public function clearProviders() { |
|
| 88 | - $this->providers = array(); |
|
| 89 | - $this->registeredProviders = array(); |
|
| 90 | - } |
|
| 84 | + /** |
|
| 85 | + * Remove all registered search providers |
|
| 86 | + */ |
|
| 87 | + public function clearProviders() { |
|
| 88 | + $this->providers = array(); |
|
| 89 | + $this->registeredProviders = array(); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Remove one existing search provider |
|
| 94 | - * @param string $provider class name of a OC\Search\Provider |
|
| 95 | - */ |
|
| 96 | - public function removeProvider($provider) { |
|
| 97 | - $this->registeredProviders = array_filter( |
|
| 98 | - $this->registeredProviders, |
|
| 99 | - function ($element) use ($provider) { |
|
| 100 | - return ($element['class'] != $provider); |
|
| 101 | - } |
|
| 102 | - ); |
|
| 103 | - // force regeneration of providers on next search |
|
| 104 | - $this->providers = array(); |
|
| 105 | - } |
|
| 92 | + /** |
|
| 93 | + * Remove one existing search provider |
|
| 94 | + * @param string $provider class name of a OC\Search\Provider |
|
| 95 | + */ |
|
| 96 | + public function removeProvider($provider) { |
|
| 97 | + $this->registeredProviders = array_filter( |
|
| 98 | + $this->registeredProviders, |
|
| 99 | + function ($element) use ($provider) { |
|
| 100 | + return ($element['class'] != $provider); |
|
| 101 | + } |
|
| 102 | + ); |
|
| 103 | + // force regeneration of providers on next search |
|
| 104 | + $this->providers = array(); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Register a new search provider to search with |
|
| 109 | - * @param string $class class name of a OC\Search\Provider |
|
| 110 | - * @param array $options optional |
|
| 111 | - */ |
|
| 112 | - public function registerProvider($class, array $options = array()) { |
|
| 113 | - $this->registeredProviders[] = array('class' => $class, 'options' => $options); |
|
| 114 | - } |
|
| 107 | + /** |
|
| 108 | + * Register a new search provider to search with |
|
| 109 | + * @param string $class class name of a OC\Search\Provider |
|
| 110 | + * @param array $options optional |
|
| 111 | + */ |
|
| 112 | + public function registerProvider($class, array $options = array()) { |
|
| 113 | + $this->registeredProviders[] = array('class' => $class, 'options' => $options); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Create instances of all the registered search providers |
|
| 118 | - */ |
|
| 119 | - private function initProviders() { |
|
| 120 | - if( ! empty($this->providers) ) { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 123 | - foreach($this->registeredProviders as $provider) { |
|
| 124 | - $class = $provider['class']; |
|
| 125 | - $options = $provider['options']; |
|
| 126 | - $this->providers[] = new $class($options); |
|
| 127 | - } |
|
| 128 | - } |
|
| 116 | + /** |
|
| 117 | + * Create instances of all the registered search providers |
|
| 118 | + */ |
|
| 119 | + private function initProviders() { |
|
| 120 | + if( ! empty($this->providers) ) { |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | + foreach($this->registeredProviders as $provider) { |
|
| 124 | + $class = $provider['class']; |
|
| 125 | + $options = $provider['options']; |
|
| 126 | + $this->providers[] = new $class($options); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | } |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
| 60 | 60 | $this->initProviders(); |
| 61 | 61 | $results = array(); |
| 62 | - foreach($this->providers as $provider) { |
|
| 62 | + foreach ($this->providers as $provider) { |
|
| 63 | 63 | /** @var $provider Provider */ |
| 64 | - if ( ! $provider->providesResultsFor($inApps) ) { |
|
| 64 | + if (!$provider->providesResultsFor($inApps)) { |
|
| 65 | 65 | continue; |
| 66 | 66 | } |
| 67 | 67 | if ($provider instanceof PagedProvider) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | public function removeProvider($provider) { |
| 97 | 97 | $this->registeredProviders = array_filter( |
| 98 | 98 | $this->registeredProviders, |
| 99 | - function ($element) use ($provider) { |
|
| 99 | + function($element) use ($provider) { |
|
| 100 | 100 | return ($element['class'] != $provider); |
| 101 | 101 | } |
| 102 | 102 | ); |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * Create instances of all the registered search providers |
| 118 | 118 | */ |
| 119 | 119 | private function initProviders() { |
| 120 | - if( ! empty($this->providers) ) { |
|
| 120 | + if (!empty($this->providers)) { |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | - foreach($this->registeredProviders as $provider) { |
|
| 123 | + foreach ($this->registeredProviders as $provider) { |
|
| 124 | 124 | $class = $provider['class']; |
| 125 | 125 | $options = $provider['options']; |
| 126 | 126 | $this->providers[] = new $class($options); |
@@ -32,51 +32,51 @@ |
||
| 32 | 32 | * @package OC\Http |
| 33 | 33 | */ |
| 34 | 34 | class Response implements IResponse { |
| 35 | - /** @var GuzzleResponse */ |
|
| 36 | - private $response; |
|
| 35 | + /** @var GuzzleResponse */ |
|
| 36 | + private $response; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var bool |
|
| 40 | - */ |
|
| 41 | - private $stream; |
|
| 38 | + /** |
|
| 39 | + * @var bool |
|
| 40 | + */ |
|
| 41 | + private $stream; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param GuzzleResponse $response |
|
| 45 | - * @param bool $stream |
|
| 46 | - */ |
|
| 47 | - public function __construct(GuzzleResponse $response, $stream = false) { |
|
| 48 | - $this->response = $response; |
|
| 49 | - $this->stream = $stream; |
|
| 50 | - } |
|
| 43 | + /** |
|
| 44 | + * @param GuzzleResponse $response |
|
| 45 | + * @param bool $stream |
|
| 46 | + */ |
|
| 47 | + public function __construct(GuzzleResponse $response, $stream = false) { |
|
| 48 | + $this->response = $response; |
|
| 49 | + $this->stream = $stream; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return string|resource |
|
| 54 | - */ |
|
| 55 | - public function getBody() { |
|
| 56 | - return $this->stream ? |
|
| 57 | - $this->response->getBody()->detach(): |
|
| 58 | - $this->response->getBody()->getContents(); |
|
| 59 | - } |
|
| 52 | + /** |
|
| 53 | + * @return string|resource |
|
| 54 | + */ |
|
| 55 | + public function getBody() { |
|
| 56 | + return $this->stream ? |
|
| 57 | + $this->response->getBody()->detach(): |
|
| 58 | + $this->response->getBody()->getContents(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @return int |
|
| 63 | - */ |
|
| 64 | - public function getStatusCode() { |
|
| 65 | - return $this->response->getStatusCode(); |
|
| 66 | - } |
|
| 61 | + /** |
|
| 62 | + * @return int |
|
| 63 | + */ |
|
| 64 | + public function getStatusCode() { |
|
| 65 | + return $this->response->getStatusCode(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param $key |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public function getHeader($key) { |
|
| 73 | - return $this->response->getHeader($key); |
|
| 74 | - } |
|
| 68 | + /** |
|
| 69 | + * @param $key |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public function getHeader($key) { |
|
| 73 | + return $this->response->getHeader($key); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - public function getHeaders() { |
|
| 80 | - return $this->response->getHeaders(); |
|
| 81 | - } |
|
| 76 | + /** |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + public function getHeaders() { |
|
| 80 | + return $this->response->getHeaders(); |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -54,8 +54,7 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | public function getBody() { |
| 56 | 56 | return $this->stream ? |
| 57 | - $this->response->getBody()->detach(): |
|
| 58 | - $this->response->getBody()->getContents(); |
|
| 57 | + $this->response->getBody()->detach() : $this->response->getBody()->getContents(); |
|
| 59 | 58 | } |
| 60 | 59 | |
| 61 | 60 | /** |
@@ -33,25 +33,25 @@ |
||
| 33 | 33 | * @package OC\Http |
| 34 | 34 | */ |
| 35 | 35 | class ClientService implements IClientService { |
| 36 | - /** @var IConfig */ |
|
| 37 | - private $config; |
|
| 38 | - /** @var ICertificateManager */ |
|
| 39 | - private $certificateManager; |
|
| 36 | + /** @var IConfig */ |
|
| 37 | + private $config; |
|
| 38 | + /** @var ICertificateManager */ |
|
| 39 | + private $certificateManager; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param IConfig $config |
|
| 43 | - * @param ICertificateManager $certificateManager |
|
| 44 | - */ |
|
| 45 | - public function __construct(IConfig $config, |
|
| 46 | - ICertificateManager $certificateManager) { |
|
| 47 | - $this->config = $config; |
|
| 48 | - $this->certificateManager = $certificateManager; |
|
| 49 | - } |
|
| 41 | + /** |
|
| 42 | + * @param IConfig $config |
|
| 43 | + * @param ICertificateManager $certificateManager |
|
| 44 | + */ |
|
| 45 | + public function __construct(IConfig $config, |
|
| 46 | + ICertificateManager $certificateManager) { |
|
| 47 | + $this->config = $config; |
|
| 48 | + $this->certificateManager = $certificateManager; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return Client |
|
| 53 | - */ |
|
| 54 | - public function newClient() { |
|
| 55 | - return new Client($this->config, $this->certificateManager, new GuzzleClient()); |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * @return Client |
|
| 53 | + */ |
|
| 54 | + public function newClient() { |
|
| 55 | + return new Client($this->config, $this->certificateManager, new GuzzleClient()); |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -38,86 +38,86 @@ |
||
| 38 | 38 | * @package OC\Session |
| 39 | 39 | */ |
| 40 | 40 | class Memory extends Session { |
| 41 | - protected $data; |
|
| 41 | + protected $data; |
|
| 42 | 42 | |
| 43 | - public function __construct($name) { |
|
| 44 | - //no need to use $name since all data is already scoped to this instance |
|
| 45 | - $this->data = array(); |
|
| 46 | - } |
|
| 43 | + public function __construct($name) { |
|
| 44 | + //no need to use $name since all data is already scoped to this instance |
|
| 45 | + $this->data = array(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param string $key |
|
| 50 | - * @param integer $value |
|
| 51 | - */ |
|
| 52 | - public function set($key, $value) { |
|
| 53 | - $this->validateSession(); |
|
| 54 | - $this->data[$key] = $value; |
|
| 55 | - } |
|
| 48 | + /** |
|
| 49 | + * @param string $key |
|
| 50 | + * @param integer $value |
|
| 51 | + */ |
|
| 52 | + public function set($key, $value) { |
|
| 53 | + $this->validateSession(); |
|
| 54 | + $this->data[$key] = $value; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param string $key |
|
| 59 | - * @return mixed |
|
| 60 | - */ |
|
| 61 | - public function get($key) { |
|
| 62 | - if (!$this->exists($key)) { |
|
| 63 | - return null; |
|
| 64 | - } |
|
| 65 | - return $this->data[$key]; |
|
| 66 | - } |
|
| 57 | + /** |
|
| 58 | + * @param string $key |
|
| 59 | + * @return mixed |
|
| 60 | + */ |
|
| 61 | + public function get($key) { |
|
| 62 | + if (!$this->exists($key)) { |
|
| 63 | + return null; |
|
| 64 | + } |
|
| 65 | + return $this->data[$key]; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param string $key |
|
| 70 | - * @return bool |
|
| 71 | - */ |
|
| 72 | - public function exists($key) { |
|
| 73 | - return isset($this->data[$key]); |
|
| 74 | - } |
|
| 68 | + /** |
|
| 69 | + * @param string $key |
|
| 70 | + * @return bool |
|
| 71 | + */ |
|
| 72 | + public function exists($key) { |
|
| 73 | + return isset($this->data[$key]); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @param string $key |
|
| 78 | - */ |
|
| 79 | - public function remove($key) { |
|
| 80 | - $this->validateSession(); |
|
| 81 | - unset($this->data[$key]); |
|
| 82 | - } |
|
| 76 | + /** |
|
| 77 | + * @param string $key |
|
| 78 | + */ |
|
| 79 | + public function remove($key) { |
|
| 80 | + $this->validateSession(); |
|
| 81 | + unset($this->data[$key]); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function clear() { |
|
| 85 | - $this->data = array(); |
|
| 86 | - } |
|
| 84 | + public function clear() { |
|
| 85 | + $this->data = array(); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Stub since the session ID does not need to get regenerated for the cache |
|
| 90 | - * |
|
| 91 | - * @param bool $deleteOldSession |
|
| 92 | - */ |
|
| 93 | - public function regenerateId($deleteOldSession = true) {} |
|
| 88 | + /** |
|
| 89 | + * Stub since the session ID does not need to get regenerated for the cache |
|
| 90 | + * |
|
| 91 | + * @param bool $deleteOldSession |
|
| 92 | + */ |
|
| 93 | + public function regenerateId($deleteOldSession = true) {} |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Wrapper around session_id |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - * @throws SessionNotAvailableException |
|
| 100 | - * @since 9.1.0 |
|
| 101 | - */ |
|
| 102 | - public function getId() { |
|
| 103 | - throw new SessionNotAvailableException('Memory session does not have an ID'); |
|
| 104 | - } |
|
| 95 | + /** |
|
| 96 | + * Wrapper around session_id |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + * @throws SessionNotAvailableException |
|
| 100 | + * @since 9.1.0 |
|
| 101 | + */ |
|
| 102 | + public function getId() { |
|
| 103 | + throw new SessionNotAvailableException('Memory session does not have an ID'); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Helper function for PHPUnit execution - don't use in non-test code |
|
| 108 | - */ |
|
| 109 | - public function reopen() { |
|
| 110 | - $this->sessionClosed = false; |
|
| 111 | - } |
|
| 106 | + /** |
|
| 107 | + * Helper function for PHPUnit execution - don't use in non-test code |
|
| 108 | + */ |
|
| 109 | + public function reopen() { |
|
| 110 | + $this->sessionClosed = false; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * In case the session has already been locked an exception will be thrown |
|
| 115 | - * |
|
| 116 | - * @throws Exception |
|
| 117 | - */ |
|
| 118 | - private function validateSession() { |
|
| 119 | - if ($this->sessionClosed) { |
|
| 120 | - throw new Exception('Session has been closed - no further changes to the session are allowed'); |
|
| 121 | - } |
|
| 122 | - } |
|
| 113 | + /** |
|
| 114 | + * In case the session has already been locked an exception will be thrown |
|
| 115 | + * |
|
| 116 | + * @throws Exception |
|
| 117 | + */ |
|
| 118 | + private function validateSession() { |
|
| 119 | + if ($this->sessionClosed) { |
|
| 120 | + throw new Exception('Session has been closed - no further changes to the session are allowed'); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | 123 | } |
@@ -38,120 +38,120 @@ |
||
| 38 | 38 | * @package OC\Session |
| 39 | 39 | */ |
| 40 | 40 | class Internal extends Session { |
| 41 | - /** |
|
| 42 | - * @param string $name |
|
| 43 | - * @throws \Exception |
|
| 44 | - */ |
|
| 45 | - public function __construct($name) { |
|
| 46 | - session_name($name); |
|
| 47 | - set_error_handler(array($this, 'trapError')); |
|
| 48 | - try { |
|
| 49 | - session_start(); |
|
| 50 | - } catch (\Exception $e) { |
|
| 51 | - setcookie(session_name(), null, -1, \OC::$WEBROOT ? : '/'); |
|
| 52 | - } |
|
| 53 | - restore_error_handler(); |
|
| 54 | - if (!isset($_SESSION)) { |
|
| 55 | - throw new \Exception('Failed to start session'); |
|
| 56 | - } |
|
| 57 | - } |
|
| 41 | + /** |
|
| 42 | + * @param string $name |
|
| 43 | + * @throws \Exception |
|
| 44 | + */ |
|
| 45 | + public function __construct($name) { |
|
| 46 | + session_name($name); |
|
| 47 | + set_error_handler(array($this, 'trapError')); |
|
| 48 | + try { |
|
| 49 | + session_start(); |
|
| 50 | + } catch (\Exception $e) { |
|
| 51 | + setcookie(session_name(), null, -1, \OC::$WEBROOT ? : '/'); |
|
| 52 | + } |
|
| 53 | + restore_error_handler(); |
|
| 54 | + if (!isset($_SESSION)) { |
|
| 55 | + throw new \Exception('Failed to start session'); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param string $key |
|
| 61 | - * @param integer $value |
|
| 62 | - */ |
|
| 63 | - public function set($key, $value) { |
|
| 64 | - $this->validateSession(); |
|
| 65 | - $_SESSION[$key] = $value; |
|
| 66 | - } |
|
| 59 | + /** |
|
| 60 | + * @param string $key |
|
| 61 | + * @param integer $value |
|
| 62 | + */ |
|
| 63 | + public function set($key, $value) { |
|
| 64 | + $this->validateSession(); |
|
| 65 | + $_SESSION[$key] = $value; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param string $key |
|
| 70 | - * @return mixed |
|
| 71 | - */ |
|
| 72 | - public function get($key) { |
|
| 73 | - if (!$this->exists($key)) { |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - return $_SESSION[$key]; |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * @param string $key |
|
| 70 | + * @return mixed |
|
| 71 | + */ |
|
| 72 | + public function get($key) { |
|
| 73 | + if (!$this->exists($key)) { |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + return $_SESSION[$key]; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @param string $key |
|
| 81 | - * @return bool |
|
| 82 | - */ |
|
| 83 | - public function exists($key) { |
|
| 84 | - return isset($_SESSION[$key]); |
|
| 85 | - } |
|
| 79 | + /** |
|
| 80 | + * @param string $key |
|
| 81 | + * @return bool |
|
| 82 | + */ |
|
| 83 | + public function exists($key) { |
|
| 84 | + return isset($_SESSION[$key]); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @param string $key |
|
| 89 | - */ |
|
| 90 | - public function remove($key) { |
|
| 91 | - if (isset($_SESSION[$key])) { |
|
| 92 | - unset($_SESSION[$key]); |
|
| 93 | - } |
|
| 94 | - } |
|
| 87 | + /** |
|
| 88 | + * @param string $key |
|
| 89 | + */ |
|
| 90 | + public function remove($key) { |
|
| 91 | + if (isset($_SESSION[$key])) { |
|
| 92 | + unset($_SESSION[$key]); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function clear() { |
|
| 97 | - session_unset(); |
|
| 98 | - $this->regenerateId(); |
|
| 99 | - @session_start(); |
|
| 100 | - $_SESSION = array(); |
|
| 101 | - } |
|
| 96 | + public function clear() { |
|
| 97 | + session_unset(); |
|
| 98 | + $this->regenerateId(); |
|
| 99 | + @session_start(); |
|
| 100 | + $_SESSION = array(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - public function close() { |
|
| 104 | - session_write_close(); |
|
| 105 | - parent::close(); |
|
| 106 | - } |
|
| 103 | + public function close() { |
|
| 104 | + session_write_close(); |
|
| 105 | + parent::close(); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Wrapper around session_regenerate_id |
|
| 110 | - * |
|
| 111 | - * @param bool $deleteOldSession Whether to delete the old associated session file or not. |
|
| 112 | - * @return void |
|
| 113 | - */ |
|
| 114 | - public function regenerateId($deleteOldSession = true) { |
|
| 115 | - @session_regenerate_id($deleteOldSession); |
|
| 116 | - } |
|
| 108 | + /** |
|
| 109 | + * Wrapper around session_regenerate_id |
|
| 110 | + * |
|
| 111 | + * @param bool $deleteOldSession Whether to delete the old associated session file or not. |
|
| 112 | + * @return void |
|
| 113 | + */ |
|
| 114 | + public function regenerateId($deleteOldSession = true) { |
|
| 115 | + @session_regenerate_id($deleteOldSession); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Wrapper around session_id |
|
| 120 | - * |
|
| 121 | - * @return string |
|
| 122 | - * @throws SessionNotAvailableException |
|
| 123 | - * @since 9.1.0 |
|
| 124 | - */ |
|
| 125 | - public function getId() { |
|
| 126 | - $id = @session_id(); |
|
| 127 | - if ($id === '') { |
|
| 128 | - throw new SessionNotAvailableException(); |
|
| 129 | - } |
|
| 130 | - return $id; |
|
| 131 | - } |
|
| 118 | + /** |
|
| 119 | + * Wrapper around session_id |
|
| 120 | + * |
|
| 121 | + * @return string |
|
| 122 | + * @throws SessionNotAvailableException |
|
| 123 | + * @since 9.1.0 |
|
| 124 | + */ |
|
| 125 | + public function getId() { |
|
| 126 | + $id = @session_id(); |
|
| 127 | + if ($id === '') { |
|
| 128 | + throw new SessionNotAvailableException(); |
|
| 129 | + } |
|
| 130 | + return $id; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @throws \Exception |
|
| 135 | - */ |
|
| 136 | - public function reopen() { |
|
| 137 | - throw new \Exception('The session cannot be reopened - reopen() is ony to be used in unit testing.'); |
|
| 138 | - } |
|
| 133 | + /** |
|
| 134 | + * @throws \Exception |
|
| 135 | + */ |
|
| 136 | + public function reopen() { |
|
| 137 | + throw new \Exception('The session cannot be reopened - reopen() is ony to be used in unit testing.'); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * @param int $errorNumber |
|
| 142 | - * @param string $errorString |
|
| 143 | - * @throws \ErrorException |
|
| 144 | - */ |
|
| 145 | - public function trapError($errorNumber, $errorString) { |
|
| 146 | - throw new \ErrorException($errorString); |
|
| 147 | - } |
|
| 140 | + /** |
|
| 141 | + * @param int $errorNumber |
|
| 142 | + * @param string $errorString |
|
| 143 | + * @throws \ErrorException |
|
| 144 | + */ |
|
| 145 | + public function trapError($errorNumber, $errorString) { |
|
| 146 | + throw new \ErrorException($errorString); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * @throws \Exception |
|
| 151 | - */ |
|
| 152 | - private function validateSession() { |
|
| 153 | - if ($this->sessionClosed) { |
|
| 154 | - throw new \Exception('Session has been closed - no further changes to the session are allowed'); |
|
| 155 | - } |
|
| 156 | - } |
|
| 149 | + /** |
|
| 150 | + * @throws \Exception |
|
| 151 | + */ |
|
| 152 | + private function validateSession() { |
|
| 153 | + if ($this->sessionClosed) { |
|
| 154 | + throw new \Exception('Session has been closed - no further changes to the session are allowed'); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | try { |
| 49 | 49 | session_start(); |
| 50 | 50 | } catch (\Exception $e) { |
| 51 | - setcookie(session_name(), null, -1, \OC::$WEBROOT ? : '/'); |
|
| 51 | + setcookie(session_name(), null, -1, \OC::$WEBROOT ?: '/'); |
|
| 52 | 52 | } |
| 53 | 53 | restore_error_handler(); |
| 54 | 54 | if (!isset($_SESSION)) { |
@@ -28,53 +28,53 @@ |
||
| 28 | 28 | |
| 29 | 29 | abstract class Session implements \ArrayAccess, ISession { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var bool |
|
| 33 | - */ |
|
| 34 | - protected $sessionClosed = false; |
|
| 31 | + /** |
|
| 32 | + * @var bool |
|
| 33 | + */ |
|
| 34 | + protected $sessionClosed = false; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * $name serves as a namespace for the session keys |
|
| 38 | - * |
|
| 39 | - * @param string $name |
|
| 40 | - */ |
|
| 41 | - abstract public function __construct($name); |
|
| 36 | + /** |
|
| 37 | + * $name serves as a namespace for the session keys |
|
| 38 | + * |
|
| 39 | + * @param string $name |
|
| 40 | + */ |
|
| 41 | + abstract public function __construct($name); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param mixed $offset |
|
| 45 | - * @return bool |
|
| 46 | - */ |
|
| 47 | - public function offsetExists($offset) { |
|
| 48 | - return $this->exists($offset); |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * @param mixed $offset |
|
| 45 | + * @return bool |
|
| 46 | + */ |
|
| 47 | + public function offsetExists($offset) { |
|
| 48 | + return $this->exists($offset); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param mixed $offset |
|
| 53 | - * @return mixed |
|
| 54 | - */ |
|
| 55 | - public function offsetGet($offset) { |
|
| 56 | - return $this->get($offset); |
|
| 57 | - } |
|
| 51 | + /** |
|
| 52 | + * @param mixed $offset |
|
| 53 | + * @return mixed |
|
| 54 | + */ |
|
| 55 | + public function offsetGet($offset) { |
|
| 56 | + return $this->get($offset); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param mixed $offset |
|
| 61 | - * @param mixed $value |
|
| 62 | - */ |
|
| 63 | - public function offsetSet($offset, $value) { |
|
| 64 | - $this->set($offset, $value); |
|
| 65 | - } |
|
| 59 | + /** |
|
| 60 | + * @param mixed $offset |
|
| 61 | + * @param mixed $value |
|
| 62 | + */ |
|
| 63 | + public function offsetSet($offset, $value) { |
|
| 64 | + $this->set($offset, $value); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param mixed $offset |
|
| 69 | - */ |
|
| 70 | - public function offsetUnset($offset) { |
|
| 71 | - $this->remove($offset); |
|
| 72 | - } |
|
| 67 | + /** |
|
| 68 | + * @param mixed $offset |
|
| 69 | + */ |
|
| 70 | + public function offsetUnset($offset) { |
|
| 71 | + $this->remove($offset); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Close the session and release the lock |
|
| 76 | - */ |
|
| 77 | - public function close() { |
|
| 78 | - $this->sessionClosed = true; |
|
| 79 | - } |
|
| 74 | + /** |
|
| 75 | + * Close the session and release the lock |
|
| 76 | + */ |
|
| 77 | + public function close() { |
|
| 78 | + $this->sessionClosed = true; |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -48,56 +48,56 @@ |
||
| 48 | 48 | * @package OC\Session |
| 49 | 49 | */ |
| 50 | 50 | class CryptoWrapper { |
| 51 | - const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
| 51 | + const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
| 52 | 52 | |
| 53 | - /** @var ISession */ |
|
| 54 | - protected $session; |
|
| 53 | + /** @var ISession */ |
|
| 54 | + protected $session; |
|
| 55 | 55 | |
| 56 | - /** @var \OCP\Security\ICrypto */ |
|
| 57 | - protected $crypto; |
|
| 56 | + /** @var \OCP\Security\ICrypto */ |
|
| 57 | + protected $crypto; |
|
| 58 | 58 | |
| 59 | - /** @var ISecureRandom */ |
|
| 60 | - protected $random; |
|
| 59 | + /** @var ISecureRandom */ |
|
| 60 | + protected $random; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param IConfig $config |
|
| 64 | - * @param ICrypto $crypto |
|
| 65 | - * @param ISecureRandom $random |
|
| 66 | - * @param IRequest $request |
|
| 67 | - */ |
|
| 68 | - public function __construct(IConfig $config, |
|
| 69 | - ICrypto $crypto, |
|
| 70 | - ISecureRandom $random, |
|
| 71 | - IRequest $request) { |
|
| 72 | - $this->crypto = $crypto; |
|
| 73 | - $this->config = $config; |
|
| 74 | - $this->random = $random; |
|
| 62 | + /** |
|
| 63 | + * @param IConfig $config |
|
| 64 | + * @param ICrypto $crypto |
|
| 65 | + * @param ISecureRandom $random |
|
| 66 | + * @param IRequest $request |
|
| 67 | + */ |
|
| 68 | + public function __construct(IConfig $config, |
|
| 69 | + ICrypto $crypto, |
|
| 70 | + ISecureRandom $random, |
|
| 71 | + IRequest $request) { |
|
| 72 | + $this->crypto = $crypto; |
|
| 73 | + $this->config = $config; |
|
| 74 | + $this->random = $random; |
|
| 75 | 75 | |
| 76 | - if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
| 77 | - $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
| 78 | - } else { |
|
| 79 | - $this->passphrase = $this->random->generate(128); |
|
| 80 | - $secureCookie = $request->getServerProtocol() === 'https'; |
|
| 81 | - // FIXME: Required for CI |
|
| 82 | - if (!defined('PHPUNIT_RUN')) { |
|
| 83 | - $webRoot = \OC::$WEBROOT; |
|
| 84 | - if($webRoot === '') { |
|
| 85 | - $webRoot = '/'; |
|
| 86 | - } |
|
| 87 | - setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 76 | + if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
| 77 | + $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
| 78 | + } else { |
|
| 79 | + $this->passphrase = $this->random->generate(128); |
|
| 80 | + $secureCookie = $request->getServerProtocol() === 'https'; |
|
| 81 | + // FIXME: Required for CI |
|
| 82 | + if (!defined('PHPUNIT_RUN')) { |
|
| 83 | + $webRoot = \OC::$WEBROOT; |
|
| 84 | + if($webRoot === '') { |
|
| 85 | + $webRoot = '/'; |
|
| 86 | + } |
|
| 87 | + setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @param ISession $session |
|
| 94 | - * @return ISession |
|
| 95 | - */ |
|
| 96 | - public function wrapSession(ISession $session) { |
|
| 97 | - if (!($session instanceof CryptoSessionData)) { |
|
| 98 | - return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
| 99 | - } |
|
| 92 | + /** |
|
| 93 | + * @param ISession $session |
|
| 94 | + * @return ISession |
|
| 95 | + */ |
|
| 96 | + public function wrapSession(ISession $session) { |
|
| 97 | + if (!($session instanceof CryptoSessionData)) { |
|
| 98 | + return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return $session; |
|
| 102 | - } |
|
| 101 | + return $session; |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -81,7 +81,7 @@ |
||
| 81 | 81 | // FIXME: Required for CI |
| 82 | 82 | if (!defined('PHPUNIT_RUN')) { |
| 83 | 83 | $webRoot = \OC::$WEBROOT; |
| 84 | - if($webRoot === '') { |
|
| 84 | + if ($webRoot === '') { |
|
| 85 | 85 | $webRoot = '/'; |
| 86 | 86 | } |
| 87 | 87 | setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
@@ -30,34 +30,34 @@ |
||
| 30 | 30 | |
| 31 | 31 | class ManagerFactory implements ICommentsManagerFactory { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Server container |
|
| 35 | - * |
|
| 36 | - * @var IServerContainer |
|
| 37 | - */ |
|
| 38 | - private $serverContainer; |
|
| 33 | + /** |
|
| 34 | + * Server container |
|
| 35 | + * |
|
| 36 | + * @var IServerContainer |
|
| 37 | + */ |
|
| 38 | + private $serverContainer; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constructor for the comments manager factory |
|
| 42 | - * |
|
| 43 | - * @param IServerContainer $serverContainer server container |
|
| 44 | - */ |
|
| 45 | - public function __construct(IServerContainer $serverContainer) { |
|
| 46 | - $this->serverContainer = $serverContainer; |
|
| 47 | - } |
|
| 40 | + /** |
|
| 41 | + * Constructor for the comments manager factory |
|
| 42 | + * |
|
| 43 | + * @param IServerContainer $serverContainer server container |
|
| 44 | + */ |
|
| 45 | + public function __construct(IServerContainer $serverContainer) { |
|
| 46 | + $this->serverContainer = $serverContainer; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * creates and returns an instance of the ICommentsManager |
|
| 51 | - * |
|
| 52 | - * @return ICommentsManager |
|
| 53 | - * @since 9.0.0 |
|
| 54 | - */ |
|
| 55 | - public function getManager() { |
|
| 56 | - return new Manager( |
|
| 57 | - $this->serverContainer->getDatabaseConnection(), |
|
| 58 | - $this->serverContainer->getLogger(), |
|
| 59 | - $this->serverContainer->getConfig(), |
|
| 60 | - $this->serverContainer->getEventDispatcher() |
|
| 61 | - ); |
|
| 62 | - } |
|
| 49 | + /** |
|
| 50 | + * creates and returns an instance of the ICommentsManager |
|
| 51 | + * |
|
| 52 | + * @return ICommentsManager |
|
| 53 | + * @since 9.0.0 |
|
| 54 | + */ |
|
| 55 | + public function getManager() { |
|
| 56 | + return new Manager( |
|
| 57 | + $this->serverContainer->getDatabaseConnection(), |
|
| 58 | + $this->serverContainer->getLogger(), |
|
| 59 | + $this->serverContainer->getConfig(), |
|
| 60 | + $this->serverContainer->getEventDispatcher() |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -27,148 +27,148 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Action implements IAction { |
| 29 | 29 | |
| 30 | - /** @var string */ |
|
| 31 | - protected $label; |
|
| 32 | - |
|
| 33 | - /** @var string */ |
|
| 34 | - protected $labelParsed; |
|
| 35 | - |
|
| 36 | - /** @var string */ |
|
| 37 | - protected $link; |
|
| 38 | - |
|
| 39 | - /** @var string */ |
|
| 40 | - protected $requestType; |
|
| 41 | - |
|
| 42 | - /** @var string */ |
|
| 43 | - protected $icon; |
|
| 44 | - |
|
| 45 | - /** @var bool */ |
|
| 46 | - protected $primary; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Constructor |
|
| 50 | - */ |
|
| 51 | - public function __construct() { |
|
| 52 | - $this->label = ''; |
|
| 53 | - $this->labelParsed = ''; |
|
| 54 | - $this->link = ''; |
|
| 55 | - $this->requestType = ''; |
|
| 56 | - $this->primary = false; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param string $label |
|
| 61 | - * @return $this |
|
| 62 | - * @throws \InvalidArgumentException if the label is invalid |
|
| 63 | - * @since 8.2.0 |
|
| 64 | - */ |
|
| 65 | - public function setLabel($label) { |
|
| 66 | - if (!is_string($label) || $label === '' || isset($label[32])) { |
|
| 67 | - throw new \InvalidArgumentException('The given label is invalid'); |
|
| 68 | - } |
|
| 69 | - $this->label = $label; |
|
| 70 | - return $this; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @return string |
|
| 75 | - * @since 8.2.0 |
|
| 76 | - */ |
|
| 77 | - public function getLabel() { |
|
| 78 | - return $this->label; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $label |
|
| 83 | - * @return $this |
|
| 84 | - * @throws \InvalidArgumentException if the label is invalid |
|
| 85 | - * @since 8.2.0 |
|
| 86 | - */ |
|
| 87 | - public function setParsedLabel($label) { |
|
| 88 | - if (!is_string($label) || $label === '') { |
|
| 89 | - throw new \InvalidArgumentException('The given parsed label is invalid'); |
|
| 90 | - } |
|
| 91 | - $this->labelParsed = $label; |
|
| 92 | - return $this; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - * @since 8.2.0 |
|
| 98 | - */ |
|
| 99 | - public function getParsedLabel() { |
|
| 100 | - return $this->labelParsed; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param $primary bool |
|
| 105 | - * @return $this |
|
| 106 | - * @throws \InvalidArgumentException if $primary is invalid |
|
| 107 | - * @since 9.0.0 |
|
| 108 | - */ |
|
| 109 | - public function setPrimary($primary) { |
|
| 110 | - if (!is_bool($primary)) { |
|
| 111 | - throw new \InvalidArgumentException('The given primary option is invalid'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $this->primary = $primary; |
|
| 115 | - return $this; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return bool |
|
| 120 | - * @since 9.0.0 |
|
| 121 | - */ |
|
| 122 | - public function isPrimary() { |
|
| 123 | - return $this->primary; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param string $link |
|
| 128 | - * @param string $requestType |
|
| 129 | - * @return $this |
|
| 130 | - * @throws \InvalidArgumentException if the link is invalid |
|
| 131 | - * @since 8.2.0 |
|
| 132 | - */ |
|
| 133 | - public function setLink($link, $requestType) { |
|
| 134 | - if (!is_string($link) || $link === '' || isset($link[256])) { |
|
| 135 | - throw new \InvalidArgumentException('The given link is invalid'); |
|
| 136 | - } |
|
| 137 | - if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) { |
|
| 138 | - throw new \InvalidArgumentException('The given request type is invalid'); |
|
| 139 | - } |
|
| 140 | - $this->link = $link; |
|
| 141 | - $this->requestType = $requestType; |
|
| 142 | - return $this; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @return string |
|
| 147 | - * @since 8.2.0 |
|
| 148 | - */ |
|
| 149 | - public function getLink() { |
|
| 150 | - return $this->link; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @return string |
|
| 155 | - * @since 8.2.0 |
|
| 156 | - */ |
|
| 157 | - public function getRequestType() { |
|
| 158 | - return $this->requestType; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return bool |
|
| 163 | - */ |
|
| 164 | - public function isValid() { |
|
| 165 | - return $this->label !== '' && $this->link !== ''; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @return bool |
|
| 170 | - */ |
|
| 171 | - public function isValidParsed() { |
|
| 172 | - return $this->labelParsed !== '' && $this->link !== ''; |
|
| 173 | - } |
|
| 30 | + /** @var string */ |
|
| 31 | + protected $label; |
|
| 32 | + |
|
| 33 | + /** @var string */ |
|
| 34 | + protected $labelParsed; |
|
| 35 | + |
|
| 36 | + /** @var string */ |
|
| 37 | + protected $link; |
|
| 38 | + |
|
| 39 | + /** @var string */ |
|
| 40 | + protected $requestType; |
|
| 41 | + |
|
| 42 | + /** @var string */ |
|
| 43 | + protected $icon; |
|
| 44 | + |
|
| 45 | + /** @var bool */ |
|
| 46 | + protected $primary; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Constructor |
|
| 50 | + */ |
|
| 51 | + public function __construct() { |
|
| 52 | + $this->label = ''; |
|
| 53 | + $this->labelParsed = ''; |
|
| 54 | + $this->link = ''; |
|
| 55 | + $this->requestType = ''; |
|
| 56 | + $this->primary = false; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param string $label |
|
| 61 | + * @return $this |
|
| 62 | + * @throws \InvalidArgumentException if the label is invalid |
|
| 63 | + * @since 8.2.0 |
|
| 64 | + */ |
|
| 65 | + public function setLabel($label) { |
|
| 66 | + if (!is_string($label) || $label === '' || isset($label[32])) { |
|
| 67 | + throw new \InvalidArgumentException('The given label is invalid'); |
|
| 68 | + } |
|
| 69 | + $this->label = $label; |
|
| 70 | + return $this; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @return string |
|
| 75 | + * @since 8.2.0 |
|
| 76 | + */ |
|
| 77 | + public function getLabel() { |
|
| 78 | + return $this->label; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $label |
|
| 83 | + * @return $this |
|
| 84 | + * @throws \InvalidArgumentException if the label is invalid |
|
| 85 | + * @since 8.2.0 |
|
| 86 | + */ |
|
| 87 | + public function setParsedLabel($label) { |
|
| 88 | + if (!is_string($label) || $label === '') { |
|
| 89 | + throw new \InvalidArgumentException('The given parsed label is invalid'); |
|
| 90 | + } |
|
| 91 | + $this->labelParsed = $label; |
|
| 92 | + return $this; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + * @since 8.2.0 |
|
| 98 | + */ |
|
| 99 | + public function getParsedLabel() { |
|
| 100 | + return $this->labelParsed; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param $primary bool |
|
| 105 | + * @return $this |
|
| 106 | + * @throws \InvalidArgumentException if $primary is invalid |
|
| 107 | + * @since 9.0.0 |
|
| 108 | + */ |
|
| 109 | + public function setPrimary($primary) { |
|
| 110 | + if (!is_bool($primary)) { |
|
| 111 | + throw new \InvalidArgumentException('The given primary option is invalid'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $this->primary = $primary; |
|
| 115 | + return $this; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return bool |
|
| 120 | + * @since 9.0.0 |
|
| 121 | + */ |
|
| 122 | + public function isPrimary() { |
|
| 123 | + return $this->primary; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param string $link |
|
| 128 | + * @param string $requestType |
|
| 129 | + * @return $this |
|
| 130 | + * @throws \InvalidArgumentException if the link is invalid |
|
| 131 | + * @since 8.2.0 |
|
| 132 | + */ |
|
| 133 | + public function setLink($link, $requestType) { |
|
| 134 | + if (!is_string($link) || $link === '' || isset($link[256])) { |
|
| 135 | + throw new \InvalidArgumentException('The given link is invalid'); |
|
| 136 | + } |
|
| 137 | + if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) { |
|
| 138 | + throw new \InvalidArgumentException('The given request type is invalid'); |
|
| 139 | + } |
|
| 140 | + $this->link = $link; |
|
| 141 | + $this->requestType = $requestType; |
|
| 142 | + return $this; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @return string |
|
| 147 | + * @since 8.2.0 |
|
| 148 | + */ |
|
| 149 | + public function getLink() { |
|
| 150 | + return $this->link; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @return string |
|
| 155 | + * @since 8.2.0 |
|
| 156 | + */ |
|
| 157 | + public function getRequestType() { |
|
| 158 | + return $this->requestType; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @return bool |
|
| 163 | + */ |
|
| 164 | + public function isValid() { |
|
| 165 | + return $this->label !== '' && $this->link !== ''; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @return bool |
|
| 170 | + */ |
|
| 171 | + public function isValidParsed() { |
|
| 172 | + return $this->labelParsed !== '' && $this->link !== ''; |
|
| 173 | + } |
|
| 174 | 174 | } |