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

2.7.0. Xpdo:: GetService (). Deciding how to use the namespace PHP for classes while respecting the PSR-4 standard #154

Open
ALexeyP0708 opened this Issue Jan 13, 2019 · 2 comments

Comments

Projects
None yet
1 participant
@ALexeyP0708
Copy link

ALexeyP0708 commented Jan 13, 2019

I understand, it is foolish to offer without detailed tests.
I will explain my situation first.
I am developing in OS "Windows".
It is known that in 'Windows', when writing paths, slash (/) and backslash (\) have the same meaning.
When writing my classes, I used a namespace.

<? php
namespace MyFirm \ Model \ Product;
class GoodClass
{
}

created object service

$ path = $modx-> getOption ('core_components', null, $modx-> getOption ('core_path'). 'components /');
#obj=$modx-> getService ('modGoodClass', 'MyFirm \\ Model \\ Product \\ GoodClass', $path);

And it works well in Windows.

Then I wondered if it was working by chance, and in Linux everything would break.

because Linux does not accept a backslash (\) as a path delimiter.
Checked MODX on Linux hosting.
There really is a problem.
Looking at the xPDO code, a solution was found.
modx 2.7.0
File: www \ core \ xpdo \ xpdo.class.php
Class: xPDO
Method: _loadClass
replace line: 653

$fqcn = str_replace ('.', '/', $fqn). '.class.php';

to

$fqcn = str_replace (['.','\\'], '/', $fqn). '.class.php';

And
replace line 662:

$mapfile = strtr ($fqn, '.', '/'). '.map.inc.php';  

to

$mapfile = str_replace (['.', '\\'], '/', $fqn). '.map.inc.php';

Changes checked on linux hosting. Everything is working.

These changes will not affect the code as a whole.
They will only conduct a more valid path validation.
And it will be possible to use the class namespace under the PSR-4 standard.

I agree that it is necessary to take a set of measures to implement the full functionality of the PHP namespace.
But this is sometimes enough to enable app development for MODX 2.7 using the PHP namespace.

@ALexeyP0708

This comment has been minimized.

Copy link
Author

ALexeyP0708 commented Jan 13, 2019

Please make such changes. Then I will have the opportunity to publish my work applications, and bring fresh solutions to MODX, which may appeal to a large circle of people and support your project.

@ALexeyP0708

This comment has been minimized.

Copy link
Author

ALexeyP0708 commented Jan 13, 2019

Actual for xPDO 3

@ALexeyP0708 ALexeyP0708 changed the title 2.7.0. Xpdo:: GetService (). Deciding how to use the namespace for classes while respecting the PSR-4 standard 2.7.0. Xpdo:: GetService (). Deciding how to use the namespace PHP for classes while respecting the PSR-4 standard Jan 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment