Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Get the MVCFactory trough the ComponentInterface #19835

Merged
merged 21 commits into from
Mar 9, 2018

Conversation

laoneo
Copy link
Member

@laoneo laoneo commented Mar 5, 2018

Pull Request for Issue #17705.

Summary of Changes

A common use case is that extensions need models from a component. There is no standard way to do that. With this pr, the ComponentInterface gets a new function to get it's MVCFactory. Internally this is provided trough a new factory in the service provider.

Testing Instructions

  • Create a latest articles module on the front end
  • Open the front end

Expected result

Latest module shows the latest articles.

Actual result

Latest module shows the latest articles.

…vcfactory/service

# Conflicts:
#	administrator/components/com_content/services/provider.php
#	libraries/src/Extension/Component.php
#	libraries/src/Extension/ComponentInterface.php
#	libraries/src/Extension/LegacyComponent.php
#	libraries/src/Extension/Service/Provider/Component.php
$this->input = $input ?: $app->input;
$this->app = $app;
$this->input = $input ?: $app->input;
$this->mvcFactory = $mvcFactory;
Copy link
Contributor

Choose a reason for hiding this comment

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

If the plan is to make this null - there needs to be a default. Else this needs to be first parameter and compulsory

Copy link
Member Author

Choose a reason for hiding this comment

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

Made it required in the last commit, together with the input.

@@ -205,8 +216,22 @@ public function getController(string $name, string $client = '', array $config =
throw new \InvalidArgumentException(\JText::sprintf('JLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS', $controllerClass));
}

$controller = new $controllerClass($config, new MVCFactory($namespace, $this->app), $this->app, $this->input);
$factory = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't required with your if/else. Also just to be clear - which one are you planning on keeping and which to be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed it as the injected factory is required now.

// Create mock of abstract class JModelForm to test concrete methods in there
$this->object = $this->getMockBuilder('JModelForm')
->getMockForAbstractClass();
$mockApp = $this->getMockCmsApp();
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was too lazy to mock the factory 🙊 . Changed that.

*
* @since __DEPLOY_VERSION__
*/
private $mvcFactory;
Copy link
Contributor

Choose a reason for hiding this comment

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

$mvcFactoryFactory please - I got really confused on us calling createFactory on this thing further down until i carefully re-read the doc blocks here


$factory = new MVCFactory($ns, \JFactory::getApplication());
}
$factory = Factory::getApplication()->bootComponent($this->option)->createMVCFactory(Factory::getApplication());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think $this->option is namespace aware from a quick look at the code. This is probably going to give rubbish names (and also probably won't be prefixed with com_)

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -33,8 +35,10 @@ class JModelItemTest extends TestCase
public function setUp()
{
// Create mock of abstract class JModelForm to test concrete methods in there
$this->object = $this->getMockBuilder('JModelItem')
->getMockForAbstractClass();
$this->object = $this->getMockForAbstractClass(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the builder still here please? PHPUnit is slowly deprecating all other approaches so I'd rather stay ahead of the curve here

@@ -35,8 +37,10 @@ public function setUp()
$this->saveFactoryState();

// Create mock of abstract class JModelForm to test concrete methods in there
$this->object = $this->getMockBuilder('JModelForm')
->getMockForAbstractClass();
$this->object = $this->getMockForAbstractClass(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - keep the builder just use the right methods on it please

@@ -33,8 +35,10 @@ class JModelAdminTest extends TestCase
public function setUp()
{
// Create mock of abstract class JModelAdmin to test concrete methods in there
$this->object = $this->getMockBuilder('JModelAdmin')
->getMockForAbstractClass();
$this->object = $this->getMockForAbstractClass(
Copy link
Contributor

Choose a reason for hiding this comment

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

And here :)

@@ -12,6 +12,6 @@
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Module\ArticlesLatest\Site\Helper\ArticlesLatestHelper;

$list = ArticlesLatestHelper::getList($params);
$list = ArticlesLatestHelper::getList($params, $app->bootComponent('com_content')->createMVCFactory($app)->createModel('Articles', 'Site'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't we going to end up with issues here because we're no longer able to insert the array('ignore_request' => true) param here - I think on list views that will mean this module breaks

@wilsonge wilsonge merged commit 0a0c86f into joomla:4.0-dev Mar 9, 2018
@wilsonge wilsonge deleted the j4/mvcfactory/service branch March 9, 2018 10:34
@wilsonge wilsonge added this to the Joomla 4.0 milestone Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants