forked from mirrors/flight-core
Compare commits
164 Commits
580-view-c
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
68b88786ad | 3 days ago |
|
|
b9d3bdcffe | 3 weeks ago |
|
|
ca330bca30 | 4 weeks ago |
|
|
b04873d258 | 4 weeks ago |
|
|
079d7bf471 | 4 weeks ago |
|
|
06f10a7eb1 | 1 month ago |
|
|
9491b93951 | 1 month ago |
|
|
eac9fef021 | 1 month ago |
|
|
8093a18fb3 | 2 months ago |
|
|
63e5bcd613 | 2 months ago |
|
|
24640dcbcb | 3 months ago |
|
|
9681cd20c8 | 3 months ago |
|
|
241541b995 | 3 months ago |
|
|
386bdc16a7 | 3 months ago |
|
|
e42c7848c4 | 3 months ago |
|
|
6b8d2f9880 | 3 months ago |
|
|
a406f917e8 | 3 months ago |
|
|
f617b5c2f6 | 3 months ago |
|
|
13af0cb63c | 3 months ago |
|
|
2880142083 | 3 months ago |
|
|
25e54f2252 | 3 months ago |
|
|
71de031cef | 3 months ago |
|
|
d332b453c0 | 3 months ago |
|
|
b26dc67adc | 3 months ago |
|
|
6a127b1f0f | 3 months ago |
|
|
89c378cc94 | 3 months ago |
|
|
2fac34fbb7 | 3 months ago |
|
|
77e68ea77b | 3 months ago |
|
|
89a9decc0b | 3 months ago |
|
|
09e222c0fa | 3 months ago |
|
|
5a83743cc7 | 3 months ago |
|
|
712792006f | 3 months ago |
|
|
1519e0cf30 | 3 months ago |
|
|
d9406bbf24 | 3 months ago |
|
|
ff5e90c592 | 3 months ago |
|
|
d9b01781e6 | 3 months ago |
|
|
6acbdb2082 | 3 months ago |
|
|
d196cc09e1 | 3 months ago |
|
|
85f5431a40 | 3 months ago |
|
|
7f1b976ca1 | 3 months ago |
|
|
30193dedac | 3 months ago |
|
|
8523025cb5 | 3 months ago |
|
|
1a8af5c96b | 3 months ago |
|
|
112796ec42 | 3 months ago |
|
|
cb27287bbc | 3 months ago |
|
|
5372672332 | 3 months ago |
|
|
240556e92b | 3 months ago |
|
|
7fc6fc1eee | 3 months ago |
|
|
df93b904f3 | 3 months ago |
|
|
73a5387b70 | 3 months ago |
|
|
cd3d8bb44e | 3 months ago |
|
|
4cb50f66ab | 3 months ago |
|
|
6c22bad3f0 | 3 months ago |
|
|
361e45e974 | 3 months ago |
|
|
4abcd23e11 | 3 months ago |
|
|
6bc62d9b0c | 3 months ago |
|
|
0d50ed97d6 | 3 months ago |
|
|
f7b2736736 | 3 months ago |
|
|
3723228c3d | 3 months ago |
|
|
8d29ad4fd0 | 3 months ago |
|
|
3066c5dcc4 | 3 months ago |
|
|
4c2a08c3e6 | 3 months ago |
|
|
7482506270 | 3 months ago |
|
|
17ed78763f | 3 months ago |
|
|
8e168e648b | 3 months ago |
|
|
cfa87bee4e | 3 months ago |
|
|
e48b976aac | 3 months ago |
|
|
bdd5bdcc24 | 3 months ago |
|
|
05831b39cb | 3 months ago |
|
|
6afe25ddb5 | 3 months ago |
|
|
9e08573896 | 3 months ago |
|
|
27598bcff5 | 3 months ago |
|
|
cbc1cb30be | 3 months ago |
|
|
4afb553a96 | 3 months ago |
|
|
35a6bbabed | 3 months ago |
|
|
740524490f | 3 months ago |
|
|
ddb57620a0 | 3 months ago |
|
|
b0203d861c | 3 months ago |
|
|
80705ec158 | 3 months ago |
|
|
2d772f3642 | 3 months ago |
|
|
2673435197 | 3 months ago |
|
|
5ea5d5b8ad | 3 months ago |
|
|
2682e3298f | 3 months ago |
|
|
bb6932e92e | 3 months ago |
|
|
bf3f86d619 | 3 months ago |
|
|
7379be00ac | 3 months ago |
|
|
318852b19b | 3 months ago |
|
|
1ae2bafeee | 3 months ago |
|
|
7beabae36d | 3 months ago |
|
|
188f147c7d | 3 months ago |
|
|
5c89341428 | 3 months ago |
|
|
988c64ed22 | 3 months ago |
|
|
0b0737f533 | 3 months ago |
|
|
8a4818cf87 | 3 months ago |
|
|
ae735c1845 | 3 months ago |
|
|
12607d9500 | 3 months ago |
|
|
6c5d9de3ca | 3 months ago |
|
|
32ff66428d | 3 months ago |
|
|
cff442d964 | 3 months ago |
|
|
edb424c2da | 3 months ago |
|
|
5f5ea34755 | 3 months ago |
|
|
31cd1b0437 | 3 months ago |
|
|
cc01169281 | 3 months ago |
|
|
d566684b7e | 3 months ago |
|
|
ae0440eb80 | 3 months ago |
|
|
b464dc18f4 | 3 months ago |
|
|
489c4e2fd0 | 3 months ago |
|
|
b28716c3ef | 3 months ago |
|
|
a86e4078ca | 3 months ago |
|
|
fa08cd68ff | 3 months ago |
|
|
412faa120f | 3 months ago |
|
|
dddd6ab72a | 3 months ago |
|
|
dc48746b3f | 3 months ago |
|
|
d8fe78449c | 3 months ago |
|
|
ee03274498 | 3 months ago |
|
|
98c9c89893 | 3 months ago |
|
|
f2df5232c4 | 4 months ago |
|
|
128af19ae9 | 4 months ago |
|
|
83d7096ee7 | 4 months ago |
|
|
eb24cff886 | 5 months ago |
|
|
53d422001e | 5 months ago |
|
|
bac3714368 | 5 months ago |
|
|
46e457f9c5 | 5 months ago |
|
|
d58cbacda1 | 5 months ago |
|
|
3ca4c86da8 | 5 months ago |
|
|
61db3b2fcc | 5 months ago |
|
|
ad7c613d55 | 5 months ago |
|
|
dcab35b729 | 5 months ago |
|
|
68f0942127 | 5 months ago |
|
|
03ed9fe706 | 5 months ago |
|
|
f20f1d2014 | 5 months ago |
|
|
18786481d9 | 5 months ago |
|
|
770d246e29 | 5 months ago |
|
|
ee9b5f2082 | 5 months ago |
|
|
8ec68173ce | 5 months ago |
|
|
cf553d36d4 | 5 months ago |
|
|
47a3702927 | 5 months ago |
|
|
db343815a3 | 5 months ago |
|
|
9aab65b7f6 | 5 months ago |
|
|
921c51a5d6 | 5 months ago |
|
|
1a37f91b99 | 5 months ago |
|
|
90a72aef7c | 5 months ago |
|
|
85d2f82f77 | 5 months ago |
|
|
4e244c8172 | 5 months ago |
|
|
760ac1a858 | 5 months ago |
|
|
c975f5551b | 5 months ago |
|
|
e3f314b2ac | 5 months ago |
|
|
6d0bbdb9a6 | 5 months ago |
|
|
036a9a5315 | 5 months ago |
|
|
867a564708 | 5 months ago |
|
|
2f533dcdf4 | 5 months ago |
|
|
23d749b8c0 | 5 months ago |
|
|
3eb34464fb | 5 months ago |
|
|
04afcb16e8 | 5 months ago |
|
|
2c47c5ec0e | 5 months ago |
|
|
5ac0ab48a7 | 5 months ago |
|
|
ec3c2ec04e | 5 months ago |
|
|
104f344352 | 5 months ago |
|
|
fbfdcc5a23 | 5 months ago |
|
|
2aa8515b11 | 5 months ago |
|
|
df326534fe | 5 months ago |
|
|
34bc93cccc | 5 months ago |
|
|
a148d8750f | 5 months ago |
|
|
0dfcb0a19c | 5 months ago |
@ -1,27 +0,0 @@
|
||||
# FlightPHP/Core Project Instructions
|
||||
|
||||
## Overview
|
||||
This is the main FlightPHP core library for building fast, simple, and extensible PHP web applications. It is dependency-free for core usage and supports PHP 7.4+.
|
||||
|
||||
## Project Guidelines
|
||||
- PHP 7.4 must be supported. PHP 8 or greater also supported, but avoid PHP 8+ only features.
|
||||
- Keep the core library dependency-free (no polyfills or interface-only repositories).
|
||||
- All Flight projects are meant to be kept simple and fast. Performance is a priority.
|
||||
- Flight is extensible and when implementing new features, consider how they can be added as plugins or extensions rather than bloating the core library.
|
||||
- Any new features built into the core should be well-documented and tested.
|
||||
- Any new features should be added with a focus on simplicity and performance, avoiding unnecessary complexity.
|
||||
- This is not a Laravel, Yii, Code Igniter or Symfony clone. It is a simple, fast, and extensible framework that allows you to build applications quickly without the overhead of large frameworks.
|
||||
|
||||
## Development & Testing
|
||||
- Run tests: `composer test` (uses phpunit/phpunit and spatie/phpunit-watcher)
|
||||
- Run test server: `composer test-server` or `composer test-server-v2`
|
||||
- Lint code: `composer lint` (uses phpstan/phpstan, level 6)
|
||||
- Beautify code: `composer beautify` (uses squizlabs/php_codesniffer, PSR1)
|
||||
- Check code style: `composer phpcs`
|
||||
- Test coverage: `composer test-coverage`
|
||||
|
||||
## Coding Standards
|
||||
- Follow PSR1 coding standards (enforced by PHPCS)
|
||||
- Use strict comparisons (`===`, `!==`)
|
||||
- PHPStan level 6 compliance
|
||||
- Focus on PHP 7.4 compatibility (avoid PHP 8+ only features)
|
||||
@ -1,13 +0,0 @@
|
||||
/.gemini export-ignore
|
||||
/.github export-ignore
|
||||
/tests export-ignore
|
||||
/.editorconfig export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/CONTRIBUTING.md export-ignore
|
||||
/index.php export-ignore
|
||||
/phpcs.xml.dist export-ignore
|
||||
/phpstan-baseline.neon export-ignore
|
||||
/phpstan.dist.neon export-ignore
|
||||
/phpunit-watcher.yml export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
@ -1,15 +1,18 @@
|
||||
.idea/
|
||||
.vscode/
|
||||
vendor/
|
||||
composer.phar
|
||||
composer.lock
|
||||
*.sublime-*
|
||||
.DS_Store
|
||||
.phpunit.result.cache
|
||||
coverage/
|
||||
*.sublime*
|
||||
.runway-config.json
|
||||
.runway-creds.json
|
||||
/.idea
|
||||
/.vscode
|
||||
/coverage
|
||||
/vendor
|
||||
clover.xml
|
||||
composer.lock
|
||||
composer.phar
|
||||
phpcs.xml
|
||||
phpstan.neon
|
||||
phpunit.xml
|
||||
.runway-config.json
|
||||
.runway-creds.json
|
||||
.DS_Store
|
||||
.phpunit-watcher.yml
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| > 3.18.0 | :white_check_mark: |
|
||||
| <= 2.0 | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Use Github to securely report the vulnerability.
|
||||
@ -1,219 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace flight\commands;
|
||||
|
||||
/**
|
||||
* @property-read ?string $configFile
|
||||
* @property-read ?string $baseDir
|
||||
*/
|
||||
class AiGenerateInstructionsCommand extends AbstractBaseCommand
|
||||
{
|
||||
/**
|
||||
* Constructor for the AiGenerateInstructionsCommand class.
|
||||
*
|
||||
* Initializes a new instance of the command.
|
||||
*
|
||||
* @param array<string,mixed> $config Config from config.php
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
parent::__construct('ai:generate-instructions', 'Generate project-specific AI coding instructions', $config);
|
||||
|
||||
$this->option(
|
||||
'--config-file',
|
||||
'Path to .runway-config.json file (deprecated, use config.php instead)',
|
||||
null,
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the command logic for generating AI instructions.
|
||||
*
|
||||
* This method is called to perform the main functionality of the
|
||||
* AiGenerateInstructionsCommand. It should contain the steps required
|
||||
* to generate and output instructions using AI, based on the command's
|
||||
* configuration and input.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function execute(): int
|
||||
{
|
||||
$io = $this->app()->io();
|
||||
|
||||
if (empty($this->config['runway'])) {
|
||||
$configFile = $this->configFile;
|
||||
$io = $this->app()->io();
|
||||
|
||||
$io->warn(
|
||||
'The --config-file option is deprecated. '
|
||||
. 'Move your config values to the \'runway\' key in the config.php file for configuration.',
|
||||
true
|
||||
);
|
||||
$runwayConfig = json_decode(file_get_contents($configFile), true) ?? [];
|
||||
} else {
|
||||
$runwayConfig = $this->config['runway'];
|
||||
}
|
||||
|
||||
// Check for runway creds ai
|
||||
if (empty($runwayConfig['ai'])) {
|
||||
$io->error('Missing AI configuration. Please run the \'ai:init\' command first.', true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
$io->info('Let\'s gather some project details to generate AI coding instructions.', true);
|
||||
|
||||
// Ask questions
|
||||
$projectDesc = $io->prompt('Please describe what your project is for?');
|
||||
|
||||
$database = $io->prompt(
|
||||
'What database are you planning on using? (e.g. MySQL, SQLite, PostgreSQL, none)',
|
||||
'none'
|
||||
);
|
||||
|
||||
$templating = $io->prompt(
|
||||
'What HTML templating engine will you plan on using (if any)? (recommend latte)',
|
||||
'latte'
|
||||
);
|
||||
|
||||
$security = $io->confirm('Is security an important element of this project?', 'y');
|
||||
$performance = $io->confirm('Is performance and speed an important part of this project?', 'y');
|
||||
|
||||
$composerLibs = $io->prompt(
|
||||
'What major composer libraries will you be using if you know them right now?',
|
||||
'none'
|
||||
);
|
||||
|
||||
$envSetup = $io->prompt(
|
||||
'How will you set up your development environment? (e.g. Docker, Vagrant, PHP dev server, other)',
|
||||
'Docker'
|
||||
);
|
||||
|
||||
$teamSize = $io->prompt('How many developers will be working on this project?', '1');
|
||||
$api = $io->confirm('Will this project expose an API?', 'n');
|
||||
$other = $io->prompt('Any other important requirements or context? (optional)', 'no');
|
||||
|
||||
// Prepare prompt for LLM
|
||||
$contextFile = $this->projectRoot . '.github/copilot-instructions.md';
|
||||
$context = file_exists($contextFile) === true ? file_get_contents($contextFile) : '';
|
||||
$userDetails = [
|
||||
'Project Description' => $projectDesc,
|
||||
'Database' => $database,
|
||||
'Templating Engine' => $templating,
|
||||
'Security Important' => $security ? 'yes' : 'no',
|
||||
'Performance Important' => $performance ? 'yes' : 'no',
|
||||
'Composer Libraries' => $composerLibs,
|
||||
'Environment Setup' => $envSetup,
|
||||
'Team Size' => $teamSize,
|
||||
'API' => $api ? 'yes' : 'no',
|
||||
'Other' => $other,
|
||||
];
|
||||
$detailsText = "";
|
||||
foreach ($userDetails as $k => $v) {
|
||||
$detailsText .= "$k: $v\n";
|
||||
}
|
||||
$prompt = <<<EOT
|
||||
You are an AI coding assistant. Update the following project instructions for this Flight PHP project based on the latest user answers. Only output the new instructions, no extra commentary.
|
||||
User answers:
|
||||
$detailsText
|
||||
Current instructions:
|
||||
$context
|
||||
EOT; // phpcs:ignore
|
||||
|
||||
// Read LLM creds
|
||||
$creds = $runwayConfig['ai'];
|
||||
$apiKey = $creds['api_key'];
|
||||
$model = $creds['model'];
|
||||
$baseUrl = $creds['base_url'];
|
||||
|
||||
// Prepare curl call (OpenAI compatible)
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
'Authorization: Bearer ' . $apiKey,
|
||||
];
|
||||
$data = [
|
||||
'model' => $model,
|
||||
'messages' => [
|
||||
[
|
||||
'role' => 'system',
|
||||
'content' => 'You are a helpful AI coding assistant focused on the Flight Framework for PHP. '
|
||||
. 'You are up to date with all your knowledge from https://docs.flightphp.com. '
|
||||
. 'As an expert into the programming language PHP, '
|
||||
. 'you are top notch at architecting out proper instructions for FlightPHP projects.'
|
||||
],
|
||||
['role' => 'user', 'content' => $prompt],
|
||||
],
|
||||
'temperature' => 0.2,
|
||||
];
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
// add info line that this may take a few minutes
|
||||
$io->info('Generating AI instructions, this may take a few minutes...', true);
|
||||
|
||||
$result = $this->callLlmApi($baseUrl, $headers, $jsonData, $io);
|
||||
if ($result === false) {
|
||||
return 1;
|
||||
}
|
||||
$response = json_decode($result, true);
|
||||
$instructions = $response['choices'][0]['message']['content'] ?? '';
|
||||
if (!$instructions) {
|
||||
$io->error('No instructions returned from LLM.', true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write to files
|
||||
$io->info(
|
||||
'Updating .github/copilot-instructions.md, '
|
||||
. '.cursor/rules/project-overview.mdc, '
|
||||
. '.gemini/GEMINI.md and .windsurfrules...',
|
||||
true
|
||||
);
|
||||
|
||||
if (!is_dir($this->projectRoot . '.github')) {
|
||||
mkdir($this->projectRoot . '.github', 0755, true);
|
||||
}
|
||||
if (!is_dir($this->projectRoot . '.cursor/rules')) {
|
||||
mkdir($this->projectRoot . '.cursor/rules', 0755, true);
|
||||
}
|
||||
if (!is_dir($this->projectRoot . '.gemini')) {
|
||||
mkdir($this->projectRoot . '.gemini', 0755, true);
|
||||
}
|
||||
file_put_contents($this->projectRoot . '.github/copilot-instructions.md', $instructions);
|
||||
file_put_contents($this->projectRoot . '.cursor/rules/project-overview.mdc', $instructions);
|
||||
file_put_contents($this->projectRoot . '.gemini/GEMINI.md', $instructions);
|
||||
file_put_contents($this->projectRoot . '.windsurfrules', $instructions);
|
||||
$io->ok('AI instructions updated successfully.', true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the LLM API call using curl
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param array<int,string> $headers
|
||||
* @param string $jsonData
|
||||
* @param object $io
|
||||
*
|
||||
* @return string|false
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function callLlmApi($baseUrl, $headers, $jsonData, $io)
|
||||
{
|
||||
$ch = curl_init($baseUrl . '/v1/chat/completions');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$io->error('Failed to call LLM API: ' . curl_error($ch), true);
|
||||
curl_close($ch);
|
||||
return false;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace flight\commands;
|
||||
|
||||
/**
|
||||
* @property-read ?string $credsFile Deprecated, use config.php instead
|
||||
*/
|
||||
class AiInitCommand extends AbstractBaseCommand
|
||||
{
|
||||
/**
|
||||
* Constructor for the AiInitCommand class.
|
||||
*
|
||||
* Initializes the command instance and sets up any required dependencies.
|
||||
*
|
||||
* @param array<string,mixed> $config Config from config.php
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
parent::__construct('ai:init', 'Initialize LLM API credentials and settings', $config);
|
||||
$this->option('--creds-file', 'Path to .runway-creds.json file (deprecated, use config.php instead)', null, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the function
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function execute(): int
|
||||
{
|
||||
$io = $this->app()->io();
|
||||
|
||||
$io->info('Welcome to AI Init!', true);
|
||||
|
||||
// Prompt for API provider with validation
|
||||
$allowedApis = [
|
||||
'1' => 'openai',
|
||||
'2' => 'grok',
|
||||
'3' => 'claude'
|
||||
];
|
||||
$apiChoice = strtolower(trim($io->choice('Which LLM API do you want to use?', $allowedApis, '1')));
|
||||
$api = $allowedApis[$apiChoice] ?? 'openai';
|
||||
|
||||
// Prompt for base URL with validation
|
||||
switch ($api) {
|
||||
case 'openai':
|
||||
$defaultBaseUrl = 'https://api.openai.com';
|
||||
break;
|
||||
case 'grok':
|
||||
$defaultBaseUrl = 'https://api.x.ai';
|
||||
break;
|
||||
case 'claude':
|
||||
$defaultBaseUrl = 'https://api.anthropic.com';
|
||||
break;
|
||||
}
|
||||
$baseUrl = trim($io->prompt('Enter the base URL for the LLM API', $defaultBaseUrl));
|
||||
if (empty($baseUrl) || !filter_var($baseUrl, FILTER_VALIDATE_URL)) {
|
||||
$io->error('Base URL cannot be empty and must be a valid URL.', true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Validate API key input
|
||||
$apiKey = trim($io->prompt('Enter your API key for ' . $api));
|
||||
if (empty($apiKey)) {
|
||||
$io->error('API key cannot be empty. Please enter a valid API key.', true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Validate model input
|
||||
switch ($api) {
|
||||
case 'openai':
|
||||
$defaultModel = 'gpt-5';
|
||||
break;
|
||||
case 'grok':
|
||||
$defaultModel = 'grok-4.1-fast-non-reasoning';
|
||||
break;
|
||||
case 'claude':
|
||||
$defaultModel = 'claude-sonnet-4-5';
|
||||
break;
|
||||
}
|
||||
|
||||
$model = trim($io->prompt(
|
||||
'Enter the model name you want to use (e.g. gpt-5, claude-sonnet-4-5, etc)',
|
||||
$defaultModel
|
||||
));
|
||||
|
||||
$runwayAiConfig = [
|
||||
'provider' => $api,
|
||||
'api_key' => $apiKey,
|
||||
'model' => $model,
|
||||
'base_url' => $baseUrl,
|
||||
];
|
||||
$this->setRunwayConfigValue('ai', $runwayAiConfig);
|
||||
|
||||
$io->ok('Credentials saved to app/config/config.php', true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace flight\core;
|
||||
|
||||
use Closure;
|
||||
use ReflectionFunction;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @template CallableWithoutFilters of Closure = Closure
|
||||
* @template Output = mixed
|
||||
*/
|
||||
final class FilteredCallable
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var CallableWithoutFilters
|
||||
*/
|
||||
private $closure;
|
||||
|
||||
/** @var (callable(mixed[] &$input): (void|never|false))[] */
|
||||
private array $beforeFilters = [];
|
||||
|
||||
/** @var (callable(mixed &$output): (void|never|false))[] */
|
||||
private array $afterFilters = [];
|
||||
|
||||
/** @param CallableWithoutFilters|callable(): Output $callable */
|
||||
public function __construct(callable $callable)
|
||||
{
|
||||
$this->closure = Closure::fromCallable($callable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed ...$input
|
||||
* @return Output
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function __invoke(...$input)
|
||||
{
|
||||
foreach ($this->beforeFilters as $filter) {
|
||||
$filterReturnValue = $filter($input);
|
||||
|
||||
if ($filterReturnValue === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$closure = $this->closure;
|
||||
|
||||
$output = $closure(...$input);
|
||||
|
||||
foreach ($this->afterFilters as $filter) {
|
||||
$filterReturnValue = $filter($output);
|
||||
|
||||
if ($filterReturnValue === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/** @param callable(mixed[] &$input): (void|never|false) $filter */
|
||||
public function pushBeforeFilter(callable $filter): void
|
||||
{
|
||||
if (!in_array($filter, $this->beforeFilters)) {
|
||||
$this->beforeFilters[] = $filter;
|
||||
}
|
||||
}
|
||||
|
||||
/** @param callable(Output &$output): (void|never|false) $filter */
|
||||
public function pushAfterFilter(callable $filter): void
|
||||
{
|
||||
if (!in_array($filter, $this->afterFilters)) {
|
||||
$filterReflectionFunction = new ReflectionFunction($filter);
|
||||
|
||||
if ($filterReflectionFunction->getNumberOfParameters() === 2) {
|
||||
$filter = static function (&$output) use ($filter) {
|
||||
static $input = [];
|
||||
|
||||
return $filter($input, $output);
|
||||
};
|
||||
}
|
||||
|
||||
$this->afterFilters[] = $filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace flight\template;
|
||||
|
||||
abstract class Component
|
||||
{
|
||||
abstract public function html(): string;
|
||||
|
||||
public function css(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function js(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
parameters:
|
||||
ignoreErrors: []
|
||||
@ -1,13 +1,13 @@
|
||||
hideManual: true
|
||||
watch:
|
||||
directories:
|
||||
- tests
|
||||
- flight
|
||||
fileMask: '*.php'
|
||||
notifications:
|
||||
passingTests: false
|
||||
failingTests: false
|
||||
passingTests: false
|
||||
phpunit:
|
||||
binaryPath: ./vendor/bin/phpunit
|
||||
arguments: '--stop-on-failure'
|
||||
binaryPath: ./vendor/bin/phpunit
|
||||
timeout: 180
|
||||
watch:
|
||||
directories:
|
||||
- tests
|
||||
- flight
|
||||
fileMask: '*.php'
|
||||
|
||||
@ -1 +0,0 @@
|
||||
my-component-from-another-path
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
class Something
|
||||
{
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$path = file_exists(__DIR__ . '/../vendor/autoload.php')
|
||||
? __DIR__ . '/../vendor/autoload.php'
|
||||
: __DIR__ . '/../flight/autoload.php';
|
||||
|
||||
require_once($path);
|
||||
@ -1,243 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is the test file where we can open up a quick test server and make
|
||||
* sure that the UI is really working the way we would expect it to.
|
||||
*
|
||||
* @author Kristaps Muižnieks https://github.com/krmu
|
||||
*/
|
||||
|
||||
namespace Tests\ServerV2 {
|
||||
class AuthCheck
|
||||
{
|
||||
public function before(): void
|
||||
{
|
||||
if (!isset($_COOKIE['user'])) {
|
||||
echo '<span id="infotext">Middleware text:</span> You are not authorized to access this route!';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
use Tests\ServerV2\AuthCheck;
|
||||
|
||||
require_once __DIR__ . '/../phpunit_autoload.php';
|
||||
|
||||
Flight::set('flight.content_length', false);
|
||||
Flight::set('flight.views.path', './');
|
||||
Flight::set('flight.views.extension', '.phtml');
|
||||
// This enables the old functionality of Flight output buffering
|
||||
Flight::set('flight.v2.output_buffering', true);
|
||||
|
||||
// Test 1: Root route
|
||||
Flight::route('/', function () {
|
||||
echo '<span id="infotext">Route text:</span> Root route works!';
|
||||
|
||||
if (Flight::request()->query['redirected']) {
|
||||
echo '<br>Redirected from /redirect route successfully!';
|
||||
}
|
||||
});
|
||||
|
||||
Flight::route('/querytestpath', function () {
|
||||
echo '<span id="infotext">Route text:</span> This ir query route<br>';
|
||||
echo 'I got such query parameters:<pre>';
|
||||
print_r(Flight::request()->query);
|
||||
echo '</pre>';
|
||||
}, false, 'querytestpath');
|
||||
|
||||
// Test 2: Simple route
|
||||
Flight::route('/test', function () {
|
||||
echo '<span id="infotext">Route text:</span> Test route works!';
|
||||
});
|
||||
|
||||
// Test 3: Route with parameter
|
||||
Flight::route('/user/@name', function ($name) {
|
||||
echo "<span id='infotext'>Route text:</span> Hello, $name!";
|
||||
});
|
||||
|
||||
Flight::route('POST /postpage', function () {
|
||||
echo '<span id="infotext">Route text:</span> THIS IS POST METHOD PAGE';
|
||||
}, false, 'postpage');
|
||||
|
||||
// Test 4: Grouped routes
|
||||
Flight::group('/group', function () {
|
||||
Flight::route('/test', function () {
|
||||
echo '<span id="infotext">Route text:</span> Group test route works!';
|
||||
});
|
||||
|
||||
Flight::route('/user/@name', function ($name) {
|
||||
echo "<span id='infotext'>Route text:</span> There is variable called name and it is $name";
|
||||
});
|
||||
|
||||
Flight::group('/group1', function () {
|
||||
Flight::group('/group2', function () {
|
||||
Flight::group('/group3', function () {
|
||||
Flight::group('/group4', function () {
|
||||
Flight::group('/group5', function () {
|
||||
Flight::group('/group6', function () {
|
||||
Flight::group('/group7', function () {
|
||||
Flight::group('/group8', function () {
|
||||
Flight::route('/final_group', function () {
|
||||
echo 'Mega Group test route works!';
|
||||
}, false, 'final_group');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Test 5: Route alias
|
||||
Flight::route('/alias', function () {
|
||||
echo '<span id="infotext">Route text:</span> Alias route works!';
|
||||
}, false, 'aliasroute');
|
||||
|
||||
$middle = new AuthCheck();
|
||||
|
||||
// Test 6: Route with middleware
|
||||
Flight::route('/protected', function () {
|
||||
echo '<span id="infotext">Route text:</span> Protected route works!';
|
||||
})->addMiddleware([$middle]);
|
||||
|
||||
// Test 7: Route with template
|
||||
Flight::route('/template/@name', function ($name) {
|
||||
Flight::render('template.phtml', ['name' => $name]);
|
||||
});
|
||||
|
||||
// Test 8: Throw an error
|
||||
Flight::route('/error', function () {
|
||||
trigger_error('This is a successful error');
|
||||
});
|
||||
|
||||
// Test 9: JSON output (should not output any other html)
|
||||
Flight::route('/json', function () {
|
||||
echo "\n\n\n\n\n";
|
||||
Flight::json(['message' => 'JSON renders successfully!']);
|
||||
echo "\n\n\n\n\n";
|
||||
});
|
||||
|
||||
// Test 13: JSONP output (should not output any other html)
|
||||
Flight::route('/jsonp', function () {
|
||||
echo "\n\n\n\n\n";
|
||||
Flight::jsonp(['message' => 'JSONP renders successfully!'], 'jsonp');
|
||||
echo "\n\n\n\n\n";
|
||||
});
|
||||
|
||||
Flight::route('/json-halt', function () {
|
||||
Flight::jsonHalt(['message' => 'JSON rendered and halted successfully with no other body content!']);
|
||||
});
|
||||
|
||||
// Test 10: Halt
|
||||
Flight::route('/halt', function () {
|
||||
Flight::halt(400, 'Halt worked successfully');
|
||||
});
|
||||
|
||||
// Test 11: Redirect
|
||||
Flight::route('/redirect', function () {
|
||||
Flight::redirect('/?redirected=1');
|
||||
});
|
||||
|
||||
Flight::set('flight.views.path', './');
|
||||
|
||||
Flight::map('error', function (Throwable $error) {
|
||||
echo "<h1> An error occurred, mapped error method worked, error below </h1>";
|
||||
echo '<pre style="border: 2px solid red; padding: 21px; background: lightgray; font-weight: bold;">';
|
||||
echo str_replace(getenv('PWD'), "***CLASSIFIED*****", $error->getTraceAsString());
|
||||
echo "</pre>";
|
||||
echo "<a href='/'>Go back</a>";
|
||||
});
|
||||
|
||||
Flight::map('notFound', function () {
|
||||
echo '<span id="infotext">Route text:</span> The requested URL was not found';
|
||||
echo "<a href='/'>Go back</a>";
|
||||
});
|
||||
|
||||
echo '
|
||||
<style>
|
||||
ul {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
li {
|
||||
float: left;
|
||||
}
|
||||
#infotext {
|
||||
font-weight: bold;
|
||||
color: blueviolet;
|
||||
}
|
||||
li a {
|
||||
display: block;
|
||||
color: white;
|
||||
text-align: center;
|
||||
padding: 14px 16px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
li a:hover {
|
||||
background-color: #111;
|
||||
}
|
||||
#container {
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
margin: 20px 0;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
#debugrequest {
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
margin: 20px 0;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
</style>
|
||||
<ul>
|
||||
<li><a href="/">Root Route</a></li>
|
||||
<li><a href="/test">Test Route</a></li>
|
||||
<li><a href="/user/John">User Route with Parameter (John)</a></li>
|
||||
<li><a href="/group/test">Grouped Test Route</a></li>
|
||||
<li><a href="/group/user/Jane">Grouped User Route with Parameter (Jane)</a></li>
|
||||
<li><a href="/alias">Alias Route</a></li>
|
||||
<li><a href="/protected">Protected path</a></li>
|
||||
<li><a href="/template/templatevariable">Template path</a></li>
|
||||
<li><a href="/querytestpath?test=1&variable2=uuid&variable3=tester">Query path</a></li>
|
||||
<li><a href="/postpage">Post method test page - should be 404</a></li>
|
||||
<li><a href="' . Flight::getUrl('final_group') . '">Mega group</a></li>
|
||||
<li><a href="/error">Error</a></li>
|
||||
<li><a href="/json">JSON</a></li>
|
||||
<li><a href="/jsonp?jsonp=myjson">JSONP</a></li>
|
||||
<li><a href="/json-halt">JSON Halt</a></li>
|
||||
<li><a href="/halt">Halt</a></li>
|
||||
<li><a href="/redirect">Redirect</a></li>
|
||||
</ul>';
|
||||
|
||||
Flight::before('start', function () {
|
||||
echo '<div id="container">';
|
||||
});
|
||||
|
||||
Flight::after('start', function () {
|
||||
echo '</div>';
|
||||
echo '<div id="debugrequest">';
|
||||
echo "Request information<pre>";
|
||||
print_r(Flight::request());
|
||||
echo "</pre>";
|
||||
echo "</div>";
|
||||
});
|
||||
|
||||
Flight::start();
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests\server_v2;
|
||||
|
||||
class AuthCheck
|
||||
{
|
||||
public function before(): void
|
||||
{
|
||||
if (!isset($_COOKIE['user'])) {
|
||||
echo '<span id="infotext">Middleware text:</span> You are not authorized to access this route!';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use tests\server_v2\AuthCheck;
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
/*
|
||||
* This is the test file where we can open up a quick test server and make
|
||||
* sure that the UI is really working the way we would expect it to.
|
||||
*
|
||||
* @author Kristaps Muižnieks https://github.com/krmu
|
||||
*/
|
||||
|
||||
Flight::set('flight.content_length', false);
|
||||
Flight::set('flight.views.path', './');
|
||||
Flight::set('flight.views.extension', '.phtml');
|
||||
// This enables the old functionality of Flight output buffering
|
||||
Flight::set('flight.v2.output_buffering', true);
|
||||
|
||||
// Test 1: Root route
|
||||
Flight::route('/', function () {
|
||||
echo '<span id="infotext">Route text:</span> Root route works!';
|
||||
|
||||
if (Flight::request()->query['redirected']) {
|
||||
echo '<br>Redirected from /redirect route successfully!';
|
||||
}
|
||||
});
|
||||
|
||||
Flight::route('/querytestpath', function () {
|
||||
echo '<span id="infotext">Route text:</span> This is query route<br>';
|
||||
echo 'I got such query parameters:<pre>';
|
||||
print_r(Flight::request()->query);
|
||||
echo '</pre>';
|
||||
}, false, 'querytestpath');
|
||||
|
||||
// Test 2: Simple route
|
||||
Flight::route('/test', function () {
|
||||
echo '<span id="infotext">Route text:</span> Test route works!';
|
||||
});
|
||||
|
||||
// Test 3: Route with parameter
|
||||
Flight::route('/user/@name', function ($name) {
|
||||
echo "<span id='infotext'>Route text:</span> Hello, $name!";
|
||||
});
|
||||
|
||||
Flight::route('POST /postpage', function () {
|
||||
echo '<span id="infotext">Route text:</span> THIS IS POST METHOD PAGE';
|
||||
}, false, 'postpage');
|
||||
|
||||
// Test 4: Grouped routes
|
||||
Flight::group('/group', function () {
|
||||
Flight::route('/test', function () {
|
||||
echo '<span id="infotext">Route text:</span> Group test route works!';
|
||||
});
|
||||
|
||||
Flight::route('/user/@name', function ($name) {
|
||||
echo "<span id='infotext'>Route text:</span> There is variable called name and it is $name";
|
||||
});
|
||||
|
||||
Flight::group('/group1', function () {
|
||||
Flight::group('/group2', function () {
|
||||
Flight::group('/group3', function () {
|
||||
Flight::group('/group4', function () {
|
||||
Flight::group('/group5', function () {
|
||||
Flight::group('/group6', function () {
|
||||
Flight::group('/group7', function () {
|
||||
Flight::group('/group8', function () {
|
||||
Flight::route('/final_group', function () {
|
||||
echo 'Mega Group test route works!';
|
||||
}, false, 'final_group');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Test 5: Route alias
|
||||
Flight::route('/alias', function () {
|
||||
echo '<span id="infotext">Route text:</span> Alias route works!';
|
||||
}, false, 'aliasroute');
|
||||
|
||||
$middle = new AuthCheck();
|
||||
|
||||
// Test 6: Route with middleware
|
||||
Flight::route('/protected', function () {
|
||||
echo '<span id="infotext">Route text:</span> Protected route works!';
|
||||
})->addMiddleware([$middle]);
|
||||
|
||||
// Test 7: Route with template
|
||||
Flight::route('/template/@name', function ($name) {
|
||||
Flight::render('template.phtml', ['name' => $name]);
|
||||
});
|
||||
|
||||
// Test 8: Throw an error
|
||||
Flight::route('/error', function () {
|
||||
trigger_error('This is a successful error');
|
||||
});
|
||||
|
||||
// Test 9: JSON output (should not output any other html)
|
||||
Flight::route('/json', function () {
|
||||
echo "\n\n\n\n\n";
|
||||
Flight::json(['message' => 'JSON renders successfully!']);
|
||||
echo "\n\n\n\n\n";
|
||||
});
|
||||
|
||||
// Test 13: JSONP output (should not output any other html)
|
||||
Flight::route('/jsonp', function () {
|
||||
echo "\n\n\n\n\n";
|
||||
Flight::jsonp(['message' => 'JSONP renders successfully!'], 'jsonp');
|
||||
echo "\n\n\n\n\n";
|
||||
});
|
||||
|
||||
Flight::route('/json-halt', function () {
|
||||
Flight::jsonHalt(['message' => 'JSON rendered and halted successfully with no other body content!']);
|
||||
});
|
||||
|
||||
// Test 10: Halt
|
||||
Flight::route('/halt', function () {
|
||||
Flight::halt(400, 'Halt worked successfully');
|
||||
});
|
||||
|
||||
// Test 11: Redirect
|
||||
Flight::route('/redirect', function () {
|
||||
Flight::redirect('/?redirected=1');
|
||||
});
|
||||
|
||||
Flight::set('flight.views.path', './');
|
||||
|
||||
Flight::map('error', function (Throwable $error) {
|
||||
echo "<h1> An error occurred, mapped error method worked, error below </h1>";
|
||||
echo '<pre style="border: 2px solid red; padding: 21px; background: lightgray; font-weight: bold;">';
|
||||
echo str_replace(getenv('PWD'), "***CLASSIFIED*****", $error->getTraceAsString());
|
||||
echo "</pre>";
|
||||
echo "<a href='/'>Go back</a>";
|
||||
});
|
||||
|
||||
Flight::map('notFound', function () {
|
||||
echo '<span id="infotext">Route text:</span> The requested URL was not found';
|
||||
echo "<a href='/'>Go back</a>";
|
||||
});
|
||||
|
||||
echo '
|
||||
<style>
|
||||
ul {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
li {
|
||||
float: left;
|
||||
}
|
||||
#infotext {
|
||||
font-weight: bold;
|
||||
color: blueviolet;
|
||||
}
|
||||
li a {
|
||||
display: block;
|
||||
color: white;
|
||||
text-align: center;
|
||||
padding: 14px 16px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
li a:hover {
|
||||
background-color: #111;
|
||||
}
|
||||
#container {
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
margin: 20px 0;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
#debugrequest {
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
margin: 20px 0;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
</style>
|
||||
<ul>
|
||||
<li><a href="/">Root Route</a></li>
|
||||
<li><a href="/test">Test Route</a></li>
|
||||
<li><a href="/user/John">User Route with Parameter (John)</a></li>
|
||||
<li><a href="/group/test">Grouped Test Route</a></li>
|
||||
<li><a href="/group/user/Jane">Grouped User Route with Parameter (Jane)</a></li>
|
||||
<li><a href="/alias">Alias Route</a></li>
|
||||
<li><a href="/protected">Protected path</a></li>
|
||||
<li><a href="/template/templatevariable">Template path</a></li>
|
||||
<li><a href="/querytestpath?test=1&variable2=uuid&variable3=tester">Query path</a></li>
|
||||
<li><a href="/postpage">Post method test page - should be 404</a></li>
|
||||
<li><a href="' . Flight::getUrl('final_group') . '">Mega group</a></li>
|
||||
<li><a href="/error">Error</a></li>
|
||||
<li><a href="/json">JSON</a></li>
|
||||
<li><a href="/jsonp?jsonp=myjson">JSONP</a></li>
|
||||
<li><a href="/json-halt">JSON Halt</a></li>
|
||||
<li><a href="/halt">Halt</a></li>
|
||||
<li><a href="/redirect">Redirect</a></li>
|
||||
</ul>';
|
||||
|
||||
Flight::before('start', function () {
|
||||
echo '<div id="container">';
|
||||
});
|
||||
|
||||
Flight::after('start', function () {
|
||||
echo '</div>';
|
||||
echo '<div id="debugrequest">';
|
||||
echo "Request information<pre>";
|
||||
print_r(Flight::request());
|
||||
echo "</pre>";
|
||||
echo "</div>";
|
||||
});
|
||||
|
||||
Flight::start();
|
||||
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests\views\components;
|
||||
|
||||
use flight\template\Component;
|
||||
use Override;
|
||||
|
||||
if (!class_exists('AnotherClassComponent')) {
|
||||
class AnotherClassComponent extends Component
|
||||
{
|
||||
#[Override]
|
||||
public function html(): string
|
||||
{
|
||||
return 'another-class-component';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
<h1>Hello, <?= $occupation ?> <?= $name ?></h1>
|
||||
@ -1 +0,0 @@
|
||||
<h1>Hello, <?= $name ?></h1>
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use tests\views\components\AnotherClassComponent;
|
||||
|
||||
require_once __DIR__ . '/another-class-component.php';
|
||||
|
||||
return new class extends AnotherClassComponent
|
||||
{
|
||||
#[Override]
|
||||
public function html(): string
|
||||
{
|
||||
return parent::html() . ' extended by my-class-component-that-extends-another-class-component';
|
||||
}
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use flight\template\Component;
|
||||
|
||||
return new class extends Component
|
||||
{
|
||||
public function html(): string
|
||||
{
|
||||
return 'my-class-component-with-custom-script-tag';
|
||||
}
|
||||
|
||||
public function js(): string
|
||||
{
|
||||
return <<<'js'
|
||||
<script type="module" data-component="my-class-component-with-custom-script-tag">
|
||||
console.log('my-class-component-with-custom-script-tag')
|
||||
</script>
|
||||
js;
|
||||
}
|
||||
};
|
||||
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use flight\template\Component;
|
||||
|
||||
return new class extends Component
|
||||
{
|
||||
public function html(): string
|
||||
{
|
||||
return <<<'html'
|
||||
<span class="my-class-component-with-custom-style-tag">
|
||||
my-class-component-with-custom-style-tag
|
||||
</span>
|
||||
html;
|
||||
}
|
||||
|
||||
public function css(): string
|
||||
{
|
||||
return <<<'css'
|
||||
<style media="print" data-component="my-class-component-with-custom-style-tag">
|
||||
.my-class-component-with-custom-style-tag {
|
||||
color: purple;
|
||||
}
|
||||
</style>
|
||||
css;
|
||||
}
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use flight\template\Component;
|
||||
|
||||
return new class($name, $occupation) extends Component
|
||||
{
|
||||
private string $name;
|
||||
private string $occupation;
|
||||
|
||||
public function __construct(string $name, string $occupation)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->occupation = $occupation;
|
||||
}
|
||||
|
||||
public function html(): string
|
||||
{
|
||||
return "class-component-with-props: $this->occupation $this->name";
|
||||
}
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use flight\template\Component;
|
||||
|
||||
return new class extends Component
|
||||
{
|
||||
#[Override]
|
||||
public function html(): string
|
||||
{
|
||||
return 'my-class-component-with-scripts';
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function js(): string
|
||||
{
|
||||
return <<<'js'
|
||||
console.log('my-class-component-with-scripts')
|
||||
js;
|
||||
}
|
||||
};
|
||||
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use flight\template\Component;
|
||||
|
||||
return new class extends Component
|
||||
{
|
||||
#[Override]
|
||||
public function html(): string
|
||||
{
|
||||
return <<<'html'
|
||||
<span class="my-class-component-with-styles">
|
||||
my-class-component-with-styles
|
||||
</span>
|
||||
html;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function css(): string
|
||||
{
|
||||
return <<<'css'
|
||||
.my-class-component-with-styles {
|
||||
color: red;
|
||||
}
|
||||
css;
|
||||
}
|
||||
};
|
||||
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use flight\template\Component;
|
||||
|
||||
return new class extends Component
|
||||
{
|
||||
#[Override]
|
||||
public function html(): string
|
||||
{
|
||||
return 'my-class-component';
|
||||
}
|
||||
};
|
||||
@ -1,4 +0,0 @@
|
||||
<div>
|
||||
my-component-with-subcomponent
|
||||
<f-subcomponent />
|
||||
</div>
|
||||
@ -1 +0,0 @@
|
||||
my-component
|
||||
@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return fn (string $name, string $occupation): string =>
|
||||
"functional-component-with-individual-props: $occupation $name";
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return fn (...$props): string => sprintf(
|
||||
'functional-component-with-props: %s %s',
|
||||
$props[1] ?? '',
|
||||
$props[0] ?? ''
|
||||
);
|
||||
@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return fn (): string => 'my-functional-component';
|
||||
@ -1 +0,0 @@
|
||||
subcomponent
|
||||
@ -1 +1 @@
|
||||
Hello, <?= $name ?>!
|
||||
Hello, <?php echo $name; ?>!
|
||||
@ -1,5 +0,0 @@
|
||||
<f-my-class-component-with-styles />
|
||||
<f-my-class-component-with-styles />
|
||||
|
||||
<f-my-class-component-with-scripts />
|
||||
<f-my-class-component-with-scripts />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-class-component-that-extends-another-class-component />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-class-component-with-custom-script-tag />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-class-component-with-custom-style-tag />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-class-component-with-props name="<?= $name ?>" occupation="<?= $occupation ?>" />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-class-component-with-scripts />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-class-component-with-styles />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-class-component />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-component-from-another-path />
|
||||
@ -1 +0,0 @@
|
||||
<<?= $prefix ?>-my-component />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-component />
|
||||
@ -1 +0,0 @@
|
||||
<?php $this->render('components/my-component') ?>
|
||||
@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
<f-greeting name="<?= $name ?>" />
|
||||
</body>
|
||||
</html>
|
||||
@ -1 +0,0 @@
|
||||
<f-greeting name="<?= $name ?>" />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-component-with-subcomponent />
|
||||
@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
<f-greeting-with-two-props name="<?= $name ?>" occupation="<?= $occupation ?>" />
|
||||
</body>
|
||||
</html>
|
||||
@ -1 +0,0 @@
|
||||
<f-my-functional-component-with-individual-props occupation="<?= $occupation ?>" name="<?= $name ?>" />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-functional-component-with-props name="<?= $name ?>" occupation="<?= $occupation ?>" />
|
||||
@ -1 +0,0 @@
|
||||
<f-my-functional-component />
|
||||
@ -1,7 +0,0 @@
|
||||
<ul>
|
||||
<?php for ($i = 1; $i <= 2; ++$i) : ?>
|
||||
<li>
|
||||
<f-my-component />
|
||||
</li>
|
||||
<?php endfor ?>
|
||||
</ul>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue