Skip to content

Commit d566644

Browse files
committed
baked plugin skeleton
1 parent 56f8611 commit d566644

File tree

7 files changed

+181
-0
lines changed

7 files changed

+181
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/composer.lock
2+
/composer.phar
3+
/phpunit.xml
4+
/.phpunit.result.cache
5+
/phpunit.phar
6+
/config/Migrations/schema-dump-default.lock
7+
/vendor/
8+
/.idea/

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "your-name-here/json-api-exception",
3+
"description": "JsonApiException plugin for CakePHP",
4+
"type": "cakephp-plugin",
5+
"license": "MIT",
6+
"require": {
7+
"php": ">=7.2",
8+
"cakephp/cakephp": "~4.2.0"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "^8.5 || ^9.3"
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"JsonApiException\\": "src/"
16+
}
17+
},
18+
"autoload-dev": {
19+
"psr-4": {
20+
"JsonApiException\\Test\\": "tests/",
21+
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
22+
}
23+
}
24+
}

phpunit.xml.dist

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
colors="true"
4+
processIsolation="false"
5+
stopOnFailure="false"
6+
bootstrap="tests/bootstrap.php"
7+
>
8+
<php>
9+
<ini name="memory_limit" value="-1"/>
10+
<ini name="apc.enable_cli" value="1"/>
11+
</php>
12+
13+
<!-- Add any additional test suites you want to run here -->
14+
<testsuites>
15+
<testsuite name="JsonApiException">
16+
<directory>tests/TestCase/</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<!-- Setup a listener for fixtures -->
21+
<listeners>
22+
<listener class="Cake\TestSuite\Fixture\FixtureInjector">
23+
<arguments>
24+
<object class="Cake\TestSuite\Fixture\FixtureManager"/>
25+
</arguments>
26+
</listener>
27+
</listeners>
28+
29+
<filter>
30+
<whitelist>
31+
<directory suffix=".php">src/</directory>
32+
</whitelist>
33+
</filter>
34+
35+
</phpunit>

src/Controller/AppController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace JsonApiException\Controller;
5+
6+
use App\Controller\AppController as BaseController;
7+
8+
class AppController extends BaseController
9+
{
10+
}

src/Plugin.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace JsonApiException;
5+
6+
use Cake\Core\BasePlugin;
7+
use Cake\Core\PluginApplicationInterface;
8+
use Cake\Http\MiddlewareQueue;
9+
use Cake\Routing\RouteBuilder;
10+
11+
/**
12+
* Plugin for JsonApiException
13+
*/
14+
class Plugin extends BasePlugin
15+
{
16+
/**
17+
* Load all the plugin configuration and bootstrap logic.
18+
*
19+
* The host application is provided as an argument. This allows you to load
20+
* additional plugin dependencies, or attach events.
21+
*
22+
* @param \Cake\Core\PluginApplicationInterface $app The host application
23+
* @return void
24+
*/
25+
public function bootstrap(PluginApplicationInterface $app): void
26+
{
27+
}
28+
29+
/**
30+
* Add routes for the plugin.
31+
*
32+
* If your plugin has many routes and you would like to isolate them into a separate file,
33+
* you can create `$plugin/config/routes.php` and delete this method.
34+
*
35+
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
36+
* @return void
37+
*/
38+
public function routes(RouteBuilder $routes): void
39+
{
40+
$routes->plugin(
41+
'JsonApiException',
42+
['path' => '/json-api-exception'],
43+
function (RouteBuilder $builder) {
44+
// Add custom routes here
45+
46+
$builder->fallbacks();
47+
}
48+
);
49+
parent::routes($routes);
50+
}
51+
52+
/**
53+
* Add middleware for the plugin.
54+
*
55+
* @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to update.
56+
* @return \Cake\Http\MiddlewareQueue
57+
*/
58+
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
59+
{
60+
// Add your middlewares here
61+
62+
return $middlewareQueue;
63+
}
64+
}

tests/bootstrap.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Test suite bootstrap for JsonApiException.
6+
*
7+
* This function is used to find the location of CakePHP whether CakePHP
8+
* has been installed as a dependency of the plugin, or the plugin is itself
9+
* installed as a dependency of an application.
10+
*/
11+
$findRoot = function ($root) {
12+
do {
13+
$lastRoot = $root;
14+
$root = dirname($root);
15+
if (is_dir($root . '/vendor/cakephp/cakephp')) {
16+
return $root;
17+
}
18+
} while ($root !== $lastRoot);
19+
20+
throw new Exception("Cannot find the root of the application, unable to run tests");
21+
};
22+
$root = $findRoot(__FILE__);
23+
unset($findRoot);
24+
25+
chdir($root);
26+
27+
require_once $root . '/vendor/autoload.php';
28+
29+
/**
30+
* Define fallback values for required constants and configuration.
31+
* To customize constants and configuration remove this require
32+
* and define the data required by your plugin here.
33+
*/
34+
require_once $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
35+
36+
if (file_exists($root . '/config/bootstrap.php')) {
37+
require $root . '/config/bootstrap.php';
38+
39+
return;
40+
}

webroot/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)