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

External dependency injection system #15266

Merged
merged 2 commits into from May 19, 2019
Merged

External dependency injection system #15266

merged 2 commits into from May 19, 2019

Conversation

Tithugues
Copy link
Contributor

@Tithugues Tithugues commented May 11, 2019

Description

What do you think about this kind of DI system please?

The current system seems to be restrictive: the definition of services should be done in PHP (which doesn't seem very readable for me), also the parameters can't be defined at the beginning (only when getting the object).

With this system, we defined the template class and it can be passed everywhere quite easily, and this may be done for other classes. Also in a second step, this would enforce the principle to use injection instead of building objects in other objects. (I would love to split the current Response class in HtmlResponse and AjaxResponse classes with a common ResponseInterface.)

Fixes #

Before submitting pull request, please review the following checklist:

  • Make sure you have read our CONTRIBUTING.md document.
  • Make sure you are making a pull request against the correct branch. For example, for bug fixes in a released version use the corresponding QA branch and for new features use the master branch. If you have a doubt, you can ask as a comment in the bug report or on the mailing list.
  • Every commit has proper Signed-off-by line as described in our DCO. This ensures that the work you're submitting is your own creation.
  • Every commit has a descriptive commit message.
  • Every commit is needed on its own, if you have just minor fixes to previous commits, you can squash them.
  • Any new functionality is covered by tests.

@MauricioFauth
Copy link
Member

I would love to split the current Response class in HtmlResponse and AjaxResponse classes with a common ResponseInterface.

Great idea. As I said in #15248 (comment), I also want to improve how we handle request and response with a HTTP library.

@Tithugues Tithugues marked this pull request as ready for review May 12, 2019 13:01
@Tithugues
Copy link
Contributor Author

If you find any bug to fix or any code to improve, please tell me, I'll do my best to do it.

@Tithugues
Copy link
Contributor Author

Hi,
Do you please know how to get rid of the errors thrown in https://travis-ci.org/phpmyadmin/phpmyadmin/jobs/531442853 ?

Undefined variable: $containerBuilder

This variable is defined in common.inc.php which is called at the beginning of all files which have the error. 😕

Thank you.

@MauricioFauth
Copy link
Member

This variable is defined in common.inc.php which is called at the beginning of all files which have the error. 😕

The static analyzer doesn't know about variables defined in another files. We have been ignoring these errors.

- '#Undefined variable: \$(cfg|db|table|url_query|text_dir|server|pmaThemeImage|action|sql_query|lang|export_type|err_url|collation_connection|filename_template|transform_key|cn|goto|partitionDetails|token_mismatch|auth_plugin|username|hostname|display_query|where_clause)#'#Others

@MauricioFauth
Copy link
Member

Some ways to solve this would be to get the variable some other way, or if it is a global variable, declare it in the file.

@Tithugues
Copy link
Contributor Author

Some ways to solve this would be to get the variable some other way, or if it is a global variable, declare it in the file.

Yes, I know this is done for other variables. But doing this would encourage use of the container through the global variable in many places, whereas the idea would rather be to provide the data as an input.
So if this is OK for you, I would prefer to fill the phpstan.neon.dist file.

@MauricioFauth
Copy link
Member

So if this is OK for you, I would prefer to fill the phpstan.neon.dist file.

No problem.

@Tithugues
Copy link
Contributor Author

Please don't merge it for now, I've an error after the creation of a table.

@Tithugues
Copy link
Contributor Author

Please don't merge it for now, I've an error after the creation of a table.

Please ignore my previous message, it was on the other PR I'm working on.

ajax.php Outdated
$GLOBALS['PMA_Config']
);
/** @var AjaxController $controller */
$controller = $containerBuilder->get('ajax_controller');
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about using AjaxController::class instead of 'ajax_controller'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is OK for me. I'll rename the controller services with the class name of the controllers.

@codecov
Copy link

codecov bot commented May 17, 2019

Codecov Report

Merging #15266 into master will decrease coverage by 0.02%.
The diff coverage is 10.57%.

