Skip to content

Commit f308d8b

Browse files
samsonasikweierophinney
authored andcommitted
Fixes #4 : Drop laminas loader, module loader and autoloader provider features
Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
1 parent 4fd075f commit f308d8b

22 files changed

+110
-1125
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@
3333
"laminas/laminas-coding-standard": "~1.0.0",
3434
"laminas/laminas-console": "^2.8",
3535
"laminas/laminas-di": "^2.6.1",
36-
"laminas/laminas-loader": "^2.6.1",
3736
"laminas/laminas-mvc": "^3.1.1",
3837
"laminas/laminas-servicemanager": "^3.4.1",
3938
"phpunit/phpunit": "^9.3.7"
4039
},
4140
"suggest": {
4241
"laminas/laminas-console": "Laminas\\Console component",
43-
"laminas/laminas-loader": "Laminas\\Loader component if you are not using Composer autoloading for your modules",
4442
"laminas/laminas-mvc": "Laminas\\Mvc component",
4543
"laminas/laminas-servicemanager": "Laminas\\ServiceManager component"
4644
},
@@ -51,8 +49,10 @@
5149
},
5250
"autoload-dev": {
5351
"files": [
54-
"test/autoload.php",
55-
"test/TestAsset/ModuleAsClass.php"
52+
"test/autoload.php"
53+
],
54+
"classmap": [
55+
"test/TestAsset/"
5656
],
5757
"psr-4": {
5858
"ListenerTestModule\\": "test/TestAsset/ListenerTestModule/",

docs/book/intro.md

Lines changed: 9 additions & 29 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.laminas.dev/laminas-loader/module-autoloader/) -
19-
`Laminas\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) - `Laminas\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
@@ -38,43 +34,27 @@ The recommended structure for an MVC-oriented Laminas 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 laminas-modulemanager` (e.g., for use outside
80-
a Laminas application).
58+
Since version 3, laminas-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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Upgrading to 3.0
2+
3+
## Module autoloading
4+
5+
laminas-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, laminas-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+
20+
```php
21+
namespace Application;
22+
23+
class Module
24+
{
25+
public function getAutoloaderConfig()
26+
{
27+
return [
28+
'Laminas\Loader\StandardAutoloader' => [
29+
'namespaces' => [
30+
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
31+
],
32+
],
33+
];
34+
}
35+
}
36+
```
37+
38+
and after:
39+
40+
```json
41+
{
42+
"name": "laminas/laminas-mvc-skeleton",
43+
"description": "Laminas MVC Skeleton Application",
44+
"type": "project",
45+
...
46+
"autoload": {
47+
"psr-4": {
48+
"Application\\": "module/Application/src/"
49+
}
50+
},
51+
"autoload-dev": {
52+
"psr-4": {
53+
"ApplicationTest\\": "module/Application/test/"
54+
}
55+
}
56+
}
57+
```
58+
59+
[laminas-composer-autoloading](https://github.com/laminas/laminas-composer-autoloading)
60+
provides a handy tool to easily add and remove autoloading rules for local modules to
61+
application's composer.json
62+
63+
After autoloading rules were updated, composer will need to update autoloader:
64+
65+
```console
66+
$ composer dump-autoload
67+
```
68+
69+
### Composer installed modules
70+
71+
For composer installed modules, autoloading rules will be automatically picked
72+
by composer from the module's composer.json and no extra effort is needed:
73+
```json
74+
{
75+
"name": "acme/my-module",
76+
"description": "Module for use with laminas-mvc applications.",
77+
"type": "library",
78+
"require": {
79+
"php": "^7.1"
80+
},
81+
"autoload": {
82+
"psr-4": {
83+
"Acme\\MyModule\\": "src/"
84+
}
85+
}
86+
}
87+
```

docs/book/module-autoloader.md

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

0 commit comments

Comments
 (0)