├── .gitignore ├── .semver ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── composer.json └── src └── Bridges └── Cakephp.php /.gitignore: -------------------------------------------------------------------------------- 1 | /tmp 2 | /vendor 3 | /.idea 4 | composer.lock 5 | .php_cs* 6 | /coverage 7 | -------------------------------------------------------------------------------- /.semver: -------------------------------------------------------------------------------- 1 | --- 2 | :major: 1 3 | :minor: 0 4 | :patch: 1 5 | :special: '' 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | Releases for CakePHP 5 5 | ---------------------- 6 | 7 | * 2.0.0 8 | * Bridge updated for CakePHP 5 compatibility 9 | 10 | 11 | Releases for CakePHP 4 12 | ---------------------- 13 | 14 | * 1.0.0 15 | * Initial release 16 | 17 | Releases for CakePHP 3 18 | ------------- 19 | 20 | * 0.0.1 21 | * Initial release 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | This repository follows the [CakeDC Plugin Standard](https://www.cakedc.com/plugin-standard). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](https://www.cakedc.com/contribution-guidelines) for detailed instructions. 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright 2009-2020 4 | Cake Development Corporation 5 | 1785 E. Sahara Avenue, Suite 490-423 6 | Las Vegas, Nevada 89104 7 | Phone: +1 702 425 5085 8 | https://www.cakedc.com 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a 11 | copy of this software and associated documentation files (the "Software"), 12 | to deal in the Software without restriction, including without limitation 13 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 | and/or sell copies of the Software, and to permit persons to whom the 15 | Software is furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in 18 | all copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CakePHP PHP PM Bridge 2 | ===================== 3 | 4 | Alpha. Please use at your own risk. 5 | IMPORTANT: Cookies not working at this point, so no sessions or Csrf available 6 | 7 | CakePHP Bridge to use with PHP-PM project (https://github.com/php-pm/php-pm). 8 | 9 | Requirements 10 | ------------ 11 | 12 | * CakePHP ^5.0 13 | * PHP ^8.0 14 | * phpcgi installed 15 | * php_pcntl extension installed and enabled 16 | 17 | Setup 18 | ----- 19 | 20 | * Via composer, add to your composer.json 21 | 22 | "cakedc/cakephp-phppm": "dev-2.next-cake5" 23 | 24 | Run 25 | --- 26 | 27 | * Execute the PM via command line 28 | * For MAX performance 29 | 30 | vendor/bin/ppm --bridge='\CakeDC\PHPPM\Bridges\Cakephp' start --debug 0 --workers 9 --logging 0 --static-directory webroot 31 | 32 | * For development 33 | 34 | vendor/bin/ppm --bridge='\CakeDC\PHPPM\Bridges\Cakephp' start --debug 1 --workers 1 --static-directory webroot 35 | 36 | 37 | Testing it 38 | ---------- 39 | 40 | * Try some benchmarks 41 | 42 | ab -n 5000 -c 100 http://127.0.0.1:8080/api/posts 43 | 44 | Important notes 45 | ------------- 46 | 47 | * Cookies: they are not working properly now, so you won't have sessions OR Csrf properly working, if you 48 | are providing an API this is not something that should bother you too much anyway... 49 | * This plugin bootstraps your application once, so ensure your bootstrap is not dynamic, for example, no 50 | dynamic routes coming from database based on request params. 51 | 52 | Support 53 | ------- 54 | 55 | Commercial support is also available, [contact us](https://www.cakedc.com/contact) for more information. 56 | 57 | Contributing 58 | ------------ 59 | 60 | This repository follows the [CakeDC Plugin Standard](https://www.cakedc.com/plugin-standard). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](https://www.cakedc.com/contribution-guidelines) for detailed instructions. 61 | 62 | License 63 | ------- 64 | 65 | Copyright 2018-2023 Cake Development Corporation (CakeDC). All rights reserved. 66 | 67 | Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file. 68 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cakedc/cakephp-phppm", 3 | "description": "PHP PM bridge for CakePHP", 4 | "type": "cakephp-plugin", 5 | "keywords": [ 6 | "cakephp", 7 | "php", 8 | "phppm" 9 | ], 10 | "homepage": "https://github.com/CakeDC/cakephp-phppm", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "CakeDC", 15 | "homepage": "https://www.cakedc.com", 16 | "role": "Author" 17 | }, 18 | { 19 | "name": "Others", 20 | "homepage": "https://github.com/CakeDC/cakephp-phppm/graphs/contributors" 21 | } 22 | ], 23 | "support": { 24 | "issues": "https://github.com/CakeDC/cakephp-phppm/issues", 25 | "source": "https://github.com/CakeDC/cakephp-phppm" 26 | }, 27 | "require": { 28 | "php": ">=8.0", 29 | "cakephp/cakephp": "^5.0", 30 | "php-pm/php-pm": "^2.3" 31 | }, 32 | "require-dev": { 33 | }, 34 | "suggest": { 35 | }, 36 | "autoload": { 37 | "psr-4": { 38 | "CakeDC\\PHPPM\\": "src" 39 | } 40 | }, 41 | "autoload-dev": { 42 | "psr-4": { 43 | "CakeDC\\PHPPM\\Test\\": "tests", 44 | "CakeDC\\PHPPM\\Test\\Fixture\\": "tests" 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Bridges/Cakephp.php: -------------------------------------------------------------------------------- 1 | application = new Application($root . '/config'); 46 | $this->application->bootstrap(); 47 | if (!Configure::read('App.base')) { 48 | Configure::write('App.base', ''); 49 | } 50 | if ($this->application instanceof \Cake\Core\PluginApplicationInterface) { 51 | $this->application->pluginBootstrap(); 52 | } 53 | $this->server = new Server($this->application); 54 | $this->runner = new Runner(); 55 | $this->middleware = $this->application->middleware(new MiddlewareQueue()); 56 | if ($this->application instanceof PluginApplicationInterface) { 57 | $this->middleware = $this->application->pluginMiddleware($this->middleware); 58 | } 59 | 60 | if (!($this->middleware instanceof MiddlewareQueue)) { 61 | throw new \RuntimeException('The application `middleware` method did not return a middleware queue.'); 62 | } 63 | $this->server->dispatchEvent('Server.buildMiddleware', ['middleware' => $this->middleware]); 64 | } 65 | 66 | /** 67 | * Handle the request and return a response. 68 | * 69 | * @param \Psr\Http\Message\ServerRequestInterface $request 70 | * @return \Psr\Http\Message\ResponseInterface 71 | */ 72 | public function handle(ServerRequestInterface $request): ResponseInterface 73 | { 74 | $this->resetApiServiceRegistry(); 75 | $request = ServerRequestFactory::fromGlobals(); 76 | $response = $this->runner->run($this->middleware, $request, $this->application); 77 | if ($request instanceof ServerRequest) { 78 | $request->getSession()->close(); 79 | } 80 | 81 | if (!($response instanceof ResponseInterface)) { 82 | throw new \RuntimeException(sprintf( 83 | 'Application did not create a response. Got "%s" instead.', 84 | is_object($response) ? get_class($response) : $response 85 | )); 86 | } 87 | 88 | return $response; 89 | } 90 | 91 | protected function resetApiServiceRegistry() 92 | { 93 | $serviceRegistryClass = '\CakeDC\Api\Service\ServiceRegistry'; 94 | if (class_exists($serviceRegistryClass)) { 95 | $locator = call_user_func($serviceRegistryClass . '::getServiceLocator'); 96 | $locator->clear(); 97 | } 98 | } 99 | } 100 | --------------------------------------------------------------------------------