@@ -34,12 +34,12 @@ |
||
| 34 | 34 | class TimeFactory implements ITimeFactory { |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return int the result of a call to time() |
|
| 39 | - */ |
|
| 40 | - public function getTime() { |
|
| 41 | - return time(); |
|
| 42 | - } |
|
| 37 | + /** |
|
| 38 | + * @return int the result of a call to time() |
|
| 39 | + */ |
|
| 40 | + public function getTime() { |
|
| 41 | + return time(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | } |
@@ -40,149 +40,149 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | class API implements IApi{ |
| 42 | 42 | |
| 43 | - private $appName; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * constructor |
|
| 47 | - * @param string $appName the name of your application |
|
| 48 | - */ |
|
| 49 | - public function __construct($appName){ |
|
| 50 | - $this->appName = $appName; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Gets the userid of the current user |
|
| 56 | - * @return string the user id of the current user |
|
| 57 | - * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID() |
|
| 58 | - */ |
|
| 59 | - public function getUserId(){ |
|
| 60 | - return \OCP\User::getUser(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Adds a new javascript file |
|
| 66 | - * @deprecated include javascript and css in template files |
|
| 67 | - * @param string $scriptName the name of the javascript in js/ without the suffix |
|
| 68 | - * @param string $appName the name of the app, defaults to the current one |
|
| 69 | - */ |
|
| 70 | - public function addScript($scriptName, $appName=null){ |
|
| 71 | - if($appName === null){ |
|
| 72 | - $appName = $this->appName; |
|
| 73 | - } |
|
| 74 | - \OCP\Util::addScript($appName, $scriptName); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Adds a new css file |
|
| 80 | - * @deprecated include javascript and css in template files |
|
| 81 | - * @param string $styleName the name of the css file in css/without the suffix |
|
| 82 | - * @param string $appName the name of the app, defaults to the current one |
|
| 83 | - */ |
|
| 84 | - public function addStyle($styleName, $appName=null){ |
|
| 85 | - if($appName === null){ |
|
| 86 | - $appName = $this->appName; |
|
| 87 | - } |
|
| 88 | - \OCP\Util::addStyle($appName, $styleName); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @deprecated include javascript and css in template files |
|
| 94 | - * shorthand for addScript for files in the 3rdparty directory |
|
| 95 | - * @param string $name the name of the file without the suffix |
|
| 96 | - */ |
|
| 97 | - public function add3rdPartyScript($name){ |
|
| 98 | - \OCP\Util::addScript($this->appName . '/3rdparty', $name); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @deprecated include javascript and css in template files |
|
| 104 | - * shorthand for addStyle for files in the 3rdparty directory |
|
| 105 | - * @param string $name the name of the file without the suffix |
|
| 106 | - */ |
|
| 107 | - public function add3rdPartyStyle($name){ |
|
| 108 | - \OCP\Util::addStyle($this->appName . '/3rdparty', $name); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @deprecated communication between apps should happen over built in |
|
| 114 | - * callbacks or interfaces (check the contacts and calendar managers) |
|
| 115 | - * Checks if an app is enabled |
|
| 116 | - * also use \OC::$server->getAppManager()->isEnabledForUser($appName) |
|
| 117 | - * @param string $appName the name of an app |
|
| 118 | - * @return bool true if app is enabled |
|
| 119 | - */ |
|
| 120 | - public function isAppEnabled($appName){ |
|
| 121 | - return \OCP\App::isEnabled($appName); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * used to return and open a new event source |
|
| 127 | - * @return \OCP\IEventSource a new open EventSource class |
|
| 128 | - * @deprecated Use \OC::$server->createEventSource(); |
|
| 129 | - */ |
|
| 130 | - public function openEventSource(){ |
|
| 131 | - return \OC::$server->createEventSource(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @deprecated register hooks directly for class that build in hook interfaces |
|
| 136 | - * connects a function to a hook |
|
| 137 | - * @param string $signalClass class name of emitter |
|
| 138 | - * @param string $signalName name of signal |
|
| 139 | - * @param string $slotClass class name of slot |
|
| 140 | - * @param string $slotName name of slot, in another word, this is the |
|
| 141 | - * name of the method that will be called when registered |
|
| 142 | - * signal is emitted. |
|
| 143 | - * @return bool always true |
|
| 144 | - */ |
|
| 145 | - public function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
| 146 | - return \OCP\Util::connectHook($signalClass, $signalName, $slotClass, $slotName); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @deprecated implement the emitter interface instead |
|
| 151 | - * Emits a signal. To get data from the slot use references! |
|
| 152 | - * @param string $signalClass class name of emitter |
|
| 153 | - * @param string $signalName name of signal |
|
| 154 | - * @param array $params default: array() array with additional data |
|
| 155 | - * @return bool true if slots exists or false if not |
|
| 156 | - */ |
|
| 157 | - public function emitHook($signalClass, $signalName, $params = array()) { |
|
| 158 | - return \OCP\Util::emitHook($signalClass, $signalName, $params); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * clear hooks |
|
| 163 | - * @deprecated clear hooks directly for class that build in hook interfaces |
|
| 164 | - * @param string $signalClass |
|
| 165 | - * @param string $signalName |
|
| 166 | - */ |
|
| 167 | - public function clearHook($signalClass=false, $signalName=false) { |
|
| 168 | - if ($signalClass) { |
|
| 169 | - \OC_Hook::clear($signalClass, $signalName); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Tells ownCloud to include a template in the admin overview |
|
| 175 | - * @param string $mainPath the path to the main php file without the php |
|
| 176 | - * suffix, relative to your apps directory! not the template directory |
|
| 177 | - * @param string $appName the name of the app, defaults to the current one |
|
| 178 | - */ |
|
| 179 | - public function registerAdmin($mainPath, $appName=null) { |
|
| 180 | - if($appName === null){ |
|
| 181 | - $appName = $this->appName; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - \OCP\App::registerAdmin($appName, $mainPath); |
|
| 185 | - } |
|
| 43 | + private $appName; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * constructor |
|
| 47 | + * @param string $appName the name of your application |
|
| 48 | + */ |
|
| 49 | + public function __construct($appName){ |
|
| 50 | + $this->appName = $appName; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Gets the userid of the current user |
|
| 56 | + * @return string the user id of the current user |
|
| 57 | + * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID() |
|
| 58 | + */ |
|
| 59 | + public function getUserId(){ |
|
| 60 | + return \OCP\User::getUser(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Adds a new javascript file |
|
| 66 | + * @deprecated include javascript and css in template files |
|
| 67 | + * @param string $scriptName the name of the javascript in js/ without the suffix |
|
| 68 | + * @param string $appName the name of the app, defaults to the current one |
|
| 69 | + */ |
|
| 70 | + public function addScript($scriptName, $appName=null){ |
|
| 71 | + if($appName === null){ |
|
| 72 | + $appName = $this->appName; |
|
| 73 | + } |
|
| 74 | + \OCP\Util::addScript($appName, $scriptName); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Adds a new css file |
|
| 80 | + * @deprecated include javascript and css in template files |
|
| 81 | + * @param string $styleName the name of the css file in css/without the suffix |
|
| 82 | + * @param string $appName the name of the app, defaults to the current one |
|
| 83 | + */ |
|
| 84 | + public function addStyle($styleName, $appName=null){ |
|
| 85 | + if($appName === null){ |
|
| 86 | + $appName = $this->appName; |
|
| 87 | + } |
|
| 88 | + \OCP\Util::addStyle($appName, $styleName); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @deprecated include javascript and css in template files |
|
| 94 | + * shorthand for addScript for files in the 3rdparty directory |
|
| 95 | + * @param string $name the name of the file without the suffix |
|
| 96 | + */ |
|
| 97 | + public function add3rdPartyScript($name){ |
|
| 98 | + \OCP\Util::addScript($this->appName . '/3rdparty', $name); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @deprecated include javascript and css in template files |
|
| 104 | + * shorthand for addStyle for files in the 3rdparty directory |
|
| 105 | + * @param string $name the name of the file without the suffix |
|
| 106 | + */ |
|
| 107 | + public function add3rdPartyStyle($name){ |
|
| 108 | + \OCP\Util::addStyle($this->appName . '/3rdparty', $name); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @deprecated communication between apps should happen over built in |
|
| 114 | + * callbacks or interfaces (check the contacts and calendar managers) |
|
| 115 | + * Checks if an app is enabled |
|
| 116 | + * also use \OC::$server->getAppManager()->isEnabledForUser($appName) |
|
| 117 | + * @param string $appName the name of an app |
|
| 118 | + * @return bool true if app is enabled |
|
| 119 | + */ |
|
| 120 | + public function isAppEnabled($appName){ |
|
| 121 | + return \OCP\App::isEnabled($appName); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * used to return and open a new event source |
|
| 127 | + * @return \OCP\IEventSource a new open EventSource class |
|
| 128 | + * @deprecated Use \OC::$server->createEventSource(); |
|
| 129 | + */ |
|
| 130 | + public function openEventSource(){ |
|
| 131 | + return \OC::$server->createEventSource(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @deprecated register hooks directly for class that build in hook interfaces |
|
| 136 | + * connects a function to a hook |
|
| 137 | + * @param string $signalClass class name of emitter |
|
| 138 | + * @param string $signalName name of signal |
|
| 139 | + * @param string $slotClass class name of slot |
|
| 140 | + * @param string $slotName name of slot, in another word, this is the |
|
| 141 | + * name of the method that will be called when registered |
|
| 142 | + * signal is emitted. |
|
| 143 | + * @return bool always true |
|
| 144 | + */ |
|
| 145 | + public function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
| 146 | + return \OCP\Util::connectHook($signalClass, $signalName, $slotClass, $slotName); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @deprecated implement the emitter interface instead |
|
| 151 | + * Emits a signal. To get data from the slot use references! |
|
| 152 | + * @param string $signalClass class name of emitter |
|
| 153 | + * @param string $signalName name of signal |
|
| 154 | + * @param array $params default: array() array with additional data |
|
| 155 | + * @return bool true if slots exists or false if not |
|
| 156 | + */ |
|
| 157 | + public function emitHook($signalClass, $signalName, $params = array()) { |
|
| 158 | + return \OCP\Util::emitHook($signalClass, $signalName, $params); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * clear hooks |
|
| 163 | + * @deprecated clear hooks directly for class that build in hook interfaces |
|
| 164 | + * @param string $signalClass |
|
| 165 | + * @param string $signalName |
|
| 166 | + */ |
|
| 167 | + public function clearHook($signalClass=false, $signalName=false) { |
|
| 168 | + if ($signalClass) { |
|
| 169 | + \OC_Hook::clear($signalClass, $signalName); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Tells ownCloud to include a template in the admin overview |
|
| 175 | + * @param string $mainPath the path to the main php file without the php |
|
| 176 | + * suffix, relative to your apps directory! not the template directory |
|
| 177 | + * @param string $appName the name of the app, defaults to the current one |
|
| 178 | + */ |
|
| 179 | + public function registerAdmin($mainPath, $appName=null) { |
|
| 180 | + if($appName === null){ |
|
| 181 | + $appName = $this->appName; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + \OCP\App::registerAdmin($appName, $mainPath); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | |
| 188 | 188 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * class and add your methods |
| 39 | 39 | * @deprecated |
| 40 | 40 | */ |
| 41 | -class API implements IApi{ |
|
| 41 | +class API implements IApi { |
|
| 42 | 42 | |
| 43 | 43 | private $appName; |
| 44 | 44 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * constructor |
| 47 | 47 | * @param string $appName the name of your application |
| 48 | 48 | */ |
| 49 | - public function __construct($appName){ |
|
| 49 | + public function __construct($appName) { |
|
| 50 | 50 | $this->appName = $appName; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @return string the user id of the current user |
| 57 | 57 | * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID() |
| 58 | 58 | */ |
| 59 | - public function getUserId(){ |
|
| 59 | + public function getUserId() { |
|
| 60 | 60 | return \OCP\User::getUser(); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | * @param string $scriptName the name of the javascript in js/ without the suffix |
| 68 | 68 | * @param string $appName the name of the app, defaults to the current one |
| 69 | 69 | */ |
| 70 | - public function addScript($scriptName, $appName=null){ |
|
| 71 | - if($appName === null){ |
|
| 70 | + public function addScript($scriptName, $appName = null) { |
|
| 71 | + if ($appName === null) { |
|
| 72 | 72 | $appName = $this->appName; |
| 73 | 73 | } |
| 74 | 74 | \OCP\Util::addScript($appName, $scriptName); |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | * @param string $styleName the name of the css file in css/without the suffix |
| 82 | 82 | * @param string $appName the name of the app, defaults to the current one |
| 83 | 83 | */ |
| 84 | - public function addStyle($styleName, $appName=null){ |
|
| 85 | - if($appName === null){ |
|
| 84 | + public function addStyle($styleName, $appName = null) { |
|
| 85 | + if ($appName === null) { |
|
| 86 | 86 | $appName = $this->appName; |
| 87 | 87 | } |
| 88 | 88 | \OCP\Util::addStyle($appName, $styleName); |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | * shorthand for addScript for files in the 3rdparty directory |
| 95 | 95 | * @param string $name the name of the file without the suffix |
| 96 | 96 | */ |
| 97 | - public function add3rdPartyScript($name){ |
|
| 98 | - \OCP\Util::addScript($this->appName . '/3rdparty', $name); |
|
| 97 | + public function add3rdPartyScript($name) { |
|
| 98 | + \OCP\Util::addScript($this->appName.'/3rdparty', $name); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * shorthand for addStyle for files in the 3rdparty directory |
| 105 | 105 | * @param string $name the name of the file without the suffix |
| 106 | 106 | */ |
| 107 | - public function add3rdPartyStyle($name){ |
|
| 108 | - \OCP\Util::addStyle($this->appName . '/3rdparty', $name); |
|
| 107 | + public function add3rdPartyStyle($name) { |
|
| 108 | + \OCP\Util::addStyle($this->appName.'/3rdparty', $name); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @param string $appName the name of an app |
| 118 | 118 | * @return bool true if app is enabled |
| 119 | 119 | */ |
| 120 | - public function isAppEnabled($appName){ |
|
| 120 | + public function isAppEnabled($appName) { |
|
| 121 | 121 | return \OCP\App::isEnabled($appName); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @return \OCP\IEventSource a new open EventSource class |
| 128 | 128 | * @deprecated Use \OC::$server->createEventSource(); |
| 129 | 129 | */ |
| 130 | - public function openEventSource(){ |
|
| 130 | + public function openEventSource() { |
|
| 131 | 131 | return \OC::$server->createEventSource(); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * @param string $signalClass |
| 165 | 165 | * @param string $signalName |
| 166 | 166 | */ |
| 167 | - public function clearHook($signalClass=false, $signalName=false) { |
|
| 167 | + public function clearHook($signalClass = false, $signalName = false) { |
|
| 168 | 168 | if ($signalClass) { |
| 169 | 169 | \OC_Hook::clear($signalClass, $signalName); |
| 170 | 170 | } |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | * suffix, relative to your apps directory! not the template directory |
| 177 | 177 | * @param string $appName the name of the app, defaults to the current one |
| 178 | 178 | */ |
| 179 | - public function registerAdmin($mainPath, $appName=null) { |
|
| 180 | - if($appName === null){ |
|
| 179 | + public function registerAdmin($mainPath, $appName = null) { |
|
| 180 | + if ($appName === null) { |
|
| 181 | 181 | $appName = $this->appName; |
| 182 | 182 | } |
| 183 | 183 | |
@@ -30,70 +30,70 @@ |
||
| 30 | 30 | * Very thin wrapper class to make output testable |
| 31 | 31 | */ |
| 32 | 32 | class Output implements IOutput { |
| 33 | - /** @var string */ |
|
| 34 | - private $webRoot; |
|
| 33 | + /** @var string */ |
|
| 34 | + private $webRoot; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param $webRoot |
|
| 38 | - */ |
|
| 39 | - public function __construct($webRoot) { |
|
| 40 | - $this->webRoot = $webRoot; |
|
| 41 | - } |
|
| 36 | + /** |
|
| 37 | + * @param $webRoot |
|
| 38 | + */ |
|
| 39 | + public function __construct($webRoot) { |
|
| 40 | + $this->webRoot = $webRoot; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param string $out |
|
| 45 | - */ |
|
| 46 | - public function setOutput($out) { |
|
| 47 | - print($out); |
|
| 48 | - } |
|
| 43 | + /** |
|
| 44 | + * @param string $out |
|
| 45 | + */ |
|
| 46 | + public function setOutput($out) { |
|
| 47 | + print($out); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string|resource $path or file handle |
|
| 52 | - * |
|
| 53 | - * @return bool false if an error occurred |
|
| 54 | - */ |
|
| 55 | - public function setReadfile($path) { |
|
| 56 | - if (is_resource($path)) { |
|
| 57 | - $output = fopen('php://output', 'w'); |
|
| 58 | - return stream_copy_to_stream($path, $output) > 0; |
|
| 59 | - } else { |
|
| 60 | - return @readfile($path); |
|
| 61 | - } |
|
| 62 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string|resource $path or file handle |
|
| 52 | + * |
|
| 53 | + * @return bool false if an error occurred |
|
| 54 | + */ |
|
| 55 | + public function setReadfile($path) { |
|
| 56 | + if (is_resource($path)) { |
|
| 57 | + $output = fopen('php://output', 'w'); |
|
| 58 | + return stream_copy_to_stream($path, $output) > 0; |
|
| 59 | + } else { |
|
| 60 | + return @readfile($path); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param string $header |
|
| 66 | - */ |
|
| 67 | - public function setHeader($header) { |
|
| 68 | - header($header); |
|
| 69 | - } |
|
| 64 | + /** |
|
| 65 | + * @param string $header |
|
| 66 | + */ |
|
| 67 | + public function setHeader($header) { |
|
| 68 | + header($header); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param int $code sets the http status code |
|
| 73 | - */ |
|
| 74 | - public function setHttpResponseCode($code) { |
|
| 75 | - http_response_code($code); |
|
| 76 | - } |
|
| 71 | + /** |
|
| 72 | + * @param int $code sets the http status code |
|
| 73 | + */ |
|
| 74 | + public function setHttpResponseCode($code) { |
|
| 75 | + http_response_code($code); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @return int returns the current http response code |
|
| 80 | - */ |
|
| 81 | - public function getHttpResponseCode() { |
|
| 82 | - return http_response_code(); |
|
| 83 | - } |
|
| 78 | + /** |
|
| 79 | + * @return int returns the current http response code |
|
| 80 | + */ |
|
| 81 | + public function getHttpResponseCode() { |
|
| 82 | + return http_response_code(); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param string $name |
|
| 87 | - * @param string $value |
|
| 88 | - * @param int $expire |
|
| 89 | - * @param string $path |
|
| 90 | - * @param string $domain |
|
| 91 | - * @param bool $secure |
|
| 92 | - * @param bool $httpOnly |
|
| 93 | - */ |
|
| 94 | - public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) { |
|
| 95 | - $path = $this->webRoot ? : '/'; |
|
| 96 | - setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly); |
|
| 97 | - } |
|
| 85 | + /** |
|
| 86 | + * @param string $name |
|
| 87 | + * @param string $value |
|
| 88 | + * @param int $expire |
|
| 89 | + * @param string $path |
|
| 90 | + * @param string $domain |
|
| 91 | + * @param bool $secure |
|
| 92 | + * @param bool $httpOnly |
|
| 93 | + */ |
|
| 94 | + public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) { |
|
| 95 | + $path = $this->webRoot ? : '/'; |
|
| 96 | + setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | } |
@@ -92,7 +92,7 @@ |
||
| 92 | 92 | * @param bool $httpOnly |
| 93 | 93 | */ |
| 94 | 94 | public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) { |
| 95 | - $path = $this->webRoot ? : '/'; |
|
| 95 | + $path = $this->webRoot ?: '/'; |
|
| 96 | 96 | setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -43,142 +43,142 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | class Dispatcher { |
| 45 | 45 | |
| 46 | - private $middlewareDispatcher; |
|
| 47 | - private $protocol; |
|
| 48 | - private $reflector; |
|
| 49 | - private $request; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @param Http $protocol the http protocol with contains all status headers |
|
| 53 | - * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
| 54 | - * runs the middleware |
|
| 55 | - * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
| 56 | - * the arguments for the controller |
|
| 57 | - * @param IRequest $request the incoming request |
|
| 58 | - */ |
|
| 59 | - public function __construct(Http $protocol, |
|
| 60 | - MiddlewareDispatcher $middlewareDispatcher, |
|
| 61 | - ControllerMethodReflector $reflector, |
|
| 62 | - IRequest $request) { |
|
| 63 | - $this->protocol = $protocol; |
|
| 64 | - $this->middlewareDispatcher = $middlewareDispatcher; |
|
| 65 | - $this->reflector = $reflector; |
|
| 66 | - $this->request = $request; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Handles a request and calls the dispatcher on the controller |
|
| 72 | - * @param Controller $controller the controller which will be called |
|
| 73 | - * @param string $methodName the method name which will be called on |
|
| 74 | - * the controller |
|
| 75 | - * @return array $array[0] contains a string with the http main header, |
|
| 76 | - * $array[1] contains headers in the form: $key => value, $array[2] contains |
|
| 77 | - * the response output |
|
| 78 | - * @throws \Exception |
|
| 79 | - */ |
|
| 80 | - public function dispatch(Controller $controller, $methodName) { |
|
| 81 | - $out = array(null, array(), null); |
|
| 82 | - |
|
| 83 | - try { |
|
| 84 | - // prefill reflector with everything thats needed for the |
|
| 85 | - // middlewares |
|
| 86 | - $this->reflector->reflect($controller, $methodName); |
|
| 87 | - |
|
| 88 | - $this->middlewareDispatcher->beforeController($controller, |
|
| 89 | - $methodName); |
|
| 90 | - $response = $this->executeController($controller, $methodName); |
|
| 91 | - |
|
| 92 | - // if an exception appears, the middleware checks if it can handle the |
|
| 93 | - // exception and creates a response. If no response is created, it is |
|
| 94 | - // assumed that theres no middleware who can handle it and the error is |
|
| 95 | - // thrown again |
|
| 96 | - } catch(\Exception $exception){ |
|
| 97 | - $response = $this->middlewareDispatcher->afterException( |
|
| 98 | - $controller, $methodName, $exception); |
|
| 99 | - if (is_null($response)) { |
|
| 100 | - throw $exception; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $response = $this->middlewareDispatcher->afterController( |
|
| 105 | - $controller, $methodName, $response); |
|
| 106 | - |
|
| 107 | - // depending on the cache object the headers need to be changed |
|
| 108 | - $out[0] = $this->protocol->getStatusHeader($response->getStatus(), |
|
| 109 | - $response->getLastModified(), $response->getETag()); |
|
| 110 | - $out[1] = array_merge($response->getHeaders()); |
|
| 111 | - $out[2] = $response->getCookies(); |
|
| 112 | - $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
| 113 | - $controller, $methodName, $response->render() |
|
| 114 | - ); |
|
| 115 | - $out[4] = $response; |
|
| 116 | - |
|
| 117 | - return $out; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Uses the reflected parameters, types and request parameters to execute |
|
| 123 | - * the controller |
|
| 124 | - * @param Controller $controller the controller to be executed |
|
| 125 | - * @param string $methodName the method on the controller that should be executed |
|
| 126 | - * @return Response |
|
| 127 | - */ |
|
| 128 | - private function executeController($controller, $methodName) { |
|
| 129 | - $arguments = array(); |
|
| 130 | - |
|
| 131 | - // valid types that will be casted |
|
| 132 | - $types = array('int', 'integer', 'bool', 'boolean', 'float'); |
|
| 133 | - |
|
| 134 | - foreach($this->reflector->getParameters() as $param => $default) { |
|
| 135 | - |
|
| 136 | - // try to get the parameter from the request object and cast |
|
| 137 | - // it to the type annotated in the @param annotation |
|
| 138 | - $value = $this->request->getParam($param, $default); |
|
| 139 | - $type = $this->reflector->getType($param); |
|
| 140 | - |
|
| 141 | - // if this is submitted using GET or a POST form, 'false' should be |
|
| 142 | - // converted to false |
|
| 143 | - if(($type === 'bool' || $type === 'boolean') && |
|
| 144 | - $value === 'false' && |
|
| 145 | - ( |
|
| 146 | - $this->request->method === 'GET' || |
|
| 147 | - strpos($this->request->getHeader('Content-Type'), |
|
| 148 | - 'application/x-www-form-urlencoded') !== false |
|
| 149 | - ) |
|
| 150 | - ) { |
|
| 151 | - $value = false; |
|
| 152 | - |
|
| 153 | - } elseif($value !== null && in_array($type, $types)) { |
|
| 154 | - settype($value, $type); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $arguments[] = $value; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $response = call_user_func_array(array($controller, $methodName), $arguments); |
|
| 161 | - |
|
| 162 | - // format response |
|
| 163 | - if($response instanceof DataResponse || !($response instanceof Response)) { |
|
| 164 | - |
|
| 165 | - // get format from the url format or request format parameter |
|
| 166 | - $format = $this->request->getParam('format'); |
|
| 167 | - |
|
| 168 | - // if none is given try the first Accept header |
|
| 169 | - if($format === null) { |
|
| 170 | - $headers = $this->request->getHeader('Accept'); |
|
| 171 | - $format = $controller->getResponderByHTTPHeader($headers, null); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if ($format !== null) { |
|
| 175 | - $response = $controller->buildResponse($response, $format); |
|
| 176 | - } else { |
|
| 177 | - $response = $controller->buildResponse($response); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return $response; |
|
| 182 | - } |
|
| 46 | + private $middlewareDispatcher; |
|
| 47 | + private $protocol; |
|
| 48 | + private $reflector; |
|
| 49 | + private $request; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @param Http $protocol the http protocol with contains all status headers |
|
| 53 | + * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
| 54 | + * runs the middleware |
|
| 55 | + * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
| 56 | + * the arguments for the controller |
|
| 57 | + * @param IRequest $request the incoming request |
|
| 58 | + */ |
|
| 59 | + public function __construct(Http $protocol, |
|
| 60 | + MiddlewareDispatcher $middlewareDispatcher, |
|
| 61 | + ControllerMethodReflector $reflector, |
|
| 62 | + IRequest $request) { |
|
| 63 | + $this->protocol = $protocol; |
|
| 64 | + $this->middlewareDispatcher = $middlewareDispatcher; |
|
| 65 | + $this->reflector = $reflector; |
|
| 66 | + $this->request = $request; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Handles a request and calls the dispatcher on the controller |
|
| 72 | + * @param Controller $controller the controller which will be called |
|
| 73 | + * @param string $methodName the method name which will be called on |
|
| 74 | + * the controller |
|
| 75 | + * @return array $array[0] contains a string with the http main header, |
|
| 76 | + * $array[1] contains headers in the form: $key => value, $array[2] contains |
|
| 77 | + * the response output |
|
| 78 | + * @throws \Exception |
|
| 79 | + */ |
|
| 80 | + public function dispatch(Controller $controller, $methodName) { |
|
| 81 | + $out = array(null, array(), null); |
|
| 82 | + |
|
| 83 | + try { |
|
| 84 | + // prefill reflector with everything thats needed for the |
|
| 85 | + // middlewares |
|
| 86 | + $this->reflector->reflect($controller, $methodName); |
|
| 87 | + |
|
| 88 | + $this->middlewareDispatcher->beforeController($controller, |
|
| 89 | + $methodName); |
|
| 90 | + $response = $this->executeController($controller, $methodName); |
|
| 91 | + |
|
| 92 | + // if an exception appears, the middleware checks if it can handle the |
|
| 93 | + // exception and creates a response. If no response is created, it is |
|
| 94 | + // assumed that theres no middleware who can handle it and the error is |
|
| 95 | + // thrown again |
|
| 96 | + } catch(\Exception $exception){ |
|
| 97 | + $response = $this->middlewareDispatcher->afterException( |
|
| 98 | + $controller, $methodName, $exception); |
|
| 99 | + if (is_null($response)) { |
|
| 100 | + throw $exception; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $response = $this->middlewareDispatcher->afterController( |
|
| 105 | + $controller, $methodName, $response); |
|
| 106 | + |
|
| 107 | + // depending on the cache object the headers need to be changed |
|
| 108 | + $out[0] = $this->protocol->getStatusHeader($response->getStatus(), |
|
| 109 | + $response->getLastModified(), $response->getETag()); |
|
| 110 | + $out[1] = array_merge($response->getHeaders()); |
|
| 111 | + $out[2] = $response->getCookies(); |
|
| 112 | + $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
| 113 | + $controller, $methodName, $response->render() |
|
| 114 | + ); |
|
| 115 | + $out[4] = $response; |
|
| 116 | + |
|
| 117 | + return $out; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Uses the reflected parameters, types and request parameters to execute |
|
| 123 | + * the controller |
|
| 124 | + * @param Controller $controller the controller to be executed |
|
| 125 | + * @param string $methodName the method on the controller that should be executed |
|
| 126 | + * @return Response |
|
| 127 | + */ |
|
| 128 | + private function executeController($controller, $methodName) { |
|
| 129 | + $arguments = array(); |
|
| 130 | + |
|
| 131 | + // valid types that will be casted |
|
| 132 | + $types = array('int', 'integer', 'bool', 'boolean', 'float'); |
|
| 133 | + |
|
| 134 | + foreach($this->reflector->getParameters() as $param => $default) { |
|
| 135 | + |
|
| 136 | + // try to get the parameter from the request object and cast |
|
| 137 | + // it to the type annotated in the @param annotation |
|
| 138 | + $value = $this->request->getParam($param, $default); |
|
| 139 | + $type = $this->reflector->getType($param); |
|
| 140 | + |
|
| 141 | + // if this is submitted using GET or a POST form, 'false' should be |
|
| 142 | + // converted to false |
|
| 143 | + if(($type === 'bool' || $type === 'boolean') && |
|
| 144 | + $value === 'false' && |
|
| 145 | + ( |
|
| 146 | + $this->request->method === 'GET' || |
|
| 147 | + strpos($this->request->getHeader('Content-Type'), |
|
| 148 | + 'application/x-www-form-urlencoded') !== false |
|
| 149 | + ) |
|
| 150 | + ) { |
|
| 151 | + $value = false; |
|
| 152 | + |
|
| 153 | + } elseif($value !== null && in_array($type, $types)) { |
|
| 154 | + settype($value, $type); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $arguments[] = $value; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $response = call_user_func_array(array($controller, $methodName), $arguments); |
|
| 161 | + |
|
| 162 | + // format response |
|
| 163 | + if($response instanceof DataResponse || !($response instanceof Response)) { |
|
| 164 | + |
|
| 165 | + // get format from the url format or request format parameter |
|
| 166 | + $format = $this->request->getParam('format'); |
|
| 167 | + |
|
| 168 | + // if none is given try the first Accept header |
|
| 169 | + if($format === null) { |
|
| 170 | + $headers = $this->request->getHeader('Accept'); |
|
| 171 | + $format = $controller->getResponderByHTTPHeader($headers, null); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if ($format !== null) { |
|
| 175 | + $response = $controller->buildResponse($response, $format); |
|
| 176 | + } else { |
|
| 177 | + $response = $controller->buildResponse($response); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return $response; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | // exception and creates a response. If no response is created, it is |
| 94 | 94 | // assumed that theres no middleware who can handle it and the error is |
| 95 | 95 | // thrown again |
| 96 | - } catch(\Exception $exception){ |
|
| 96 | + } catch (\Exception $exception) { |
|
| 97 | 97 | $response = $this->middlewareDispatcher->afterException( |
| 98 | 98 | $controller, $methodName, $exception); |
| 99 | 99 | if (is_null($response)) { |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | // valid types that will be casted |
| 132 | 132 | $types = array('int', 'integer', 'bool', 'boolean', 'float'); |
| 133 | 133 | |
| 134 | - foreach($this->reflector->getParameters() as $param => $default) { |
|
| 134 | + foreach ($this->reflector->getParameters() as $param => $default) { |
|
| 135 | 135 | |
| 136 | 136 | // try to get the parameter from the request object and cast |
| 137 | 137 | // it to the type annotated in the @param annotation |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | // if this is submitted using GET or a POST form, 'false' should be |
| 142 | 142 | // converted to false |
| 143 | - if(($type === 'bool' || $type === 'boolean') && |
|
| 143 | + if (($type === 'bool' || $type === 'boolean') && |
|
| 144 | 144 | $value === 'false' && |
| 145 | 145 | ( |
| 146 | 146 | $this->request->method === 'GET' || |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | ) { |
| 151 | 151 | $value = false; |
| 152 | 152 | |
| 153 | - } elseif($value !== null && in_array($type, $types)) { |
|
| 153 | + } elseif ($value !== null && in_array($type, $types)) { |
|
| 154 | 154 | settype($value, $type); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | $response = call_user_func_array(array($controller, $methodName), $arguments); |
| 161 | 161 | |
| 162 | 162 | // format response |
| 163 | - if($response instanceof DataResponse || !($response instanceof Response)) { |
|
| 163 | + if ($response instanceof DataResponse || !($response instanceof Response)) { |
|
| 164 | 164 | |
| 165 | 165 | // get format from the url format or request format parameter |
| 166 | 166 | $format = $this->request->getParam('format'); |
| 167 | 167 | |
| 168 | 168 | // if none is given try the first Accept header |
| 169 | - if($format === null) { |
|
| 169 | + if ($format === null) { |
|
| 170 | 170 | $headers = $this->request->getHeader('Accept'); |
| 171 | 171 | $format = $controller->getResponderByHTTPHeader($headers, null); |
| 172 | 172 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param array $server $_SERVER |
| 42 | 42 | * @param string $protocolVersion the http version to use defaults to HTTP/1.1 |
| 43 | 43 | */ |
| 44 | - public function __construct($server, $protocolVersion='HTTP/1.1') { |
|
| 44 | + public function __construct($server, $protocolVersion = 'HTTP/1.1') { |
|
| 45 | 45 | $this->server = $server; |
| 46 | 46 | $this->protocolVersion = $protocolVersion; |
| 47 | 47 | |
@@ -116,16 +116,16 @@ discard block |
||
| 116 | 116 | * @param string $ETag the etag |
| 117 | 117 | * @return string |
| 118 | 118 | */ |
| 119 | - public function getStatusHeader($status, \DateTime $lastModified=null, |
|
| 120 | - $ETag=null) { |
|
| 119 | + public function getStatusHeader($status, \DateTime $lastModified = null, |
|
| 120 | + $ETag = null) { |
|
| 121 | 121 | |
| 122 | - if(!is_null($lastModified)) { |
|
| 122 | + if (!is_null($lastModified)) { |
|
| 123 | 123 | $lastModified = $lastModified->format(\DateTime::RFC2822); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // if etag or lastmodified have not changed, return a not modified |
| 127 | 127 | if ((isset($this->server['HTTP_IF_NONE_MATCH']) |
| 128 | - && trim(trim($this->server['HTTP_IF_NONE_MATCH']), '"') === (string)$ETag) |
|
| 128 | + && trim(trim($this->server['HTTP_IF_NONE_MATCH']), '"') === (string) $ETag) |
|
| 129 | 129 | |
| 130 | 130 | || |
| 131 | 131 | |
@@ -139,13 +139,13 @@ discard block |
||
| 139 | 139 | // we have one change currently for the http 1.0 header that differs |
| 140 | 140 | // from 1.1: STATUS_TEMPORARY_REDIRECT should be STATUS_FOUND |
| 141 | 141 | // if this differs any more, we want to create childclasses for this |
| 142 | - if($status === self::STATUS_TEMPORARY_REDIRECT |
|
| 142 | + if ($status === self::STATUS_TEMPORARY_REDIRECT |
|
| 143 | 143 | && $this->protocolVersion === 'HTTP/1.0') { |
| 144 | 144 | |
| 145 | 145 | $status = self::STATUS_FOUND; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - return $this->protocolVersion . ' ' . $status . ' ' . |
|
| 148 | + return $this->protocolVersion.' '.$status.' '. |
|
| 149 | 149 | $this->headers[$status]; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -33,121 +33,121 @@ |
||
| 33 | 33 | |
| 34 | 34 | class Http extends BaseHttp { |
| 35 | 35 | |
| 36 | - private $server; |
|
| 37 | - private $protocolVersion; |
|
| 38 | - protected $headers; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param array $server $_SERVER |
|
| 42 | - * @param string $protocolVersion the http version to use defaults to HTTP/1.1 |
|
| 43 | - */ |
|
| 44 | - public function __construct($server, $protocolVersion='HTTP/1.1') { |
|
| 45 | - $this->server = $server; |
|
| 46 | - $this->protocolVersion = $protocolVersion; |
|
| 47 | - |
|
| 48 | - $this->headers = array( |
|
| 49 | - self::STATUS_CONTINUE => 'Continue', |
|
| 50 | - self::STATUS_SWITCHING_PROTOCOLS => 'Switching Protocols', |
|
| 51 | - self::STATUS_PROCESSING => 'Processing', |
|
| 52 | - self::STATUS_OK => 'OK', |
|
| 53 | - self::STATUS_CREATED => 'Created', |
|
| 54 | - self::STATUS_ACCEPTED => 'Accepted', |
|
| 55 | - self::STATUS_NON_AUTHORATIVE_INFORMATION => 'Non-Authorative Information', |
|
| 56 | - self::STATUS_NO_CONTENT => 'No Content', |
|
| 57 | - self::STATUS_RESET_CONTENT => 'Reset Content', |
|
| 58 | - self::STATUS_PARTIAL_CONTENT => 'Partial Content', |
|
| 59 | - self::STATUS_MULTI_STATUS => 'Multi-Status', // RFC 4918 |
|
| 60 | - self::STATUS_ALREADY_REPORTED => 'Already Reported', // RFC 5842 |
|
| 61 | - self::STATUS_IM_USED => 'IM Used', // RFC 3229 |
|
| 62 | - self::STATUS_MULTIPLE_CHOICES => 'Multiple Choices', |
|
| 63 | - self::STATUS_MOVED_PERMANENTLY => 'Moved Permanently', |
|
| 64 | - self::STATUS_FOUND => 'Found', |
|
| 65 | - self::STATUS_SEE_OTHER => 'See Other', |
|
| 66 | - self::STATUS_NOT_MODIFIED => 'Not Modified', |
|
| 67 | - self::STATUS_USE_PROXY => 'Use Proxy', |
|
| 68 | - self::STATUS_RESERVED => 'Reserved', |
|
| 69 | - self::STATUS_TEMPORARY_REDIRECT => 'Temporary Redirect', |
|
| 70 | - self::STATUS_BAD_REQUEST => 'Bad request', |
|
| 71 | - self::STATUS_UNAUTHORIZED => 'Unauthorized', |
|
| 72 | - self::STATUS_PAYMENT_REQUIRED => 'Payment Required', |
|
| 73 | - self::STATUS_FORBIDDEN => 'Forbidden', |
|
| 74 | - self::STATUS_NOT_FOUND => 'Not Found', |
|
| 75 | - self::STATUS_METHOD_NOT_ALLOWED => 'Method Not Allowed', |
|
| 76 | - self::STATUS_NOT_ACCEPTABLE => 'Not Acceptable', |
|
| 77 | - self::STATUS_PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required', |
|
| 78 | - self::STATUS_REQUEST_TIMEOUT => 'Request Timeout', |
|
| 79 | - self::STATUS_CONFLICT => 'Conflict', |
|
| 80 | - self::STATUS_GONE => 'Gone', |
|
| 81 | - self::STATUS_LENGTH_REQUIRED => 'Length Required', |
|
| 82 | - self::STATUS_PRECONDITION_FAILED => 'Precondition failed', |
|
| 83 | - self::STATUS_REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large', |
|
| 84 | - self::STATUS_REQUEST_URI_TOO_LONG => 'Request-URI Too Long', |
|
| 85 | - self::STATUS_UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type', |
|
| 86 | - self::STATUS_REQUEST_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable', |
|
| 87 | - self::STATUS_EXPECTATION_FAILED => 'Expectation Failed', |
|
| 88 | - self::STATUS_IM_A_TEAPOT => 'I\'m a teapot', // RFC 2324 |
|
| 89 | - self::STATUS_UNPROCESSABLE_ENTITY => 'Unprocessable Entity', // RFC 4918 |
|
| 90 | - self::STATUS_LOCKED => 'Locked', // RFC 4918 |
|
| 91 | - self::STATUS_FAILED_DEPENDENCY => 'Failed Dependency', // RFC 4918 |
|
| 92 | - self::STATUS_UPGRADE_REQUIRED => 'Upgrade required', |
|
| 93 | - self::STATUS_PRECONDITION_REQUIRED => 'Precondition required', // draft-nottingham-http-new-status |
|
| 94 | - self::STATUS_TOO_MANY_REQUESTS => 'Too Many Requests', // draft-nottingham-http-new-status |
|
| 95 | - self::STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large', // draft-nottingham-http-new-status |
|
| 96 | - self::STATUS_INTERNAL_SERVER_ERROR => 'Internal Server Error', |
|
| 97 | - self::STATUS_NOT_IMPLEMENTED => 'Not Implemented', |
|
| 98 | - self::STATUS_BAD_GATEWAY => 'Bad Gateway', |
|
| 99 | - self::STATUS_SERVICE_UNAVAILABLE => 'Service Unavailable', |
|
| 100 | - self::STATUS_GATEWAY_TIMEOUT => 'Gateway Timeout', |
|
| 101 | - self::STATUS_HTTP_VERSION_NOT_SUPPORTED => 'HTTP Version not supported', |
|
| 102 | - self::STATUS_VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates', |
|
| 103 | - self::STATUS_INSUFFICIENT_STORAGE => 'Insufficient Storage', // RFC 4918 |
|
| 104 | - self::STATUS_LOOP_DETECTED => 'Loop Detected', // RFC 5842 |
|
| 105 | - self::STATUS_BANDWIDTH_LIMIT_EXCEEDED => 'Bandwidth Limit Exceeded', // non-standard |
|
| 106 | - self::STATUS_NOT_EXTENDED => 'Not extended', |
|
| 107 | - self::STATUS_NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required', // draft-nottingham-http-new-status |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Gets the correct header |
|
| 114 | - * @param int Http::CONSTANT $status the constant from the Http class |
|
| 115 | - * @param \DateTime $lastModified formatted last modified date |
|
| 116 | - * @param string $ETag the etag |
|
| 117 | - * @return string |
|
| 118 | - */ |
|
| 119 | - public function getStatusHeader($status, \DateTime $lastModified=null, |
|
| 120 | - $ETag=null) { |
|
| 121 | - |
|
| 122 | - if(!is_null($lastModified)) { |
|
| 123 | - $lastModified = $lastModified->format(\DateTime::RFC2822); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // if etag or lastmodified have not changed, return a not modified |
|
| 127 | - if ((isset($this->server['HTTP_IF_NONE_MATCH']) |
|
| 128 | - && trim(trim($this->server['HTTP_IF_NONE_MATCH']), '"') === (string)$ETag) |
|
| 129 | - |
|
| 130 | - || |
|
| 131 | - |
|
| 132 | - (isset($this->server['HTTP_IF_MODIFIED_SINCE']) |
|
| 133 | - && trim($this->server['HTTP_IF_MODIFIED_SINCE']) === |
|
| 134 | - $lastModified)) { |
|
| 135 | - |
|
| 136 | - $status = self::STATUS_NOT_MODIFIED; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // we have one change currently for the http 1.0 header that differs |
|
| 140 | - // from 1.1: STATUS_TEMPORARY_REDIRECT should be STATUS_FOUND |
|
| 141 | - // if this differs any more, we want to create childclasses for this |
|
| 142 | - if($status === self::STATUS_TEMPORARY_REDIRECT |
|
| 143 | - && $this->protocolVersion === 'HTTP/1.0') { |
|
| 144 | - |
|
| 145 | - $status = self::STATUS_FOUND; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $this->protocolVersion . ' ' . $status . ' ' . |
|
| 149 | - $this->headers[$status]; |
|
| 150 | - } |
|
| 36 | + private $server; |
|
| 37 | + private $protocolVersion; |
|
| 38 | + protected $headers; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param array $server $_SERVER |
|
| 42 | + * @param string $protocolVersion the http version to use defaults to HTTP/1.1 |
|
| 43 | + */ |
|
| 44 | + public function __construct($server, $protocolVersion='HTTP/1.1') { |
|
| 45 | + $this->server = $server; |
|
| 46 | + $this->protocolVersion = $protocolVersion; |
|
| 47 | + |
|
| 48 | + $this->headers = array( |
|
| 49 | + self::STATUS_CONTINUE => 'Continue', |
|
| 50 | + self::STATUS_SWITCHING_PROTOCOLS => 'Switching Protocols', |
|
| 51 | + self::STATUS_PROCESSING => 'Processing', |
|
| 52 | + self::STATUS_OK => 'OK', |
|
| 53 | + self::STATUS_CREATED => 'Created', |
|
| 54 | + self::STATUS_ACCEPTED => 'Accepted', |
|
| 55 | + self::STATUS_NON_AUTHORATIVE_INFORMATION => 'Non-Authorative Information', |
|
| 56 | + self::STATUS_NO_CONTENT => 'No Content', |
|
| 57 | + self::STATUS_RESET_CONTENT => 'Reset Content', |
|
| 58 | + self::STATUS_PARTIAL_CONTENT => 'Partial Content', |
|
| 59 | + self::STATUS_MULTI_STATUS => 'Multi-Status', // RFC 4918 |
|
| 60 | + self::STATUS_ALREADY_REPORTED => 'Already Reported', // RFC 5842 |
|
| 61 | + self::STATUS_IM_USED => 'IM Used', // RFC 3229 |
|
| 62 | + self::STATUS_MULTIPLE_CHOICES => 'Multiple Choices', |
|
| 63 | + self::STATUS_MOVED_PERMANENTLY => 'Moved Permanently', |
|
| 64 | + self::STATUS_FOUND => 'Found', |
|
| 65 | + self::STATUS_SEE_OTHER => 'See Other', |
|
| 66 | + self::STATUS_NOT_MODIFIED => 'Not Modified', |
|
| 67 | + self::STATUS_USE_PROXY => 'Use Proxy', |
|
| 68 | + self::STATUS_RESERVED => 'Reserved', |
|
| 69 | + self::STATUS_TEMPORARY_REDIRECT => 'Temporary Redirect', |
|
| 70 | + self::STATUS_BAD_REQUEST => 'Bad request', |
|
| 71 | + self::STATUS_UNAUTHORIZED => 'Unauthorized', |
|
| 72 | + self::STATUS_PAYMENT_REQUIRED => 'Payment Required', |
|
| 73 | + self::STATUS_FORBIDDEN => 'Forbidden', |
|
| 74 | + self::STATUS_NOT_FOUND => 'Not Found', |
|
| 75 | + self::STATUS_METHOD_NOT_ALLOWED => 'Method Not Allowed', |
|
| 76 | + self::STATUS_NOT_ACCEPTABLE => 'Not Acceptable', |
|
| 77 | + self::STATUS_PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required', |
|
| 78 | + self::STATUS_REQUEST_TIMEOUT => 'Request Timeout', |
|
| 79 | + self::STATUS_CONFLICT => 'Conflict', |
|
| 80 | + self::STATUS_GONE => 'Gone', |
|
| 81 | + self::STATUS_LENGTH_REQUIRED => 'Length Required', |
|
| 82 | + self::STATUS_PRECONDITION_FAILED => 'Precondition failed', |
|
| 83 | + self::STATUS_REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large', |
|
| 84 | + self::STATUS_REQUEST_URI_TOO_LONG => 'Request-URI Too Long', |
|
| 85 | + self::STATUS_UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type', |
|
| 86 | + self::STATUS_REQUEST_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable', |
|
| 87 | + self::STATUS_EXPECTATION_FAILED => 'Expectation Failed', |
|
| 88 | + self::STATUS_IM_A_TEAPOT => 'I\'m a teapot', // RFC 2324 |
|
| 89 | + self::STATUS_UNPROCESSABLE_ENTITY => 'Unprocessable Entity', // RFC 4918 |
|
| 90 | + self::STATUS_LOCKED => 'Locked', // RFC 4918 |
|
| 91 | + self::STATUS_FAILED_DEPENDENCY => 'Failed Dependency', // RFC 4918 |
|
| 92 | + self::STATUS_UPGRADE_REQUIRED => 'Upgrade required', |
|
| 93 | + self::STATUS_PRECONDITION_REQUIRED => 'Precondition required', // draft-nottingham-http-new-status |
|
| 94 | + self::STATUS_TOO_MANY_REQUESTS => 'Too Many Requests', // draft-nottingham-http-new-status |
|
| 95 | + self::STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large', // draft-nottingham-http-new-status |
|
| 96 | + self::STATUS_INTERNAL_SERVER_ERROR => 'Internal Server Error', |
|
| 97 | + self::STATUS_NOT_IMPLEMENTED => 'Not Implemented', |
|
| 98 | + self::STATUS_BAD_GATEWAY => 'Bad Gateway', |
|
| 99 | + self::STATUS_SERVICE_UNAVAILABLE => 'Service Unavailable', |
|
| 100 | + self::STATUS_GATEWAY_TIMEOUT => 'Gateway Timeout', |
|
| 101 | + self::STATUS_HTTP_VERSION_NOT_SUPPORTED => 'HTTP Version not supported', |
|
| 102 | + self::STATUS_VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates', |
|
| 103 | + self::STATUS_INSUFFICIENT_STORAGE => 'Insufficient Storage', // RFC 4918 |
|
| 104 | + self::STATUS_LOOP_DETECTED => 'Loop Detected', // RFC 5842 |
|
| 105 | + self::STATUS_BANDWIDTH_LIMIT_EXCEEDED => 'Bandwidth Limit Exceeded', // non-standard |
|
| 106 | + self::STATUS_NOT_EXTENDED => 'Not extended', |
|
| 107 | + self::STATUS_NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required', // draft-nottingham-http-new-status |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Gets the correct header |
|
| 114 | + * @param int Http::CONSTANT $status the constant from the Http class |
|
| 115 | + * @param \DateTime $lastModified formatted last modified date |
|
| 116 | + * @param string $ETag the etag |
|
| 117 | + * @return string |
|
| 118 | + */ |
|
| 119 | + public function getStatusHeader($status, \DateTime $lastModified=null, |
|
| 120 | + $ETag=null) { |
|
| 121 | + |
|
| 122 | + if(!is_null($lastModified)) { |
|
| 123 | + $lastModified = $lastModified->format(\DateTime::RFC2822); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // if etag or lastmodified have not changed, return a not modified |
|
| 127 | + if ((isset($this->server['HTTP_IF_NONE_MATCH']) |
|
| 128 | + && trim(trim($this->server['HTTP_IF_NONE_MATCH']), '"') === (string)$ETag) |
|
| 129 | + |
|
| 130 | + || |
|
| 131 | + |
|
| 132 | + (isset($this->server['HTTP_IF_MODIFIED_SINCE']) |
|
| 133 | + && trim($this->server['HTTP_IF_MODIFIED_SINCE']) === |
|
| 134 | + $lastModified)) { |
|
| 135 | + |
|
| 136 | + $status = self::STATUS_NOT_MODIFIED; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // we have one change currently for the http 1.0 header that differs |
|
| 140 | + // from 1.1: STATUS_TEMPORARY_REDIRECT should be STATUS_FOUND |
|
| 141 | + // if this differs any more, we want to create childclasses for this |
|
| 142 | + if($status === self::STATUS_TEMPORARY_REDIRECT |
|
| 143 | + && $this->protocolVersion === 'HTTP/1.0') { |
|
| 144 | + |
|
| 145 | + $status = self::STATUS_FOUND; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $this->protocolVersion . ' ' . $status . ' ' . |
|
| 149 | + $this->headers[$status]; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | |
| 153 | 153 | } |
@@ -45,116 +45,116 @@ |
||
| 45 | 45 | * https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS |
| 46 | 46 | */ |
| 47 | 47 | class CORSMiddleware extends Middleware { |
| 48 | - /** @var IRequest */ |
|
| 49 | - private $request; |
|
| 50 | - /** @var ControllerMethodReflector */ |
|
| 51 | - private $reflector; |
|
| 52 | - /** @var Session */ |
|
| 53 | - private $session; |
|
| 54 | - /** @var Throttler */ |
|
| 55 | - private $throttler; |
|
| 48 | + /** @var IRequest */ |
|
| 49 | + private $request; |
|
| 50 | + /** @var ControllerMethodReflector */ |
|
| 51 | + private $reflector; |
|
| 52 | + /** @var Session */ |
|
| 53 | + private $session; |
|
| 54 | + /** @var Throttler */ |
|
| 55 | + private $throttler; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param IRequest $request |
|
| 59 | - * @param ControllerMethodReflector $reflector |
|
| 60 | - * @param Session $session |
|
| 61 | - * @param Throttler $throttler |
|
| 62 | - */ |
|
| 63 | - public function __construct(IRequest $request, |
|
| 64 | - ControllerMethodReflector $reflector, |
|
| 65 | - Session $session, |
|
| 66 | - Throttler $throttler) { |
|
| 67 | - $this->request = $request; |
|
| 68 | - $this->reflector = $reflector; |
|
| 69 | - $this->session = $session; |
|
| 70 | - $this->throttler = $throttler; |
|
| 71 | - } |
|
| 57 | + /** |
|
| 58 | + * @param IRequest $request |
|
| 59 | + * @param ControllerMethodReflector $reflector |
|
| 60 | + * @param Session $session |
|
| 61 | + * @param Throttler $throttler |
|
| 62 | + */ |
|
| 63 | + public function __construct(IRequest $request, |
|
| 64 | + ControllerMethodReflector $reflector, |
|
| 65 | + Session $session, |
|
| 66 | + Throttler $throttler) { |
|
| 67 | + $this->request = $request; |
|
| 68 | + $this->reflector = $reflector; |
|
| 69 | + $this->session = $session; |
|
| 70 | + $this->throttler = $throttler; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * This is being run in normal order before the controller is being |
|
| 75 | - * called which allows several modifications and checks |
|
| 76 | - * |
|
| 77 | - * @param Controller $controller the controller that is being called |
|
| 78 | - * @param string $methodName the name of the method that will be called on |
|
| 79 | - * the controller |
|
| 80 | - * @throws SecurityException |
|
| 81 | - * @since 6.0.0 |
|
| 82 | - */ |
|
| 83 | - public function beforeController($controller, $methodName){ |
|
| 84 | - // ensure that @CORS annotated API routes are not used in conjunction |
|
| 85 | - // with session authentication since this enables CSRF attack vectors |
|
| 86 | - if ($this->reflector->hasAnnotation('CORS') && |
|
| 87 | - !$this->reflector->hasAnnotation('PublicPage')) { |
|
| 88 | - $user = $this->request->server['PHP_AUTH_USER']; |
|
| 89 | - $pass = $this->request->server['PHP_AUTH_PW']; |
|
| 73 | + /** |
|
| 74 | + * This is being run in normal order before the controller is being |
|
| 75 | + * called which allows several modifications and checks |
|
| 76 | + * |
|
| 77 | + * @param Controller $controller the controller that is being called |
|
| 78 | + * @param string $methodName the name of the method that will be called on |
|
| 79 | + * the controller |
|
| 80 | + * @throws SecurityException |
|
| 81 | + * @since 6.0.0 |
|
| 82 | + */ |
|
| 83 | + public function beforeController($controller, $methodName){ |
|
| 84 | + // ensure that @CORS annotated API routes are not used in conjunction |
|
| 85 | + // with session authentication since this enables CSRF attack vectors |
|
| 86 | + if ($this->reflector->hasAnnotation('CORS') && |
|
| 87 | + !$this->reflector->hasAnnotation('PublicPage')) { |
|
| 88 | + $user = $this->request->server['PHP_AUTH_USER']; |
|
| 89 | + $pass = $this->request->server['PHP_AUTH_PW']; |
|
| 90 | 90 | |
| 91 | - $this->session->logout(); |
|
| 92 | - try { |
|
| 93 | - if (!$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) { |
|
| 94 | - throw new SecurityException('CORS requires basic auth', Http::STATUS_UNAUTHORIZED); |
|
| 95 | - } |
|
| 96 | - } catch (PasswordLoginForbiddenException $ex) { |
|
| 97 | - throw new SecurityException('Password login forbidden, use token instead', Http::STATUS_UNAUTHORIZED); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 91 | + $this->session->logout(); |
|
| 92 | + try { |
|
| 93 | + if (!$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) { |
|
| 94 | + throw new SecurityException('CORS requires basic auth', Http::STATUS_UNAUTHORIZED); |
|
| 95 | + } |
|
| 96 | + } catch (PasswordLoginForbiddenException $ex) { |
|
| 97 | + throw new SecurityException('Password login forbidden, use token instead', Http::STATUS_UNAUTHORIZED); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * This is being run after a successful controllermethod call and allows |
|
| 104 | - * the manipulation of a Response object. The middleware is run in reverse order |
|
| 105 | - * |
|
| 106 | - * @param Controller $controller the controller that is being called |
|
| 107 | - * @param string $methodName the name of the method that will be called on |
|
| 108 | - * the controller |
|
| 109 | - * @param Response $response the generated response from the controller |
|
| 110 | - * @return Response a Response object |
|
| 111 | - * @throws SecurityException |
|
| 112 | - */ |
|
| 113 | - public function afterController($controller, $methodName, Response $response){ |
|
| 114 | - // only react if its a CORS request and if the request sends origin and |
|
| 102 | + /** |
|
| 103 | + * This is being run after a successful controllermethod call and allows |
|
| 104 | + * the manipulation of a Response object. The middleware is run in reverse order |
|
| 105 | + * |
|
| 106 | + * @param Controller $controller the controller that is being called |
|
| 107 | + * @param string $methodName the name of the method that will be called on |
|
| 108 | + * the controller |
|
| 109 | + * @param Response $response the generated response from the controller |
|
| 110 | + * @return Response a Response object |
|
| 111 | + * @throws SecurityException |
|
| 112 | + */ |
|
| 113 | + public function afterController($controller, $methodName, Response $response){ |
|
| 114 | + // only react if its a CORS request and if the request sends origin and |
|
| 115 | 115 | |
| 116 | - if(isset($this->request->server['HTTP_ORIGIN']) && |
|
| 117 | - $this->reflector->hasAnnotation('CORS')) { |
|
| 116 | + if(isset($this->request->server['HTTP_ORIGIN']) && |
|
| 117 | + $this->reflector->hasAnnotation('CORS')) { |
|
| 118 | 118 | |
| 119 | - // allow credentials headers must not be true or CSRF is possible |
|
| 120 | - // otherwise |
|
| 121 | - foreach($response->getHeaders() as $header => $value) { |
|
| 122 | - if(strtolower($header) === 'access-control-allow-credentials' && |
|
| 123 | - strtolower(trim($value)) === 'true') { |
|
| 124 | - $msg = 'Access-Control-Allow-Credentials must not be '. |
|
| 125 | - 'set to true in order to prevent CSRF'; |
|
| 126 | - throw new SecurityException($msg); |
|
| 127 | - } |
|
| 128 | - } |
|
| 119 | + // allow credentials headers must not be true or CSRF is possible |
|
| 120 | + // otherwise |
|
| 121 | + foreach($response->getHeaders() as $header => $value) { |
|
| 122 | + if(strtolower($header) === 'access-control-allow-credentials' && |
|
| 123 | + strtolower(trim($value)) === 'true') { |
|
| 124 | + $msg = 'Access-Control-Allow-Credentials must not be '. |
|
| 125 | + 'set to true in order to prevent CSRF'; |
|
| 126 | + throw new SecurityException($msg); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - $origin = $this->request->server['HTTP_ORIGIN']; |
|
| 131 | - $response->addHeader('Access-Control-Allow-Origin', $origin); |
|
| 132 | - } |
|
| 133 | - return $response; |
|
| 134 | - } |
|
| 130 | + $origin = $this->request->server['HTTP_ORIGIN']; |
|
| 131 | + $response->addHeader('Access-Control-Allow-Origin', $origin); |
|
| 132 | + } |
|
| 133 | + return $response; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * If an SecurityException is being caught return a JSON error response |
|
| 138 | - * |
|
| 139 | - * @param Controller $controller the controller that is being called |
|
| 140 | - * @param string $methodName the name of the method that will be called on |
|
| 141 | - * the controller |
|
| 142 | - * @param \Exception $exception the thrown exception |
|
| 143 | - * @throws \Exception the passed in exception if it can't handle it |
|
| 144 | - * @return Response a Response object or null in case that the exception could not be handled |
|
| 145 | - */ |
|
| 146 | - public function afterException($controller, $methodName, \Exception $exception){ |
|
| 147 | - if($exception instanceof SecurityException){ |
|
| 148 | - $response = new JSONResponse(['message' => $exception->getMessage()]); |
|
| 149 | - if($exception->getCode() !== 0) { |
|
| 150 | - $response->setStatus($exception->getCode()); |
|
| 151 | - } else { |
|
| 152 | - $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 153 | - } |
|
| 154 | - return $response; |
|
| 155 | - } |
|
| 136 | + /** |
|
| 137 | + * If an SecurityException is being caught return a JSON error response |
|
| 138 | + * |
|
| 139 | + * @param Controller $controller the controller that is being called |
|
| 140 | + * @param string $methodName the name of the method that will be called on |
|
| 141 | + * the controller |
|
| 142 | + * @param \Exception $exception the thrown exception |
|
| 143 | + * @throws \Exception the passed in exception if it can't handle it |
|
| 144 | + * @return Response a Response object or null in case that the exception could not be handled |
|
| 145 | + */ |
|
| 146 | + public function afterException($controller, $methodName, \Exception $exception){ |
|
| 147 | + if($exception instanceof SecurityException){ |
|
| 148 | + $response = new JSONResponse(['message' => $exception->getMessage()]); |
|
| 149 | + if($exception->getCode() !== 0) { |
|
| 150 | + $response->setStatus($exception->getCode()); |
|
| 151 | + } else { |
|
| 152 | + $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 153 | + } |
|
| 154 | + return $response; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - throw $exception; |
|
| 158 | - } |
|
| 157 | + throw $exception; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | 160 | } |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | * @throws SecurityException |
| 81 | 81 | * @since 6.0.0 |
| 82 | 82 | */ |
| 83 | - public function beforeController($controller, $methodName){ |
|
| 83 | + public function beforeController($controller, $methodName) { |
|
| 84 | 84 | // ensure that @CORS annotated API routes are not used in conjunction |
| 85 | 85 | // with session authentication since this enables CSRF attack vectors |
| 86 | 86 | if ($this->reflector->hasAnnotation('CORS') && |
| 87 | - !$this->reflector->hasAnnotation('PublicPage')) { |
|
| 87 | + !$this->reflector->hasAnnotation('PublicPage')) { |
|
| 88 | 88 | $user = $this->request->server['PHP_AUTH_USER']; |
| 89 | 89 | $pass = $this->request->server['PHP_AUTH_PW']; |
| 90 | 90 | |
@@ -110,16 +110,16 @@ discard block |
||
| 110 | 110 | * @return Response a Response object |
| 111 | 111 | * @throws SecurityException |
| 112 | 112 | */ |
| 113 | - public function afterController($controller, $methodName, Response $response){ |
|
| 113 | + public function afterController($controller, $methodName, Response $response) { |
|
| 114 | 114 | // only react if its a CORS request and if the request sends origin and |
| 115 | 115 | |
| 116 | - if(isset($this->request->server['HTTP_ORIGIN']) && |
|
| 116 | + if (isset($this->request->server['HTTP_ORIGIN']) && |
|
| 117 | 117 | $this->reflector->hasAnnotation('CORS')) { |
| 118 | 118 | |
| 119 | 119 | // allow credentials headers must not be true or CSRF is possible |
| 120 | 120 | // otherwise |
| 121 | - foreach($response->getHeaders() as $header => $value) { |
|
| 122 | - if(strtolower($header) === 'access-control-allow-credentials' && |
|
| 121 | + foreach ($response->getHeaders() as $header => $value) { |
|
| 122 | + if (strtolower($header) === 'access-control-allow-credentials' && |
|
| 123 | 123 | strtolower(trim($value)) === 'true') { |
| 124 | 124 | $msg = 'Access-Control-Allow-Credentials must not be '. |
| 125 | 125 | 'set to true in order to prevent CSRF'; |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | * @throws \Exception the passed in exception if it can't handle it |
| 144 | 144 | * @return Response a Response object or null in case that the exception could not be handled |
| 145 | 145 | */ |
| 146 | - public function afterException($controller, $methodName, \Exception $exception){ |
|
| 147 | - if($exception instanceof SecurityException){ |
|
| 148 | - $response = new JSONResponse(['message' => $exception->getMessage()]); |
|
| 149 | - if($exception->getCode() !== 0) { |
|
| 146 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 147 | + if ($exception instanceof SecurityException) { |
|
| 148 | + $response = new JSONResponse(['message' => $exception->getMessage()]); |
|
| 149 | + if ($exception->getCode() !== 0) { |
|
| 150 | 150 | $response->setStatus($exception->getCode()); |
| 151 | 151 | } else { |
| 152 | 152 | $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | * @package OC\AppFramework\Middleware\Security\Exceptions |
| 32 | 32 | */ |
| 33 | 33 | class NotConfirmedException extends SecurityException { |
| 34 | - public function __construct() { |
|
| 35 | - parent::__construct('Password confirmation is required', Http::STATUS_FORBIDDEN); |
|
| 36 | - } |
|
| 34 | + public function __construct() { |
|
| 35 | + parent::__construct('Password confirmation is required', Http::STATUS_FORBIDDEN); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @package OC\AppFramework\Middleware\Security\Exceptions |
| 35 | 35 | */ |
| 36 | 36 | class CrossSiteRequestForgeryException extends SecurityException { |
| 37 | - public function __construct() { |
|
| 38 | - parent::__construct('CSRF check failed', Http::STATUS_PRECONDITION_FAILED); |
|
| 39 | - } |
|
| 37 | + public function __construct() { |
|
| 38 | + parent::__construct('CSRF check failed', Http::STATUS_PRECONDITION_FAILED); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @package OC\AppFramework\Middleware\Security\Exceptions |
| 35 | 35 | */ |
| 36 | 36 | class AppNotEnabledException extends SecurityException { |
| 37 | - public function __construct() { |
|
| 38 | - parent::__construct('App is not enabled', Http::STATUS_PRECONDITION_FAILED); |
|
| 39 | - } |
|
| 37 | + public function __construct() { |
|
| 38 | + parent::__construct('App is not enabled', Http::STATUS_PRECONDITION_FAILED); |
|
| 39 | + } |
|
| 40 | 40 | } |