@@             Coverage Diff              @@
##             master   #15266      +/-   ##
============================================
- Coverage     52.82%    52.8%   -0.03%     
  Complexity    14059    14059              
============================================
  Files           484      484              
  Lines         62163    62198      +35     
============================================
+ Hits          32840    32841       +1     
- Misses        29323    29357      +34

Copy link
Member

@williamdes williamdes left a comment

Choose a reason for hiding this comment

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

Good work!

db_events.php Outdated Show resolved Hide resolved
db_multi_table_query.php Outdated Show resolved Hide resolved
db_central_columns.php Outdated Show resolved Hide resolved
db_central_columns.php Outdated Show resolved Hide resolved
db_central_columns.php Outdated Show resolved Hide resolved

if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}

require_once ROOT_PATH . 'libraries/common.inc.php';

$response = $containerBuilder->get('response', ContainerInterface::NULL_ON_INVALID_REFERENCE) ?? Response::getInstance();
Copy link
Member

Choose a reason for hiding this comment

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

Can you use ::class ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I defined response as a service in the other PR, I would like to do it in the other one if this is OK for you.

Copy link
Member

@MauricioFauth MauricioFauth left a comment

Choose a reason for hiding this comment

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

Excellent work!

@MauricioFauth
Copy link
Member

@Tithugues Do you think it's now possible to remove our custom DIC (PhpMyAdmin\Di\Container)?

@Tithugues
Copy link
Contributor Author

Tithugues commented May 18, 2019

@Tithugues Do you think it's now possible to remove our custom DIC (PhpMyAdmin\Di\Container)?

Not yet. But I should confess this is one on my aims…
I think we should go further before this. Your current Container has one advantage that I would like not to implement with the new one: getInstance. Thanks to this, you can retrieve every service everywhere. But if we achieve to inject dependencies instead of creating objects, we should be able to remove the current container, I think.
(This is a bit confusing because I think that I'm currently doing 2 things at the same time: defining the services externally thanks to the Symfony DI + injecting dependencies.)
The first things I'm currently trying to get rid of the current container are:

  • registering every old services as a service with the new container;
  • replacing as much as possible the get of services by a get through the new container.

When all the get will be replaced, it won't be fully finished, because there is also some magic in your container that loads the parameters regarding name and/or type (don't really remember, I had a quick look) of registered services.

db_datadict.php Outdated Show resolved Hide resolved
Copy link
Member

@williamdes williamdes left a comment

Choose a reason for hiding this comment

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

💯

@Tithugues
Copy link
Contributor Author

Do you want me to squash the commits before merging the branch?

@MauricioFauth
Copy link
Member

You can do it, if you want.

Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
@Tithugues
Copy link
Contributor Author

Done.

@MauricioFauth
Copy link
Member

There are a few Selenium errors. You can open the link in the log to see the video of the test.

https://travis-ci.org/phpmyadmin/phpmyadmin/jobs/534311833#L494

Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
@Tithugues
Copy link
Contributor Author

There are a few Selenium errors. You can open the link in the log to see the video of the test.

https://travis-ci.org/phpmyadmin/phpmyadmin/jobs/534311833#L494

Thanks, I did some fixes. I'll wait for Selenium feedback.

@MauricioFauth MauricioFauth merged commit 1a846ba into phpmyadmin:master May 19, 2019
@MauricioFauth
Copy link
Member

Excellent work! Thank you for your contribution.

@MauricioFauth MauricioFauth self-assigned this May 19, 2019
@MauricioFauth MauricioFauth added this to the 5.0.0 milestone May 19, 2019
@Tithugues Tithugues deleted the feature/DI branch May 19, 2019 15:56
MauricioFauth added a commit that referenced this pull request Jun 1, 2019
External dependency injection system

[ci skip]

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
murex971 pushed a commit to murex971/phpmyadmin that referenced this pull request Jun 2, 2019
External dependency injection system

[ci skip]

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Signed-off-by: Nupur Agrawal <nupur202000@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants