Right, I knew I would forget this.
We register 2 PSR-4 roots for each app:
1. OCA\MyApp for apps/myapp/lib/
2. OCA\MyApp\Tests for apps/myapp/tests/
the 2nd root is only registered when the PHPUNIT_RUN constant is defined:
https://github.com/owncloud/announcementcenter/blob/3a75e64e2664753eee3d0500ed4da541ef995004/tests/bootstrap.php#L22-L24
This prevents test code from being loaded/executed and doing harm on
live instances, since they
are only ever loaded when running tests.
What I also forgot to mention was, that the old autoloading is still in
place,
so 9.0 apps will continue working for a while longer ;)
cheers nickvergessen
Am 03.05.2016 um 10:29 schrieb Vincent Petry:
Does it also affect test classes in some way ? (the ones stored under
MyApp/test)
Cheers,
Vincent
On 03.05.2016 10:23, Joas Schilling wrote:
Hi there,
today we merged a PR that also allows apps to use PSR-4 compatible
autoloading standard.
If you don't know what PSR-4 is, it means that files and folders have
the exact same name
and casing, the class or namespace has.
Let me give you an example:
* ownCloud <9.1: OCA\MyApp\Namespace\ClassName used to lie in
apps/myapp/namespace/classname.php or
apps/myapp/lib/namespace/classname.php
* PSR-4: OCA\MyApp\Namespace\ClassName lies in
apps/myapp/lib/Namespace/ClassName.php
By default ownCloud just uppercases the first character of your app ID
to guess the namespace.
If that is not your namespace (e.g. because you use MyApp instead of
Myapp), you can specify that in your info.xml:
https://github.com/owncloud/announcementcenter/blob/3a75e64e2664753eee3d0500ed4da541ef995004/appinfo/info.xml#L9
You should only put namespaced classes into the lib/ folder. Any
non-class code should remain outside
of that directory. E.g. app.php, update.php, install.php, route.php
from the appinfo/ folder can stay there
https://github.com/owncloud/announcementcenter/tree/3a75e64e2664753eee3d0500ed4da541ef995004/appinfo
while all classes are moved to lib/ using camelcases
https://github.com/owncloud/announcementcenter/tree/3a75e64e2664753eee3d0500ed4da541ef995004/lib
The biggest advantage of the PSR-4 change are:
* we can stop maintaining our own code for loading files
* we can use speed improvements from composers autoloading by
compiling a list of classes on release
* we follow a standard and make it easier for people to get in
cheers nickvergessen
Am 02.05.2016 um 07:57 schrieb Roeland Douma:
Howdy!
We are slowly moving the classes in core to the PSR-4 [1] naming
standard.
This allows for easier lookup and using the well known composer
autoloader.
At the moment we do not yet support PSR-4 in our apps. But we are
thinking about
how to do this. Of course we will still support the current
autoloader as well.
There should not be any breakage for app developers. As long as you
spell the namespaces
and classes correct :)
Cheers,
--Roeland
[1] http://www.php-fig.org/psr/psr-4/
_______________________________________________
Devel mailing list
Devel@owncloud.org
http://mailman.owncloud.org/mailman/listinfo/devel
_______________________________________________
Devel mailing list
Devel@owncloud.org
http://mailman.owncloud.org/mailman/listinfo/devel
_______________________________________________
Devel mailing list
Devel@owncloud.org
http://mailman.owncloud.org/mailman/listinfo/devel
_______________________________________________
Devel mailing list
Devel@owncloud.org
http://mailman.owncloud.org/mailman/listinfo/devel