diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-12-17 19:20:21 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-01-18 14:06:07 +0100 |
commit | 73759298658da929fe2da06d0446a93a56859067 (patch) | |
tree | 99972490a099d31c70a0f856d681f71e194103a3 | |
parent | f741d1fd502687aafede499ab55c0803ad469df3 (diff) |
first stab at intelligent container
-rw-r--r-- | admin/admin.php | 2 | ||||
-rw-r--r-- | appinfo/application.php | 346 | ||||
-rw-r--r-- | appinfo/info.xml | 3 | ||||
-rw-r--r-- | appinfo/routes.php | 9 | ||||
-rw-r--r-- | config/config.php | 5 | ||||
-rw-r--r-- | controller/admincontroller.php | 8 | ||||
-rw-r--r-- | controller/exportcontroller.php | 8 | ||||
-rw-r--r-- | controller/feedapicontroller.php | 12 | ||||
-rw-r--r-- | controller/feedcontroller.php | 8 | ||||
-rw-r--r-- | controller/folderapicontroller.php | 8 | ||||
-rw-r--r-- | controller/foldercontroller.php | 8 | ||||
-rw-r--r-- | controller/itemapicontroller.php | 8 | ||||
-rw-r--r-- | controller/itemcontroller.php | 8 | ||||
-rw-r--r-- | controller/pagecontroller.php | 8 | ||||
-rw-r--r-- | controller/utilityapicontroller.php | 4 | ||||
-rw-r--r-- | cron/updater.php | 8 | ||||
-rw-r--r-- | db/mapperfactory.php | 4 | ||||
-rw-r--r-- | service/feedservice.php | 11 | ||||
-rw-r--r-- | service/folderservice.php | 4 | ||||
-rw-r--r-- | service/itemservice.php | 3 | ||||
-rw-r--r-- | tests/unit/service/FeedServiceTest.php | 10 | ||||
-rw-r--r-- | tests/unit/service/FolderServiceTest.php | 4 | ||||
-rw-r--r-- | tests/unit/service/ItemServiceTest.php | 4 |
23 files changed, 111 insertions, 382 deletions
diff --git a/admin/admin.php b/admin/admin.php index 9880e49c6..2ecc281e2 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -17,6 +17,6 @@ use OCA\News\AppInfo\Application; $app = new Application(); $container = $app->getContainer(); -$response = $container->query('AdminController')->index(); +$response = $container->query('OCA\News\Controller\AdminController')->index(); return $response->render();
\ No newline at end of file diff --git a/appinfo/application.php b/appinfo/application.php index ccaae0f09..b73684191 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -15,50 +15,26 @@ namespace OCA\News\AppInfo; require_once __DIR__ . '/autoload.php'; +use HTMLPurifier; +use HTMLPurifier_Config; + use \PicoFeed\Config\Config as PicoFeedConfig; use \PicoFeed\Reader\Reader as PicoFeedReader; use \OC\Files\View; use \OCP\AppFramework\App; -use \OCP\Util; -use \OCP\User; use \OCA\News\Config\AppConfig; use \OCA\News\Config\Config; -use \OCA\News\Controller\AdminController; -use \OCA\News\Controller\PageController; -use \OCA\News\Controller\FolderController; -use \OCA\News\Controller\FeedController; -use \OCA\News\Controller\ItemController; -use \OCA\News\Controller\ExportController; -use \OCA\News\Controller\UtilityApiController; -use \OCA\News\Controller\FolderApiController; -use \OCA\News\Controller\FeedApiController; -use \OCA\News\Controller\ItemApiController; - -use \OCA\News\Service\FolderService; use \OCA\News\Service\FeedService; -use \OCA\News\Service\ItemService; -use \OCA\News\Db\FolderMapper; -use \OCA\News\Db\FeedMapper; -use \OCA\News\Db\ItemMapper; use \OCA\News\Db\MapperFactory; -use \OCA\News\Db\StatusFlag; - -use \OCA\News\Utility\OPMLExporter; -use \OCA\News\Utility\Updater; -use \OCA\News\Utility\PicoFeedClientFactory; -use \OCA\News\Utility\PicoFeedFaviconFactory; -use \OCA\News\Utility\ProxyConfigParser; use \OCA\News\Fetcher\Fetcher; use \OCA\News\Fetcher\FeedFetcher; -use \OCA\News\Fetcher\YoutubeFetcher; use \OCA\News\ArticleEnhancer\Enhancer; -use \OCA\News\ArticleEnhancer\GlobalArticleEnhancer; use \OCA\News\ArticleEnhancer\XPathArticleEnhancer; use \OCA\News\ArticleEnhancer\RegexArticleEnhancer; @@ -72,191 +48,12 @@ class Application extends App { $container = $this->getContainer(); - - /** - * Controllers - */ - $container->registerService('PageController', function($c) { - return new PageController( - $c->query('AppName'), - $c->query('Request'), - $c->query('CoreConfig'), - $c->query('URLGenerator'), - $c->query('AppConfig'), - $c->query('Config'), - $c->query('L10N'), - $c->query('RecommendedSites'), - $c->query('UserId') - ); - }); - - $container->registerService('AdminController', function($c) { - return new AdminController( - $c->query('AppName'), - $c->query('Request'), - $c->query('Config'), - $c->query('ConfigPath') - ); - }); - - $container->registerService('FolderController', function($c) { - return new FolderController( - $c->query('AppName'), - $c->query('Request'), - $c->query('FolderService'), - $c->query('FeedService'), - $c->query('ItemService'), - $c->query('UserId') - ); - }); - - $container->registerService('FeedController', function($c) { - return new FeedController( - $c->query('AppName'), - $c->query('Request'), - $c->query('FolderService'), - $c->query('FeedService'), - $c->query('ItemService'), - $c->query('CoreConfig'), - $c->query('UserId') - ); - }); - - $container->registerService('ItemController', function($c) { - return new ItemController( - $c->query('AppName'), - $c->query('Request'), - $c->query('FeedService'), - $c->query('ItemService'), - $c->query('CoreConfig'), - $c->query('UserId') - ); - }); - - $container->registerService('ExportController', function($c) { - return new ExportController( - $c->query('AppName'), - $c->query('Request'), - $c->query('FolderService'), - $c->query('FeedService'), - $c->query('ItemService'), - $c->query('OPMLExporter'), - $c->query('UserId') - ); - }); - - $container->registerService('UtilityApiController', function($c) { - return new UtilityApiController( - $c->query('AppName'), - $c->query('Request'), - $c->query('Updater'), - $c->query('CoreConfig') - ); - }); - - $container->registerService('FolderApiController', function($c) { - return new FolderApiController( - $c->query('AppName'), - $c->query('Request'), - $c->query('FolderService'), - $c->query('ItemService'), - $c->query('UserId') - ); - }); - - $container->registerService('FeedApiController', function($c) { - return new FeedApiController( - $c->query('AppName'), - $c->query('Request'), - $c->query('FeedService'), - $c->query('ItemService'), - $c->query('Logger'), - $c->query('UserId'), - $c->query('LoggerParameters') - ); - }); - - $container->registerService('ItemApiController', function($c) { - return new ItemApiController( - $c->query('AppName'), - $c->query('Request'), - $c->query('ItemService'), - $c->query('UserId') - ); - }); - - /** - * Business Layer - */ - $container->registerService('FolderService', function($c) { - return new FolderService( - $c->query('FolderMapper'), - $c->query('L10N'), - $c->query('TimeFactory'), - $c->query('Config') - ); - }); - - $container->registerService('FeedService', function($c) { - return new FeedService( - $c->query('FeedMapper'), - $c->query('Fetcher'), - $c->query('ItemMapper'), - $c->query('Logger'), - $c->query('L10N'), - $c->query('TimeFactory'), - $c->query('Config'), - $c->query('Enhancer'), - $c->query('HTMLPurifier'), - $c->query('LoggerParameters') - ); - }); - - $container->registerService('ItemService', function($c) { - return new ItemService( - $c->query('ItemMapper'), - $c->query('StatusFlag'), - $c->query('TimeFactory'), - $c->query('Config') - ); - }); - - // compability for plugins pre 3.0 - $container->registerService('FolderBusinessLayer', function($c) { - return $c->query('FolderService'); - }); - $container->registerService('FeedBusinessLayer', function($c) { - return $c->query('FeedService'); - }); - $container->registerService('ItemBusinessLayer', function($c) { - return $c->query('ItemService'); - }); - /** * Mappers */ - $container->registerService('MapperFactory', function($c) { - return new MapperFactory( - $c->query('DatabaseType'), - $c->query('Db') - ); - }); - - $container->registerService('FolderMapper', function($c) { - return new FolderMapper( - $c->query('Db') - ); - }); - - $container->registerService('FeedMapper', function($c) { - return new FeedMapper( - $c->query('Db') - ); - }); - - $container->registerService('ItemMapper', function($c) { - return $c->query('MapperFactory')->getItemMapper( - $c->query('Db') + $container->registerService('OCA\News\Db\ItemMapper', function($c) { + return $c->query('OCA\News\Db\MapperFactory')->getItemMapper( + $c->query('OCP\IDb') ); }); @@ -264,10 +61,10 @@ class Application extends App { /** * App config parser */ - $container->registerService('AppConfig', function($c) { + $container->registerService('OCA\News\Config\AppConfig', function($c) { $config = new AppConfig( - $c->query('ServerContainer')->getNavigationManager(), - $c->query('URLGenerator') + $c->query('OCP\INavigationManager'), + $c->query('OCP\IURLGenerator') ); $config->loadConfig(__DIR__ . '/info.xml'); @@ -278,37 +75,12 @@ class Application extends App { /** * Core */ - $container->registerService('L10N', function($c) { - return $c->query('ServerContainer')->getL10N($c->query('AppName')); - }); - - $container->registerService('URLGenerator', function($c) { - return $c->query('ServerContainer')->getURLGenerator(); - }); - - $container->registerService('UserId', function() { - return User::getUser(); - }); - - $container->registerService('Logger', function($c) { - return $c->query('ServerContainer')->getLogger(); - }); - $container->registerService('LoggerParameters', function($c) { return ['app' => $c->query('AppName')]; }); - $container->registerService('Db', function($c) { - return $c->query('ServerContainer')->getDb(); - }); - - $container->registerService('CoreConfig', function($c) { - return $c->query('ServerContainer')->getConfig(); - }); - $container->registerService('DatabaseType', function($c) { - return $c->query('ServerContainer') - ->getConfig()->getSystemValue('dbtype'); + return $c->query('OCP\\IConfig')->getSystemValue('dbtype'); }); @@ -328,10 +100,10 @@ class Application extends App { return 'config.ini'; }); - $container->registerService('Config', function($c) { + $container->registerService('OCA\News\Config\Config', function($c) { $config = new Config( $c->query('ConfigView'), - $c->query('Logger'), + $c->query('OCP\ILogger'), $c->query('LoggerParameters') ); $config->read($c->query('ConfigPath'), true); @@ -339,14 +111,14 @@ class Application extends App { }); $container->registerService('HTMLPurifier', function($c) { - $directory = $c->query('CoreConfig') + $directory = $c->query('OCP\IConfig') ->getSystemValue('datadirectory') . '/news/cache/purifier'; if(!is_dir($directory)) { mkdir($directory, 0770, true); } - $config = \HTMLPurifier_Config::createDefault(); + $config = HTMLPurifier_Config::createDefault(); $config->set('HTML.ForbiddenAttributes', 'class'); $config->set('Cache.SerializerPath', $directory); $config->set('HTML.SafeIframe', true); @@ -354,14 +126,10 @@ class Application extends App { '%^(?:https?:)?//(' . 'www.youtube(?:-nocookie)?.com/embed/|' . 'player.vimeo.com/video/)%'); //allow YouTube and Vimeo - return new \HTMLPurifier($config); - }); - - $container->registerService('GlobalArticleEnhancer', function() { - return new GlobalArticleEnhancer(); + return new HTMLPurifier($config); }); - $container->registerService('Enhancer', function($c) { + $container->registerService('OCA\News\ArticleEnhancer\Enhancer', function($c) { $enhancer = new Enhancer(); // register simple enhancers from config json file @@ -372,7 +140,7 @@ class Application extends App { $xpathEnhancerConfig = json_decode($xpathEnhancerConfig, true); foreach($xpathEnhancerConfig as $feed => $config) { $articleEnhancer = new XPathArticleEnhancer( - $c->query('PicoFeedClientFactory'), + $c->query('OCA\News\Utility\PicoFeedClientFactory'), $config ); $enhancer->registerEnhancer($feed, $articleEnhancer); @@ -391,7 +159,7 @@ class Application extends App { } $enhancer->registerGlobalEnhancer( - $c->query('GlobalArticleEnhancer') + $c->query('OCA\News\ArticleEnhancer\GlobalArticleEnhancer') ); return $enhancer; @@ -400,11 +168,11 @@ class Application extends App { /** * Fetchers */ - $container->registerService('PicoFeedConfig', function($c) { + $container->registerService('PicoFeed\Config\Config', function($c) { // FIXME: move this into a separate class for testing? - $config = $c->query('Config'); - $appConfig = $c->query('AppConfig'); - $proxy = $c->query('ProxyConfigParser'); + $config = $c->query('OCA\News\Config\Config'); + $appConfig = $c->query('OCA\News\Config\AppConfig'); + $proxy = $c->query('OCA\News\Utility\ProxyConfigParser'); $userAgent = 'ownCloud News/' . $appConfig->getConfig('version') . ' (+https://owncloud.org/; 1 subscriber;)'; @@ -442,83 +210,33 @@ class Application extends App { return $pico; }); - $container->registerService('PicoFeedReader', function($c) { - return new PicoFeedReader($c->query('PicoFeedConfig')); - }); - - $container->registerService('PicoFeedClientFactory', function($c) { - return new PicoFeedClientFactory($c->query('PicoFeedConfig')); - }); - - $container->registerService('PicoFeedFaviconFactory', function($c) { - return new PicoFeedFaviconFactory($c->query('PicoFeedConfig')); - }); - - $container->registerService('Fetcher', function($c) { + $container->registerService('OCA\News\Fetcher\Fetcher', function($c) { $fetcher = new Fetcher(); // register fetchers in order // the most generic fetcher should be the last one - $fetcher->registerFetcher($c->query('YoutubeFetcher')); - $fetcher->registerFetcher($c->query('FeedFetcher')); + $fetcher->registerFetcher($c->query('OCA\News\Fetcher\YoutubeFetcher')); + $fetcher->registerFetcher($c->query('OCA\News\Fetcher\FeedFetcher')); return $fetcher; }); - $container->registerService('FeedFetcher', function($c) { + $container->registerService('OCA\News\Fetcher\FeedFetcher', function($c) { return new FeedFetcher( - $c->query('PicoFeedReader'), - $c->query('PicoFeedFaviconFactory'), - $c->query('L10N'), - $c->query('TimeFactory') + $c->query('PicoFeed\Reader\Reader'), + $c->query('OCA\News\Utility\PicoFeedFaviconFactory'), + $c->query('OCP\IL10N'), + $c->query('OCP\AppFramework\Utility\ITimeFactory') ); }); - $container->registerService('YoutubeFetcher', function($c) { - return new YoutubeFetcher( - $c->query('FeedFetcher') - ); - }); - - $container->registerService('StatusFlag', function() { - return new StatusFlag(); - }); - - $container->registerService('OPMLExporter', function() { - return new OPMLExporter(); - }); - - $container->registerService('ProxyConfigParser', function($c) { - return new ProxyConfigParser( - $c->query('CoreConfig') - ); - }); - - $container->registerService('Updater', function($c) { - return new Updater( - $c->query('FolderService'), - $c->query('FeedService'), - $c->query('ItemService') - ); - }); - - $container->registerService('RecommendedSites', function($c) { + $container->registerService('OCA\News\Explore\RecommendedSites', function($c) { return new RecommendedSites(__DIR__ . '/../explore'); }); } public function getAppConfig() { - return $this->getContainer()->query('AppConfig'); - } - - - public function getLogger() { - return $this->getContainer()->query('Logger'); - } - - - public function getLoggerParameters() { - return $this->getContainer()->query('LoggerParameters'); + return $this->getContainer()->query('OCA\News\Config\AppConfig'); } diff --git a/appinfo/info.xml b/appinfo/info.xml index 6f616237c..33a1336f3 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -7,7 +7,8 @@ <author>Bernhard Posselt, Alessandro Cosentino, Jan-Christoph Borchardt</author> <category>multimedia</category> <licence>AGPL</licence> - <version>4.3.2</version> + <version>5.0.0</version> + <namespace>News</namespace> <!-- resources --> <documentation> diff --git a/appinfo/routes.php b/appinfo/routes.php index 7b2028865..954656d2d 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -11,12 +11,7 @@ * @copyright Bernhard Posselt 2012, 2014 */ -namespace OCA\News\AppInfo; - -use \OCA\News\AppInfo\Application; - -$application = new Application(); -$application->registerRoutes($this, ['routes' => [ +return ['routes' => [ // page ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'page#settings', 'url' => '/settings', 'verb' => 'GET'], @@ -97,4 +92,4 @@ $application->registerRoutes($this, ['routes' => [ ['name' => 'item_api#star_multiple', 'url' => '/api/v1-2/items/star/multiple', 'verb' => 'PUT'], // FIXME: POST would be more correct ['name' => 'item_api#unstar_multiple', 'url' => '/api/v1-2/items/unstar/multiple', 'verb' => 'PUT'], // FIXME: POST would be more correct -]]); +]]; diff --git a/config/config.php b/config/config.php index 0e1eec64b..4df8ba853 100644 --- a/config/config.php +++ b/config/config.php @@ -33,7 +33,8 @@ class Config { private $exploreUrl; - public function __construct($fileSystem, ILogger $logger, $loggerParams) { + public function __construct($fileSystem, ILogger $logger, + $LoggerParameters) { $this->fileSystem = $fileSystem; $this->autoPurgeMinimumInterval = 60; $this->autoPurgeCount = 200; @@ -47,7 +48,7 @@ class Config { $this->proxyUser = ''; $this->proxyPassword = ''; $this->exploreUrl = ''; - $this->loggerParams = $loggerParams; + $this->loggerParams = $LoggerParameters; } public function getProxyPort() { diff --git a/controller/admincontroller.php b/controller/admincontroller.php index 5adaef500..15b94fe2d 100644 --- a/controller/admincontroller.php +++ b/controller/admincontroller.php @@ -24,11 +24,11 @@ class AdminController extends Controller { private $config; private $configPath; - public function __construct($appName, IRequest $request, Config $config, - $configPath){ - parent::__construct($appName, $request); + public function __construct($AppName, IRequest $request, Config $config, + $ConfigPath){ + parent::__construct($AppName, $request); $this->config = $config; - $this->configPath = $configPath; + $this->configPath = $ConfigPath; } // There are no checks for the index method since the output is rendered diff --git a/controller/exportcontroller.php b/controller/exportcontroller.php index b1d62f015..bc9fc0ff1 100644 --- a/controller/exportcontroller.php +++ b/controller/exportcontroller.php @@ -32,19 +32,19 @@ class ExportController extends Controller { private $itemService; private $userId; - public function __construct($appName, + public function __construct($AppName, IRequest $request, FolderService $folderService, FeedService $feedService, ItemService $itemService, OPMLExporter $opmlExporter, - $userId){ - parent::__construct($appName, $request); + $UserId){ + parent::__construct($AppName, $request); $this->feedService = $feedService; $this->folderService = $folderService; $this->opmlExporter = $opmlExporter; $this->itemService = $itemService; - $this->userId = $userId; + $this->userId = $UserId; } diff --git a/controller/feedapicontroller.php b/controller/feedapicontroller.php index 2e48b5afe..0d9e985f7 100644 --- a/controller/feedapicontroller.php +++ b/controller/feedapicontroller.php @@ -35,19 +35,19 @@ class FeedApiController extends ApiController { private $loggerParams; private $serializer; - public function __construct($appName, + public function __construct($AppName, IRequest $request, FeedService $feedService, ItemService $itemService, ILogger $logger, - $userId, - $loggerParams){ - parent::__construct($appName, $request); + $UserId, + $LoggerParameters){ + parent::__construct($AppName, $request); $this->feedService = $feedService; $this->itemService = $itemService; - $this->userId = $userId; + $this->userId = $UserId; $this->logger = $logger; - $this->loggerParams = $loggerParams; + $this->loggerParams = $LoggerParameters; $this->serializer = new EntityApiSerializer('feeds'); } diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index e1544bff0..3be802a34 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.php @@ -36,18 +36,18 @@ class FeedController extends Controller { private $userId; private $settings; - public function __construct($appName, + public function __construct($AppName, IRequest $request, FolderService $folderService, FeedService $feedService, ItemService $itemService, IConfig $settings, - $userId){ - parent::__construct($appName, $request); + $UserId){ + parent::__construct($AppName, $request); $this->feedService = $feedService; $this->folderService = $folderService; $this->itemService = $itemService; - $this->userId = $userId; + $this->userId = $UserId; $this->settings = $settings; } diff --git a/controller/folderapicontroller.php b/controller/folderapicontroller.php index ab2b5601f..53693e84f 100644 --- a/controller/folderapicontroller.php +++ b/controller/folderapicontroller.php @@ -33,15 +33,15 @@ class FolderApiController extends ApiController { private $userId; private $serializer; - public function __construct($appName, + public function __construct($AppName, IRequest $request, FolderService $folderService, ItemService $itemService, - $userId){ - parent::__construct($appName, $request); + $UserId){ + parent::__construct($AppName, $request); $this->folderService = $folderService; $this->itemService = $itemService; - $this->userId = $userId; + $this->userId = $UserId; $this->serializer = new EntityApiSerializer('folders'); } diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php index e5ad9a24f..e8c0b0e6c 100644 --- a/controller/foldercontroller.php +++ b/controller/foldercontroller.php |