Package
How to setup an Arrow package
Introduction
Packages are a key factor to the Arrow framework. They allow features of the framework to be self-contained and only loaded on demand. Because they are self-contained, they can be tailored more to integrate more tightly with the framework and project.
Setup
It is strongly recommended that the project be managed with Composer. The definition of the composer.json
file can be found on their website. Arrow suggests that you require the version of Arrow your package was developed for.
composer.json
Below is a snippet from /arrowphp/cli/composer.json used by the arrowphp/cli
package.
...
"require": {
"arrowphp/arrow": "@dev"
},
...
Structure
The recommended project structure is defined below.
Modules and other project files should be in the src
directory.
/
config/
config.php
src/
arrow-install.php
composer.json
composer.json
Define the autoload namespace of the project to point to the src
directory.
Below is a snippet from /arrowphp/cli/composer.json used by the arrowphp/cli
package.
...
"autoload": {
"psr-4": {
"Arrow\\CLI\\": "src/"
}
},
...
Definition
There are two key factors that are required for a package. The arrow-install.php
file and the config/config.php
file.
arrow-install.php
This file is required for the package to be identified as an Arrow package. It must return a function which takes an instance of the \Arrow\Application
class as it's only argument.
The typical use of the install function is to register a Middleware with the application. However this is not required for the package to simply be used as another source of modules.
Below is /arrowphp/cli/arrow-install.php used by the arrowphp/cli
package.
<?php
declare(strict_types=1);
use Arrow\Application;
use Arrow\CLI\Middleware;
use Arrow\CLI\Constant;
return function (Application $app) {
$app->config()->add('middleware', Middleware::class);
};
config/config.php
This file is included by the Arrow framework. It must return an array. It should be used to define the Namespace and setup the defaults for the package. These config values can be overwritten by the user in their project.
The Namespace
property is a required config value for a package. It is used by the framework to load the modules.
Below is /arrowphp/cli/config/config.php used by the arrowphp/cli
package.
<?php
return [
'Namespace' => 'Arrow\\CLI',
];
Last updated
Was this helpful?