Skip to content

Commit

Permalink
Fixes #4 : Drop laminas loader, module loader and autoloader provider…
Browse files Browse the repository at this point in the history
… features

Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik committed Aug 30, 2020
1 parent 6ccf180 commit a85820a
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 1,125 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-console": "^2.8",
"laminas/laminas-di": "^2.6.1",
"laminas/laminas-loader": "^2.6.1",
"laminas/laminas-mvc": "^3.1.1",
"laminas/laminas-servicemanager": "^3.4.1",
"phpunit/phpunit": "^9.3.7"
},
"suggest": {
"laminas/laminas-console": "Laminas\\Console component",
"laminas/laminas-loader": "Laminas\\Loader component if you are not using Composer autoloading for your modules",
"laminas/laminas-mvc": "Laminas\\Mvc component",
"laminas/laminas-servicemanager": "Laminas\\ServiceManager component"
},
Expand All @@ -55,8 +53,10 @@
},
"autoload-dev": {
"files": [
"test/autoload.php",
"test/TestAsset/ModuleAsClass.php"
"test/autoload.php"
],
"classmap": [
"test/TestAsset/"
],
"psr-4": {
"ListenerTestModule\\": "test/TestAsset/ListenerTestModule/",
Expand Down
38 changes: 9 additions & 29 deletions docs/book/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ CSS, and JavaScript. The possibilities are endless.
The module system is made up of the following:

- [The Module Autoloader](https://docs.laminas.dev/laminas-loader/module-autoloader/) -
`Laminas\Loader\ModuleAutoloader` is a specialized autoloader that is responsible
for the locating and loading of modules' `Module` classes from a variety of
sources.
- [The Module Manager](module-manager.md) - `Laminas\ModuleManager\ModuleManager`
takes an array of module names and fires a sequence of events for each one,
allowing the behavior of the module system to be defined entirely by the
Expand All @@ -38,43 +34,27 @@ The recommended structure for an MVC-oriented Laminas module is as follows:

```text
module_root/
Module.php
autoload_classmap.php
autoload_function.php
autoload_register.php
config/
module.config.php
public/
images/
css/
js/
src/
<module_namespace>/
<code files>
Module.php
<code files as per PSR-4>
test/
phpunit.xml
bootstrap.php
<module_namespace>/
<test code files>
<test code files>
view/
<dir-named-after-module-namespace>/
<dir-named-after-a-controller>/
<.phtml files>
phpunit.xml.dist
composer.json
```

## The autoload\_\*.php Files
## Autoloading

The three `autoload_*.php` files are not required, but recommended. They provide the following:

- `autoload_classmap.php` should return an array classmap of class name/filename
pairs (with the filenames resolved via the `__DIR__` magic constant).
- `autoload_function.php` should return a PHP callback that can be passed to
`spl_autoload_register()`. Typically, this callback should utilize the map
returned by `autoload_classmap.php`.
- `autoload_register.php` should register a PHP callback (typically that
returned by `autoload_function.php` with `spl_autoload_register()`.

The purpose of these three files is to provide reasonable default mechanisms for
autoloading the classes contained in the module, thus providing a trivial way to
consume the module without requiring laminas-modulemanager` (e.g., for use outside
a Laminas application).
Since version 3, laminas-modulemanager does not provide own autoloading mechanisms
and instead relies on [Composer dependency manager](https://getcomposer.org/)
to provide autoloading.
87 changes: 87 additions & 0 deletions docs/book/migration/to-v3-0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Upgrading to 3.0

## Module autoloading

laminas-modulemanager originates from before the Composer was created, where each
framework had to provide its own autoloading implementation.
Since then Composer became the de-facto standard in managing dependencies and
autoloading for the php projects.
In light of that, laminas-servicemanager removes ModuleLoader and autoload
providers support in version 3.0 in favor of
[Composer dependency manager](https://getcomposer.org/).

### Application local modules

Autoloading rules for application local modules should now be defined in
application's composer.json

Before:

```php
namespace Application;

class Module
{
public function getAutoloaderConfig()
{
return [
'Laminas\Loader\StandardAutoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
],
],
];
}
}
```

and after:

```json
{
"name": "laminas/laminas-mvc-skeleton",
"description": "Laminas MVC Skeleton Application",
"type": "project",
...
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/"
}
},
"autoload-dev": {
"psr-4": {
"ApplicationTest\\": "module/Application/test/"
}
}
}
```

[laminas-composer-autoloading](https://github.com/laminas/laminas-composer-autoloading)
provides a handy tool to easily add and remove autoloading rules for local modules to
application's composer.json

After autoloading rules were updated, composer will need to update autoloader:

```console
$ composer dump-autoload
```

### Composer installed modules

For composer installed modules, autoloading rules will be automatically picked
by composer from the module's composer.json and no extra effort is needed:
```json
{
"name": "acme/my-module",
"description": "Module for use with laminas-mvc applications.",
"type": "library",
"require": {
"php": "^7.1"
},
"autoload": {
"psr-4": {
"Acme\\MyModule\\": "src/"
}
}
}
```
161 changes: 0 additions & 161 deletions docs/book/module-autoloader.md

This file was deleted.

Loading

0 comments on commit a85820a

Please sign in to comment.