Ejemplo n.º 1
0
 /**
  * @param string $webRoot
  */
 public function __construct($webRoot)
 {
     parent::__construct();
     $this->webRoot = $webRoot;
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('PreviewManager', function (Server $c) {
         return new PreviewManager($c->getConfig());
     });
     $this->registerService('EncryptionManager', function (Server $c) {
         $view = new View();
         $util = new Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\Manager($c->getConfig(), $c->getLogger(), $c->getL10N('core'), new View(), $util);
     });
     $this->registerService('EncryptionFileHelper', function (Server $c) {
         $util = new Encryption\Util(new View(), $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\File($util);
     });
     $this->registerService('EncryptionKeyStorage', function (Server $c) {
         $view = new View();
         $util = new Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\Keys\Storage($view, $util);
     });
     $this->registerService('TagMapper', function (Server $c) {
         return new TagMapper($c->getDatabaseConnection());
     });
     $this->registerService('TagManager', function (Server $c) {
         $tagMapper = $c->query('TagMapper');
         return new TagManager($tagMapper, $c->getUserSession());
     });
     $this->registerService('SystemTagManager', function (Server $c) {
         return new SystemTag\SystemTagManager($c->getDatabaseConnection());
     });
     $this->registerService('SystemTagObjectMapper', function (Server $c) {
         return new SystemTag\SystemTagObjectMapper($c->getDatabaseConnection(), $c->getSystemTagManager());
     });
     $this->registerService('RootFolder', function (Server $c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         $root = new Root($manager, $view, $user);
         $connector = new HookConnector($root, $view);
         $connector->viewToNode();
         return $root;
     });
     $this->registerService('UserManager', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function (Server $c) {
         $groupManager = new \OC\Group\Manager($this->getUserManager());
         $groupManager->listen('\\OC\\Group', 'preCreate', function ($gid) {
             \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
         });
         $groupManager->listen('\\OC\\Group', 'postCreate', function (\OC\Group\Group $gid) {
             \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
             //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
             \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         return $groupManager;
     });
     $this->registerService('UserSession', function (Server $c) {
         $manager = $c->getUserManager();
         $session = new \OC\Session\Memory('');
         $userSession = new \OC\User\Session($manager, $session);
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function (Server $c) {
         return new \OC\AllConfig($c->getSystemConfig());
     });
     $this->registerService('SystemConfig', function ($c) {
         return new \OC\SystemConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function (Server $c) {
         $config = $c->getConfig();
         $cacheFactory = $c->getMemCacheFactory();
         return new \OC\URLGenerator($config, $cacheFactory);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new Cache\File();
     });
     $this->registerService('MemCacheFactory', function (Server $c) {
         $config = $c->getConfig();
         if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
             $v = \OC_App::getAppVersions();
             $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
             $version = implode(',', $v);
             $instanceId = \OC_Util::getInstanceId();
             $path = \OC::$SERVERROOT;
             $prefix = md5($instanceId . '-' . $version . '-' . $path);
             return new \OC\Memcache\Factory($prefix, $c->getLogger(), $config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.distributed', null), $config->getSystemValue('memcache.locking', null));
         }
         return new \OC\Memcache\Factory('', $c->getLogger(), '\\OC\\Memcache\\ArrayCache', '\\OC\\Memcache\\ArrayCache', '\\OC\\Memcache\\ArrayCache');
     });
     $this->registerService('ActivityManager', function (Server $c) {
         return new ActivityManager($c->getRequest(), $c->getUserSession(), $c->getConfig());
     });
     $this->registerService('AvatarManager', function (Server $c) {
         return new AvatarManager($c->getUserManager(), $c->getRootFolder(), $c->getL10N('lib'));
     });
     $this->registerService('Logger', function (Server $c) {
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function (Server $c) {
         $cacheFactory = $c->getMemCacheFactory();
         $logger = $c->getLogger();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
         } else {
             $router = new \OC\Route\Router($logger);
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function (Server $c) {
         return new Crypto($c->getConfig(), $c->getSecureRandom());
     });
     $this->registerService('Hasher', function (Server $c) {
         return new Hasher($c->getConfig());
     });
     $this->registerService('DatabaseConnection', function (Server $c) {
         $factory = new \OC\DB\ConnectionFactory();
         $systemConfig = $c->getSystemConfig();
         $type = $systemConfig->getValue('dbtype', 'sqlite');
         if (!$factory->isValidType($type)) {
             throw new \OC\DatabaseException('Invalid database type');
         }
         $connectionParams = $factory->createConnectionParams($systemConfig);
         $connection = $factory->getConnection($type, $connectionParams);
         $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
         return $connection;
     });
     $this->registerService('Db', function (Server $c) {
         return new Db($c->getDatabaseConnection());
     });
     $this->registerService('HTTPHelper', function (Server $c) {
         $config = $c->getConfig();
         return new HTTPHelper($config, $c->getHTTPClientService());
     });
     $this->registerService('HttpClientService', function (Server $c) {
         $user = \OC_User::getUser();
         $uid = $user ? $user : null;
         return new ClientService($c->getConfig(), new \OC\Security\CertificateManager($uid, new View(), $c->getConfig()));
     });
     $this->registerService('EventLogger', function (Server $c) {
         if ($c->getSystemConfig()->getValue('debug', false)) {
             return new EventLogger();
         } else {
             return new NullEventLogger();
         }
     });
     $this->registerService('QueryLogger', function (Server $c) {
         if ($c->getSystemConfig()->getValue('debug', false)) {
             return new QueryLogger();
         } else {
             return new NullQueryLogger();
         }
     });
     $this->registerService('TempManager', function (Server $c) {
         return new TempManager($c->getLogger(), $c->getConfig());
     });
     $this->registerService('AppManager', function (Server $c) {
         return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory());
     });
     $this->registerService('DateTimeZone', function (Server $c) {
         return new DateTimeZone($c->getConfig(), $c->getSession());
     });
     $this->registerService('DateTimeFormatter', function (Server $c) {
         $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
         return new DateTimeFormatter($c->getDateTimeZone()->getTimeZone(), $c->getL10N('lib', $language));
     });
     $this->registerService('MountConfigManager', function () {
         $loader = \OC\Files\Filesystem::getLoader();
         return new \OC\Files\Config\MountProviderCollection($loader);
     });
     $this->registerService('IniWrapper', function ($c) {
         return new IniGetWrapper();
     });
     $this->registerService('AsyncCommandBus', function (Server $c) {
         $jobList = $c->getJobList();
         return new AsyncBus($jobList);
     });
     $this->registerService('TrustedDomainHelper', function ($c) {
         return new TrustedDomainHelper($this->getConfig());
     });
     $this->registerService('IntegrityCodeChecker', function (Server $c) {
         // IConfig and IAppManager requires a working database. This code
         // might however be called when ownCloud is not yet setup.
         if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
             $config = $c->getConfig();
             $appManager = $c->getAppManager();
         } else {
             $config = null;
             $appManager = null;
         }
         return new Checker(new EnvironmentHelper(), new FileAccessHelper(), new AppLocator(), $config, $c->getMemCacheFactory(), $appManager);
     });
     $this->registerService('Request', function ($c) {
         if (isset($this['urlParams'])) {
             $urlParams = $this['urlParams'];
         } else {
             $urlParams = [];
         }
         if ($this->getSession()->exists('requesttoken')) {
             $requestToken = $this->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken], $this->getSecureRandom(), $this->getConfig(), $stream);
     });
     $this->registerService('Mailer', function (Server $c) {
         return new Mailer($c->getConfig(), $c->getLogger(), new \OC_Defaults());
     });
     $this->registerService('OcsClient', function (Server $c) {
         return new OCSClient($this->getHTTPClientService(), $this->getConfig(), $this->getLogger());
     });
     $this->registerService('LockingProvider', function (Server $c) {
         if ($c->getConfig()->getSystemValue('filelocking.enabled', true) or defined('PHPUNIT_RUN') && PHPUNIT_RUN) {
             /** @var \OC\Memcache\Factory $memcacheFactory */
             $memcacheFactory = $c->getMemCacheFactory();
             $memcache = $memcacheFactory->createLocking('lock');
             if (!$memcache instanceof \OC\Memcache\NullCache) {
                 return new MemcacheLockingProvider($memcache);
             }
             return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory());
         }
         return new NoopLockingProvider();
     });
     $this->registerService('MountManager', function () {
         return new \OC\Files\Mount\Manager();
     });
     $this->registerService('MimeTypeDetector', function (Server $c) {
         return new \OC\Files\Type\Detection($c->getURLGenerator(), \OC::$SERVERROOT . '/config/', \OC::$SERVERROOT . '/resources/config/');
     });
     $this->registerService('MimeTypeLoader', function (Server $c) {
         return new \OC\Files\Type\Loader($c->getDatabaseConnection());
     });
     $this->registerService('NotificationManager', function () {
         return new Manager();
     });
     $this->registerService('CapabilitiesManager', function (Server $c) {
         $manager = new \OC\CapabilitiesManager();
         $manager->registerCapability(function () use($c) {
             return new \OC\OCS\CoreCapabilities($c->getConfig());
         });
         return $manager;
     });
     $this->registerService('CommentsManager', function (Server $c) {
         $config = $c->getConfig();
         $factoryClass = $config->getSystemValue('comments.managerFactory', '\\OC\\Comments\\ManagerFactory');
         /** @var \OCP\Comments\ICommentsManagerFactory $factory */
         $factory = new $factoryClass();
         return $factory->getManager();
     });
     $this->registerService('EventDispatcher', function () {
         return new EventDispatcher();
     });
     $this->registerService('CryptoWrapper', function (Server $c) {
         // FIXME: Instantiiated here due to cyclic dependency
         $request = new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null], new SecureRandom(), $c->getConfig());
         return new CryptoWrapper($c->getConfig(), $c->getCrypto(), $c->getSecureRandom(), $request);
     });
 }
 /**
  * Test deep identical capabilities
  */
 public function testDeepIdenticalCapabilities()
 {
     $manager = new \OC\CapabilitiesManager();
     $manager->registerCapability(function () {
         return new DeepCapability();
     });
     $manager->registerCapability(function () {
         return new DeepCapability();
     });
     $res = $manager->getCapabilities();
     $expected = ['foo' => ['bar' => ['baz' => true]]];
     $this->assertEquals($expected, $res);
 }