]> source.dussan.org Git - nextcloud-server.git/commitdiff
Introducing IContainer into public api
authorThomas Müller <thomas.mueller@tmit.eu>
Tue, 20 Aug 2013 15:21:14 +0000 (17:21 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 20 Aug 2013 15:21:14 +0000 (17:21 +0200)
lib/appframework/dependencyinjection/dicontainer.php
lib/appframework/utility/simplecontainer.php [new file with mode: 0644]
tests/lib/appframework/classloader.php

index 69c645b1be339d10881386730f1e28c1d6aed7dd..88ad2cd414a064c98d8f8a060dbd1ee02a3085d5 100644 (file)
@@ -30,19 +30,11 @@ use OC\AppFramework\Http\Dispatcher;
 use OC\AppFramework\Core\API;
 use OC\AppFramework\Middleware\MiddlewareDispatcher;
 use OC\AppFramework\Middleware\Security\SecurityMiddleware;
+use OC\AppFramework\Utility\SimpleContainer;
 use OC\AppFramework\Utility\TimeFactory;
 
-// register 3rdparty autoloaders
-require_once __DIR__ . '/../../../3rdparty/Pimple/Pimple.php';
 
-
-/**
- * This class extends Pimple (http://pimple.sensiolabs.org/) for reusability
- * To use this class, extend your own container from this. Should you require it
- * you can overwrite the dependencies with your own classes by simply redefining
- * a dependency
- */
-class DIContainer extends \Pimple {
+class DIContainer extends SimpleContainer {
 
 
        /**
@@ -61,8 +53,14 @@ class DIContainer extends \Pimple {
                 * Http
                 */
                $this['Request'] = $this->share(function($c) {
-                       $params = json_decode(file_get_contents('php://input'), true);
-                       $params = is_array($params) ? $params: array();
+
+                       $params = array();
+
+                       // we json decode the body only in case of content type json
+                       if (isset($_SERVER['CONTENT_TYPE']) && stripos($_SERVER['CONTENT_TYPE'],'json') === true ) {
+                               $params = json_decode(file_get_contents('php://input'), true);
+                               $params = is_array($params) ? $params: array();
+                       }
 
                        return new Request(
                                array(
diff --git a/lib/appframework/utility/simplecontainer.php b/lib/appframework/utility/simplecontainer.php
new file mode 100644 (file)
index 0000000..04b6cd7
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+namespace OC\AppFramework\Utility;
+
+// register 3rdparty autoloaders
+require_once __DIR__ . '/../../../3rdparty/Pimple/Pimple.php';
+
+/**
+ * Class SimpleContainer
+ *
+ * SimpleContainer is a simple implementation of IContainer on basis of \Pimple
+ */
+class SimpleContainer extends \Pimple implements \OCP\Core\IContainer {
+
+       /**
+        * @param string $name name of the service to query for
+        * @return object registered service for the given $name
+        */
+       public function query($name) {
+               return $this->offsetGet($name);
+       }
+
+       function registerParameter($name, $value)
+       {
+               $this[$name] = $value;
+       }
+
+       /**
+        * The given closure is call the first time the given service is queried.
+        * The closure has to return the instance for the given service.
+        * Created instance will be cached in case $shared is true.
+        *
+        * @param string $name name of the service to register another backend for
+        * @param callable $closure the closure to be called on service creation
+        */
+       function registerService($name, \Closure $closure, $shared = true)
+       {
+               if ($shared) {
+                       $this[$name] = \Pimple::share($closure);
+               } else {
+                       $this[$name] = $closure;
+               }
+       }
+}
index ae485e67b2c9cf6e25147274f8e968bf7426d730..cd9f893df30a72cf8e868d44357387001518e0cf 100644 (file)
@@ -32,6 +32,15 @@ spl_autoload_register(function ($className){
                }
        }
 
+       if (strpos($className, 'OCP\\') === 0) {
+               $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
+               $relPath = __DIR__ . '/../../../lib/public' . $path;
+
+               if(file_exists($relPath)){
+                       require_once $relPath;
+               }
+       }
+
        // FIXME: this will most probably not work anymore
        if (strpos($className, 'OCA\\') === 0) {