1. Go to this page and download the library: Download boundwize/structarmed library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
boundwize / structarmed example snippets
// structarmed.php
use Boundwize\StructArmed\Architecture;
use Boundwize\StructArmed\Preset\Preset;
return Architecture::define()
->withPreset(Preset::PSR4());
use Boundwize\StructArmed\Architecture;
use Boundwize\StructArmed\Preset\Preset;
return Architecture::define()
->cacheDirectory('var/cache/structarmed')
->withPreset(Preset::PSR4());
use Boundwize\StructArmed\Architecture;
use Boundwize\StructArmed\Preset\Preset;
use Boundwize\StructArmed\Preset\Presets\DddPreset;
use Boundwize\StructArmed\Rule\Rules\Class_\MustBeFinalRule;
use Boundwize\StructArmed\Rule\Rules\Layer\MayNotDependOnRule;
use Boundwize\StructArmed\Rule\Rules\Method\MustHaveReturnTypeRule;
return Architecture::define()
->layer('Domain', 'src/Domain/')
->layer('Application', 'src/Application/')
->layer('Infrastructure', 'src/Infrastructure/')
->skip([
'tests/Fixtures/',
'var/cache/*',
DddPreset::DOMAIN_NO_DATETIME,
DddPreset::ENTITY_MUST_BE_FINAL => ['src/Legacy/'],
])
->withPreset(Preset::DDD())
// Replace a rule with a different configuration
->replaceRule(
DddPreset::ENTITY_MUST_BE_FINAL,
new MustBeFinalRule(layer: 'Domain', classNamePattern: '/Entity$|Aggregate$/')
)
// Add your own custom rule
->rule(
'domain.must_not_depend_on_infrastructure',
new MayNotDependOnRule(from: 'Domain', to: 'Infrastructure', toPath: 'Infrastructure')
)
->rule(
'domain.public_methods_must_have_return_types',
new MustHaveReturnTypeRule(layer: 'Domain')
);
return Architecture::define()
->layerPattern('API', '/^App\\\\API\\\\.*$/')
->layerPattern('HTTP', '/^App\\\\HTTP\\\\.*$/')
->layerPattern('Database', '/^App\\\\Database\\\\.*$/')
->ruleset([
'API' => ['HTTP'], // API may only depend on HTTP
'HTTP' => ['Database'], // HTTP may only depend on Database
'Database' => [], // Database may not depend on any layer
]);
use Boundwize\StructArmed\Architecture;
use Boundwize\StructArmed\Preset\PresetInterface;
use Boundwize\StructArmed\Rule\Rules\Method\MustHaveReturnTypeRule;
final class MyPreset implements PresetInterface
{
public const METHODS_MUST_HAVE_RETURN_TYPES = 'source.methods_must_have_return_types';
public function apply(Architecture $architecture): void
{
$architecture
->layer('Source', 'src/')
->rule(
self::METHODS_MUST_HAVE_RETURN_TYPES,
new MustHaveReturnTypeRule(layer: 'Source')
);
}
}
use App\Architecture\MyPreset;
use Boundwize\StructArmed\Architecture;
return Architecture::define()
->withPreset(new MyPreset());