Completed
Pull Request — master (#8565)
by Joas
105:07 queued 85:11
created
lib/public/AppFramework/Http/IOutput.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -32,48 +32,48 @@
 block discarded – undo
32 32
  */
33 33
 interface IOutput {
34 34
 
35
-	/**
36
-	 * @param string $out
37
-	 * @since 8.1.0
38
-	 */
39
-	public function setOutput($out);
35
+    /**
36
+     * @param string $out
37
+     * @since 8.1.0
38
+     */
39
+    public function setOutput($out);
40 40
 
41
-	/**
42
-	 * @param string|resource $path or file handle
43
-	 *
44
-	 * @return bool false if an error occurred
45
-	 * @since 8.1.0
46
-	 */
47
-	public function setReadfile($path);
41
+    /**
42
+     * @param string|resource $path or file handle
43
+     *
44
+     * @return bool false if an error occurred
45
+     * @since 8.1.0
46
+     */
47
+    public function setReadfile($path);
48 48
 
49
-	/**
50
-	 * @param string $header
51
-	 * @since 8.1.0
52
-	 */
53
-	public function setHeader($header);
49
+    /**
50
+     * @param string $header
51
+     * @since 8.1.0
52
+     */
53
+    public function setHeader($header);
54 54
 
55
-	/**
56
-	 * @return int returns the current http response code
57
-	 * @since 8.1.0
58
-	 */
59
-	public function getHttpResponseCode();
55
+    /**
56
+     * @return int returns the current http response code
57
+     * @since 8.1.0
58
+     */
59
+    public function getHttpResponseCode();
60 60
 
61
-	/**
62
-	 * @param int $code sets the http status code
63
-	 * @since 8.1.0
64
-	 */
65
-	public function setHttpResponseCode($code);
61
+    /**
62
+     * @param int $code sets the http status code
63
+     * @since 8.1.0
64
+     */
65
+    public function setHttpResponseCode($code);
66 66
 
67
-	/**
68
-	 * @param string $name
69
-	 * @param string $value
70
-	 * @param int $expire
71
-	 * @param string $path
72
-	 * @param string $domain
73
-	 * @param bool $secure
74
-	 * @param bool $httpOnly
75
-	 * @since 8.1.0
76
-	 */
77
-	public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
67
+    /**
68
+     * @param string $name
69
+     * @param string $value
70
+     * @param int $expire
71
+     * @param string $path
72
+     * @param string $domain
73
+     * @param bool $secure
74
+     * @param bool $httpOnly
75
+     * @since 8.1.0
76
+     */
77
+    public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
78 78
 
79 79
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/DownloadResponse.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -32,22 +32,22 @@
 block discarded – undo
32 32
  */
33 33
 class DownloadResponse extends \OCP\AppFramework\Http\Response {
34 34
 
35
-	private $filename;
36
-	private $contentType;
37
-
38
-	/**
39
-	 * Creates a response that prompts the user to download the file
40
-	 * @param string $filename the name that the downloaded file should have
41
-	 * @param string $contentType the mimetype that the downloaded file should have
42
-	 * @since 7.0.0
43
-	 */
44
-	public function __construct($filename, $contentType) {
45
-		$this->filename = $filename;
46
-		$this->contentType = $contentType;
47
-
48
-		$this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
49
-		$this->addHeader('Content-Type', $contentType);
50
-	}
35
+    private $filename;
36
+    private $contentType;
37
+
38
+    /**
39
+     * Creates a response that prompts the user to download the file
40
+     * @param string $filename the name that the downloaded file should have
41
+     * @param string $contentType the mimetype that the downloaded file should have
42
+     * @since 7.0.0
43
+     */
44
+    public function __construct($filename, $contentType) {
45
+        $this->filename = $filename;
46
+        $this->contentType = $contentType;
47
+
48
+        $this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
49
+        $this->addHeader('Content-Type', $contentType);
50
+    }
51 51
 
52 52
 
53 53
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
 		$this->filename = $filename;
46 46
 		$this->contentType = $contentType;
47 47
 
48
-		$this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
48
+		$this->addHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
49 49
 		$this->addHeader('Content-Type', $contentType);
50 50
 	}
51 51
 
Please login to merge, or discard this patch.
lib/public/AppFramework/App.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
 	 * @return string the starting namespace for the app
56 56
 	 * @since 8.0.0
57 57
 	 */
58
-	public static function buildAppNamespace($appId, $topNamespace='OCA\\') {
58
+	public static function buildAppNamespace($appId, $topNamespace = 'OCA\\') {
59 59
 		return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
60 60
 	}
61 61
 
Please login to merge, or discard this patch.
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -45,95 +45,95 @@
 block discarded – undo
45 45
 class App {
46 46
 
47 47
 
48
-	/**
49
-	 * Turns an app id into a namespace by convetion. The id is split at the
50
-	 * underscores, all parts are camelcased and reassembled. e.g.:
51
-	 * some_app_id -> OCA\SomeAppId
52
-	 * @param string $appId the app id
53
-	 * @param string $topNamespace the namespace which should be prepended to
54
-	 * the transformed app id, defaults to OCA\
55
-	 * @return string the starting namespace for the app
56
-	 * @since 8.0.0
57
-	 */
58
-	public static function buildAppNamespace($appId, $topNamespace='OCA\\') {
59
-		return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
60
-	}
48
+    /**
49
+     * Turns an app id into a namespace by convetion. The id is split at the
50
+     * underscores, all parts are camelcased and reassembled. e.g.:
51
+     * some_app_id -> OCA\SomeAppId
52
+     * @param string $appId the app id
53
+     * @param string $topNamespace the namespace which should be prepended to
54
+     * the transformed app id, defaults to OCA\
55
+     * @return string the starting namespace for the app
56
+     * @since 8.0.0
57
+     */
58
+    public static function buildAppNamespace($appId, $topNamespace='OCA\\') {
59
+        return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
60
+    }
61 61
 
62 62
 
63
-	/**
64
-	 * @param array $urlParams an array with variables extracted from the routes
65
-	 * @since 6.0.0
66
-	 */
67
-	public function __construct($appName, $urlParams = array()) {
68
-		$this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
69
-	}
63
+    /**
64
+     * @param array $urlParams an array with variables extracted from the routes
65
+     * @since 6.0.0
66
+     */
67
+    public function __construct($appName, $urlParams = array()) {
68
+        $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
69
+    }
70 70
 
71
-	private $container;
71
+    private $container;
72 72
 
73
-	/**
74
-	 * @return IAppContainer
75
-	 * @since 6.0.0
76
-	 */
77
-	public function getContainer() {
78
-		return $this->container;
79
-	}
73
+    /**
74
+     * @return IAppContainer
75
+     * @since 6.0.0
76
+     */
77
+    public function getContainer() {
78
+        return $this->container;
79
+    }
80 80
 
81
-	/**
82
-	 * This function is to be called to create single routes and restful routes based on the given $routes array.
83
-	 *
84
-	 * Example code in routes.php of tasks app (it will register two restful resources):
85
-	 * $routes = array(
86
-	 *		'resources' => array(
87
-	 *		'lists' => array('url' => '/tasklists'),
88
-	 *		'tasks' => array('url' => '/tasklists/{listId}/tasks')
89
-	 *	)
90
-	 *	);
91
-	 *
92
-	 * $a = new TasksApp();
93
-	 * $a->registerRoutes($this, $routes);
94
-	 *
95
-	 * @param \OCP\Route\IRouter $router
96
-	 * @param array $routes
97
-	 * @since 6.0.0
98
-	 * @suppress PhanAccessMethodInternal
99
-	 */
100
-	public function registerRoutes($router, $routes) {
101
-		$routeConfig = new RouteConfig($this->container, $router, $routes);
102
-		$routeConfig->register();
103
-	}
81
+    /**
82
+     * This function is to be called to create single routes and restful routes based on the given $routes array.
83
+     *
84
+     * Example code in routes.php of tasks app (it will register two restful resources):
85
+     * $routes = array(
86
+     *		'resources' => array(
87
+     *		'lists' => array('url' => '/tasklists'),
88
+     *		'tasks' => array('url' => '/tasklists/{listId}/tasks')
89
+     *	)
90
+     *	);
91
+     *
92
+     * $a = new TasksApp();
93
+     * $a->registerRoutes($this, $routes);
94
+     *
95
+     * @param \OCP\Route\IRouter $router
96
+     * @param array $routes
97
+     * @since 6.0.0
98
+     * @suppress PhanAccessMethodInternal
99
+     */
100
+    public function registerRoutes($router, $routes) {
101
+        $routeConfig = new RouteConfig($this->container, $router, $routes);
102
+        $routeConfig->register();
103
+    }
104 104
 
105
-	/**
106
-	 * This function is called by the routing component to fire up the frameworks dispatch mechanism.
107
-	 *
108
-	 * Example code in routes.php of the task app:
109
-	 * $this->create('tasks_index', '/')->get()->action(
110
-	 *		function($params){
111
-	 *			$app = new TaskApp($params);
112
-	 *			$app->dispatch('PageController', 'index');
113
-	 *		}
114
-	 *	);
115
-	 *
116
-	 *
117
-	 * Example for for TaskApp implementation:
118
-	 * class TaskApp extends \OCP\AppFramework\App {
119
-	 *
120
-	 *		public function __construct($params){
121
-	 *			parent::__construct('tasks', $params);
122
-	 *
123
-	 *			$this->getContainer()->registerService('PageController', function(IAppContainer $c){
124
-	 *				$a = $c->query('API');
125
-	 *				$r = $c->query('Request');
126
-	 *				return new PageController($a, $r);
127
-	 *			});
128
-	 *		}
129
-	 *	}
130
-	 *
131
-	 * @param string $controllerName the name of the controller under which it is
132
-	 *                               stored in the DI container
133
-	 * @param string $methodName the method that you want to call
134
-	 * @since 6.0.0
135
-	 */
136
-	public function dispatch($controllerName, $methodName) {
137
-		\OC\AppFramework\App::main($controllerName, $methodName, $this->container);
138
-	}
105
+    /**
106
+     * This function is called by the routing component to fire up the frameworks dispatch mechanism.
107
+     *
108
+     * Example code in routes.php of the task app:
109
+     * $this->create('tasks_index', '/')->get()->action(
110
+     *		function($params){
111
+     *			$app = new TaskApp($params);
112
+     *			$app->dispatch('PageController', 'index');
113
+     *		}
114
+     *	);
115
+     *
116
+     *
117
+     * Example for for TaskApp implementation:
118
+     * class TaskApp extends \OCP\AppFramework\App {
119
+     *
120
+     *		public function __construct($params){
121
+     *			parent::__construct('tasks', $params);
122
+     *
123
+     *			$this->getContainer()->registerService('PageController', function(IAppContainer $c){
124
+     *				$a = $c->query('API');
125
+     *				$r = $c->query('Request');
126
+     *				return new PageController($a, $r);
127
+     *			});
128
+     *		}
129
+     *	}
130
+     *
131
+     * @param string $controllerName the name of the controller under which it is
132
+     *                               stored in the DI container
133
+     * @param string $methodName the method that you want to call
134
+     * @since 6.0.0
135
+     */
136
+    public function dispatch($controllerName, $methodName) {
137
+        \OC\AppFramework\App::main($controllerName, $methodName, $this->container);
138
+    }
139 139
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Middleware.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -44,69 +44,69 @@
 block discarded – undo
44 44
 abstract class Middleware {
45 45
 
46 46
 
47
-	/**
48
-	 * This is being run in normal order before the controller is being
49
-	 * called which allows several modifications and checks
50
-	 *
51
-	 * @param Controller $controller the controller that is being called
52
-	 * @param string $methodName the name of the method that will be called on
53
-	 *                           the controller
54
-	 * @since 6.0.0
55
-	 */
56
-	public function beforeController($controller, $methodName){
47
+    /**
48
+     * This is being run in normal order before the controller is being
49
+     * called which allows several modifications and checks
50
+     *
51
+     * @param Controller $controller the controller that is being called
52
+     * @param string $methodName the name of the method that will be called on
53
+     *                           the controller
54
+     * @since 6.0.0
55
+     */
56
+    public function beforeController($controller, $methodName){
57 57
 
58
-	}
58
+    }
59 59
 
60 60
 
61
-	/**
62
-	 * This is being run when either the beforeController method or the
63
-	 * controller method itself is throwing an exception. The middleware is
64
-	 * asked in reverse order to handle the exception and to return a response.
65
-	 * If the response is null, it is assumed that the exception could not be
66
-	 * handled and the error will be thrown again
67
-	 *
68
-	 * @param Controller $controller the controller that is being called
69
-	 * @param string $methodName the name of the method that will be called on
70
-	 *                           the controller
71
-	 * @param \Exception $exception the thrown exception
72
-	 * @throws \Exception the passed in exception if it can't handle it
73
-	 * @return Response a Response object in case that the exception was handled
74
-	 * @since 6.0.0
75
-	 */
76
-	public function afterException($controller, $methodName, \Exception $exception){
77
-		throw $exception;
78
-	}
61
+    /**
62
+     * This is being run when either the beforeController method or the
63
+     * controller method itself is throwing an exception. The middleware is
64
+     * asked in reverse order to handle the exception and to return a response.
65
+     * If the response is null, it is assumed that the exception could not be
66
+     * handled and the error will be thrown again
67
+     *
68
+     * @param Controller $controller the controller that is being called
69
+     * @param string $methodName the name of the method that will be called on
70
+     *                           the controller
71
+     * @param \Exception $exception the thrown exception
72
+     * @throws \Exception the passed in exception if it can't handle it
73
+     * @return Response a Response object in case that the exception was handled
74
+     * @since 6.0.0
75
+     */
76
+    public function afterException($controller, $methodName, \Exception $exception){
77
+        throw $exception;
78
+    }
79 79
 
80 80
 
81
-	/**
82
-	 * This is being run after a successful controllermethod call and allows
83
-	 * the manipulation of a Response object. The middleware is run in reverse order
84
-	 *
85
-	 * @param Controller $controller the controller that is being called
86
-	 * @param string $methodName the name of the method that will be called on
87
-	 *                           the controller
88
-	 * @param Response $response the generated response from the controller
89
-	 * @return Response a Response object
90
-	 * @since 6.0.0
91
-	 */
92
-	public function afterController($controller, $methodName, Response $response){
93
-		return $response;
94
-	}
81
+    /**
82
+     * This is being run after a successful controllermethod call and allows
83
+     * the manipulation of a Response object. The middleware is run in reverse order
84
+     *
85
+     * @param Controller $controller the controller that is being called
86
+     * @param string $methodName the name of the method that will be called on
87
+     *                           the controller
88
+     * @param Response $response the generated response from the controller
89
+     * @return Response a Response object
90
+     * @since 6.0.0
91
+     */
92
+    public function afterController($controller, $methodName, Response $response){
93
+        return $response;
94
+    }
95 95
 
96 96
 
97
-	/**
98
-	 * This is being run after the response object has been rendered and
99
-	 * allows the manipulation of the output. The middleware is run in reverse order
100
-	 *
101
-	 * @param Controller $controller the controller that is being called
102
-	 * @param string $methodName the name of the method that will be called on
103
-	 *                           the controller
104
-	 * @param string $output the generated output from a response
105
-	 * @return string the output that should be printed
106
-	 * @since 6.0.0
107
-	 */
108
-	public function beforeOutput($controller, $methodName, $output){
109
-		return $output;
110
-	}
97
+    /**
98
+     * This is being run after the response object has been rendered and
99
+     * allows the manipulation of the output. The middleware is run in reverse order
100
+     *
101
+     * @param Controller $controller the controller that is being called
102
+     * @param string $methodName the name of the method that will be called on
103
+     *                           the controller
104
+     * @param string $output the generated output from a response
105
+     * @return string the output that should be printed
106
+     * @since 6.0.0
107
+     */
108
+    public function beforeOutput($controller, $methodName, $output){
109
+        return $output;
110
+    }
111 111
 
112 112
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 *                           the controller
54 54
 	 * @since 6.0.0
55 55
 	 */
56
-	public function beforeController($controller, $methodName){
56
+	public function beforeController($controller, $methodName) {
57 57
 
58 58
 	}
59 59
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return Response a Response object in case that the exception was handled
74 74
 	 * @since 6.0.0
75 75
 	 */
76
-	public function afterException($controller, $methodName, \Exception $exception){
76
+	public function afterException($controller, $methodName, \Exception $exception) {
77 77
 		throw $exception;
78 78
 	}
79 79
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 * @return Response a Response object
90 90
 	 * @since 6.0.0
91 91
 	 */
92
-	public function afterController($controller, $methodName, Response $response){
92
+	public function afterController($controller, $methodName, Response $response) {
93 93
 		return $response;
94 94
 	}
95 95
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @return string the output that should be printed
106 106
 	 * @since 6.0.0
107 107
 	 */
108
-	public function beforeOutput($controller, $methodName, $output){
108
+	public function beforeOutput($controller, $methodName, $output) {
109 109
 		return $output;
110 110
 	}
111 111
 
Please login to merge, or discard this patch.
lib/public/AppFramework/Http.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -35,63 +35,63 @@
 block discarded – undo
35 35
  */
36 36
 class Http {
37 37
 
38
-	const STATUS_CONTINUE = 100;
39
-	const STATUS_SWITCHING_PROTOCOLS = 101;
40
-	const STATUS_PROCESSING = 102;
41
-	const STATUS_OK = 200;
42
-	const STATUS_CREATED = 201;
43
-	const STATUS_ACCEPTED = 202;
44
-	const STATUS_NON_AUTHORATIVE_INFORMATION = 203;
45
-	const STATUS_NO_CONTENT = 204;
46
-	const STATUS_RESET_CONTENT = 205;
47
-	const STATUS_PARTIAL_CONTENT = 206;
48
-	const STATUS_MULTI_STATUS = 207;
49
-	const STATUS_ALREADY_REPORTED = 208;
50
-	const STATUS_IM_USED = 226;
51
-	const STATUS_MULTIPLE_CHOICES = 300;
52
-	const STATUS_MOVED_PERMANENTLY = 301;
53
-	const STATUS_FOUND = 302;
54
-	const STATUS_SEE_OTHER = 303;
55
-	const STATUS_NOT_MODIFIED = 304;
56
-	const STATUS_USE_PROXY = 305;
57
-	const STATUS_RESERVED = 306;
58
-	const STATUS_TEMPORARY_REDIRECT = 307;
59
-	const STATUS_BAD_REQUEST = 400;
60
-	const STATUS_UNAUTHORIZED = 401;
61
-	const STATUS_PAYMENT_REQUIRED = 402;
62
-	const STATUS_FORBIDDEN = 403;
63
-	const STATUS_NOT_FOUND = 404;
64
-	const STATUS_METHOD_NOT_ALLOWED = 405;
65
-	const STATUS_NOT_ACCEPTABLE = 406;
66
-	const STATUS_PROXY_AUTHENTICATION_REQUIRED = 407;
67
-	const STATUS_REQUEST_TIMEOUT = 408;
68
-	const STATUS_CONFLICT = 409;
69
-	const STATUS_GONE = 410;
70
-	const STATUS_LENGTH_REQUIRED = 411;
71
-	const STATUS_PRECONDITION_FAILED = 412;
72
-	const STATUS_REQUEST_ENTITY_TOO_LARGE = 413;
73
-	const STATUS_REQUEST_URI_TOO_LONG = 414;
74
-	const STATUS_UNSUPPORTED_MEDIA_TYPE = 415;
75
-	const STATUS_REQUEST_RANGE_NOT_SATISFIABLE = 416;
76
-	const STATUS_EXPECTATION_FAILED = 417;
77
-	const STATUS_IM_A_TEAPOT = 418;
78
-	const STATUS_UNPROCESSABLE_ENTITY = 422;
79
-	const STATUS_LOCKED = 423;
80
-	const STATUS_FAILED_DEPENDENCY = 424;
81
-	const STATUS_UPGRADE_REQUIRED = 426;
82
-	const STATUS_PRECONDITION_REQUIRED = 428;
83
-	const STATUS_TOO_MANY_REQUESTS = 429;
84
-	const STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
85
-	const STATUS_INTERNAL_SERVER_ERROR = 500;
86
-	const STATUS_NOT_IMPLEMENTED = 501;
87
-	const STATUS_BAD_GATEWAY = 502;
88
-	const STATUS_SERVICE_UNAVAILABLE = 503;
89
-	const STATUS_GATEWAY_TIMEOUT = 504;
90
-	const STATUS_HTTP_VERSION_NOT_SUPPORTED = 505;
91
-	const STATUS_VARIANT_ALSO_NEGOTIATES = 506;
92
-	const STATUS_INSUFFICIENT_STORAGE = 507;
93
-	const STATUS_LOOP_DETECTED = 508;
94
-	const STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509;
95
-	const STATUS_NOT_EXTENDED = 510;
96
-	const STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511;
38
+    const STATUS_CONTINUE = 100;
39
+    const STATUS_SWITCHING_PROTOCOLS = 101;
40
+    const STATUS_PROCESSING = 102;
41
+    const STATUS_OK = 200;
42
+    const STATUS_CREATED = 201;
43
+    const STATUS_ACCEPTED = 202;
44
+    const STATUS_NON_AUTHORATIVE_INFORMATION = 203;
45
+    const STATUS_NO_CONTENT = 204;
46
+    const STATUS_RESET_CONTENT = 205;
47
+    const STATUS_PARTIAL_CONTENT = 206;
48
+    const STATUS_MULTI_STATUS = 207;
49
+    const STATUS_ALREADY_REPORTED = 208;
50
+    const STATUS_IM_USED = 226;
51
+    const STATUS_MULTIPLE_CHOICES = 300;
52
+    const STATUS_MOVED_PERMANENTLY = 301;
53
+    const STATUS_FOUND = 302;
54
+    const STATUS_SEE_OTHER = 303;
55
+    const STATUS_NOT_MODIFIED = 304;
56
+    const STATUS_USE_PROXY = 305;
57
+    const STATUS_RESERVED = 306;
58
+    const STATUS_TEMPORARY_REDIRECT = 307;
59
+    const STATUS_BAD_REQUEST = 400;
60
+    const STATUS_UNAUTHORIZED = 401;
61
+    const STATUS_PAYMENT_REQUIRED = 402;
62
+    const STATUS_FORBIDDEN = 403;
63
+    const STATUS_NOT_FOUND = 404;
64
+    const STATUS_METHOD_NOT_ALLOWED = 405;
65
+    const STATUS_NOT_ACCEPTABLE = 406;
66
+    const STATUS_PROXY_AUTHENTICATION_REQUIRED = 407;
67
+    const STATUS_REQUEST_TIMEOUT = 408;
68
+    const STATUS_CONFLICT = 409;
69
+    const STATUS_GONE = 410;
70
+    const STATUS_LENGTH_REQUIRED = 411;
71
+    const STATUS_PRECONDITION_FAILED = 412;
72
+    const STATUS_REQUEST_ENTITY_TOO_LARGE = 413;
73
+    const STATUS_REQUEST_URI_TOO_LONG = 414;
74
+    const STATUS_UNSUPPORTED_MEDIA_TYPE = 415;
75
+    const STATUS_REQUEST_RANGE_NOT_SATISFIABLE = 416;
76
+    const STATUS_EXPECTATION_FAILED = 417;
77
+    const STATUS_IM_A_TEAPOT = 418;
78
+    const STATUS_UNPROCESSABLE_ENTITY = 422;
79
+    const STATUS_LOCKED = 423;
80
+    const STATUS_FAILED_DEPENDENCY = 424;
81
+    const STATUS_UPGRADE_REQUIRED = 426;
82
+    const STATUS_PRECONDITION_REQUIRED = 428;
83
+    const STATUS_TOO_MANY_REQUESTS = 429;
84
+    const STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
85
+    const STATUS_INTERNAL_SERVER_ERROR = 500;
86
+    const STATUS_NOT_IMPLEMENTED = 501;
87
+    const STATUS_BAD_GATEWAY = 502;
88
+    const STATUS_SERVICE_UNAVAILABLE = 503;
89
+    const STATUS_GATEWAY_TIMEOUT = 504;
90
+    const STATUS_HTTP_VERSION_NOT_SUPPORTED = 505;
91
+    const STATUS_VARIANT_ALSO_NEGOTIATES = 506;
92
+    const STATUS_INSUFFICIENT_STORAGE = 507;
93
+    const STATUS_LOOP_DETECTED = 508;
94
+    const STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509;
95
+    const STATUS_NOT_EXTENDED = 510;
96
+    const STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511;
97 97
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/ApiController.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      * defaults to 'Authorization, Content-Type, Accept'
56 56
      * @param int $corsMaxAge number in seconds how long a preflighted OPTIONS
57 57
      * request should be cached, defaults to 1728000 seconds
58
-	 * @since 7.0.0
58
+     * @since 7.0.0
59 59
      */
60 60
     public function __construct($appName,
61 61
                                 IRequest $request,
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      * @NoAdminRequired
77 77
      * @NoCSRFRequired
78 78
      * @PublicPage
79
-	 * @since 7.0.0
79
+     * @since 7.0.0
80 80
      */
81 81
     public function preflightedCors() {
82 82
         if(isset($this->request->server['HTTP_ORIGIN'])) {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function __construct($appName,
61 61
                                 IRequest $request,
62
-                                $corsMethods='PUT, POST, GET, DELETE, PATCH',
63
-                                $corsAllowedHeaders='Authorization, Content-Type, Accept',
64
-                                $corsMaxAge=1728000){
62
+                                $corsMethods = 'PUT, POST, GET, DELETE, PATCH',
63
+                                $corsAllowedHeaders = 'Authorization, Content-Type, Accept',
64
+                                $corsMaxAge = 1728000) {
65 65
         parent::__construct($appName, $request);
66 66
         $this->corsMethods = $corsMethods;
67 67
         $this->corsAllowedHeaders = $corsAllowedHeaders;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @since 7.0.0
80 80
      */
81 81
     public function preflightedCors() {
82
-        if(isset($this->request->server['HTTP_ORIGIN'])) {
82
+        if (isset($this->request->server['HTTP_ORIGIN'])) {
83 83
             $origin = $this->request->server['HTTP_ORIGIN'];
84 84
         } else {
85 85
             $origin = '*';
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         $response = new Response();
89 89
         $response->addHeader('Access-Control-Allow-Origin', $origin);
90 90
         $response->addHeader('Access-Control-Allow-Methods', $this->corsMethods);
91
-        $response->addHeader('Access-Control-Max-Age', (string)$this->corsMaxAge);
91
+        $response->addHeader('Access-Control-Max-Age', (string) $this->corsMaxAge);
92 92
         $response->addHeader('Access-Control-Allow-Headers', $this->corsAllowedHeaders);
93 93
         $response->addHeader('Access-Control-Allow-Credentials', 'false');
94 94
         return $response;
Please login to merge, or discard this patch.
lib/public/AppFramework/Db/MultipleObjectsReturnedException.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@
 block discarded – undo
32 32
  */
33 33
 class MultipleObjectsReturnedException extends \Exception {
34 34
 
35
-	/**
36
-	 * Constructor
37
-	 * @param string $msg the error message
38
-	 * @since 7.0.0
39
-	 */
40
-	public function __construct($msg){
41
-		parent::__construct($msg);
42
-	}
35
+    /**
36
+     * Constructor
37
+     * @param string $msg the error message
38
+     * @since 7.0.0
39
+     */
40
+    public function __construct($msg){
41
+        parent::__construct($msg);
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 	 * @param string $msg the error message
38 38
 	 * @since 7.0.0
39 39
 	 */
40
-	public function __construct($msg){
40
+	public function __construct($msg) {
41 41
 		parent::__construct($msg);
42 42
 	}
43 43
 
Please login to merge, or discard this patch.
lib/public/AppFramework/Db/Mapper.php 2 patches
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
 	 * mapped to queries without using sql
49 49
 	 * @since 7.0.0
50 50
 	 */
51
-	public function __construct(IDBConnection $db, $tableName, $entityClass=null){
51
+	public function __construct(IDBConnection $db, $tableName, $entityClass = null) {
52 52
 		$this->db = $db;
53
-		$this->tableName = '*PREFIX*' . $tableName;
53
+		$this->tableName = '*PREFIX*'.$tableName;
54 54
 
55 55
 		// if not given set the entity name to the class without the mapper part
56 56
 		// cache it here for later use since reflection is slow
57
-		if($entityClass === null) {
57
+		if ($entityClass === null) {
58 58
 			$this->entityClass = str_replace('Mapper', '', get_class($this));
59 59
 		} else {
60 60
 			$this->entityClass = $entityClass;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return string the table name
67 67
 	 * @since 7.0.0
68 68
 	 */
69
-	public function getTableName(){
69
+	public function getTableName() {
70 70
 		return $this->tableName;
71 71
 	}
72 72
 
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 	 * @return Entity the deleted entity
78 78
 	 * @since 7.0.0 - return value added in 8.1.0
79 79
 	 */
80
-	public function delete(Entity $entity){
81
-		$sql = 'DELETE FROM `' . $this->tableName . '` WHERE `id` = ?';
80
+	public function delete(Entity $entity) {
81
+		$sql = 'DELETE FROM `'.$this->tableName.'` WHERE `id` = ?';
82 82
 		$stmt = $this->execute($sql, [$entity->getId()]);
83 83
 		$stmt->closeCursor();
84 84
 		return $entity;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @return Entity the saved entity with the set id
92 92
 	 * @since 7.0.0
93 93
 	 */
94
-	public function insert(Entity $entity){
94
+	public function insert(Entity $entity) {
95 95
 		// get updated fields to save, fields have to be set using a setter to
96 96
 		// be saved
97 97
 		$properties = $entity->getUpdatedFields();
@@ -101,15 +101,15 @@  discard block
 block discarded – undo
101 101
 
102 102
 		// build the fields
103 103
 		$i = 0;
104
-		foreach($properties as $property => $updated) {
104
+		foreach ($properties as $property => $updated) {
105 105
 			$column = $entity->propertyToColumn($property);
106
-			$getter = 'get' . ucfirst($property);
106
+			$getter = 'get'.ucfirst($property);
107 107
 
108
-			$columns .= '`' . $column . '`';
108
+			$columns .= '`'.$column.'`';
109 109
 			$values .= '?';
110 110
 
111 111
 			// only append colon if there are more entries
112
-			if($i < count($properties)-1){
112
+			if ($i < count($properties) - 1) {
113 113
 				$columns .= ',';
114 114
 				$values .= ',';
115 115
 			}
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 
120 120
 		}
121 121
 
122
-		$sql = 'INSERT INTO `' . $this->tableName . '`(' .
123
-				$columns . ') VALUES(' . $values . ')';
122
+		$sql = 'INSERT INTO `'.$this->tableName.'`('.
123
+				$columns.') VALUES('.$values.')';
124 124
 
125 125
 		$stmt = $this->execute($sql, $params);
126 126
 
@@ -140,16 +140,16 @@  discard block
 block discarded – undo
140 140
 	 * @return Entity the saved entity with the set id
141 141
 	 * @since 7.0.0 - return value was added in 8.0.0
142 142
 	 */
143
-	public function update(Entity $entity){
143
+	public function update(Entity $entity) {
144 144
 		// if entity wasn't changed it makes no sense to run a db query
145 145
 		$properties = $entity->getUpdatedFields();
146
-		if(count($properties) === 0) {
146
+		if (count($properties) === 0) {
147 147
 			return $entity;
148 148
 		}
149 149
 
150 150
 		// entity needs an id
151 151
 		$id = $entity->getId();
152
-		if($id === null){
152
+		if ($id === null) {
153 153
 			throw new \InvalidArgumentException(
154 154
 				'Entity which should be updated has no id');
155 155
 		}
@@ -164,15 +164,15 @@  discard block
 block discarded – undo
164 164
 
165 165
 		// build the fields
166 166
 		$i = 0;
167
-		foreach($properties as $property => $updated) {
167
+		foreach ($properties as $property => $updated) {
168 168
 
169 169
 			$column = $entity->propertyToColumn($property);
170
-			$getter = 'get' . ucfirst($property);
170
+			$getter = 'get'.ucfirst($property);
171 171
 
172
-			$columns .= '`' . $column . '` = ?';
172
+			$columns .= '`'.$column.'` = ?';
173 173
 
174 174
 			// only append colon if there are more entries
175
-			if($i < count($properties)-1){
175
+			if ($i < count($properties) - 1) {
176 176
 				$columns .= ',';
177 177
 			}
178 178
 
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
 			$i++;
181 181
 		}
182 182
 
183
-		$sql = 'UPDATE `' . $this->tableName . '` SET ' .
184
-				$columns . ' WHERE `id` = ?';
183
+		$sql = 'UPDATE `'.$this->tableName.'` SET '.
184
+				$columns.' WHERE `id` = ?';
185 185
 		$params[] = $id;
186 186
 
187 187
 		$stmt = $this->execute($sql, $params);
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 * @return \PDOStatement the database query result
228 228
 	 * @since 7.0.0
229 229
 	 */
230
-	protected function execute($sql, array $params=[], $limit=null, $offset=null){
230
+	protected function execute($sql, array $params = [], $limit = null, $offset = null) {
231 231
 		$query = $this->db->prepare($sql, $limit, $offset);
232 232
 
233 233
 		if ($this->isAssocArray($params)) {
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 				$query->bindValue($key, $param, $pdoConstant);
237 237
 			}
238 238
 		} else {
239
-			$index = 1;  // bindParam is 1 indexed
239
+			$index = 1; // bindParam is 1 indexed
240 240
 			foreach ($params as $param) {
241 241
 				$pdoConstant = $this->getPDOType($param);
242 242
 				$query->bindValue($index, $param, $pdoConstant);
@@ -263,11 +263,11 @@  discard block
 block discarded – undo
263 263
 	 * @return array the result as row
264 264
 	 * @since 7.0.0
265 265
 	 */
266
-	protected function findOneQuery($sql, array $params=[], $limit=null, $offset=null){
266
+	protected function findOneQuery($sql, array $params = [], $limit = null, $offset = null) {
267 267
 		$stmt = $this->execute($sql, $params, $limit, $offset);
268 268
 		$row = $stmt->fetch();
269 269
 
270
-		if($row === false || $row === null){
270
+		if ($row === false || $row === null) {
271 271
 			$stmt->closeCursor();
272 272
 			$msg = $this->buildDebugMessage(
273 273
 				'Did expect one result but found none when executing', $sql, $params, $limit, $offset
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 		$row2 = $stmt->fetch();
278 278
 		$stmt->closeCursor();
279 279
 		//MDB2 returns null, PDO and doctrine false when no row is available
280
-		if( ! ($row2 === false || $row2 === null )) {
280
+		if (!($row2 === false || $row2 === null)) {
281 281
 			$msg = $this->buildDebugMessage(
282 282
 				'Did not expect more than one result when executing', $sql, $params, $limit, $offset
283 283
 			);
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 	 * @return string formatted error message string
299 299
 	 * @since 9.1.0
300 300
 	 */
301
-	private function buildDebugMessage($msg, $sql, array $params=[], $limit=null, $offset=null) {
302
-		return $msg .
303
-					': query "' .	$sql . '"; ' .
304
-					'parameters ' . print_r($params, true) . '; ' .
305
-					'limit "' . $limit . '"; '.
306
-					'offset "' . $offset . '"';
301
+	private function buildDebugMessage($msg, $sql, array $params = [], $limit = null, $offset = null) {
302
+		return $msg.
303
+					': query "'.$sql.'"; '.
304
+					'parameters '.print_r($params, true).'; '.
305
+					'limit "'.$limit.'"; '.
306
+					'offset "'.$offset.'"';
307 307
 	}
308 308
 
309 309
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @since 7.0.0
316 316
 	 */
317 317
 	protected function mapRowToEntity($row) {
318
-		return call_user_func($this->entityClass .'::fromRow', $row);
318
+		return call_user_func($this->entityClass.'::fromRow', $row);
319 319
 	}
320 320
 
321 321
 
@@ -328,12 +328,12 @@  discard block
 block discarded – undo
328 328
 	 * @return array all fetched entities
329 329
 	 * @since 7.0.0
330 330
 	 */
331
-	protected function findEntities($sql, array $params=[], $limit=null, $offset=null) {
331
+	protected function findEntities($sql, array $params = [], $limit = null, $offset = null) {
332 332
 		$stmt = $this->execute($sql, $params, $limit, $offset);
333 333
 
334 334
 		$entities = [];
335 335
 
336
-		while($row = $stmt->fetch()){
336
+		while ($row = $stmt->fetch()) {
337 337
 			$entities[] = $this->mapRowToEntity($row);
338 338
 		}
339 339
 
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	 * @return Entity the entity
356 356
 	 * @since 7.0.0
357 357
 	 */
358
-	protected function findEntity($sql, array $params=[], $limit=null, $offset=null){
358
+	protected function findEntity($sql, array $params = [], $limit = null, $offset = null) {
359 359
 		return $this->mapRowToEntity($this->findOneQuery($sql, $params, $limit, $offset));
360 360
 	}
361 361
 
Please login to merge, or discard this patch.
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -37,327 +37,327 @@
 block discarded – undo
37 37
  */
38 38
 abstract class Mapper {
39 39
 
40
-	protected $tableName;
41
-	protected $entityClass;
42
-	protected $db;
43
-
44
-	/**
45
-	 * @param IDBConnection $db Instance of the Db abstraction layer
46
-	 * @param string $tableName the name of the table. set this to allow entity
47
-	 * @param string $entityClass the name of the entity that the sql should be
48
-	 * mapped to queries without using sql
49
-	 * @since 7.0.0
50
-	 */
51
-	public function __construct(IDBConnection $db, $tableName, $entityClass=null){
52
-		$this->db = $db;
53
-		$this->tableName = '*PREFIX*' . $tableName;
54
-
55
-		// if not given set the entity name to the class without the mapper part
56
-		// cache it here for later use since reflection is slow
57
-		if($entityClass === null) {
58
-			$this->entityClass = str_replace('Mapper', '', get_class($this));
59
-		} else {
60
-			$this->entityClass = $entityClass;
61
-		}
62
-	}
63
-
64
-
65
-	/**
66
-	 * @return string the table name
67
-	 * @since 7.0.0
68
-	 */
69
-	public function getTableName(){
70
-		return $this->tableName;
71
-	}
72
-
73
-
74
-	/**
75
-	 * Deletes an entity from the table
76
-	 * @param Entity $entity the entity that should be deleted
77
-	 * @return Entity the deleted entity
78
-	 * @since 7.0.0 - return value added in 8.1.0
79
-	 */
80
-	public function delete(Entity $entity){
81
-		$sql = 'DELETE FROM `' . $this->tableName . '` WHERE `id` = ?';
82
-		$stmt = $this->execute($sql, [$entity->getId()]);
83
-		$stmt->closeCursor();
84
-		return $entity;
85
-	}
86
-
87
-
88
-	/**
89
-	 * Creates a new entry in the db from an entity
90
-	 * @param Entity $entity the entity that should be created
91
-	 * @return Entity the saved entity with the set id
92
-	 * @since 7.0.0
93
-	 */
94
-	public function insert(Entity $entity){
95
-		// get updated fields to save, fields have to be set using a setter to
96
-		// be saved
97
-		$properties = $entity->getUpdatedFields();
98
-		$values = '';
99
-		$columns = '';
100
-		$params = [];
101
-
102
-		// build the fields
103
-		$i = 0;
104
-		foreach($properties as $property => $updated) {
105
-			$column = $entity->propertyToColumn($property);
106
-			$getter = 'get' . ucfirst($property);
107
-
108
-			$columns .= '`' . $column . '`';
109
-			$values .= '?';
110
-
111
-			// only append colon if there are more entries
112
-			if($i < count($properties)-1){
113
-				$columns .= ',';
114
-				$values .= ',';
115
-			}
116
-
117
-			$params[] = $entity->$getter();
118
-			$i++;
119
-
120
-		}
121
-
122
-		$sql = 'INSERT INTO `' . $this->tableName . '`(' .
123
-				$columns . ') VALUES(' . $values . ')';
124
-
125
-		$stmt = $this->execute($sql, $params);
126
-
127
-		$entity->setId((int) $this->db->lastInsertId($this->tableName));
128
-
129
-		$stmt->closeCursor();
130
-
131
-		return $entity;
132
-	}
133
-
134
-
135
-
136
-	/**
137
-	 * Updates an entry in the db from an entity
138
-	 * @throws \InvalidArgumentException if entity has no id
139
-	 * @param Entity $entity the entity that should be created
140
-	 * @return Entity the saved entity with the set id
141
-	 * @since 7.0.0 - return value was added in 8.0.0
142
-	 */
143
-	public function update(Entity $entity){
144
-		// if entity wasn't changed it makes no sense to run a db query
145
-		$properties = $entity->getUpdatedFields();
146
-		if(count($properties) === 0) {
147
-			return $entity;
148
-		}
149
-
150
-		// entity needs an id
151
-		$id = $entity->getId();
152
-		if($id === null){
153
-			throw new \InvalidArgumentException(
154
-				'Entity which should be updated has no id');
155
-		}
156
-
157
-		// get updated fields to save, fields have to be set using a setter to
158
-		// be saved
159
-		// do not update the id field
160
-		unset($properties['id']);
161
-
162
-		$columns = '';
163
-		$params = [];
164
-
165
-		// build the fields
166
-		$i = 0;
167
-		foreach($properties as $property => $updated) {
168
-
169
-			$column = $entity->propertyToColumn($property);
170
-			$getter = 'get' . ucfirst($property);
171
-
172
-			$columns .= '`' . $column . '` = ?';
173
-
174
-			// only append colon if there are more entries
175
-			if($i < count($properties)-1){
176
-				$columns .= ',';
177
-			}
178
-
179
-			$params[] = $entity->$getter();
180
-			$i++;
181
-		}
182
-
183
-		$sql = 'UPDATE `' . $this->tableName . '` SET ' .
184
-				$columns . ' WHERE `id` = ?';
185
-		$params[] = $id;
186
-
187
-		$stmt = $this->execute($sql, $params);
188
-		$stmt->closeCursor();
189
-
190
-		return $entity;
191
-	}
192
-
193
-	/**
194
-	 * Checks if an array is associative
195
-	 * @param array $array
196
-	 * @return bool true if associative
197
-	 * @since 8.1.0
198
-	 */
199
-	private function isAssocArray(array $array) {
200
-		return array_values($array) !== $array;
201
-	}
202
-
203
-	/**
204
-	 * Returns the correct PDO constant based on the value type
205
-	 * @param $value
206
-	 * @return int PDO constant
207
-	 * @since 8.1.0
208
-	 */
209
-	private function getPDOType($value) {
210
-		switch (gettype($value)) {
211
-			case 'integer':
212
-				return \PDO::PARAM_INT;
213
-			case 'boolean':
214
-				return \PDO::PARAM_BOOL;
215
-			default:
216
-				return \PDO::PARAM_STR;
217
-		}
218
-	}
219
-
220
-
221
-	/**
222
-	 * Runs an sql query
223
-	 * @param string $sql the prepare string
224
-	 * @param array $params the params which should replace the ? in the sql query
225
-	 * @param int $limit the maximum number of rows
226
-	 * @param int $offset from which row we want to start
227
-	 * @return \PDOStatement the database query result
228
-	 * @since 7.0.0
229
-	 */
230
-	protected function execute($sql, array $params=[], $limit=null, $offset=null){
231
-		$query = $this->db->prepare($sql, $limit, $offset);
232
-
233
-		if ($this->isAssocArray($params)) {
234
-			foreach ($params as $key => $param) {
235
-				$pdoConstant = $this->getPDOType($param);
236
-				$query->bindValue($key, $param, $pdoConstant);
237
-			}
238
-		} else {
239
-			$index = 1;  // bindParam is 1 indexed
240
-			foreach ($params as $param) {
241
-				$pdoConstant = $this->getPDOType($param);
242
-				$query->bindValue($index, $param, $pdoConstant);
243
-				$index++;
244
-			}
245
-		}
246
-
247
-		$query->execute();
248
-
249
-		return $query;
250
-	}
251
-
252
-
253
-	/**
254
-	 * Returns an db result and throws exceptions when there are more or less
255
-	 * results
256
-	 * @see findEntity
257
-	 * @param string $sql the sql query
258
-	 * @param array $params the parameters of the sql query
259
-	 * @param int $limit the maximum number of rows
260
-	 * @param int $offset from which row we want to start
261
-	 * @throws DoesNotExistException if the item does not exist
262
-	 * @throws MultipleObjectsReturnedException if more than one item exist
263
-	 * @return array the result as row
264
-	 * @since 7.0.0
265
-	 */
266
-	protected function findOneQuery($sql, array $params=[], $limit=null, $offset=null){
267
-		$stmt = $this->execute($sql, $params, $limit, $offset);
268
-		$row = $stmt->fetch();
269
-
270
-		if($row === false || $row === null){
271
-			$stmt->closeCursor();
272
-			$msg = $this->buildDebugMessage(
273
-				'Did expect one result but found none when executing', $sql, $params, $limit, $offset
274
-			);
275
-			throw new DoesNotExistException($msg);
276
-		}
277
-		$row2 = $stmt->fetch();
278
-		$stmt->closeCursor();
279
-		//MDB2 returns null, PDO and doctrine false when no row is available
280
-		if( ! ($row2 === false || $row2 === null )) {
281
-			$msg = $this->buildDebugMessage(
282
-				'Did not expect more than one result when executing', $sql, $params, $limit, $offset
283
-			);
284
-			throw new MultipleObjectsReturnedException($msg);
285
-		} else {
286
-			return $row;
287
-		}
288
-	}
289
-
290
-	/**
291
-	 * Builds an error message by prepending the $msg to an error message which
292
-	 * has the parameters
293
-	 * @see findEntity
294
-	 * @param string $sql the sql query
295
-	 * @param array $params the parameters of the sql query
296
-	 * @param int $limit the maximum number of rows
297
-	 * @param int $offset from which row we want to start
298
-	 * @return string formatted error message string
299
-	 * @since 9.1.0
300
-	 */
301
-	private function buildDebugMessage($msg, $sql, array $params=[], $limit=null, $offset=null) {
302
-		return $msg .
303
-					': query "' .	$sql . '"; ' .
304
-					'parameters ' . print_r($params, true) . '; ' .
305
-					'limit "' . $limit . '"; '.
306
-					'offset "' . $offset . '"';
307
-	}
308
-
309
-
310
-	/**
311
-	 * Creates an entity from a row. Automatically determines the entity class
312
-	 * from the current mapper name (MyEntityMapper -> MyEntity)
313
-	 * @param array $row the row which should be converted to an entity
314
-	 * @return Entity the entity
315
-	 * @since 7.0.0
316
-	 */
317
-	protected function mapRowToEntity($row) {
318
-		return call_user_func($this->entityClass .'::fromRow', $row);
319
-	}
320
-
321
-
322
-	/**
323
-	 * Runs a sql query and returns an array of entities
324
-	 * @param string $sql the prepare string
325
-	 * @param array $params the params which should replace the ? in the sql query
326
-	 * @param int $limit the maximum number of rows
327
-	 * @param int $offset from which row we want to start
328
-	 * @return array all fetched entities
329
-	 * @since 7.0.0
330
-	 */
331
-	protected function findEntities($sql, array $params=[], $limit=null, $offset=null) {
332
-		$stmt = $this->execute($sql, $params, $limit, $offset);
333
-
334
-		$entities = [];
335
-
336
-		while($row = $stmt->fetch()){
337
-			$entities[] = $this->mapRowToEntity($row);
338
-		}
339
-
340
-		$stmt->closeCursor();
341
-
342
-		return $entities;
343
-	}
344
-
345
-
346
-	/**
347
-	 * Returns an db result and throws exceptions when there are more or less
348
-	 * results
349
-	 * @param string $sql the sql query
350
-	 * @param array $params the parameters of the sql query
351
-	 * @param int $limit the maximum number of rows
352
-	 * @param int $offset from which row we want to start
353
-	 * @throws DoesNotExistException if the item does not exist
354
-	 * @throws MultipleObjectsReturnedException if more than one item exist
355
-	 * @return Entity the entity
356
-	 * @since 7.0.0
357
-	 */
358
-	protected function findEntity($sql, array $params=[], $limit=null, $offset=null){
359
-		return $this->mapRowToEntity($this->findOneQuery($sql, $params, $limit, $offset));
360
-	}
40
+    protected $tableName;
41
+    protected $entityClass;
42
+    protected $db;
43
+
44
+    /**
45
+     * @param IDBConnection $db Instance of the Db abstraction layer
46
+     * @param string $tableName the name of the table. set this to allow entity
47
+     * @param string $entityClass the name of the entity that the sql should be
48
+     * mapped to queries without using sql
49
+     * @since 7.0.0
50
+     */
51
+    public function __construct(IDBConnection $db, $tableName, $entityClass=null){
52
+        $this->db = $db;
53
+        $this->tableName = '*PREFIX*' . $tableName;
54
+
55
+        // if not given set the entity name to the class without the mapper part
56
+        // cache it here for later use since reflection is slow
57
+        if($entityClass === null) {
58
+            $this->entityClass = str_replace('Mapper', '', get_class($this));
59
+        } else {
60
+            $this->entityClass = $entityClass;
61
+        }
62
+    }
63
+
64
+
65
+    /**
66
+     * @return string the table name
67
+     * @since 7.0.0
68
+     */
69
+    public function getTableName(){
70
+        return $this->tableName;
71
+    }
72
+
73
+
74
+    /**
75
+     * Deletes an entity from the table
76
+     * @param Entity $entity the entity that should be deleted
77
+     * @return Entity the deleted entity
78
+     * @since 7.0.0 - return value added in 8.1.0
79
+     */
80
+    public function delete(Entity $entity){
81
+        $sql = 'DELETE FROM `' . $this->tableName . '` WHERE `id` = ?';
82
+        $stmt = $this->execute($sql, [$entity->getId()]);
83
+        $stmt->closeCursor();
84
+        return $entity;
85
+    }
86
+
87
+
88
+    /**
89
+     * Creates a new entry in the db from an entity
90
+     * @param Entity $entity the entity that should be created
91
+     * @return Entity the saved entity with the set id
92
+     * @since 7.0.0
93
+     */
94
+    public function insert(Entity $entity){
95
+        // get updated fields to save, fields have to be set using a setter to
96
+        // be saved
97
+        $properties = $entity->getUpdatedFields();
98
+        $values = '';
99
+        $columns = '';
100
+        $params = [];
101
+
102
+        // build the fields
103
+        $i = 0;
104
+        foreach($properties as $property => $updated) {
105
+            $column = $entity->propertyToColumn($property);
106
+            $getter = 'get' . ucfirst($property);
107
+
108
+            $columns .= '`' . $column . '`';
109
+            $values .= '?';
110
+
111
+            // only append colon if there are more entries
112
+            if($i < count($properties)-1){
113
+                $columns .= ',';
114
+                $values .= ',';
115
+            }
116
+
117
+            $params[] = $entity->$getter();
118
+            $i++;
119
+
120
+        }
121
+
122
+        $sql = 'INSERT INTO `' . $this->tableName . '`(' .
123
+                $columns . ') VALUES(' . $values . ')';
124
+
125
+        $stmt = $this->execute($sql, $params);
126
+
127
+        $entity->setId((int) $this->db->lastInsertId($this->tableName));
128
+
129
+        $stmt->closeCursor();
130
+
131
+        return $entity;
132
+    }
133
+
134
+
135
+
136
+    /**
137
+     * Updates an entry in the db from an entity
138
+     * @throws \InvalidArgumentException if entity has no id
139
+     * @param Entity $entity the entity that should be created
140
+     * @return Entity the saved entity with the set id
141
+     * @since 7.0.0 - return value was added in 8.0.0
142
+     */
143
+    public function update(Entity $entity){
144
+        // if entity wasn't changed it makes no sense to run a db query
145
+        $properties = $entity->getUpdatedFields();
146
+        if(count($properties) === 0) {
147
+            return $entity;
148
+        }
149
+
150
+        // entity needs an id
151
+        $id = $entity->getId();
152
+        if($id === null){
153
+            throw new \InvalidArgumentException(
154
+                'Entity which should be updated has no id');
155
+        }
156
+
157
+        // get updated fields to save, fields have to be set using a setter to
158
+        // be saved
159
+        // do not update the id field
160
+        unset($properties['id']);
161
+
162
+        $columns = '';
163
+        $params = [];
164
+
165
+        // build the fields
166
+        $i = 0;
167
+        foreach($properties as $property => $updated) {
168
+
169
+            $column = $entity->propertyToColumn($property);
170
+            $getter = 'get' . ucfirst($property);
171
+
172
+            $columns .= '`' . $column . '` = ?';
173
+
174
+            // only append colon if there are more entries
175
+            if($i < count($properties)-1){
176
+                $columns .= ',';
177
+            }
178
+
179
+            $params[] = $entity->$getter();
180
+            $i++;
181
+        }
182
+
183
+        $sql = 'UPDATE `' . $this->tableName . '` SET ' .
184
+                $columns . ' WHERE `id` = ?';
185
+        $params[] = $id;
186
+
187
+        $stmt = $this->execute($sql, $params);
188
+        $stmt->closeCursor();
189
+
190
+        return $entity;
191
+    }
192
+
193
+    /**
194
+     * Checks if an array is associative
195
+     * @param array $array
196
+     * @return bool true if associative
197
+     * @since 8.1.0
198
+     */
199
+    private function isAssocArray(array $array) {
200
+        return array_values($array) !== $array;
201
+    }
202
+
203
+    /**
204
+     * Returns the correct PDO constant based on the value type
205
+     * @param $value
206
+     * @return int PDO constant
207
+     * @since 8.1.0
208
+     */
209
+    private function getPDOType($value) {
210
+        switch (gettype($value)) {
211
+            case 'integer':
212
+                return \PDO::PARAM_INT;
213
+            case 'boolean':
214
+                return \PDO::PARAM_BOOL;
215
+            default:
216
+                return \PDO::PARAM_STR;
217
+        }
218
+    }
219
+
220
+
221
+    /**
222
+     * Runs an sql query
223
+     * @param string $sql the prepare string
224
+     * @param array $params the params which should replace the ? in the sql query
225
+     * @param int $limit the maximum number of rows
226
+     * @param int $offset from which row we want to start
227
+     * @return \PDOStatement the database query result
228
+     * @since 7.0.0
229
+     */
230
+    protected function execute($sql, array $params=[], $limit=null, $offset=null){
231
+        $query = $this->db->prepare($sql, $limit, $offset);
232
+
233
+        if ($this->isAssocArray($params)) {
234
+            foreach ($params as $key => $param) {
235
+                $pdoConstant = $this->getPDOType($param);
236
+                $query->bindValue($key, $param, $pdoConstant);
237
+            }
238
+        } else {
239
+            $index = 1;  // bindParam is 1 indexed
240
+            foreach ($params as $param) {
241
+                $pdoConstant = $this->getPDOType($param);
242
+                $query->bindValue($index, $param, $pdoConstant);
243
+                $index++;
244
+            }
245
+        }
246
+
247
+        $query->execute();
248
+
249
+        return $query;
250
+    }
251
+
252
+
253
+    /**
254
+     * Returns an db result and throws exceptions when there are more or less
255
+     * results
256
+     * @see findEntity
257
+     * @param string $sql the sql query
258
+     * @param array $params the parameters of the sql query
259
+     * @param int $limit the maximum number of rows
260
+     * @param int $offset from which row we want to start
261
+     * @throws DoesNotExistException if the item does not exist
262
+     * @throws MultipleObjectsReturnedException if more than one item exist
263
+     * @return array the result as row
264
+     * @since 7.0.0
265
+     */
266
+    protected function findOneQuery($sql, array $params=[], $limit=null, $offset=null){
267
+        $stmt = $this->execute($sql, $params, $limit, $offset);
268
+        $row = $stmt->fetch();
269
+
270
+        if($row === false || $row === null){
271
+            $stmt->closeCursor();
272
+            $msg = $this->buildDebugMessage(
273
+                'Did expect one result but found none when executing', $sql, $params, $limit, $offset
274
+            );
275
+            throw new DoesNotExistException($msg);
276
+        }
277
+        $row2 = $stmt->fetch();
278
+        $stmt->closeCursor();
279
+        //MDB2 returns null, PDO and doctrine false when no row is available
280
+        if( ! ($row2 === false || $row2 === null )) {
281
+            $msg = $this->buildDebugMessage(
282
+                'Did not expect more than one result when executing', $sql, $params, $limit, $offset
283
+            );
284
+            throw new MultipleObjectsReturnedException($msg);
285
+        } else {
286
+            return $row;
287
+        }
288
+    }
289
+
290
+    /**
291
+     * Builds an error message by prepending the $msg to an error message which
292
+     * has the parameters
293
+     * @see findEntity
294
+     * @param string $sql the sql query
295
+     * @param array $params the parameters of the sql query
296
+     * @param int $limit the maximum number of rows
297
+     * @param int $offset from which row we want to start
298
+     * @return string formatted error message string
299
+     * @since 9.1.0
300
+     */
301
+    private function buildDebugMessage($msg, $sql, array $params=[], $limit=null, $offset=null) {
302
+        return $msg .
303
+                    ': query "' .	$sql . '"; ' .
304
+                    'parameters ' . print_r($params, true) . '; ' .
305
+                    'limit "' . $limit . '"; '.
306
+                    'offset "' . $offset . '"';
307
+    }
308
+
309
+
310
+    /**
311
+     * Creates an entity from a row. Automatically determines the entity class
312
+     * from the current mapper name (MyEntityMapper -> MyEntity)
313
+     * @param array $row the row which should be converted to an entity
314
+     * @return Entity the entity
315
+     * @since 7.0.0
316
+     */
317
+    protected function mapRowToEntity($row) {
318
+        return call_user_func($this->entityClass .'::fromRow', $row);
319
+    }
320
+
321
+
322
+    /**
323
+     * Runs a sql query and returns an array of entities
324
+     * @param string $sql the prepare string
325
+     * @param array $params the params which should replace the ? in the sql query
326
+     * @param int $limit the maximum number of rows
327
+     * @param int $offset from which row we want to start
328
+     * @return array all fetched entities
329
+     * @since 7.0.0
330
+     */
331
+    protected function findEntities($sql, array $params=[], $limit=null, $offset=null) {
332
+        $stmt = $this->execute($sql, $params, $limit, $offset);
333
+
334
+        $entities = [];
335
+
336
+        while($row = $stmt->fetch()){
337
+            $entities[] = $this->mapRowToEntity($row);
338
+        }
339
+
340
+        $stmt->closeCursor();
341
+
342
+        return $entities;
343
+    }
344
+
345
+
346
+    /**
347
+     * Returns an db result and throws exceptions when there are more or less
348
+     * results
349
+     * @param string $sql the sql query
350
+     * @param array $params the parameters of the sql query
351
+     * @param int $limit the maximum number of rows
352
+     * @param int $offset from which row we want to start
353
+     * @throws DoesNotExistException if the item does not exist
354
+     * @throws MultipleObjectsReturnedException if more than one item exist
355
+     * @return Entity the entity
356
+     * @since 7.0.0
357
+     */
358
+    protected function findEntity($sql, array $params=[], $limit=null, $offset=null){
359
+        return $this->mapRowToEntity($this->findOneQuery($sql, $params, $limit, $offset));
360
+    }
361 361
 
362 362
 
363 363
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Db/DoesNotExistException.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@
 block discarded – undo
32 32
  */
33 33
 class DoesNotExistException extends \Exception {
34 34
 
35
-	/**
36
-	 * Constructor
37
-	 * @param string $msg the error message
38
-	 * @since 7.0.0
39
-	 */
40
-	public function __construct($msg){
41
-		parent::__construct($msg);
42
-	}
35
+    /**
36
+     * Constructor
37
+     * @param string $msg the error message
38
+     * @since 7.0.0
39
+     */
40
+    public function __construct($msg){
41
+        parent::__construct($msg);
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 	 * @param string $msg the error message
38 38
 	 * @since 7.0.0
39 39
 	 */
40
-	public function __construct($msg){
40
+	public function __construct($msg) {
41 41
 		parent::__construct($msg);
42 42
 	}
43 43
 
Please login to merge, or discard this patch.