Skip to content

[ClassLoader] A PSR-4 compatible class loader #10100

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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CS fixes
  • Loading branch information
derrabus committed Jan 21, 2014
commit 9549cf150465ab38c14b89a79ec1e572798c645c
12 changes: 7 additions & 5 deletions src/Symfony/Component/ClassLoader/Psr4ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Symfony\Component\ClassLoader;

/**
* ClassLoader implements an PSR-4 class loader
* A PSR-4 compatible class loader.
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md
* See http://www.php-fig.org/psr/psr-4/
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn’t this be using @see ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, why not.

*
* @author Alexander M. Turek <me@derrabus.de>
*/
Expand All @@ -31,13 +31,14 @@ class Psr4ClassLoader
*/
public function addPrefix($prefix, $baseDir)
{
$prefix = trim($prefix, '\\') . '\\';
$prefix = trim($prefix, '\\').'\\';
$baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$this->prefixes[] = array($prefix, $baseDir);
}

/**
* @param string $class
*
* @return string|null
*/
public function findFile($class)
Expand All @@ -46,7 +47,7 @@ public function findFile($class)

foreach ($this->prefixes as $current) {
list($currentPrefix, $currentBaseDir) = $current;
if (strpos($class, $currentPrefix) === 0) {
if (0 === strpos($class, $currentPrefix)) {
$classWithoutPrefix = substr($class, strlen($currentPrefix));
$file = $currentBaseDir . str_replace('\\', DIRECTORY_SEPARATOR, $classWithoutPrefix) . '.php';
if (file_exists($file)) {
Expand All @@ -60,12 +61,13 @@ public function findFile($class)

/**
* @param string $class
*
* @return bool
Copy link
Member

Choose a reason for hiding this comment

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

add an empty comment line between @param and @return

Copy link
Contributor

Choose a reason for hiding this comment

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

Symfony CS uses Boolean (with the first letter uppercase)

*/
public function loadClass($class)
{
$file = $this->findFile($class);
if ($file !== null) {
if (null !== $file) {
require $file;

return true;
Expand Down