Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
94d9d73
Introduce category factory
laoneo Jun 8, 2018
229a9a5
Merge branch '4.0-dev' into j4/category/factory
laoneo Jun 8, 2018
b4d5180
Merge branch '4.0-dev' into j4/category/factory
laoneo Jun 20, 2018
04585ee
Merge remote-tracking branch 'remotes/upstream/4.0-dev' into j4/categ…
laoneo Jul 17, 2018
b082c79
Adapt banners
laoneo Jul 17, 2018
ab035be
Introduce CategoryInterface
laoneo Jul 17, 2018
b853e72
Merge branch '4.0-dev' into j4/category/factory
laoneo Jul 17, 2018
6effc50
Merge branch '4.0-dev' into j4/category/factory
laoneo Jul 31, 2018
f4433e1
Merge branch '4.0-dev' into j4/category/factory
laoneo Aug 7, 2018
ae2c1d4
Merge conflicts
laoneo Aug 15, 2018
928a192
Merge remote-tracking branch 'origin/j4/category/factory' into j4/cat…
laoneo Aug 15, 2018
cfa75cd
Merge branch '4.0-dev' into j4/category/factory
laoneo Aug 17, 2018
415a9fb
Merge branch '4.0-dev' into j4/category/factory
laoneo Aug 20, 2018
bde3fce
Merge branch '4.0-dev' into j4/category/factory
laoneo Aug 21, 2018
582fa3e
Merge branch '4.0-dev' into j4/category/factory
laoneo Aug 23, 2018
8a98738
Merge branch '4.0-dev' into j4/category/factory
laoneo Aug 31, 2018
1096d28
Less strict method signature
laoneo Aug 31, 2018
970f7fa
Restore typed classes
laoneo Aug 31, 2018
006c385
Merge remote-tracking branch 'origin/j4/category/factory' into j4/cat…
laoneo Aug 31, 2018
3a7a601
doc block
laoneo Aug 31, 2018
34b8bfc
Remove obsolete code
laoneo Aug 31, 2018
c15cfd5
Merge branch '4.0-dev' into j4/category/factory
laoneo Sep 12, 2018
2b14500
Merge branch '4.0-dev' into j4/category/factory
laoneo Sep 13, 2018
5dca489
Merge remote-tracking branch 'remotes/upstream/4.0-dev' into j4/categ…
laoneo Sep 18, 2018
bddbd98
Merge remote-tracking branch 'origin/j4/category/factory' into j4/cat…
laoneo Sep 18, 2018
a1b8f49
Rename CategoriesServiceTrait to CategoryServiceTrait
laoneo Sep 18, 2018
ff0b995
Rename CategoriesServiceInterface to CategoryServiceInterface
laoneo Sep 18, 2018
c86ba15
Rename CategoriesFactoryInterface to CategoryFactoryInterface
laoneo Sep 18, 2018
684acdb
Rename setCategoriesFactory to setCategoryFactory
laoneo Sep 18, 2018
bda3a8b
Rename CategoriesFactory service provider to CategoryFactory
laoneo Sep 18, 2018
ab9ffc7
Merge branch '4.0-dev' into j4/category/factory
laoneo Sep 19, 2018
d2680ac
Merge branch '4.0-dev' into j4/category/factory
laoneo Sep 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions administrator/components/com_banners/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

defined('_JEXEC') or die;

