-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
2,209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/* | ||
* PSX is an open source PHP framework to develop RESTful APIs. | ||
* For the current version and information visit <https://phpsx.org> | ||
* | ||
* Copyright 2010-2023 Christoph Kappestein <christoph.kappestein@gmail.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace PSX\Api\Tests\Generator\Server; | ||
|
||
use PSX\Api\Generator\Server\PHP; | ||
use PSX\Api\Tests\Generator\GeneratorTestCase; | ||
|
||
/** | ||
* PHPTest | ||
* | ||
* @author Christoph Kappestein <christoph.kappestein@gmail.com> | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 | ||
* @link https://phpsx.org | ||
*/ | ||
class PHPTest extends GeneratorTestCase | ||
{ | ||
public function testGenerate() | ||
{ | ||
$generator = new PHP(); | ||
|
||
$result = $generator->generate($this->getSpecification()); | ||
$target = __DIR__ . '/resource/php'; | ||
|
||
$this->writeChunksToFolder($result, $target); | ||
|
||
$this->assertFileExists($target . '/src/Controller/App.php'); | ||
$this->assertFileExists($target . '/src/Model/Entry.php'); | ||
} | ||
|
||
public function testGenerateCollection() | ||
{ | ||
$generator = new PHP(); | ||
|
||
$result = $generator->generate($this->getSpecificationCollection()); | ||
$target = __DIR__ . '/resource/php_complex'; | ||
|
||
$this->writeChunksToFolder($result, $target); | ||
|
||
$this->assertFileExists($target . '/src/Controller/Foo/Bar.php'); | ||
$this->assertFileExists($target . '/src/Controller/Foo/Baz.php'); | ||
$this->assertFileExists($target . '/src/Controller/Bar.php'); | ||
$this->assertFileExists($target . '/src/Model/Entry.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
APP_URL=http://127.0.0.1/projects/psx/public/ | ||
APP_ENV=dev | ||
APP_DEBUG=on | ||
APP_CONNECTION=mysql://root:test1234@localhost/psx | ||
APP_MAILER=native://default | ||
SDKGEN_CLIENT_ID= | ||
SDKGEN_CLIENT_SECRET= |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
/* | ||
* PSX is a open source PHP framework to develop RESTful APIs. | ||
* For the current version and informations visit <http://phpsx.org> | ||
* | ||
* Copyright 2010-2023 Christoph Kappestein <christoph.kappestein@gmail.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
$files = array( | ||
__DIR__ . '/../vendor/autoload.php', | ||
__DIR__ . '/../../../autoload.php', | ||
); | ||
|
||
$autoloadFile = null; | ||
|
||
foreach ($files as $file) { | ||
if (file_exists($file)) { | ||
$autoloadFile = $file; | ||
break; | ||
} | ||
} | ||
|
||
if (!empty($autoloadFile)) { | ||
require_once($autoloadFile); | ||
|
||
$containerFile = strstr($autoloadFile, 'autoload.php', true) . '../container.php'; | ||
|
||
if (is_file($containerFile)) { | ||
$container = require_once($containerFile); | ||
|
||
PSX\Framework\Bootstrap::setupEnvironment(); | ||
|
||
$container->get(\Symfony\Component\Console\Application::class)->run(); | ||
} else { | ||
die('Could not find container at: ' . $containerFile); | ||
} | ||
} else { | ||
die('You need to set up the project dependencies through composer'); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "psx/psx", | ||
"type": "project", | ||
"description": "PHP REST API Framework", | ||
"keywords": ["API", "Framework", "REST"], | ||
"homepage": "https://phpsx.org", | ||
"license": "Apache-2.0", | ||
"authors": [ | ||
{ | ||
"name": "Christoph Kappestein", | ||
"email": "christoph.kappestein@gmail.com", | ||
"homepage": "https://chrisk.app/" | ||
} | ||
], | ||
"require": { | ||
"php": ">=8.1", | ||
"psx/framework": "^7.0" | ||
}, | ||
"require-dev": { | ||
"vimeo/psalm": "^5.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"App\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"App\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use Monolog\Logger; | ||
use function Symfony\Component\DependencyInjection\Loader\Configurator\env; | ||
|
||
return [ | ||
|
||
// The url to the psx public folder (i.e. http://api.acme.com or http://127.0.0.1/psx/public) | ||
'psx_url' => env('APP_URL')->string(), | ||
|
||
// The input path 'index.php/' or '' if every request is served to the index.php file | ||
'psx_dispatch' => '', | ||
|
||
// Defines the current environment i.e. prod or dev | ||
'psx_env' => env('APP_ENV')->string(), | ||
|
||
// Whether the app runs in debug mode or not. If not error reporting is set to 0, also several caches are used if | ||
// the debug mode is false | ||
'psx_debug' => env('APP_DEBUG')->bool(), | ||
|
||
// Database parameters which are used for the doctrine DBAL connection | ||
// https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html | ||
'psx_connection' => env('APP_CONNECTION')->string(), | ||
|
||
// Mailer connection which is used to send mails | ||
// https://symfony.com/doc/current/mailer.html#using-built-in-transports | ||
'psx_mailer' => env('APP_MAILER')->string(), | ||
|
||
// Optional an SDKgen access token which adds support for different SDK generators | ||
// https://sdkgen.app/ | ||
'sdkgen_client_id' => env('SDKGEN_CLIENT_ID')->string(), | ||
'sdkgen_client_secret' => env('SDKGEN_CLIENT_SECRET')->string(), | ||
|
||
// The log level | ||
'psx_log_level' => Logger::ERROR, | ||
|
||
// Folder locations | ||
'psx_path_cache' => __DIR__ . '/cache', | ||
'psx_path_src' => __DIR__ . '/src', | ||
'psx_path_log' => __DIR__ . '/log', | ||
|
||
// Supported writers | ||
'psx_supported_writer' => [ | ||
\PSX\Data\Writer\Json::class, | ||
\PSX\Data\Writer\Jsonp::class, | ||
\PSX\Data\Writer\Jsonx::class, | ||
], | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return \PSX\Framework\Dependency\ContainerBuilder::build( | ||
__DIR__, | ||
true, | ||
__DIR__ . '/vendor/psx/framework/resources/container.php', | ||
__DIR__ . '/resources/container.php', | ||
); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
errorLevel="1" | ||
resolveFromConfigFile="true" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" | ||
> | ||
<projectFiles> | ||
<directory name="src" /> | ||
<ignoreFiles> | ||
<directory name="vendor" /> | ||
</ignoreFiles> | ||
</projectFiles> | ||
</psalm> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/* | ||
* PSX is a open source PHP framework to develop RESTful APIs. | ||
* For the current version and informations visit <http://phpsx.org> | ||
* | ||
* Copyright 2010-2023 Christoph Kappestein <christoph.kappestein@gmail.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
require_once(__DIR__ . '/../vendor/autoload.php'); | ||
|
||
$container = require_once(__DIR__ . '/../container.php'); | ||
|
||
$engine = new \PSX\Engine\WebServer\Engine($container->getParameter('psx_url')); | ||
$dispatcher = $container->get(\PSX\Engine\DispatchInterface::class); | ||
$environment = new \PSX\Framework\Environment\Environment($dispatcher, $engine); | ||
|
||
return $environment->serve(); |
27 changes: 27 additions & 0 deletions
27
tests/Generator/Server/resource/php/resources/container.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use PSX\Framework\Controller\ControllerInterface; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $container) { | ||
$services = $container->services(); | ||
$services->defaults() | ||
->autowire() | ||
->autoconfigure(); | ||
|
||
$services | ||
->instanceof(ControllerInterface::class) | ||
->tag('psx.controller'); | ||
|
||
$services->load('App\\Controller\\', __DIR__ . '/../src/Controller') | ||
->public(); | ||
|
||
/* | ||
$services->load('App\\Service\\', __DIR__ . '/../src/Service') | ||
->public(); | ||
$services->load('App\\Table\\', __DIR__ . '/../src/Table/*.php') | ||
->public(); | ||
*/ | ||
|
||
}; |
42 changes: 42 additions & 0 deletions
42
tests/Generator/Server/resource/php/src/Controller/App.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
class App extends ControllerAbstract | ||
{ | ||
#[Get] | ||
#[Path('/foo/:name/:type')] | ||
#[StatusCode(200)] | ||
public function get(#[Param('name')] string $name, #[Param('type')] string $type, #[Query('startIndex')] int $startIndex, #[Query('float')] float $float, #[Query('boolean')] bool $boolean, #[Query('date')] \PSX\DateTime\LocalDate $date, #[Query('datetime')] \PSX\DateTime\LocalDateTime $datetime, #[Query('args')] Entry $args): EntryCollection { | ||
// @TODO implement method | ||
} | ||
|
||
#[Post] | ||
#[Path('/foo/:name/:type')] | ||
#[StatusCode(201)] | ||
public function create(#[Param('name')] string $name, #[Param('type')] string $type, #[Body] EntryCreate $payload): EntryMessage { | ||
// @TODO implement method | ||
} | ||
|
||
#[Put] | ||
#[Path('/foo/:name/:type')] | ||
#[StatusCode(200)] | ||
public function update(#[Param('name')] string $name, #[Param('type')] string $type, #[Body] \PSX\Record\Record $payload): \PSX\Record\Record { | ||
// @TODO implement method | ||
} | ||
|
||
#[Delete] | ||
#[Path('/foo/:name/:type')] | ||
#[StatusCode(204)] | ||
public function delete(#[Param('name')] string $name, #[Param('type')] string $type, #[Body] EntryDelete $payload): EntryMessage { | ||
// @TODO implement method | ||
} | ||
|
||
#[Patch] | ||
#[Path('/foo/:name/:type')] | ||
#[StatusCode(200)] | ||
public function patch(#[Param('name')] string $name, #[Param('type')] string $type, #[Body] array $payload): array { | ||
// @TODO implement method | ||
} | ||
|
||
} |
Oops, something went wrong.