Skip to content

Commit

Permalink
Use PSR-4 for autoloading
Browse files Browse the repository at this point in the history
When we introduced the use of Composer classmaps for autoloading in
df6f5d0, we lost the ability to define
custom spouts without dumping the autoloader. PSR-4 would fix this issue
but at the time I came to conclusion we would have to change selfoss
file structure to support it.

Since that assumption seems to be false, we are switching to PSR-4, thus
having the cake and eating it too. The only caveat is the need for more
strict file naming conventions.

Closes: #958

### Upgrading

If you use any custom classes like spouts, make sure they follow the
[PSR-4], namely the namespace should match the file path (even in letter
case).

For example, if you have custom spout class named `PrivateSpout` in
`spouts\private` namespace, it will have to be located in
`spouts/private/PrivateSpout.php`.

This also means each file can only contain a single class.

[PSR-4]: http://www.php-fig.org/psr/psr-4/

### Upgrading (developers)
Once you checked for compliance, run `composer install` as described in
the [development section] of README to switch to PSR-4 autoloader.

[development section]: https://github.com/SSilence/selfoss/blob/master/README.md#development
  • Loading branch information
jtojnar committed Jun 25, 2017
1 parent 9dd648c commit bad459c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ $rules = [
'trailing_comma_in_multiline_array' => false,
// additional rules
'array_syntax' => ['syntax' => 'short'],
'psr4' => true,
'phpdoc_order' => true,
];

return PhpCsFixer\Config::create()
->setRules($rules)
->setRiskyAllowed(true)
->setFinder($finder);
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
}
],
"autoload": {
"classmap": [
"controllers/",
"daos/",
"helpers/",
"spouts/"
]
"psr-4": {
"controllers\\": "controllers/",
"daos\\": "daos/",
"helpers\\": "helpers/",
"spouts\\": "spouts/"
}
},
"config": {
"platform": {
Expand Down

0 comments on commit bad459c

Please sign in to comment.