-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
…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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
e72be05
to
eaa4c43
Compare
…ctory/service # Conflicts: # libraries/src/Dispatcher/DispatcherFactory.php
// Create mock of abstract class JModelForm to test concrete methods in there | ||
$this->object = $this->getMockBuilder('JModelForm') | ||
->getMockForAbstractClass(); | ||
$mockApp = $this->getMockCmsApp(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
db8f66f
to
a5bdbb3
Compare
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
private $mvcFactory; |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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_
)
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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')); |
There was a problem hiding this comment.
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
0a81c4f
to
6580ab7
Compare
6580ab7
to
873533d
Compare
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'sMVCFactory
. Internally this is provided trough a new factory in the service provider.Testing Instructions
Expected result
Latest module shows the latest articles.
Actual result
Latest module shows the latest articles.