use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Categories\CategoriesFactoryInterface;
use Joomla\CMS\Dispatcher\DispatcherFactoryInterface;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\Service\Provider\CategoriesFactory;
use Joomla\CMS\Extension\Service\Provider\DispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactoryFactory;
use Joomla\CMS\HTML\Registry;
use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface;
use Joomla\Component\Banners\Administrator\Extension\BannersComponent;
use Joomla\Component\Banners\Site\Service\Category;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand All @@ -39,8 +39,7 @@
*/
public function register(Container $container)
{
$container->set(Categories::class, ['' => new Category]);

$container->registerServiceProvider(new CategoriesFactory(['table' => '#__banners', 'extension' => 'com_banners']));
$container->registerServiceProvider(new MVCFactoryFactory('\\Joomla\\Component\\Banners'));
$container->registerServiceProvider(new DispatcherFactory('\\Joomla\\Component\\Banners'));

Expand All @@ -52,7 +51,7 @@ function (Container $container)

$component->setRegistry($container->get(Registry::class));
$component->setMvcFactoryFactory($container->get(MVCFactoryFactoryInterface::class));
$component->setCategories($container->get(Categories::class));
$component->setCategoriesFactory($container->get(CategoriesFactoryInterface::class));

return $component;
}
Expand Down
8 changes: 4 additions & 4 deletions administrator/components/com_content/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
defined('_JEXEC') or die;

use Joomla\CMS\Association\AssociationExtensionInterface;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Categories\CategoriesFactoryInterface;
use Joomla\CMS\Dispatcher\DispatcherFactoryInterface;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\Service\Provider\CategoriesFactory;
use Joomla\CMS\Extension\Service\Provider\DispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactoryFactory;
use Joomla\CMS\HTML\Registry;
use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface;
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
use Joomla\Component\Content\Administrator\Helper\AssociationsHelper;
use Joomla\Component\Content\Site\Service\Category;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand All @@ -41,9 +41,9 @@
*/
public function register(Container $container)
{
$container->set(Categories::class, ['' => new Category]);
$container->set(AssociationExtensionInterface::class, new AssociationsHelper);

$container->registerServiceProvider(new CategoriesFactory(['table' => '#__content', 'extension' => 'com_content']));
$container->registerServiceProvider(new MVCFactoryFactory('\\Joomla\\Component\\Content'));
$container->registerServiceProvider(new DispatcherFactory('\\Joomla\\Component\\Content'));

Expand All @@ -55,7 +55,7 @@ function (Container $container)

$component->setRegistry($container->get(Registry::class));
$component->setMvcFactoryFactory($container->get(MVCFactoryFactoryInterface::class));
$component->setCategories($container->get(Categories::class));
$component->setCategoriesFactory($container->get(CategoriesFactoryInterface::class));
$component->setAssociationExtension($container->get(AssociationExtensionInterface::class));

return $component;
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_fields/Model/FieldModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ protected function preprocessForm(\JForm $form, $data, $group = 'content')
throw new SectionNotFoundException;
}

$cat = $componentObject->getCategories();
$cat = $componentObject->getCategory();

if ($cat->get('root')->hasChildren())
{
Expand Down
37 changes: 0 additions & 37 deletions components/com_banners/Service/Category.php

This file was deleted.

37 changes: 0 additions & 37 deletions components/com_content/Service/Category.php

This file was deleted.

19 changes: 8 additions & 11 deletions libraries/src/Categories/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @since 1.6
*/
class Categories
class Categories implements CategoryInterface
{
/**
* Array to hold the object instances
Expand Down Expand Up @@ -146,7 +146,7 @@ public static function getInstance($extension, $options = array())

if ($component instanceof CategoriesServiceInterface)
{
$categories = $component->getCategories($options, count($parts) > 1 ? $parts[1] : '');
$categories = $component->getCategory($options, count($parts) > 1 ? $parts[1] : '');
}
}
catch (SectionNotFoundException $e)
Expand All @@ -160,16 +160,18 @@ public static function getInstance($extension, $options = array())
}

/**
* Loads a specific category and all its children in a CategoryNode object
* Loads a specific category and all its children in a CategoryNode object.
*
* @param mixed $id an optional id integer or equal to 'root'
* @param boolean $forceload True to force the _load method to execute
*
* @return CategoryNode|null|boolean CategoryNode object or null if $id is not valid
* @return CategoryNode CategoryNode object
*
* @since 1.6
*
* @throws CategoryNotFoundException
*/
public function get($id = 'root', $forceload = false)
public function get($id = 'root', $forceload = false): CategoryNode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is a b/c break for people who are subclassing JCategories and overriding this method.

Having said that I doubt people are overriding this method so it's probably ok. any thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, lets revert it then.

{
if ($id !== 'root')
{
Expand All @@ -192,13 +194,8 @@ public function get($id = 'root', $forceload = false)
{
return $this->_nodes[$id];
}
// If we processed this $id already and it was not valid, then return null.
elseif (isset($this->_checkedCategories[$id]))
{
return;
}

return false;
throw new CategoryNotFoundException;
}

/**
Expand Down
61 changes: 61 additions & 0 deletions libraries/src/Categories/CategoriesFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\CMS\Categories;

defined('_JEXEC') or die;

/**
* Option based categories factory.
*
* @since __DEPLOY_VERSION__
*/
class CategoriesFactory implements CategoriesFactoryInterface
{
/**
* The options
*
* @var array
*
* @since __DEPLOY_VERSION__
*/
private $options;

/**
* CategoriesFactory constructor.
*
* @param array $options The options
*
* @since __DEPLOY_VERSION__
*/
public function __construct(array $options)
{
$this->options = $options;
}

/**
* Creates a category.
*
* @param string $section The section
*
* @return CategoryInterface
*
* @since __DEPLOY_VERSION__
*
* @throws SectionNotFoundException
*/
public function createCategory(string $section): CategoryInterface
{
if (!array_key_exists($section, $this->options))
{
throw new SectionNotFoundException;
}

return new Categories($this->options[$section]);
}
}
32 changes: 32 additions & 0 deletions libraries/src/Categories/CategoriesFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Categories;

defined('_JEXEC') or die;

/**
* Categories factory interface
*
* @since __DEPLOY_VERSION__
*/
interface CategoriesFactoryInterface
{
/**
* Creates a category.
*
* @param string $section The section
*
* @return CategoryInterface
*
* @since __DEPLOY_VERSION__
*
* @throws SectionNotFoundException
*/
public function createCategory(string $section): CategoryInterface;
}
6 changes: 3 additions & 3 deletions libraries/src/Categories/CategoriesServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ interface CategoriesServiceInterface
* @param array $options The options
* @param string $section The section
*
* @return Categories
* @return CategoryInterface
*
* @see Categories::setOptions()
* @see CategoryInterface::setOptions()
*
* @since 4.0.0
* @throws SectionNotFoundException
*/
public function getCategories(array $options = [], $section = ''): Categories;
public function getCategory(array $options = [], $section = ''): CategoryInterface;

/**
* Adds Count Items for Category Manager.
Expand Down
33 changes: 13 additions & 20 deletions libraries/src/Categories/CategoriesServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,47 @@
trait CategoriesServiceTrait
{
/**
* An array of categories.
* The categories factory
*
* @var Categories[]
* @var CategoriesFactoryInterface
*
* @since 4.0.0
*/
private $categories;
private $categoriesFactory;

/**
* Returns the category service.
*
* @param array $options The options
* @param string $section The section
*
* @return Categories
* @return CategoryInterface
*
* @see Categories::setOptions()
* @see CategoryInterface::setOptions()
*
* @since 4.0.0
* @throws SectionNotFoundException
*/
public function getCategories(array $options = [], $section = ''): Categories
public function getCategory(array $options = [], $section = ''): CategoryInterface
{
if (!array_key_exists($section, $this->categories))
{
throw new SectionNotFoundException;
}

$categories = clone $this->categories[$section];
$categories->setOptions($options);
$category = $this->categoriesFactory->createCategory($section);
$category->setOptions($options);

return $categories;
return $category;
}

/**
* An array of categories where the key is the name of the section.
* If the component has no sections then the array must have at least
* an empty key.
* Sets the internal categories factory.
*
* @param array $categories The categories
* @param CategoriesFactoryInterface $categoriesFactory The categories factory
*
* @return void
*
* @since 4.0.0
*/
public function setCategories(array $categories)
public function setCategoriesFactory(CategoriesFactoryInterface $categoriesFactory)
{
$this->categories = $categories;
$this->categoriesFactory = $categoriesFactory;
}

/**
Expand Down
Loading