Introducing IContainer into public api

remotes/origin/stable6
Thomas Müller 12 years ago
parent cdada78aa4
commit 93194bb396
  1. 22
      lib/appframework/dependencyinjection/dicontainer.php
  2. 44
      lib/appframework/utility/simplecontainer.php
  3. 9
      tests/lib/appframework/classloader.php

@ -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(

@ -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;
}
}
}

@ -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) {

Loading…
Cancel
Save