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

Already on GitHub? Sign in to your account

Use PSR-4 everywhere instead of PSR-0 #11199

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
7 participants
Member

Seldaek commented Jun 22, 2014

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #11189
License MIT

Includes and replaces #11190 + psr-4 support for ClassNotFoundFatalErrorHandler (not sure if this is considered as a new feature, it's kinda trivial)

Member

Seldaek commented Jun 22, 2014

The travis failure is now json-related in the latest 5.4/5.5/5.6 releases. Should not block this PR.

@stof stof and 1 other commented on an outdated diff Jun 22, 2014

.../FatalErrorHandler/ClassNotFoundFatalErrorHandler.php
@@ -116,6 +116,11 @@ private function getClassCandidates($class)
$classes = array_merge($classes, $this->findClassInPath($path, $class));
}
}
+ foreach ($function[0]->getPrefixesPsr4() as $prefix => $paths) {
@stof

stof Jun 22, 2014

Member

getPrefixesPsr4 only exists in the Composer ClassLoader, not in the Symfony one

@Seldaek

Seldaek Jun 22, 2014

Member

Oh right I missed the second part of the if above, will fix :)

@stof stof and 1 other commented on an outdated diff Jun 22, 2014

.../FatalErrorHandler/ClassNotFoundFatalErrorHandler.php
{
- $namespacedClass = str_replace(array($path.DIRECTORY_SEPARATOR, '.php', '/'), array('', '', '\\'), $file);
+ $namespacedClass = $prefix . str_replace(array($path.DIRECTORY_SEPARATOR, '.php', '/'), array('', '', '\\'), $file);
$pearClass = str_replace('\\', '_', $namespacedClass);
@stof

stof Jun 22, 2014

Member

this transformation should not be applied for PSR-4 autoloaders

@Seldaek

Seldaek Jun 22, 2014

Member

It doesn't really matter I guess but yeah to be 100% correct we can skip it.

@stof

stof Jun 22, 2014

Member

well, it can lead to misleading error messages

@Tobion Tobion and 1 other commented on an outdated diff Jun 22, 2014

.../FatalErrorHandler/ClassNotFoundFatalErrorHandler.php
@@ -148,18 +156,19 @@ private function findClassInPath($path, $class)
/**
* @param string $path
* @param string $file
+ * @param string $psr4Prefix
@Tobion

Tobion Jun 22, 2014

Member

string|null

@Taluu Taluu commented on the diff Jun 22, 2014

...alErrorHandler/ClassNotFoundFatalErrorHandlerTest.php
class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase
{
+ public static function setUpBeforeClass()
+ {
+ foreach (spl_autoload_functions() as $function) {
+ if (!is_array($function)) {
+ continue;
+ }
+
+ // get class loaders wrapped by DebugClassLoader
+ if ($function[0] instanceof DebugClassLoader) {
+ $function = $function[0]->getClassLoader();
+ }
+
+ if ($function[0] instanceof ComposerClassLoader) {
+ $function[0]->add('Symfony\Component\Debug\Tests\Fixtures', dirname(dirname(dirname(dirname(dirname(__DIR__))))));
@Taluu

Taluu Jun 22, 2014

Contributor

Out of curiosity : Why so many dirnames, instead of ../s ?

@Seldaek

Seldaek Jun 22, 2014

Member

Just to give it an absolute path directly, but yeah maybe this isn't so
nice at this point :)

@apfelbox

apfelbox Jun 22, 2014

Contributor

You could use realpath(__DIR__ . "/../../../../../").

@Seldaek

Seldaek Jun 23, 2014

Member

Yes I could but is there really a difference? Either way is fairly unreadable junk that forces you to count dir levels.

@alex-moreno

alex-moreno Jun 27, 2014

is not more readable using the standard unix '../' instead of dirname? Just asking.

Member

Tobion commented Jun 27, 2014

👍

Member

stof commented Jun 27, 2014

👍

Member

Tobion commented Sep 24, 2014

Needs to be updated for VarDumper component and DebugBundle.

Contributor

derrabus commented Nov 11, 2014

Now that PSR-0 is considered deprecated, it's maybe a good time to perform the switch. What do you think?

Member

Seldaek commented Nov 11, 2014

If it's good for everyone I guess I'll update it for the new components and it can go in 2.7 and up.

Contributor

derrabus commented Nov 11, 2014

👍

Tobion and others added some commits Jun 20, 2014

@Tobion @Seldaek Tobion Use PSR-4 everywhere instead of PSR-0 739a123
@Seldaek Seldaek Add psr-4 support to the ClassNotFoundFatalErrorHandler ff3ec56
@Seldaek Seldaek Add two more components to psr-4
7cdc049
Member

Seldaek commented Nov 12, 2014

Closing in favor of #12466 against 2.7

@Seldaek Seldaek closed this Nov 12, 2014

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