merged branch robocoder/autoloader (PR #4168)

Commits
-------

b2afd9f use require instead of include
1ed8b72 Autoloader should not throw exception because PHP will continue to call other registered autoloaders.

Discussion
----------

[DoctrineBundle] Proxy autoloader should not throw exception

Also change 'require' to non-fatal '@include' in the event no file is generated.

---------------------------------------------------------------------------

by stof at 2012-05-01T06:13:34Z

The goal of the exception was to make debugging easier. And all Symfony2 autoloaders are using ``require``

---------------------------------------------------------------------------

by robocoder at 2012-05-01T16:09:04Z

I changed the include back to a require.

Whether or not the exception makes debugging easier is debatable.  But throwing an exception from an autoloader is both unconventional and unexpected given that (1) exceptions are propagated while php calls other registered autoloaders, and (2) php will throw a fatal error where the usage actually occurs if the class doesn't exist.

---------------------------------------------------------------------------

by fabpot at 2012-05-15T06:01:11Z

ping @beberlei

---------------------------------------------------------------------------

by beberlei at 2012-05-15T10:20:06Z

Its tricky, the message does try to give some additional information - but later autoloaders could handle this issue anyways. I guess the PR makes sense as users have absolutely no control over this autoloader and it should therefore behave less strictly.
This commit is contained in:
Fabien Potencier 2012-05-15 12:45:21 +02:00
commit ec45169f4f

View File

@ -79,13 +79,11 @@ class DoctrineBundle extends Bundle
}
clearstatcache($file);
if (!file_exists($file)) {
throw new \RuntimeException(sprintf('The proxy file "%s" does not exist. If you still have objects serialized in the session, you need to clear the session manually.', $file));
}
}
require $file;
if (file_exists($file)) {
require $file;
}
}
};
spl_autoload_register($this->autoloader);