Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,24 @@ jobs:
- name: "Install highest dependencies"
run: "composer update --no-interaction --no-progress"

- name: "Run every demo showcase through the weaver"
- name: "Run every demo showcase with and without the weaver"
run: |
for showcase in $(grep -o "case '[a-z-]*'" demos/index.php | cut -d"'" -f2); do
echo "::group::${showcase}"
php -r "\$_GET['showcase'] = '${showcase}'; include 'demos/index.php';" > "demo-${showcase}.html"
if grep -qiE '(fatal error|uncaught|warning|deprecated|notice)' "demo-${showcase}.html"; then
grep -iE '(fatal error|uncaught|warning|deprecated|notice)' "demo-${showcase}.html"
exit 1
fi
echo "::endgroup::"
showcases=$(php -r 'require "vendor/autoload.php"; foreach ((new Demo\Showcase\ShowcaseCatalog())->all() as $showcase) echo $showcase->id, PHP_EOL;')
for aop in on off; do
for showcase in "" ${showcases}; do
page="demo-${showcase:-index}-aop-${aop}.html"
echo "::group::${showcase:-index} (AOP ${aop})"
php -r "\$_COOKIE['aop'] = '${aop}'; \$_GET['showcase'] = '${showcase}'; include 'demos/index.php';" > "${page}"
if grep -qiE '(fatal error|uncaught|warning|deprecated|notice)' "${page}"; then
grep -iE '(fatal error|uncaught|warning|deprecated|notice)' "${page}"
exit 1
fi
# A page cut short leaves the navigation and the AOP switch without their script
if ! grep -q '</html>' "${page}"; then
echo "The page is not rendered completely"
tail -n 20 "${page}"
exit 1
fi
echo "::endgroup::"
done
done
31 changes: 0 additions & 31 deletions demos/Demo/Highlighter.php

This file was deleted.

72 changes: 72 additions & 0 deletions demos/Demo/Showcase/Showcase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);
/*
* Go! AOP framework
*
* @copyright Copyright 2026, Lisachenko Alexander <lisachenko.it@gmail.com>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*/

namespace Demo\Showcase;

use Closure;
use Go\Aop\Aspect;
use ReflectionClass;
use ReflectionObject;

/**
* One example of the demo: an aspect and the scenario that shows it in action
*/
final readonly class Showcase
{
/**
* @param string $id Identifier used in the URL
* @param string $group Navigation group of the showcase
* @param string $title Short title for the navigation
* @param string $summary One sentence about what the aspect does
* @param class-string<Aspect> $aspect Aspect demonstrated by the showcase
* @param Closure(): (object|null) $scenario Example code, returns the object whose class is shown
*/
public function __construct(
public string $id,
public string $group,
public string $title,
public string $summary,
public string $aspect,
private Closure $scenario,
) {}

/**
* Short name of the aspect class
*/
public function aspectName(): string
{
return new ReflectionClass($this->aspect)->getShortName();
}

/**
* Runs the scenario and collects its output together with the source code involved
*/
public function run(): ShowcaseResult
{
$startedAt = hrtime(true);
ob_start();
try {
$subject = ($this->scenario)();
} finally {
$output = (string) ob_get_clean();
}
$elapsedMs = (hrtime(true) - $startedAt) / 1e6;

return new ShowcaseResult(
output: $output,
elapsedMs: $elapsedMs,
usage: SourceCode::ofClosure($this->scenario),
aspect: SourceCode::ofClass(new ReflectionClass($this->aspect)),
subject: $subject !== null ? SourceCode::ofClass(new ReflectionObject($subject)) : null,
);
}
}
Loading
Loading