moved to its own repo
This commit is contained in:
		
							parent
							
								
									10b9a78d31
								
							
						
					
					
						commit
						15f02e6f0a
					
				|  | @ -1,27 +1,8 @@ | ||||||
| # ---> CakePHP | /composer.lock | ||||||
| # CakePHP 3 | /composer.phar | ||||||
| 
 | /phpunit.xml | ||||||
| /vendor/* | /.phpunit.result.cache | ||||||
| /config/app.php | /phpunit.phar | ||||||
| 
 | /config/Migrations/schema-dump-default.lock | ||||||
| /tmp/cache/models/* | /vendor/ | ||||||
| !/tmp/cache/models/empty | /.idea/ | ||||||
| /tmp/cache/persistent/* |  | ||||||
| !/tmp/cache/persistent/empty |  | ||||||
| /tmp/cache/views/* |  | ||||||
| !/tmp/cache/views/empty |  | ||||||
| /tmp/sessions/* |  | ||||||
| !/tmp/sessions/empty |  | ||||||
| /tmp/tests/* |  | ||||||
| !/tmp/tests/empty |  | ||||||
| 
 |  | ||||||
| /logs/* |  | ||||||
| !/logs/empty |  | ||||||
| 
 |  | ||||||
| # CakePHP 2 |  | ||||||
| 
 |  | ||||||
| /app/tmp/* |  | ||||||
| /app/Config/core.php |  | ||||||
| /app/Config/database.php |  | ||||||
| /vendors/* |  | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -0,0 +1,34 @@ | ||||||
|  | { | ||||||
|  |     "name": "hi-powered-dev/cheese-cake", | ||||||
|  |     "description": "A CakePHP plugin with misc. goodies ", | ||||||
|  |     "type": "cakephp-plugin", | ||||||
|  |     "license": "AGPL-3.0-or-later", | ||||||
|  |     "keywords": [ | ||||||
|  |         "cakephp" | ||||||
|  |     ], | ||||||
|  |     "authors": [ | ||||||
|  |         { | ||||||
|  |             "name": "HiPoweredDev", | ||||||
|  |             "homepage": "https://hipowered.dev", | ||||||
|  |             "role": "Author" | ||||||
|  |         } | ||||||
|  |     ], | ||||||
|  |     "require": { | ||||||
|  |         "php": ">=8.1", | ||||||
|  |         "cakephp/cakephp": "^5.0.0" | ||||||
|  |     }, | ||||||
|  |     "require-dev": { | ||||||
|  |         "phpunit/phpunit": "^10.1" | ||||||
|  |     }, | ||||||
|  |     "autoload": { | ||||||
|  |         "psr-4": { | ||||||
|  |             "CheeseCake\\": "src/" | ||||||
|  |         } | ||||||
|  |     }, | ||||||
|  |     "autoload-dev": { | ||||||
|  |         "psr-4": { | ||||||
|  |             "CheeseCake\\Test\\": "tests/", | ||||||
|  |             "Cake\\Test\\": "vendor/cakephp/cakephp/tests/" | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,22 @@ | ||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache"> | ||||||
|  |   <php> | ||||||
|  |     <ini name="memory_limit" value="-1"/> | ||||||
|  |     <ini name="apc.enable_cli" value="1"/> | ||||||
|  |   </php> | ||||||
|  |   <!-- Add any additional test suites you want to run here --> | ||||||
|  |   <testsuites> | ||||||
|  |     <testsuite name="CheeseCake"> | ||||||
|  |       <directory>tests/TestCase/</directory> | ||||||
|  |     </testsuite> | ||||||
|  |   </testsuites> | ||||||
|  |   <!-- Setup the extension for fixtures --> | ||||||
|  |   <extensions> | ||||||
|  |     <bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/> | ||||||
|  |   </extensions> | ||||||
|  |   <source> | ||||||
|  |     <include> | ||||||
|  |       <directory suffix=".php">src/</directory> | ||||||
|  |     </include> | ||||||
|  |   </source> | ||||||
|  | </phpunit> | ||||||
|  | @ -0,0 +1,84 @@ | ||||||
|  | <?php | ||||||
|  | declare(strict_types=1); | ||||||
|  | 
 | ||||||
|  | namespace CheeseCake; | ||||||
|  | 
 | ||||||
|  | use Cake\Console\CommandCollection; | ||||||
|  | use Cake\Core\BasePlugin; | ||||||
|  | use Cake\Core\ContainerInterface; | ||||||
|  | use Cake\Core\PluginApplicationInterface; | ||||||
|  | use Cake\Http\MiddlewareQueue; | ||||||
|  | use Cake\Routing\RouteBuilder; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Plugin for CheeseCake | ||||||
|  |  */ | ||||||
|  | class CheeseCakePlugin extends BasePlugin | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Load all the plugin configuration and bootstrap logic. | ||||||
|  |      * | ||||||
|  |      * The host application is provided as an argument. This allows you to load | ||||||
|  |      * additional plugin dependencies, or attach events. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Core\PluginApplicationInterface $app The host application | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function bootstrap(PluginApplicationInterface $app): void | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Add routes for the plugin. | ||||||
|  |      * | ||||||
|  |      * If your plugin has many routes and you would like to isolate them into a separate file, | ||||||
|  |      * you can create `$plugin/config/routes.php` and delete this method. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Routing\RouteBuilder $routes The route builder to update. | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function routes(RouteBuilder $routes): void | ||||||
|  |     { | ||||||
|  |         parent::routes($routes); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Add middleware for the plugin. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update. | ||||||
|  |      * @return \Cake\Http\MiddlewareQueue | ||||||
|  |      */ | ||||||
|  |     public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue | ||||||
|  |     { | ||||||
|  |         // Add your middlewares here
 | ||||||
|  | 
 | ||||||
|  |         return $middlewareQueue; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Add commands for the plugin. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Console\CommandCollection $commands The command collection to update. | ||||||
|  |      * @return \Cake\Console\CommandCollection | ||||||
|  |      */ | ||||||
|  |     public function console(CommandCollection $commands): CommandCollection | ||||||
|  |     { | ||||||
|  |         // Add your commands here
 | ||||||
|  | 
 | ||||||
|  |         $commands = parent::console($commands); | ||||||
|  | 
 | ||||||
|  |         return $commands; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Register application container services. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Core\ContainerInterface $container The Container to update. | ||||||
|  |      * @return void | ||||||
|  |      * @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
 | ||||||
|  |      */ | ||||||
|  |     public function services(ContainerInterface $container): void | ||||||
|  |     { | ||||||
|  |         // Add your services here
 | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,10 @@ | ||||||
|  | <?php | ||||||
|  | declare(strict_types=1); | ||||||
|  | 
 | ||||||
|  | namespace CheeseCake\Controller; | ||||||
|  | 
 | ||||||
|  | use App\Controller\AppController as BaseController; | ||||||
|  | 
 | ||||||
|  | class AppController extends BaseController | ||||||
|  | { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,55 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         1.7.4 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Command", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\Command\\Command', | ||||||
|  |         'Cake\\Console\\Arguments', | ||||||
|  |         'Cake\\Console\\ConsoleIo', | ||||||
|  |         'Cake\\Console\\ConsoleOptionParser', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} command. | ||||||
|  |  */ | ||||||
|  | class {{ name }}Command extends Command | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Hook method for defining this command's option parser. | ||||||
|  |      * | ||||||
|  |      * @see https://book.cakephp.org/4/en/console-commands/commands.html#defining-arguments-and-options | ||||||
|  |      * @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined | ||||||
|  |      * @return \Cake\Console\ConsoleOptionParser The built parser. | ||||||
|  |      */ | ||||||
|  |     public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser | ||||||
|  |     { | ||||||
|  |         $parser = parent::buildOptionParser($parser); | ||||||
|  | 
 | ||||||
|  |         return $parser; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Implement this method with your command's logic. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Console\Arguments $args The command arguments. | ||||||
|  |      * @param \Cake\Console\ConsoleIo $io The console io | ||||||
|  |      * @return int|null|void The exit code or null for success | ||||||
|  |      */ | ||||||
|  |     public function execute(Arguments $args, ConsoleIo $io) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,37 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.6.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Command\\Helper", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\Console\\Helper', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} command helper. | ||||||
|  |  */ | ||||||
|  | class {{ name }}Helper extends Helper | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * This method should output content using `$this->_io`. | ||||||
|  |      * | ||||||
|  |      * @param array $args The arguments for the helper. | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function output(array $args): void | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,35 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Controller\\Component", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\Controller\\Component', | ||||||
|  |         'Cake\\Controller\\ComponentRegistry', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} component | ||||||
|  |  */ | ||||||
|  | class {{ name }}Component extends Component | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Default configuration. | ||||||
|  |      * | ||||||
|  |      * @var array<string, mixed> | ||||||
|  |      */ | ||||||
|  |     protected array $_defaultConfig = []; | ||||||
|  | } | ||||||
|  | @ -0,0 +1,62 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * Controller bake template file | ||||||
|  |  * | ||||||
|  |  * Allows templating of Controllers generated from bake. | ||||||
|  |  * | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Controller#{prefix}", | ||||||
|  |     classImports: (plugin or prefix) ? ["#{baseNamespace}\\Controller\\AppController"] : [], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} Controller | ||||||
|  |  * | ||||||
|  | {% if defaultModel %} | ||||||
|  |  * @property \{{ defaultModel }} ${{ name }} | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- for component in components %} | ||||||
|  | {% set classInfo = Bake.classInfo(component, 'Controller/Component', 'Component') %} | ||||||
|  |  * @property {{ classInfo.fqn }} ${{ classInfo.name }} | ||||||
|  | {% endfor %} | ||||||
|  |  */ | ||||||
|  | class {{ name }}Controller extends AppController | ||||||
|  | { | ||||||
|  | {% if components or helpers %} | ||||||
|  |     /** | ||||||
|  |      * Initialize controller | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function initialize(): void | ||||||
|  |     { | ||||||
|  |         parent::initialize(); | ||||||
|  | 
 | ||||||
|  | {% for component in components %} | ||||||
|  |         $this->loadComponent('{{ component }}'); | ||||||
|  | {% endfor %} | ||||||
|  | {% if helpers %} | ||||||
|  |         $this->viewBuilder()->setHelpers({{ Bake.exportArray(helpers)|raw }}); | ||||||
|  | {% endif %} | ||||||
|  |     } | ||||||
|  | {% if actions|length %}{{ "\n" }}{% endif %} | ||||||
|  | {% endif %} | ||||||
|  | {%- for action in actions %} | ||||||
|  | {% if loop.index > 1 %}{{ "\n" }}{% endif %} | ||||||
|  |     {{- element('Bake.Controller/' ~ action) -}} | ||||||
|  | {% endfor %} | ||||||
|  | } | ||||||
|  | @ -0,0 +1,62 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  | * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  | * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  | * | ||||||
|  | * Licensed under The MIT License | ||||||
|  | * For full copyright and license information, please see the LICENSE.txt | ||||||
|  | * Redistributions of files must retain the above copyright notice. | ||||||
|  | * | ||||||
|  | * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  | * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  | * @since         2.0.0 | ||||||
|  | * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  | */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Form", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\Form\\Form', | ||||||
|  |         'Cake\\Form\\Schema', | ||||||
|  |         'Cake\\Validation\\Validator', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} Form. | ||||||
|  |  */ | ||||||
|  | class {{ name }}Form extends Form | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Builds the schema for the modelless form | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Form\Schema $schema From schema | ||||||
|  |      * @return \Cake\Form\Schema | ||||||
|  |      */ | ||||||
|  |     protected function _buildSchema(Schema $schema): Schema | ||||||
|  |     { | ||||||
|  |         return $schema; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Form validation builder | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Validation\Validator $validator to use against the form | ||||||
|  |      * @return \Cake\Validation\Validator | ||||||
|  |      */ | ||||||
|  |     public function validationDefault(Validator $validator): Validator | ||||||
|  |     { | ||||||
|  |         return $validator; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Defines what to execute once the Form is processed | ||||||
|  |      * | ||||||
|  |      * @param array $data Form data. | ||||||
|  |      * @return bool | ||||||
|  |      */ | ||||||
|  |     protected function _execute(array $data): bool | ||||||
|  |     { | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,34 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Mailer", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\Mailer\\Mailer', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} mailer. | ||||||
|  |  */ | ||||||
|  | class {{ name }}Mailer extends Mailer | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Mailer's name. | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     public static string $name = '{{ name }}'; | ||||||
|  | } | ||||||
|  | @ -0,0 +1,42 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Middleware", | ||||||
|  |     classImports: [ | ||||||
|  |         'Psr\\Http\\Message\\ResponseInterface', | ||||||
|  |         'Psr\\Http\\Message\\ServerRequestInterface', | ||||||
|  |         'Psr\\Http\\Server\\MiddlewareInterface', | ||||||
|  |         'Psr\\Http\\Server\\RequestHandlerInterface', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} middleware | ||||||
|  |  */ | ||||||
|  | class {{ name }}Middleware implements MiddlewareInterface | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Process method. | ||||||
|  |      * | ||||||
|  |      * @param \Psr\Http\Message\ServerRequestInterface $request The request. | ||||||
|  |      * @param \Psr\Http\Server\RequestHandlerInterface $handler The request handler. | ||||||
|  |      * @return \Psr\Http\Message\ResponseInterface A response. | ||||||
|  |      */ | ||||||
|  |     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||||||
|  |     { | ||||||
|  |         return $handler->handle($request); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,35 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Model\\Behavior", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\ORM\\Behavior', | ||||||
|  |         'Cake\\ORM\\Table', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} behavior | ||||||
|  |  */ | ||||||
|  | class {{ name }}Behavior extends Behavior | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Default configuration. | ||||||
|  |      * | ||||||
|  |      * @var array<string, mixed> | ||||||
|  |      */ | ||||||
|  |     protected array $_defaultConfig = []; | ||||||
|  | } | ||||||
|  | @ -0,0 +1,76 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {% set propertyHintMap = DocBlock.buildEntityPropertyHintTypeMap(propertySchema ?: []) %} | ||||||
|  | {% set associationHintMap = DocBlock.buildEntityAssociationHintTypeMap(propertySchema ?: []) %} | ||||||
|  | {% set annotations = DocBlock.propertyHints(propertyHintMap) %} | ||||||
|  | 
 | ||||||
|  | {%- if associationHintMap %} | ||||||
|  |     {%- set annotations = annotations|merge(['']) %} | ||||||
|  |     {%- set annotations = annotations|merge(DocBlock.propertyHints(associationHintMap)) %} | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- set accessible = Bake.getFieldAccessibility(fields, primaryKey) %} | ||||||
|  | 
 | ||||||
|  | {%- set generatedProperties = [] %} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: fileBuilder.namespace, | ||||||
|  |     classImports: fileBuilder.classImports(['Cake\\ORM\\Entity']), | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | {{ DocBlock.classDescription(name, 'Entity', annotations)|raw }} | ||||||
|  | class {{ name }} extends Entity{{ fileBuilder.classBuilder.implements ? ' implements ' ~ fileBuilder.classBuilder.implements|join(', ') : '' }} | ||||||
|  | { | ||||||
|  | {% set userConstants = fileBuilder.classBuilder.userConstants([]) %} | ||||||
|  | {% if userConstants %} | ||||||
|  |     {{~ Bake.concat('\n\n', userConstants) }} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {% if accessible %} | ||||||
|  | {%- set generatedProperties = generatedProperties|merge(['_accessible']) %} | ||||||
|  |     /** | ||||||
|  |      * Fields that can be mass assigned using newEntity() or patchEntity(). | ||||||
|  |      * | ||||||
|  |      * Note that when '*' is set to true, this allows all unspecified fields to | ||||||
|  |      * be mass assigned. For security purposes, it is advised to set '*' to false | ||||||
|  |      * (or remove it), and explicitly make individual fields accessible as needed. | ||||||
|  |      * | ||||||
|  |      * @var array<string, bool> | ||||||
|  |      */ | ||||||
|  |     protected array $_accessible = {{ Bake.exportVar(accessible, 1)|raw }}; | ||||||
|  | {% endif %} | ||||||
|  | {% if accessible and hidden %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {%- if hidden %} | ||||||
|  | {%- set generatedProperties = generatedProperties|merge(['_hidden']) %} | ||||||
|  |     /** | ||||||
|  |      * Fields that are excluded from JSON versions of the entity. | ||||||
|  |      * | ||||||
|  |      * @var array<string> | ||||||
|  |      */ | ||||||
|  |     protected array $_hidden = {{ Bake.exportVar(hidden, 1)|raw }}; | ||||||
|  | {% endif %} | ||||||
|  | {% set userProperties = fileBuilder.classBuilder.userProperties(generatedProperties) %} | ||||||
|  | {% if userProperties %} | ||||||
|  | 
 | ||||||
|  |     {{~ Bake.concat('\n\n', userProperties) }} | ||||||
|  | {% endif %} | ||||||
|  | {% set userFunctions = fileBuilder.classBuilder.userFunctions([]) %} | ||||||
|  | {% if userFunctions %} | ||||||
|  | 
 | ||||||
|  |     {{~ Bake.concat('\n\n', userFunctions) }} | ||||||
|  | {% endif %} | ||||||
|  | } | ||||||
|  | @ -0,0 +1,162 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {% set annotations = DocBlock.buildTableAnnotations(associations, associationInfo, behaviors, entity, namespace) %} | ||||||
|  | {% set generatedFunctions = ['initialize'] %} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: fileBuilder.namespace, | ||||||
|  |     classImports: fileBuilder.classImports(['Cake\\ORM\\Query\\SelectQuery', 'Cake\\ORM\\RulesChecker', 'Cake\\ORM\\Table', 'Cake\\Validation\\Validator']), | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | {{ DocBlock.classDescription(name, 'Model', annotations)|raw }} | ||||||
|  | class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' implements ' ~ fileBuilder.classBuilder.implements|join(', ') : '' }} | ||||||
|  | { | ||||||
|  | {% set userConstants = fileBuilder.classBuilder.userConstants([]) %} | ||||||
|  | {% if userConstants %} | ||||||
|  |     {{~ Bake.concat('\n\n', userConstants) }} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {% set userProperties = fileBuilder.classBuilder.userProperties([]) %} | ||||||
|  | {% if userProperties %} | ||||||
|  |     {{~ Bake.concat('\n\n', userProperties) }} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  |     /** | ||||||
|  |      * Initialize method | ||||||
|  |      * | ||||||
|  |      * @param array<string, mixed> $config The configuration for the Table. | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function initialize(array $config): void | ||||||
|  |     { | ||||||
|  |         parent::initialize($config); | ||||||
|  | 
 | ||||||
|  | {% if table %} | ||||||
|  |         $this->setTable('{{ table }}'); | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if displayField %} | ||||||
|  |         $this->setDisplayField({{ (displayField is iterable ? Bake.exportArray(displayField) : Bake.exportVar(displayField))|raw }}); | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if primaryKey %} | ||||||
|  |     {%- if primaryKey is iterable and primaryKey|length > 1 %} | ||||||
|  |         $this->setPrimaryKey({{ Bake.exportArray(primaryKey)|raw }}); | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- else %} | ||||||
|  |         $this->setPrimaryKey('{{ primaryKey|as_array|first }}'); | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- endif %} | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if behaviors %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- for behavior, behaviorData in behaviors %} | ||||||
|  |         $this->addBehavior('{{ behavior }}'{{ (behaviorData ? (", " ~ Bake.exportArray(behaviorData, 2)|raw ~ '') : '')|raw }}); | ||||||
|  | {% endfor %} | ||||||
|  | 
 | ||||||
|  | {%- if associations.belongsTo or associations.hasMany or associations.belongsToMany %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- for type, assocs in associations %} | ||||||
|  |     {%- for assoc in assocs %} | ||||||
|  |         {%- set assocData = [] %} | ||||||
|  |         {%- for key, val in assoc %} | ||||||
|  |             {%- if key is not same as('alias') %} | ||||||
|  |                 {%- set assocData = assocData|merge({(key): val}) %} | ||||||
|  |             {%- endif %} | ||||||
|  |         {%- endfor %} | ||||||
|  |         $this->{{ type }}('{{ assoc.alias }}', {{ Bake.exportArray(assocData, 2)|raw }}); | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- endfor %} | ||||||
|  | {% endfor %} | ||||||
|  |     } | ||||||
|  | {{- "\n" }} | ||||||
|  | 
 | ||||||
|  | {%- if validation %} | ||||||
|  | {% set generatedFunctions = generatedFunctions|merge(['validationDefault']) %} | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Default validation rules. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Validation\Validator $validator Validator instance. | ||||||
|  |      * @return \Cake\Validation\Validator | ||||||
|  |      */ | ||||||
|  |     public function validationDefault(Validator $validator): Validator | ||||||
|  |     { | ||||||
|  | {% for field, rules in validation %} | ||||||
|  | {% set validationMethods = Bake.getValidationMethods(field, rules) %} | ||||||
|  | {% if validationMethods %} | ||||||
|  |         $validator | ||||||
|  | {% for validationMethod in validationMethods %} | ||||||
|  | {% if loop.last %} | ||||||
|  | {% set validationMethod = validationMethod ~ ';' %} | ||||||
|  | {% endif %} | ||||||
|  |             {{ validationMethod|raw }} | ||||||
|  | {% endfor %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {% endfor %} | ||||||
|  |         return $validator; | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if rulesChecker %} | ||||||
|  | {% set generatedFunctions = generatedFunctions|merge(['buildRules']) %} | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Returns a rules checker object that will be used for validating | ||||||
|  |      * application integrity. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. | ||||||
|  |      * @return \Cake\ORM\RulesChecker | ||||||
|  |      */ | ||||||
|  |     public function buildRules(RulesChecker $rules): RulesChecker | ||||||
|  |     { | ||||||
|  | {% for field, rule in rulesChecker %} | ||||||
|  | {% set fields = rule.fields is defined ? Bake.exportArray(rule.fields) : Bake.exportVar(field) %} | ||||||
|  | {% set options = '' %} | ||||||
|  | {% for optionName, optionValue in rule.options %} | ||||||
|  |     {%~ set options = (loop.first ? '[' : options) ~ "'#{optionName}' => " ~ Bake.exportVar(optionValue) ~ (loop.last ? ']' : ', ') %} | ||||||
|  | {% endfor %} | ||||||
|  |         $rules->add($rules->{{ rule.name }}({{ fields|raw }}{{ (rule.extra|default ? ", '#{rule.extra}'" : '')|raw }}{{ (options ? ', ' ~ options : '')|raw }}), ['errorField' => '{{ field }}']); | ||||||
|  | {% endfor %} | ||||||
|  | 
 | ||||||
|  |         return $rules; | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if connection is not same as('default') %} | ||||||
|  | {% set generatedFunctions = generatedFunctions|merge(['defaultConnectionName']) %} | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Returns the database connection name to use by default. | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|  |     public static function defaultConnectionName(): string | ||||||
|  |     { | ||||||
|  |         return '{{ connection }}'; | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | {% set userFunctions = fileBuilder.classBuilder.userFunctions(generatedFunctions) %} | ||||||
|  | {% if userFunctions %} | ||||||
|  | 
 | ||||||
|  |     {{~ Bake.concat('\n\n', userFunctions) }} | ||||||
|  | {% endif %} | ||||||
|  | } | ||||||
|  | @ -0,0 +1,8 @@ | ||||||
|  | /composer.lock | ||||||
|  | /composer.phar | ||||||
|  | /phpunit.xml | ||||||
|  | /.phpunit.result.cache | ||||||
|  | /phpunit.phar | ||||||
|  | /config/Migrations/schema-dump-default.lock | ||||||
|  | /vendor/ | ||||||
|  | /.idea/ | ||||||
|  | @ -0,0 +1,26 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | # {{ plugin }} plugin for CakePHP | ||||||
|  | 
 | ||||||
|  | ## Installation | ||||||
|  | 
 | ||||||
|  | You can install this plugin into your CakePHP application using [composer](https://getcomposer.org). | ||||||
|  | 
 | ||||||
|  | The recommended way to install composer packages is: | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | composer require {{ package }} | ||||||
|  | ``` | ||||||
|  | @ -0,0 +1,40 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {% set namespace = namespace|replace({'\\': '\\\\'}) %} | ||||||
|  | { | ||||||
|  |     "name": "{{ package }}", | ||||||
|  |     "description": "{{ plugin }} plugin for CakePHP", | ||||||
|  |     "type": "cakephp-plugin", | ||||||
|  |     "license": "MIT", | ||||||
|  |     "require": { | ||||||
|  |         "php": ">=8.1", | ||||||
|  |         "cakephp/cakephp": "{{ cakeVersion|raw }}" | ||||||
|  |     }, | ||||||
|  |     "require-dev": { | ||||||
|  |         "phpunit/phpunit": "^10.1" | ||||||
|  |     }, | ||||||
|  |     "autoload": { | ||||||
|  |         "psr-4": { | ||||||
|  |             "{{ namespace }}\\": "src/" | ||||||
|  |         } | ||||||
|  |     }, | ||||||
|  |     "autoload-dev": { | ||||||
|  |         "psr-4": { | ||||||
|  |             "{{ namespace }}\\Test\\": "tests/", | ||||||
|  |             "Cake\\Test\\": "vendor/cakephp/cakephp/tests/" | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,45 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <phpunit | ||||||
|  |     colors="true" | ||||||
|  |     processIsolation="false" | ||||||
|  |     stopOnFailure="false" | ||||||
|  |     bootstrap="tests/bootstrap.php" | ||||||
|  |     > | ||||||
|  |     <php> | ||||||
|  |         <ini name="memory_limit" value="-1"/> | ||||||
|  |         <ini name="apc.enable_cli" value="1"/> | ||||||
|  |     </php> | ||||||
|  | 
 | ||||||
|  |     <!-- Add any additional test suites you want to run here --> | ||||||
|  |     <testsuites> | ||||||
|  |         <testsuite name="{{ plugin }}"> | ||||||
|  |             <directory>tests/TestCase/</directory> | ||||||
|  |         </testsuite> | ||||||
|  |     </testsuites> | ||||||
|  | 
 | ||||||
|  |     <!-- Setup fixture extension --> | ||||||
|  |     <extensions> | ||||||
|  |         <extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/> | ||||||
|  |     </extensions> | ||||||
|  | 
 | ||||||
|  |     <coverage> | ||||||
|  |         <include> | ||||||
|  |             <directory suffix=".php">src/</directory> | ||||||
|  |         </include> | ||||||
|  |     </coverage> | ||||||
|  | </phpunit> | ||||||
|  | @ -0,0 +1,25 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Controller", | ||||||
|  |     classImports: { | ||||||
|  |         'BaseController': "#{baseNamespace}\\Controller\\AppController", | ||||||
|  |     }, | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | class AppController extends BaseController | ||||||
|  | { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,108 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         1.7.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\Console\\CommandCollection', | ||||||
|  |         'Cake\\Core\\BasePlugin', | ||||||
|  |         'Cake\\Core\\ContainerInterface', | ||||||
|  |         'Cake\\Core\\PluginApplicationInterface', | ||||||
|  |         'Cake\\Http\\MiddlewareQueue', | ||||||
|  |         'Cake\\Routing\\RouteBuilder', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Plugin for {{ namespace }} | ||||||
|  |  */ | ||||||
|  | class {{ name }}Plugin extends BasePlugin | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Load all the plugin configuration and bootstrap logic. | ||||||
|  |      * | ||||||
|  |      * The host application is provided as an argument. This allows you to load | ||||||
|  |      * additional plugin dependencies, or attach events. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Core\PluginApplicationInterface $app The host application | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function bootstrap(PluginApplicationInterface $app): void | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Add routes for the plugin. | ||||||
|  |      * | ||||||
|  |      * If your plugin has many routes and you would like to isolate them into a separate file, | ||||||
|  |      * you can create `$plugin/config/routes.php` and delete this method. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Routing\RouteBuilder $routes The route builder to update. | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function routes(RouteBuilder $routes): void | ||||||
|  |     { | ||||||
|  |         $routes->plugin( | ||||||
|  |             '{{ plugin }}', | ||||||
|  |             ['path' => '/{{ routePath }}'], | ||||||
|  |             function (RouteBuilder $builder) { | ||||||
|  |                 // Add custom routes here | ||||||
|  | 
 | ||||||
|  |                 $builder->fallbacks(); | ||||||
|  |             } | ||||||
|  |         ); | ||||||
|  |         parent::routes($routes); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Add middleware for the plugin. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update. | ||||||
|  |      * @return \Cake\Http\MiddlewareQueue | ||||||
|  |      */ | ||||||
|  |     public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue | ||||||
|  |     { | ||||||
|  |         // Add your middlewares here | ||||||
|  | 
 | ||||||
|  |         return $middlewareQueue; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Add commands for the plugin. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Console\CommandCollection $commands The command collection to update. | ||||||
|  |      * @return \Cake\Console\CommandCollection | ||||||
|  |      */ | ||||||
|  |     public function console(CommandCollection $commands): CommandCollection | ||||||
|  |     { | ||||||
|  |         // Add your commands here | ||||||
|  | 
 | ||||||
|  |         $commands = parent::console($commands); | ||||||
|  | 
 | ||||||
|  |         return $commands; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Register application container services. | ||||||
|  |      * | ||||||
|  |      * @param \Cake\Core\ContainerInterface $container The Container to update. | ||||||
|  |      * @return void | ||||||
|  |      * @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection | ||||||
|  |      */ | ||||||
|  |     public function services(ContainerInterface $container): void | ||||||
|  |     { | ||||||
|  |         // Add your services here | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,71 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * Tests bootstrap file | ||||||
|  |  * | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header',{namespace: null}) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Test suite bootstrap for {{ plugin }}. | ||||||
|  |  * | ||||||
|  |  * This function is used to find the location of CakePHP whether CakePHP | ||||||
|  |  * has been installed as a dependency of the plugin, or the plugin is itself | ||||||
|  |  * installed as a dependency of an application. | ||||||
|  |  */ | ||||||
|  | $findRoot = function ($root) { | ||||||
|  |     do { | ||||||
|  |         $lastRoot = $root; | ||||||
|  |         $root = dirname($root); | ||||||
|  |         if (is_dir($root . '/vendor/cakephp/cakephp')) { | ||||||
|  |             return $root; | ||||||
|  |         } | ||||||
|  |     } while ($root !== $lastRoot); | ||||||
|  | 
 | ||||||
|  |     throw new Exception('Cannot find the root of the application, unable to run tests'); | ||||||
|  | }; | ||||||
|  | $root = $findRoot(__FILE__); | ||||||
|  | unset($findRoot); | ||||||
|  | 
 | ||||||
|  | chdir($root); | ||||||
|  | 
 | ||||||
|  | require_once $root . '/vendor/autoload.php'; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Define fallback values for required constants and configuration. | ||||||
|  |  * To customize constants and configuration remove this require | ||||||
|  |  * and define the data required by your plugin here. | ||||||
|  |  */ | ||||||
|  | require_once $root . '/vendor/cakephp/cakephp/tests/bootstrap.php'; | ||||||
|  | 
 | ||||||
|  | if (file_exists($root . '/config/bootstrap.php')) { | ||||||
|  |     require $root . '/config/bootstrap.php'; | ||||||
|  | 
 | ||||||
|  |     return; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Load schema from a SQL dump file. | ||||||
|  |  * | ||||||
|  |  * If your plugin does not use database fixtures you can | ||||||
|  |  * safely delete this. | ||||||
|  |  * | ||||||
|  |  * If you want to support multiple databases, consider | ||||||
|  |  * using migrations to provide schema for your plugin, | ||||||
|  |  * and using \Migrations\TestSuite\Migrator to load schema. | ||||||
|  |  */ | ||||||
|  | use Cake\TestSuite\Fixture\SchemaLoader; | ||||||
|  | 
 | ||||||
|  | // Load a schema dump file. | ||||||
|  | (new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test'); | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | -- Test database schema for {{ plugin }} | ||||||
|  | @ -0,0 +1,15 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | @ -0,0 +1,35 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * @var \{{ namespace }}\View\AppView $this | ||||||
|  |  * @var \{{ entityClass }} ${{ singularVar }} | ||||||
|  |         {{- "\n" }} | ||||||
|  | {%- if associations.BelongsTo is defined %} | ||||||
|  |     {%- for assocName, assocData in associations.BelongsTo %} | ||||||
|  |  * @var \Cake\Collection\CollectionInterface|string[] ${{ assocData.variable }} | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- endfor %} | ||||||
|  | {% endif %} | ||||||
|  | {%- if associations.BelongsToMany is defined %} | ||||||
|  |     {%- for assocName, assocData in associations.BelongsToMany %} | ||||||
|  |  * @var \Cake\Collection\CollectionInterface|string[] ${{ assocData.variable }} | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- endfor %} | ||||||
|  | {% endif %} | ||||||
|  |  */ | ||||||
|  | ?> | ||||||
|  | {{ element('Bake.form') }} | ||||||
|  | @ -0,0 +1,35 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * @var \{{ namespace }}\View\AppView $this | ||||||
|  |  * @var \{{ entityClass }} ${{ singularVar }} | ||||||
|  |         {{- "\n" }} | ||||||
|  | {%- if associations.BelongsTo is defined %} | ||||||
|  |     {%- for assocName, assocData in associations.BelongsTo %} | ||||||
|  |  * @var string[]|\Cake\Collection\CollectionInterface ${{ assocData.variable }} | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- endfor %} | ||||||
|  | {% endif %} | ||||||
|  | {%- if associations.BelongsToMany is defined %} | ||||||
|  |     {%- for assocName, assocData in associations.BelongsToMany %} | ||||||
|  |  * @var string[]|\Cake\Collection\CollectionInterface ${{ assocData.variable }} | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- endfor %} | ||||||
|  | {% endif %} | ||||||
|  |  */ | ||||||
|  | ?> | ||||||
|  | {{ element('Bake.form') }} | ||||||
|  | @ -0,0 +1,82 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * @var \{{ namespace }}\View\AppView $this | ||||||
|  |  * @var iterable<\{{ entityClass }}> ${{ pluralVar }} | ||||||
|  |  */ | ||||||
|  | ?> | ||||||
|  | <div class="{{ pluralVar }} index content"> | ||||||
|  | {% set fields = Bake.filterFields(fields, schema, modelObject, indexColumns, ['binary', 'text']) %} | ||||||
|  |     <?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add'], ['class' => 'button float-right']) ?> | ||||||
|  | {% set done = [] %} | ||||||
|  |     <h3><?= __('{{ pluralHumanName }}') ?></h3> | ||||||
|  |     <div class="table-responsive"> | ||||||
|  |         <table> | ||||||
|  |             <thead> | ||||||
|  |                 <tr> | ||||||
|  | {% for field in fields %} | ||||||
|  |                     <th><?= $this->Paginator->sort('{{ field }}') ?></th> | ||||||
|  | {% endfor %} | ||||||
|  |                     <th class="actions"><?= __('Actions') ?></th> | ||||||
|  |                 </tr> | ||||||
|  |             </thead> | ||||||
|  |             <tbody> | ||||||
|  |                 <?php foreach (${{ pluralVar }} as ${{ singularVar }}): ?> | ||||||
|  |                 <tr> | ||||||
|  | {% for field in fields %} | ||||||
|  | {% set isKey = false %} | ||||||
|  | {% if associations.BelongsTo is defined %} | ||||||
|  | {% for alias, details in associations.BelongsTo %} | ||||||
|  | {% if field == details.foreignKey %} | ||||||
|  | {% set isKey = true %} | ||||||
|  |                     <td><?= ${{ singularVar }}->hasValue('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?></td> | ||||||
|  | {% endif %} | ||||||
|  | {% endfor %} | ||||||
|  | {% endif %} | ||||||
|  | {% if isKey is not same as(true) %} | ||||||
|  | {% set columnData = Bake.columnData(field, schema) %} | ||||||
|  | {% if columnData.type not in ['integer', 'float', 'decimal', 'biginteger', 'smallinteger', 'tinyinteger'] %} | ||||||
|  |                     <td><?= h(${{ singularVar }}->{{ field }}) ?></td> | ||||||
|  | {% elseif columnData.null %} | ||||||
|  |                     <td><?= ${{ singularVar }}->{{ field }} === null ? '' : $this->Number->format(${{ singularVar }}->{{ field }}) ?></td> | ||||||
|  | {% else %} | ||||||
|  |                     <td><?= $this->Number->format(${{ singularVar }}->{{ field }}) ?></td> | ||||||
|  | {% endif %} | ||||||
|  | {% endif %} | ||||||
|  | {% endfor %} | ||||||
|  | {% set pk = '$' ~ singularVar ~ '->' ~ primaryKey[0] %} | ||||||
|  |                     <td class="actions"> | ||||||
|  |                         <?= $this->Html->link(__('View'), ['action' => 'view', {{ pk|raw }}]) ?> | ||||||
|  |                         <?= $this->Html->link(__('Edit'), ['action' => 'edit', {{ pk|raw }}]) ?> | ||||||
|  |                         <?= $this->Form->postLink(__('Delete'), ['action' => 'delete', {{ pk|raw }}], ['confirm' => __('Are you sure you want to delete # {0}?', {{ pk|raw }})]) ?> | ||||||
|  |                     </td> | ||||||
|  |                 </tr> | ||||||
|  |                 <?php endforeach; ?> | ||||||
|  |             </tbody> | ||||||
|  |         </table> | ||||||
|  |     </div> | ||||||
|  |     <div class="paginator"> | ||||||
|  |         <ul class="pagination"> | ||||||
|  |             <?= $this->Paginator->first('<< ' . __('first')) ?> | ||||||
|  |             <?= $this->Paginator->prev('< ' . __('previous')) ?> | ||||||
|  |             <?= $this->Paginator->numbers() ?> | ||||||
|  |             <?= $this->Paginator->next(__('next') . ' >') ?> | ||||||
|  |             <?= $this->Paginator->last(__('last') . ' >>') ?> | ||||||
|  |         </ul> | ||||||
|  |         <p><?= $this->Paginator->counter(__('Page {{ '{{' }}page{{ '}}' }} of {{ '{{' }}pages{{ '}}' }}, showing {{ '{{' }}current{{ '}}' }} record(s) out of {{ '{{' }}count{{ '}}' }} total')) ?></p> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
|  | @ -0,0 +1,30 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * @var \{{ namespace }}\View\AppView $this | ||||||
|  |  */ | ||||||
|  | ?> | ||||||
|  | <div class="{{ pluralVar }} form content"> | ||||||
|  |     <?= $this->Form->create() ?> | ||||||
|  |     <fieldset> | ||||||
|  |         <legend><?= __('Please enter your username and password') ?></legend> | ||||||
|  |         <?= $this->Form->control('username') ?> | ||||||
|  |         <?= $this->Form->control('password') ?> | ||||||
|  |     </fieldset> | ||||||
|  |     <?= $this->Form->button(__('Login')); ?> | ||||||
|  |     <?= $this->Form->end() ?> | ||||||
|  | </div> | ||||||
|  | @ -0,0 +1,141 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * @var \{{ namespace }}\View\AppView $this | ||||||
|  |  * @var \{{ entityClass }} ${{ singularVar }} | ||||||
|  |  */ | ||||||
|  | ?> | ||||||
|  | {% set associations = {'BelongsTo': [], 'HasOne': [], 'HasMany': [], 'BelongsToMany': []}|merge(associations) %} | ||||||
|  | {% set fieldsData = Bake.getViewFieldsData(fields, schema, associations) %} | ||||||
|  | {% set associationFields = fieldsData.associationFields %} | ||||||
|  | {% set groupedFields = fieldsData.groupedFields %} | ||||||
|  | {% set pK = '$' ~ singularVar ~ '->' ~ primaryKey[0] %} | ||||||
|  | <div class="row"> | ||||||
|  |     <aside class="column"> | ||||||
|  |         <div class="side-nav"> | ||||||
|  |             <h4 class="heading"><?= __('Actions') ?></h4> | ||||||
|  |             <?= $this->Html->link(__('Edit {{ singularHumanName }}'), ['action' => 'edit', {{ pK|raw }}], ['class' => 'side-nav-item']) ?> | ||||||
|  |             <?= $this->Form->postLink(__('Delete {{ singularHumanName }}'), ['action' => 'delete', {{ pK|raw }}], ['confirm' => __('Are you sure you want to delete # {0}?', {{ pK|raw }}), 'class' => 'side-nav-item']) ?> | ||||||
|  |             <?= $this->Html->link(__('List {{ pluralHumanName }}'), ['action' => 'index'], ['class' => 'side-nav-item']) ?> | ||||||
|  |             <?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add'], ['class' => 'side-nav-item']) ?> | ||||||
|  | {% set done = [] %} | ||||||
|  |         </div> | ||||||
|  |     </aside> | ||||||
|  |     <div class="column column-80"> | ||||||
|  |         <div class="{{ pluralVar }} view content"> | ||||||
|  |             <h3><?= h(${{ singularVar }}->{{ displayField }}) ?></h3> | ||||||
|  |             <table> | ||||||
|  | {% if groupedFields['string'] %} | ||||||
|  | {% for field in groupedFields['string'] %} | ||||||
|  | {% if associationFields[field] is defined %} | ||||||
|  | {% set details = associationFields[field] %} | ||||||
|  |                 <tr> | ||||||
|  |                     <th><?= __('{{ details.property|humanize }}') ?></th> | ||||||
|  |                     <td><?= ${{ singularVar }}->hasValue('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?></td> | ||||||
|  |                 </tr> | ||||||
|  | {% else %} | ||||||
|  |                 <tr> | ||||||
|  |                     <th><?= __('{{ field|humanize }}') ?></th> | ||||||
|  |                     <td><?= h(${{ singularVar }}->{{ field }}) ?></td> | ||||||
|  |                 </tr> | ||||||
|  | {% endif %} | ||||||
|  | {% endfor %} | ||||||
|  | {% endif %} | ||||||
|  | {% if associations.HasOne %} | ||||||
|  | {% for alias, details in associations.HasOne %} | ||||||
|  |                 <tr> | ||||||
|  |                     <th><?= __('{{ alias|underscore|singularize|humanize }}') ?></th> | ||||||
|  |                     <td><?= ${{ singularVar }}->hasValue('{{ details.property }}') ? $this->Html->link(${{ singularVar }}->{{ details.property }}->{{ details.displayField }}, ['controller' => '{{ details.controller }}', 'action' => 'view', ${{ singularVar }}->{{ details.property }}->{{ details.primaryKey[0] }}]) : '' ?></td> | ||||||
|  |                 </tr> | ||||||
|  | {% endfor %} | ||||||
|  | {% endif %} | ||||||
|  | {% if groupedFields.number %} | ||||||
|  | {% for field in groupedFields.number %} | ||||||
|  |                 <tr> | ||||||
|  |                     <th><?= __('{{ field|humanize }}') ?></th> | ||||||
|  | {% set columnData = Bake.columnData(field, schema) %} | ||||||
|  | {% if columnData.null %} | ||||||
|  |                     <td><?= ${{ singularVar }}->{{ field }} === null ? '' : $this->Number->format(${{ singularVar }}->{{ field }}) ?></td> | ||||||
|  | {% else %} | ||||||
|  |                     <td><?= $this->Number->format(${{ singularVar }}->{{ field }}) ?></td> | ||||||
|  | {% endif %} | ||||||
|  |                 </tr> | ||||||
|  | {% endfor %} | ||||||
|  | {% endif %} | ||||||
|  | {% if groupedFields.date %} | ||||||
|  | {% for field in groupedFields.date %} | ||||||
|  |                 <tr> | ||||||
|  |                     <th><?= __('{{ field|humanize }}') ?></th> | ||||||
|  |                     <td><?= h(${{ singularVar }}->{{ field }}) ?></td> | ||||||
|  |                 </tr> | ||||||
|  | {% endfor %} | ||||||
|  | {% endif %} | ||||||
|  | {% if groupedFields.boolean %} | ||||||
|  | {% for field in groupedFields.boolean %} | ||||||
|  |                 <tr> | ||||||
|  |                     <th><?= __('{{ field|humanize }}') ?></th> | ||||||
|  |                     <td><?= ${{ singularVar }}->{{ field }} ? __('Yes') : __('No'); ?></td> | ||||||
|  |                 </tr> | ||||||
|  | {% endfor %} | ||||||
|  | {% endif %} | ||||||
|  |             </table> | ||||||
|  | {% if groupedFields.text %} | ||||||
|  | {% for field in groupedFields.text %} | ||||||
|  |             <div class="text"> | ||||||
|  |                 <strong><?= __('{{ field|humanize }}') ?></strong> | ||||||
|  |                 <blockquote> | ||||||
|  |                     <?= $this->Text->autoParagraph(h(${{ singularVar }}->{{ field }})); ?> | ||||||
|  |                 </blockquote> | ||||||
|  |             </div> | ||||||
|  | {% endfor %} | ||||||
|  | {% endif %} | ||||||
|  | {% set relations = associations.BelongsToMany|merge(associations.HasMany) %} | ||||||
|  | {% for alias, details in relations %} | ||||||
|  | {% set otherSingularVar = alias|variable %} | ||||||
|  | {% set otherPluralHumanName = details.controller|underscore|humanize %} | ||||||
|  |             <div class="related"> | ||||||
|  |                 <h4><?= __('Related {{ otherPluralHumanName }}') ?></h4> | ||||||
|  |                 <?php if (!empty(${{ singularVar }}->{{ details.property }})) : ?> | ||||||
|  |                 <div class="table-responsive"> | ||||||
|  |                     <table> | ||||||
|  |                         <tr> | ||||||
|  | {% for field in details.fields %} | ||||||
|  |                             <th><?= __('{{ field|humanize }}') ?></th> | ||||||
|  | {% endfor %} | ||||||
|  |                             <th class="actions"><?= __('Actions') ?></th> | ||||||
|  |                         </tr> | ||||||
|  |                         <?php foreach (${{ singularVar }}->{{ details.property }} as ${{ otherSingularVar }}) : ?> | ||||||
|  |                         <tr> | ||||||
|  | {% for field in details.fields %} | ||||||
|  |                             <td><?= h(${{ otherSingularVar }}->{{ field }}) ?></td> | ||||||
|  | {% endfor %} | ||||||
|  | {% set otherPk = '$' ~ otherSingularVar ~ '->' ~ details.primaryKey[0] %} | ||||||
|  |                             <td class="actions"> | ||||||
|  |                                 <?= $this->Html->link(__('View'), ['controller' => '{{ details.controller }}', 'action' => 'view', {{ otherPk|raw }}]) ?> | ||||||
|  |                                 <?= $this->Html->link(__('Edit'), ['controller' => '{{ details.controller }}', 'action' => 'edit', {{ otherPk|raw }}]) ?> | ||||||
|  |                                 <?= $this->Form->postLink(__('Delete'), ['controller' => '{{ details.controller }}', 'action' => 'delete', {{ otherPk|raw }}], ['confirm' => __('Are you sure you want to delete # {0}?', {{ otherPk|raw }})]) ?> | ||||||
|  |                             </td> | ||||||
|  |                         </tr> | ||||||
|  |                         <?php endforeach; ?> | ||||||
|  |                     </table> | ||||||
|  |                 </div> | ||||||
|  |                 <?php endif; ?> | ||||||
|  |             </div> | ||||||
|  | {% endfor %} | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
|  | @ -0,0 +1,53 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\View\\Cell#{prefix}", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\View\\Cell', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} cell | ||||||
|  |  */ | ||||||
|  | class {{ name }}Cell extends Cell | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * List of valid options that can be passed into this | ||||||
|  |      * cell's constructor. | ||||||
|  |      * | ||||||
|  |      * @var array<string, mixed> | ||||||
|  |      */ | ||||||
|  |     protected array $_validCellOptions = []; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Initialization logic run at the end of object construction. | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function initialize(): void | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Default display method. | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function display() | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,35 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\View\\Helper", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\View\\Helper', | ||||||
|  |         'Cake\\View\\View', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }} helper | ||||||
|  |  */ | ||||||
|  | class {{ name }}Helper extends Helper | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Default configuration. | ||||||
|  |      * | ||||||
|  |      * @var array<string, mixed> | ||||||
|  |      */ | ||||||
|  |     protected array $_defaultConfig = []; | ||||||
|  | } | ||||||
|  | @ -0,0 +1,45 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {% set compact = ["'#{singularName}'"] %} | ||||||
|  |     /** | ||||||
|  |      * Add method | ||||||
|  |      * | ||||||
|  |      * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. | ||||||
|  |      */ | ||||||
|  |     public function add() | ||||||
|  |     { | ||||||
|  |         ${{ singularName }} = $this->{{ currentModelName }}->newEmptyEntity(); | ||||||
|  |         if ($this->request->is('post')) { | ||||||
|  |             ${{ singularName }} = $this->{{ currentModelName }}->patchEntity(${{ singularName }}, $this->request->getData()); | ||||||
|  |             if ($this->{{ currentModelName }}->save(${{ singularName }})) { | ||||||
|  |                 $this->Flash->success(__('The {{ singularHumanName|lower }} has been saved.')); | ||||||
|  | 
 | ||||||
|  |                 return $this->redirect(['action' => 'index']); | ||||||
|  |             } | ||||||
|  |             $this->Flash->error(__('The {{ singularHumanName|lower }} could not be saved. Please, try again.')); | ||||||
|  |         } | ||||||
|  | {% set associations = Bake.aliasExtractor(modelObj, 'BelongsTo') %} | ||||||
|  | {% set associations = associations|merge(Bake.aliasExtractor(modelObj, 'BelongsToMany')) %} | ||||||
|  | 
 | ||||||
|  | {%- for assoc in associations %} | ||||||
|  |     {%- set otherName = Bake.getAssociatedTableAlias(modelObj, assoc) %} | ||||||
|  |     {%- set otherPlural = otherName|variable %} | ||||||
|  |         ${{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('list', limit: 200)->all(); | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- set compact = compact|merge(["'#{otherPlural}'"]) %} | ||||||
|  | {% endfor %} | ||||||
|  |         $this->set(compact({{ compact|join(', ')|raw }})); | ||||||
|  |     } | ||||||
|  | @ -0,0 +1,34 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  |     /** | ||||||
|  |      * Delete method | ||||||
|  |      * | ||||||
|  |      * @param string|null $id {{ singularHumanName }} id. | ||||||
|  |      * @return \Cake\Http\Response|null Redirects to index. | ||||||
|  |      * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||||||
|  |      */ | ||||||
|  |     public function delete($id = null) | ||||||
|  |     { | ||||||
|  |         $this->request->allowMethod(['post', 'delete']); | ||||||
|  |         ${{ singularName }} = $this->{{ currentModelName }}->get($id); | ||||||
|  |         if ($this->{{ currentModelName }}->delete(${{ singularName }})) { | ||||||
|  |             $this->Flash->success(__('The {{ singularHumanName|lower }} has been deleted.')); | ||||||
|  |         } else { | ||||||
|  |             $this->Flash->error(__('The {{ singularHumanName|lower }} could not be deleted. Please, try again.')); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return $this->redirect(['action' => 'index']); | ||||||
|  |     } | ||||||
|  | @ -0,0 +1,46 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {% set belongsTo = Bake.aliasExtractor(modelObj, 'BelongsTo') %} | ||||||
|  | {% set belongsToMany = Bake.aliasExtractor(modelObj, 'belongsToMany') %} | ||||||
|  | {% set compact = ["'#{singularName}'"] %} | ||||||
|  |     /** | ||||||
|  |      * Edit method | ||||||
|  |      * | ||||||
|  |      * @param string|null $id {{ singularHumanName }} id. | ||||||
|  |      * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. | ||||||
|  |      * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||||||
|  |      */ | ||||||
|  |     public function edit($id = null) | ||||||
|  |     { | ||||||
|  |         ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(belongsToMany)|raw }}); | ||||||
|  |         if ($this->request->is(['patch', 'post', 'put'])) { | ||||||
|  |             ${{ singularName }} = $this->{{ currentModelName }}->patchEntity(${{ singularName }}, $this->request->getData()); | ||||||
|  |             if ($this->{{ currentModelName }}->save(${{ singularName }})) { | ||||||
|  |                 $this->Flash->success(__('The {{ singularHumanName|lower }} has been saved.')); | ||||||
|  | 
 | ||||||
|  |                 return $this->redirect(['action' => 'index']); | ||||||
|  |             } | ||||||
|  |             $this->Flash->error(__('The {{ singularHumanName|lower }} could not be saved. Please, try again.')); | ||||||
|  |         } | ||||||
|  | {% for assoc in belongsTo|merge(belongsToMany) %} | ||||||
|  |     {%- set otherName = Bake.getAssociatedTableAlias(modelObj, assoc) %} | ||||||
|  |     {%- set otherPlural = otherName|variable %} | ||||||
|  |         ${{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('list', limit: 200)->all(); | ||||||
|  |         {{- "\n" }} | ||||||
|  |     {%- set compact = compact|merge(["'#{otherPlural}'"]) %} | ||||||
|  | {% endfor %} | ||||||
|  |         $this->set(compact({{ compact|join(', ')|raw }})); | ||||||
|  |     } | ||||||
|  | @ -0,0 +1,33 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  |     /** | ||||||
|  |      * Index method | ||||||
|  |      * | ||||||
|  |      * @return \Cake\Http\Response|null|void Renders view | ||||||
|  |      */ | ||||||
|  |     public function index() | ||||||
|  |     { | ||||||
|  | {% set belongsTo = Bake.aliasExtractor(modelObj, 'BelongsTo') %} | ||||||
|  | {% if belongsTo %} | ||||||
|  |         $query = $this->{{ currentModelName }}->find() | ||||||
|  |             ->contain({{ Bake.exportArray(belongsTo)|raw }}); | ||||||
|  | {% else %} | ||||||
|  |         $query = $this->{{ currentModelName }}->find(); | ||||||
|  | {% endif %} | ||||||
|  |         ${{ pluralName }} = $this->paginate($query); | ||||||
|  | 
 | ||||||
|  |         $this->set(compact('{{ pluralName }}')); | ||||||
|  |     } | ||||||
|  | @ -0,0 +1,31 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {% set allAssociations = Bake.aliasExtractor(modelObj, 'BelongsTo') %} | ||||||
|  | {% set allAssociations = allAssociations|merge(Bake.aliasExtractor(modelObj, 'BelongsToMany')) %} | ||||||
|  | {% set allAssociations = allAssociations|merge(Bake.aliasExtractor(modelObj, 'HasOne')) %} | ||||||
|  | {% set allAssociations = allAssociations|merge(Bake.aliasExtractor(modelObj, 'HasMany')) %} | ||||||
|  |     /** | ||||||
|  |      * View method | ||||||
|  |      * | ||||||
|  |      * @param string|null $id {{ singularHumanName }} id. | ||||||
|  |      * @return \Cake\Http\Response|null|void Renders view | ||||||
|  |      * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||||||
|  |      */ | ||||||
|  |     public function view($id = null) | ||||||
|  |     { | ||||||
|  |         ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(allAssociations)|raw }}); | ||||||
|  |         $this->set(compact('{{ singularName }}')); | ||||||
|  |     } | ||||||
|  | @ -0,0 +1,6 @@ | ||||||
|  |     /** | ||||||
|  |      * {{ name|humanize }} | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public array ${{ name }} = {{ Bake.exportArray(value)|raw }}; | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | <?php | ||||||
|  | declare(strict_types=1); | ||||||
|  | {{- namespace ? "\n\nnamespace #{namespace};" : '' }} | ||||||
|  | {{- Bake.concat('\n', [Bake.classUses(classImports ?? []), Bake.functionUses(functionImports ?? []), Bake.constUses(constImports ?? [])], '\n\n') }} | ||||||
|  | @ -0,0 +1,75 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {% set fields = Bake.filterFields(fields, schema, modelObject) %} | ||||||
|  | <div class="row"> | ||||||
|  |     <aside class="column"> | ||||||
|  |         <div class="side-nav"> | ||||||
|  |             <h4 class="heading"><?= __('Actions') ?></h4> | ||||||
|  | {% if 'add' not in action %} | ||||||
|  |             <?= $this->Form->postLink( | ||||||
|  |                 __('Delete'), | ||||||
|  |                 ['action' => 'delete', ${{ singularVar }}->{{ primaryKey[0] }}], | ||||||
|  |                 ['confirm' => __('Are you sure you want to delete # {0}?', ${{ singularVar }}->{{ primaryKey[0] }}), 'class' => 'side-nav-item'] | ||||||
|  |             ) ?> | ||||||
|  | {% endif %} | ||||||
|  |             <?= $this->Html->link(__('List {{ pluralHumanName }}'), ['action' => 'index'], ['class' => 'side-nav-item']) ?> | ||||||
|  |             {{- "\n" }} | ||||||
|  | {%- set done = [] %} | ||||||
|  |         </div> | ||||||
|  |     </aside> | ||||||
|  |     <div class="column column-80"> | ||||||
|  |         <div class="{{ pluralVar }} form content"> | ||||||
|  |             <?= $this->Form->create(${{ singularVar }}) ?> | ||||||
|  |             <fieldset> | ||||||
|  |                 <legend><?= __('{{ action|humanize }} {{ singularHumanName }}') ?></legend> | ||||||
|  |                 <?php | ||||||
|  | {% for field in fields %} | ||||||
|  | {%- if field not in primaryKey %} | ||||||
|  |     {%- if keyFields[field] is defined %} | ||||||
|  |         {%- set fieldData = Bake.columnData(field, schema) %} | ||||||
|  |         {%- if fieldData.null %} | ||||||
|  |                     echo $this->Form->control('{{ field }}', ['options' => ${{ keyFields[field] }}, 'empty' => true]); | ||||||
|  |                     {{- "\n" }} | ||||||
|  |         {%- else %} | ||||||
|  |                     echo $this->Form->control('{{ field }}', ['options' => ${{ keyFields[field] }}]); | ||||||
|  |                     {{- "\n" }} | ||||||
|  |         {%- endif %} | ||||||
|  |     {%- elseif field not in ['created', 'modified', 'updated'] %} | ||||||
|  |         {%- set fieldData = Bake.columnData(field, schema) %} | ||||||
|  |         {%- if fieldData.type in ['date', 'datetime', 'time'] and fieldData.null %} | ||||||
|  |                     echo $this->Form->control('{{ field }}', ['empty' => true]); | ||||||
|  |                     {{- "\n" }} | ||||||
|  |         {%- else %} | ||||||
|  |                     echo $this->Form->control('{{ field }}'); | ||||||
|  |                     {{- "\n" }} | ||||||
|  |         {%- endif %} | ||||||
|  |     {%- endif %} | ||||||
|  | {%- endif %} | ||||||
|  | {%- endfor %} | ||||||
|  | 
 | ||||||
|  | {%- if associations.BelongsToMany is defined %} | ||||||
|  | {%- for assocName, assocData in associations.BelongsToMany %} | ||||||
|  |                     echo $this->Form->control('{{ assocData.property }}._ids', ['options' => ${{ assocData.variable }}]); | ||||||
|  |                     {{- "\n" }} | ||||||
|  | {%- endfor %} | ||||||
|  | {% endif %} | ||||||
|  |                 ?> | ||||||
|  |             </fieldset> | ||||||
|  |             <?= $this->Form->button(__('Submit')) ?> | ||||||
|  |             <?= $this->Form->end() ?> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
|  | @ -0,0 +1,16 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ fetch('content') }} | ||||||
|  | @ -0,0 +1,74 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * Fixture Template file | ||||||
|  |  * | ||||||
|  |  * Fixture Template used when baking fixtures with bake | ||||||
|  |  * | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {{ element('Bake.file_header', { | ||||||
|  |     namespace: "#{namespace}\\Test\\Fixture", | ||||||
|  |     classImports: [ | ||||||
|  |         'Cake\\TestSuite\\Fixture\\TestFixture', | ||||||
|  |     ], | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ name }}Fixture | ||||||
|  |  */ | ||||||
|  | class {{ name }}Fixture extends TestFixture | ||||||
|  | { | ||||||
|  | {% if table %} | ||||||
|  |     /** | ||||||
|  |      * Table name | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     public string $table = '{{ table|raw }}'; | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if import %} | ||||||
|  |     /** | ||||||
|  |      * Import | ||||||
|  |      * | ||||||
|  |      * @var array<string, mixed> | ||||||
|  |      */ | ||||||
|  |     public array $import = {{ import|raw }}; | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if schema %} | ||||||
|  |     /** | ||||||
|  |      * Fields | ||||||
|  |      * | ||||||
|  |      * @var array<string, mixed> | ||||||
|  |      */ | ||||||
|  |     // phpcs:disable | ||||||
|  |     public array $fields = {{ schema|raw }}; | ||||||
|  |     // phpcs:enable | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if records %} | ||||||
|  |     /** | ||||||
|  |      * Init method | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function init(): void | ||||||
|  |     { | ||||||
|  |         $this->records = {{ records|raw }}; | ||||||
|  |         parent::init(); | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | } | ||||||
|  | @ -0,0 +1,569 @@ | ||||||
|  | {# | ||||||
|  | /** | ||||||
|  |  * Test Case bake template | ||||||
|  |  * | ||||||
|  |  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||||||
|  |  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * | ||||||
|  |  * Licensed under The MIT License | ||||||
|  |  * For full copyright and license information, please see the LICENSE.txt | ||||||
|  |  * Redistributions of files must retain the above copyright notice. | ||||||
|  |  * | ||||||
|  |  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||||||
|  |  * @link          https://cakephp.org CakePHP(tm) Project | ||||||
|  |  * @since         2.0.0 | ||||||
|  |  * @license       https://www.opensource.org/licenses/mit-license.php MIT License | ||||||
|  |  */ | ||||||
|  | #} | ||||||
|  | {% set isController = type|lower == 'controller' %} | ||||||
|  | {% set isPlugin = 'app'|lower == 'app' %} | ||||||
|  | {% set isTable = type|lower == 'table' or type|lower == 'model/table' %} | ||||||
|  | {% set isCommand = type|lower == 'command' %} | ||||||
|  | {% if isController %} | ||||||
|  |     {%- set traitName = 'IntegrationTestTrait' %} | ||||||
|  |     {%- set uses = uses|merge(['Cake\\TestSuite\\IntegrationTestTrait', 'PHPUnit\\Exception']) %} | ||||||
|  | {% elseif isCommand %} | ||||||
|  |     {%- set traitName = 'ConsoleIntegrationTestTrait' %} | ||||||
|  |     {%- set uses = uses|merge(['Cake\\Console\\TestSuite\\ConsoleIntegrationTestTrait']) %} | ||||||
|  | {% endif %} | ||||||
|  | {%- set uses = uses|merge(["Cake\\TestSuite\\TestCase"]) %} | ||||||
|  | 
 | ||||||
|  | {{- element('Bake.file_header', { | ||||||
|  |     namespace: "#{baseNamespace}\\Test\\TestCase\\#{subNamespace}", | ||||||
|  |     classImports: uses, | ||||||
|  | }) }} | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * {{ fullClassName }} Test Case | ||||||
|  | {% if isController or isCommand %} | ||||||
|  |  * | ||||||
|  |  * @uses \{{ fullClassName }} | ||||||
|  | {% endif %} | ||||||
|  |  */ | ||||||
|  | class {{ className }}Test extends TestCase | ||||||
|  | { | ||||||
|  | {% if traitName is defined %} | ||||||
|  |     use {{ traitName }}; | ||||||
|  | {% if properties or fixtures or construction or methods %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {% endif %} | ||||||
|  | {% if properties %} | ||||||
|  | {% for propertyInfo in properties %} | ||||||
|  | {% if loop.index > 1 %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  |     /** | ||||||
|  |      * {{ propertyInfo.description }} | ||||||
|  |      * | ||||||
|  |      * @var {{ propertyInfo.type }} | ||||||
|  |      */ | ||||||
|  |     protected ${{ propertyInfo.name }}{% if propertyInfo.value is defined and propertyInfo.value %} = {{ propertyInfo.value }}{% endif %}; | ||||||
|  | {% if loop.last and (fixtures or construction or methods) %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {% endfor %} | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if fixtures %} | ||||||
|  |     /** | ||||||
|  |      * Fixtures | ||||||
|  |      * | ||||||
|  |      * @var array<string> | ||||||
|  |      */ | ||||||
|  |     protected array $fixtures = {{ Bake.exportVar(fixtures|values, 1)|raw }}; | ||||||
|  | {% if construction or methods %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if construction or isController %} | ||||||
|  |     /** | ||||||
|  |      * setUp method | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     protected function setUp(): void | ||||||
|  |     { | ||||||
|  |         parent::setUp(); | ||||||
|  | {% if preConstruct %} | ||||||
|  |         {{ preConstruct|raw }} | ||||||
|  | {% endif %} | ||||||
|  | {% if isCommand %} | ||||||
|  |         {{ construction|raw }} | ||||||
|  | {% elseif isController %} | ||||||
|  |         $this->{{ subject }} = $this->getTableLocator()->get('{{ subject }}'); | ||||||
|  | {% else %} | ||||||
|  |         $this->{{ (subject ~ ' = ' ~ construction)|raw }} | ||||||
|  | {% endif %} | ||||||
|  | {% if postConstruct %} | ||||||
|  |         {{ postConstruct|raw }} | ||||||
|  | {% endif %} | ||||||
|  |     } | ||||||
|  | {% if not isCommand %} | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * tearDown method | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     protected function tearDown(): void | ||||||
|  |     { | ||||||
|  |         unset($this->{{ subject }}); | ||||||
|  | 
 | ||||||
|  |         parent::tearDown(); | ||||||
|  |     } | ||||||
|  | {% if methods %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {% endif %} | ||||||
|  | {% endif %} | ||||||
|  | 
 | ||||||
|  | {%- if isTable %} | ||||||
|  |     /** | ||||||
|  |     * TestInitialize method | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     * @uses \{{ fullClassName }}::initialize() | ||||||
|  |     */ | ||||||
|  |     public function testInitialize(): void | ||||||
|  |     { | ||||||
|  |         // verify all associations loaded | ||||||
|  |         $expectedAssociations = []; | ||||||
|  |         $associations = $this->{{ subject}}->associations(); | ||||||
|  | 
 | ||||||
|  |         $this->assertCount(count($expectedAssociations), $associations); | ||||||
|  |         foreach ($expectedAssociations as $expectedAssociation) { | ||||||
|  |             $this->assertTrue($this->{{ subject }}->hasAssociation($expectedAssociation)); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // verify all behaviors loaded | ||||||
|  |         $expectedBehaviors = []; | ||||||
|  |         $behaviors = $this->{{ subject }}->behaviors(); | ||||||
|  | 
 | ||||||
|  |         $this->assertCount(count($expectedBehaviors), $behaviors); | ||||||
|  |         foreach ($expectedBehaviors as $expectedBehavior) { | ||||||
|  |             $this->assertTrue($this->{{ subject }}->hasBehavior($expectedBehavior)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {%- for method in methods %} | ||||||
|  | {% if loop.index > 1 %} | ||||||
|  | 
 | ||||||
|  | {% endif %} | ||||||
|  | {%- if isController and method|lower == 'index' %} | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with an unauthenticated user (not logged in) | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}GetUnauthenticated(): void | ||||||
|  |     { | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |         ]; | ||||||
|  |         $this->get($url); | ||||||
|  |         $this->assertResponseCode(302); | ||||||
|  |         $this->assertRedirectContains('login'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}GetLoggedIn(): void | ||||||
|  |     { | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |         ]; | ||||||
|  |         $this->get($url); | ||||||
|  |         $this->assertResponseCode(200); | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | {%- if isController and method|lower == 'view' %} | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with an unauthenticated user (not logged in) | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}GetUnauthenticated(): void | ||||||
|  |     { | ||||||
|  |         $id = 1; | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |             $id, | ||||||
|  |         ]; | ||||||
|  |         $this->get($url); | ||||||
|  |         $this->assertResponseCode(302); | ||||||
|  |         $this->assertRedirectContains('login'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}GetLoggedIn(): void | ||||||
|  |     { | ||||||
|  |         $id = 1; | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |             $id, | ||||||
|  |         ]; | ||||||
|  |         $this->get($url); | ||||||
|  |         $this->assertResponseCode(200); | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | {%- if isController and method|lower == 'add' %} | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with an unauthenticated user (not logged in) | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}GetUnauthenticated(): void | ||||||
|  |     { | ||||||
|  |         $cntBefore = $this->{{ subject }}->find()->count(); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |         ]; | ||||||
|  |         $this->get($url); | ||||||
|  |         $this->assertResponseCode(302); | ||||||
|  |         $this->assertRedirectContains('login'); | ||||||
|  | 
 | ||||||
|  |         $cntAfter = $this->{{ subject }}->find()->count(); | ||||||
|  |         $this->assertEquals($cntBefore, $cntAfter); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}GetLoggedIn(): void | ||||||
|  |     { | ||||||
|  |         $cntBefore = $this->{{ subject }}->find()->count(); | ||||||
|  | 
 | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |         ]; | ||||||
|  |         $this->get($url); | ||||||
|  |         $this->assertResponseCode(200); | ||||||
|  | 
 | ||||||
|  |         $cntAfter = $this->{{ subject }}->find()->count(); | ||||||
|  |         $this->assertEquals($cntBefore, $cntAfter); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests a POST request to the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}PostLoggedInSuccess(): void | ||||||
|  |     { | ||||||
|  |         $cntBefore = $this->{{ subject }}->find()->count(); | ||||||
|  | 
 | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |         ]; | ||||||
|  |         $data = []; | ||||||
|  |         $this->post($url, $data); | ||||||
|  |         $this->assertResponseCode(302); | ||||||
|  |         $this->assertRedirectContains('{{ subject|lower }}/view'); | ||||||
|  | 
 | ||||||
|  |         $cntAfter = $this->{{ subject }}->find()->count(); | ||||||
|  |         $this->assertEquals($cntBefore + 1, $cntAfter); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests a POST request to the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}PostLoggedInFailure(): void | ||||||
|  |     { | ||||||
|  |         $cntBefore = $this->{{ subject }}->find()->count(); | ||||||
|  | 
 | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |         ]; | ||||||
|  |         $data = []; | ||||||
|  |         $this->post($url, $data); | ||||||
|  |         $this->assertResponseCode(200); | ||||||
|  | 
 | ||||||
|  |         $cntAfter = $this->{{ subject }}->find()->count(); | ||||||
|  |         $this->assertEquals($cntBefore, $cntAfter); | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | {%- if isController and method|lower == 'edit' %} | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with an unauthenticated user (not logged in) | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}GetUnauthenticated(): void | ||||||
|  |     { | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |             1, | ||||||
|  |         ]; | ||||||
|  |         $this->get($url); | ||||||
|  |         $this->assertResponseCode(302); | ||||||
|  |         $this->assertRedirectContains('login'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}GetLoggedIn(): void | ||||||
|  |     { | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |             1, | ||||||
|  |         ]; | ||||||
|  |         $this->get($url); | ||||||
|  |         $this->assertResponseCode(200); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests a PUT request to the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}PutLoggedInSuccess(): void | ||||||
|  |     { | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $id = 1; | ||||||
|  |         $before = $this->{{ subject }}->get($id); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |             $id, | ||||||
|  |         ]; | ||||||
|  |         $data = [ | ||||||
|  |             // test new data here | ||||||
|  |         ]; | ||||||
|  |         $this->put($url, $data); | ||||||
|  | 
 | ||||||
|  |         $this->assertResponseCode(302); | ||||||
|  |         $this->assertRedirectContains('{{ subject|lower }}/view'); | ||||||
|  | 
 | ||||||
|  |         $after = $this->{{ subject }}->get($id); | ||||||
|  |         // assert saved properly below | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests a PUT request to the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}PutLoggedInFailure(): void | ||||||
|  |     { | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $id = 1; | ||||||
|  |         $before = $this->{{ subject }}->get($id); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |             $id, | ||||||
|  |         ]; | ||||||
|  |         $data = []; | ||||||
|  |         $this->put($url, $data); | ||||||
|  |         $this->assertResponseCode(200); | ||||||
|  |         $after = $this->{{ subject }}->get($id); | ||||||
|  | 
 | ||||||
|  |         // assert save failed below | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | {%- if isController and method|lower == 'delete' %} | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with an unauthenticated user (not logged in) | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}Unauthenticated(): void | ||||||
|  |     { | ||||||
|  |         $cntBefore = $this->{{ subject }}->find()->count(); | ||||||
|  | 
 | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |             1, | ||||||
|  |         ]; | ||||||
|  |         $this->delete($url); | ||||||
|  |         $this->assertResponseCode(302); | ||||||
|  |         $this->assertRedirectContains('login'); | ||||||
|  | 
 | ||||||
|  |         $cntAfter = $this->{{ subject }}->find()->count(); | ||||||
|  |         $this->assertEquals($cntBefore, $cntAfter); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * Tests the {{ method }} action with a logged in user | ||||||
|  |     * | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     * @throws Exception | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}LoggedIn(): void | ||||||
|  |     { | ||||||
|  |         $cntBefore = $this->{{ subject }}->find()->count(); | ||||||
|  | 
 | ||||||
|  |         // $this->loginUserByRole('admin'); | ||||||
|  |         $url = [ | ||||||
|  | {% if baseNamespace != 'App' %} | ||||||
|  |             'plugin' => '{{ baseNamespace }}', | ||||||
|  | {% endif %} | ||||||
|  |             'controller' => '{{ subject }}', | ||||||
|  |             'action' => '{{ method|lower }}', | ||||||
|  |             1, | ||||||
|  |         ]; | ||||||
|  |         $this->delete($url); | ||||||
|  |         $this->assertResponseCode(302); | ||||||
|  |         $this->assertRedirectContains('{{ subject|lower }}'); | ||||||
|  | 
 | ||||||
|  |         $cntAfter = $this->{{ subject }}->find()->count(); | ||||||
|  |         $this->assertEquals($cntBefore - 1, $cntAfter); | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | {%- if isController and (method|lower == 'index' or method|lower == 'view' or method|lower == 'add' or method|lower == 'edit' or method|lower == 'delete') %} | ||||||
|  | {% else %} | ||||||
|  |     /** | ||||||
|  |     * Test {{ method }} method | ||||||
|  |     * | ||||||
|  |     * @return void | ||||||
|  |     * @uses \{{ fullClassName }}::{{ method }}() | ||||||
|  |     */ | ||||||
|  |     public function test{{ method|camelize }}(): void | ||||||
|  |     { | ||||||
|  |         $this->markTestIncomplete('Not implemented yet.'); | ||||||
|  |     } | ||||||
|  | {% endif %} | ||||||
|  | {% endfor %} | ||||||
|  | } | ||||||
|  | @ -0,0 +1,55 @@ | ||||||
|  | <?php | ||||||
|  | declare(strict_types=1); | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Test suite bootstrap for CheeseCakePlugin. | ||||||
|  |  * | ||||||
|  |  * This function is used to find the location of CakePHP whether CakePHP | ||||||
|  |  * has been installed as a dependency of the plugin, or the plugin is itself | ||||||
|  |  * installed as a dependency of an application. | ||||||
|  |  */ | ||||||
|  | $findRoot = function ($root) { | ||||||
|  |     do { | ||||||
|  |         $lastRoot = $root; | ||||||
|  |         $root = dirname($root); | ||||||
|  |         if (is_dir($root . '/vendor/cakephp/cakephp')) { | ||||||
|  |             return $root; | ||||||
|  |         } | ||||||
|  |     } while ($root !== $lastRoot); | ||||||
|  | 
 | ||||||
|  |     throw new Exception('Cannot find the root of the application, unable to run tests'); | ||||||
|  | }; | ||||||
|  | $root = $findRoot(__FILE__); | ||||||
|  | unset($findRoot); | ||||||
|  | 
 | ||||||
|  | chdir($root); | ||||||
|  | 
 | ||||||
|  | require_once $root . '/vendor/autoload.php'; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Define fallback values for required constants and configuration. | ||||||
|  |  * To customize constants and configuration remove this require | ||||||
|  |  * and define the data required by your plugin here. | ||||||
|  |  */ | ||||||
|  | require_once $root . '/vendor/cakephp/cakephp/tests/bootstrap.php'; | ||||||
|  | 
 | ||||||
|  | if (file_exists($root . '/config/bootstrap.php')) { | ||||||
|  |     require $root . '/config/bootstrap.php'; | ||||||
|  | 
 | ||||||
|  |     return; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Load schema from a SQL dump file. | ||||||
|  |  * | ||||||
|  |  * If your plugin does not use database fixtures you can | ||||||
|  |  * safely delete this. | ||||||
|  |  * | ||||||
|  |  * If you want to support multiple databases, consider | ||||||
|  |  * using migrations to provide schema for your plugin, | ||||||
|  |  * and using \Migrations\TestSuite\Migrator to load schema. | ||||||
|  |  */ | ||||||
|  | use Cake\TestSuite\Fixture\SchemaLoader; | ||||||
|  | 
 | ||||||
|  | // Load a schema dump file.
 | ||||||
|  | (new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test'); | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | -- Test database schema for CheeseCake | ||||||
		Loading…
	
		Reference in New Issue