8000 Update docs for autoloader removal · zendframework/zend-modulemanager@5186cea · GitHub
[go: up one dir, main page]

Skip to content 8000
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 5186cea

Browse files
committed
Update docs for autoloader removal
1 parent 9db9907 commit 5186cea

File tree

7 files changed

+105
-223
lines changed

7 files changed

+105
-223
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ architecture for PHP applcations.
1414

1515

1616
- File issues at https://github.com/zendframework/zend-modulemanager/issues
17-
- Documentation is at http://framework.zend.com/manual/current/en/index.html#zend-modulemanager
17+
- Documentation is at https://docs.zendframework.com/zend-modulemanager/

docs/book/intro.md

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ CSS, and JavaScript. The possibilities are endless.
1515
1616
The module system is made up of the following:
1717

18-
- [The Module Autoloader](https://docs.zendframework.com/zend-loader/module-autoloader/) -
19-
`Zend\Loader\ModuleAutoloader` is a specialized autoloader that is responsible
20-
for the locating and loading of modules' `Module` classes from a variety of
21-
sources.
2218
- [The Module Manager](module-manager.md) - `Zend\ModuleManager\ModuleManager`
2319
takes an array of module names and fires a sequence of events for each one,
2420
allowing the behavior of the module system to be defined entirely by the
@@ -34,47 +30,31 @@ The module system is made up of the following:
3430
> [PHP namespace](http://php.net/namespaces), and must follow all of the same
3531
> rules for naming.
3632
37-
The recommended structure for an MVC-oriented ZF2 module is as follows:
33+
The recommended structure for a zend-mvc oriented module is as follows:
3834

3935
```text
4036
module_root/
41-
Module.php
42-
autoload_classmap.php
43-
autoload_function.php
44-
autoload_register.php
4537
config/
4638
module.config.php
4739
public/
4840
images/
4941
css/
5042
js/
5143
src/
52-
<module_namespace>/
53-
<code files>
44+
Module.php
45+
<code files as per PSR-4>
5446
test/
55-
phpunit.xml
56-
bootstrap.php
57-
<module_namespace>/
58-
<test code files>
47+
<test code files>
5948
view/
6049
<dir-named-after-module-namespace>/
6150
<dir-named-after-a-controller>/
6251
<.phtml files>
52+
phpunit.xml.dist
53+
composer.json
6354
```
6455

65-
## The autoload\_\*.php Files
56+
## Autoloading
6657

67-
The three `autoload_*.php` files are not required, but recommended. They provide the following:
68-
69-
- `autoload_classmap.php` should return an array classmap of class name/filename
70-
pairs (with the filenames resolved via the `__DIR__` magic constant).
71-
- `autoload_function.php` should return a PHP callback that can be passed to
72-
`spl_autoload_register()`. Typically, this callback should utilize the map
73-
returned by `autoload_classmap.php`.
74-
- `autoload_register.php` should register a PHP callback (typically that
75-
returned by `autoload_function.php` with `spl_autoload_register()`.
76-
77-
The purpose of these three files is to provide reasonable default mechanisms for
78-
autoloading the classes contained in the module, thus providing a trivial way to
79-
consume the module without requiring zend-modulemanager` (e.g., for use outside
80-
a ZF2 application).
58+
Since version 3, zend-modulemanager does not provide own autoloading mechanisms
59+
and instead relies on [Composer dependency manager](https://getcomposer.org/)
60+
to provide autoloading.

docs/book/migration/to-v3-0.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Upgrading to 3.0
2+
3+
## Module autoloading
4+
5+
zend-modulemanager originates from before the Composer was created, where each
6+
framework had to provide its own autoloading implementation.
7+
Since then Composer became the de-facto standard in managing dependencies and
8+
autoloading for the php projects.
9+
In light of that, zend-servicemanager removes ModuleLoader and autoload
10+
providers support in version 3.0 in favor of
11+
[Composer dependency manager](https://getcomposer.org/).
12+
13+
### Application local modules
14+
15+
Autoloading rules for application local modules should now be defined in
16+
application's composer.json
17+
18+
Before:
19+
```php
20+
namespace Application;
21+
22+
class Module
23+
{
24+
public function getAutoloaderConfig()
25+
{
26+
return array(
27+
'Zend\Loader\StandardAutoloader' => array(
28+
'namespaces' => array(
29+
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
30+
),
31+
),
32+
);
33+
}
34+
}
35+
```
36+
and after:
37+
```json
38+
{
39+
"name": "zendframework/skeleton-application",
40+
"description": "Skeleton Application for Zend Framework zend-mvc applications",
41+
"type": "project",
42+
...
43+
"autoload": {
44+
"psr-4": {
45+
"Application\\": "module/Application/src/"
46+
}
47+
},
48+
"autoload-dev": {
49+
"psr-4": {
50+
"ApplicationTest\\": "module/Application/test/"
51+
}
52+
}
53+
}
54+
```
55+
56+
[zf-composer-autoloading](https://github.com/zfcampus/zf-composer-autoloading)
57+
provides a handy tool to easily add and remove autoloading rules for local modules to
58+
application's composer.json
59+
60+
After autoloading rules were updated, composer will need to update autoloader:
61+
62+
```console
63+
$ composer dump-autoload
64+
```
65+
66+
### Composer installed modules
67+
68+
For composer installed modules, autoloading rules will be automatically picked
69+
by composer from the module's composer.json and no extra effort is needed:
70+
```json
71+
{
72+
"name": "acme/my-module",
73+
"description": "Module for use with zend-mvc applications.",
74+
"type": "library",
75+
"require": {
76+
"php": "^7.1"
77+
},
78+
"autoload": {
79+
"psr-4": {
80+
"Acme\\MyModule\\": "src/"
81+
}
82+
}
83+
}
84+
```

docs/book/module-autoloader.md

Lines changed: 0 additions & 161 deletions
This file was deleted.

docs/book/module-class.md

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ of `{moduleName}\Module` for each enabled module.
99

1010
As an example, provided the module name "MyModule",
1111
`Zend\ModuleManager\Listener\ModuleResolverListener` will expect the class
12-
`MyModule\Module` to be available. It relies on a registered autoloader
13-
(typically `Zend\Loader\ModuleAutoloader`) to find and include the
14-
`MyModule\Module` class if it isn't already available.
12+
`MyModule\Module` to be available.
1513

1614
> ### Module classes
1715
>
@@ -26,7 +24,8 @@ something like this:
2624

2725
```text
2826
MyModule/
29-
Module.php
27+
src/
28+
Module.php
3029
```
3130

3231
Within `Module.php`, you define your `MyModule\Module` class:
@@ -46,7 +45,7 @@ module system!
4645
This `Module` class serves as the single entry point for `ModuleManager`
4746
listeners to interact with a module. From within this class, modules can
4847
override or provide additional application configuration, perform initialization
49-
tasks such as registering autoloader(s), services and event listeners, declaring
48+
tasks such as registering services and event listeners, declaring
5049
dependencies, and much more.
5150

5251
## A Typical Module Class
@@ -58,29 +57,16 @@ namespace MyModule;
5857

5958
class Module
6059
{
61-
public function getAutoloaderConfig()
62-
{
63-
return [
64-
'Zend\Loader\ClassMapAutoloader' => [
65-
__DIR__ . '/autoload_classmap.php',
66-
],
67-
'Zend\Loader\StandardAutoloader' => [
68-
'namespaces' => [
69-
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
70-
],
71-
],
72-
];
73-
}
74-
7560
public function getConfig()
7661
{
7762
return include __DIR__ . '/config/module.config.php';
7863
}
7964
}
8065
```
8166

82-
For a list of the provided module manager listeners and the interfaces and methods that `Module`
83-
classes may implement in order to interact with the module manager and application, see the
67+
For a list of the provided module manager listeners and the interfaces and
68+
methods that `Module` classes may implement in order to interact with the
69+
module manager and application, see the
8470
[module manager listeners](module-manager.md#module-manager-listeners) and the
8571
[module mananger events](module-manager.md#module-manager-events) documentation.
8672

0 commit comments

Comments
 (0)
0