1. Go to this page and download the library: Download sweikenb/boundaries 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/ */
sweikenb / boundaries example snippets
class MyCustomCheckForNeedles extends AbstractCheck
{
public static function getConfigKey(): string
{
// This is the checks-key in the "boundaries.yaml"-file that will be active the check and contains specific
// configurations.
return 'needles';
}
public static function getPriority(): int
{
// In order to influence the execution order of checks, you can specify a priority here,
// the lower the number the earlier the execution.
return self::PRIO_DEFAULT;
}
public function execute(
array $checkConfig,
string $dir,
string $filename,
string &$content,
array &$violations
): void {
// Please note that the $violations and $content variables must be passed as reference!
// While adding error-messages to the $violations is the intended way, the $content is passed by reference
// to maintain viable performance and prevent memory issues.
//
// IMPORTANT: Changes to $content WILL affect other checks and should only be done intentionally!
//
if (isset($checkConfig['filename']) && preg_match($checkConfig['filename'], $filename)) {
$this->addViolation($violations, $dir, $filename, sprintf('A needle was found in filename "%s"', $filename));
break;
}
if (isset($checkConfig['content']) && preg_match($checkConfig['content'], $content)) {
$this->addViolation($violations, $dir, $filename, sprintf('A needle was found in file-content "%s"', $filename));
break;
}
}
}
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;
use Sweikenb\Library\Boundaries\Service\CheckService;
class MyCustomBoundariesChecksPlugin implements PluginInterface
{
public function activate(Composer $composer, IOInterface $io): void
{
CheckService::registerChecks(
new MyCustomCheckForNeedles()
);
}
public function deactivate(Composer $composer, IOInterface $io): void
{
// nothing to do here
}
public function uninstall(Composer $composer, IOInterface $io): void
{
// nothing to do here
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.