├── .gitignore ├── .travis.yml ├── CHANGES.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── cli └── console.php ├── composer.json ├── config ├── Common.php ├── Dev.php ├── Prod.php ├── Test.php └── _env.php ├── phpunit.php ├── phpunit.sh ├── phpunit.xml.dist ├── src └── .placeholder ├── tests └── FrameworkProjectTest.php ├── tmp ├── .placeholder ├── cache │ └── .placeholder └── log │ └── .placeholder └── web ├── .htaccess └── index.php /.gitignore: -------------------------------------------------------------------------------- 1 | /composer.lock 2 | /tmp/* 3 | !/tmp/.placeholder 4 | /vendor 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 5.4 4 | - 5.5 5 | - 5.6 6 | - 7 7 | before_script: 8 | - composer self-update 9 | - composer install 10 | script: 11 | - ./phpunit.sh 12 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | This release modifies the testing structure and updates other support files. 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We are happy to review any contributions you want to make. When contributing, please follow the rules outlined at . 4 | 5 | The time between submitting a contribution and its review one may be extensive; do not be discouraged if there is not immediate feedback. 6 | 7 | Thanks! 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2015, Aura for PHP 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | - Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Aura.Framework_Project 2 | 3 | This package provides a minimal framework for combined web and command-line projects. 4 | 5 | By "minimal" we mean *very* minimal. The package provides only a dependency 6 | injection container, a configuration system, a web router and dispatcher, a CLI dispatcher, a pair of web request and response objects, a pair of CLI context and standard I/O objects, and a logging instance. 7 | 8 | This minimal implementation should not be taken as "restrictive". The DI 9 | container, with its two-stage configuration system, allows a wide range of 10 | programmatic service definitions. The router and dispatchers are built with 11 | iterative refactoring in mind, so you can start with micro-framework-like 12 | closures, and work your way into more complex controller and command objects of 13 | your own design. 14 | 15 | ## Foreword 16 | 17 | ### Requirements 18 | 19 | This project requires PHP 5.4 or later; we recommend using the latest available version of PHP as a matter of principle. 20 | 21 | Unlike Aura library packages, this project package has userland dependencies, which themselves may have other dependencies: 22 | 23 | - [aura/cli-kernel](https://packagist.org/packages/aura/cli-kernel) 24 | - [aura/web-kernel](https://packagist.org/packages/aura/web-kernel) 25 | - [monolog/monolog](https://packagist.org/packages/monolog/monolog) 26 | 27 | ### Installation 28 | 29 | Install this project via Composer to a `{$PROJECT_PATH}` of your choosing: 30 | 31 | composer create-project aura/framework-project {$PROJECT_PATH} 32 | 33 | This will create the project skeleton and install all of the necessary packages. 34 | 35 | ### Tests 36 | 37 | [![Build Status](https://travis-ci.org/auraphp/Aura.Framework_Project.png)](https://travis-ci.org/auraphp/Aura.Framework_Project) 38 | 39 | To run the unit tests at the command line, issue `./phpunit.sh` at the package root. This requires [PHPUnit](http://phpunit.de/) to be available as `phpunit`. 40 | 41 | Alternatively, after you have installed the project, try the "hello world" CLI and web apps. 42 | 43 | For the CLI, go to the project directory and issue the following command: 44 | 45 | cd {$PROJECT_PATH} 46 | php cli/console.php hello 47 | 48 | You should see the output `Hello World!`. Try passing a name after `hello` to 49 | see `Hello name!`. 50 | 51 | For the web, start the built-in PHP server with the `web/` directory as the document root: 52 | 53 | cd {$PROJECT_PATH} 54 | php -S localhost:8000 -t web/ 55 | 56 | When you browse to you should see "Hello World!" as the output. Terminate the built-in server process thereafter. (Be sure to use the built-in PHP server only for testing, never for production.) 57 | 58 | ### PSR Compliance 59 | 60 | This projects attempts to comply with [PSR-1][], [PSR-2][], and [PSR-4][]. If you notice compliance oversights, please send a patch via pull request. 61 | 62 | [PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md 63 | [PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md 64 | [PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md 65 | 66 | ### Community 67 | 68 | To ask questions, provide feedback, or otherwise communicate with the Aura community, please join our [Google Group](http://groups.google.com/group/auraphp), follow [@auraphp on Twitter](http://twitter.com/auraphp), or chat with us on #auraphp on Freenode. 69 | 70 | ### Services 71 | 72 | This package uses services defined by: 73 | 74 | - [Aura.Project_Kernel](https://github.com/auraphp/Aura.Project_Kernel#services) 75 | - [Aura.Cli_Kernel](https://github.com/auraphp/Aura.Cli_Kernel#services) 76 | - [Aura.Web_Kernel](https://github.com/auraphp/Aura.Web_Kernel#services) 77 | 78 | This project resets the following services: 79 | 80 | - `logger`: an instance of `Monolog\Logger` 81 | 82 | ## Getting Started 83 | 84 | This framework project package is not much more than a combination of the CLI and web project packages. Please see them for their respective "getting started" instructions" 85 | 86 | - [Getting Started (CLI)](https://github.com/auraphp/Aura.Cli_Project#getting-started) 87 | 88 | - [Getting Started (web)](https://github.com/auraphp/Aura.Web_Project#getting-started) 89 | -------------------------------------------------------------------------------- /cli/console.php: -------------------------------------------------------------------------------- 1 | newKernel( 14 | $path, 15 | 'Aura\Cli_Kernel\CliKernel' 16 | ); 17 | $status = $kernel(); 18 | exit($status); 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aura/framework-project", 3 | "type": "project", 4 | "description": "A minimal web+cli framework built from Aura v2 packages", 5 | "keywords": [ 6 | "framework" 7 | ], 8 | "license": "BSD-2-Clause", 9 | "authors": [ 10 | { 11 | "name": "Aura.Framework_Project Contributors", 12 | "homepage": "https://github.com/auraphp/Aura.Framework_Project/contributors" 13 | } 14 | ], 15 | "require": { 16 | "aura/cli-kernel": "~2.0", 17 | "aura/web-kernel": "~2.0", 18 | "monolog/monolog": "~1.0" 19 | }, 20 | "autoload": { 21 | "psr-4": { 22 | "": "src/", 23 | "Aura\\Framework_Project\\_Config\\": "config/" 24 | } 25 | }, 26 | "extra": { 27 | "aura": { 28 | "type": "project", 29 | "config": { 30 | "common": "Aura\\Framework_Project\\_Config\\Common", 31 | "dev": "Aura\\Framework_Project\\_Config\\Dev", 32 | "test": "Aura\\Framework_Project\\_Config\\Test", 33 | "prod": "Aura\\Framework_Project\\_Config\\Prod" 34 | } 35 | } 36 | }, 37 | "autoload-dev": { 38 | "psr-4": { 39 | "Aura\\Framework_Project\\": "tests/" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /config/Common.php: -------------------------------------------------------------------------------- 1 | set('aura/project-kernel:logger', $di->lazyNew('Monolog\Logger')); 12 | } 13 | 14 | public function modify(Container $di) 15 | { 16 | $this->modifyLogger($di); 17 | $this->modifyCliDispatcher($di); 18 | $this->modifyWebRouter($di); 19 | $this->modifyWebDispatcher($di); 20 | } 21 | 22 | protected function modifyLogger(Container $di) 23 | { 24 | $project = $di->get('project'); 25 | $mode = $project->getMode(); 26 | $file = $project->getPath("tmp/log/{$mode}.log"); 27 | 28 | $logger = $di->get('aura/project-kernel:logger'); 29 | $logger->pushHandler($di->newInstance( 30 | 'Monolog\Handler\StreamHandler', 31 | array( 32 | 'stream' => $file, 33 | ) 34 | )); 35 | } 36 | 37 | protected function modifyCliDispatcher(Container $di) 38 | { 39 | $context = $di->get('aura/cli-kernel:context'); 40 | $stdio = $di->get('aura/cli-kernel:stdio'); 41 | $logger = $di->get('aura/project-kernel:logger'); 42 | $dispatcher = $di->get('aura/cli-kernel:dispatcher'); 43 | $dispatcher->setObject( 44 | 'hello', 45 | function ($name = 'World') use ($context, $stdio, $logger) { 46 | $stdio->outln("Hello {$name}!"); 47 | $logger->debug("Said hello to '{$name}'"); 48 | } 49 | ); 50 | } 51 | 52 | public function modifyWebRouter(Container $di) 53 | { 54 | $router = $di->get('aura/web-kernel:router'); 55 | 56 | $router->add('hello', '/') 57 | ->setValues(array('action' => 'hello')); 58 | } 59 | 60 | public function modifyWebDispatcher($di) 61 | { 62 | $dispatcher = $di->get('aura/web-kernel:dispatcher'); 63 | 64 | $dispatcher->setObject('hello', function () use ($di) { 65 | $response = $di->get('aura/web-kernel:response'); 66 | $response->content->set('Hello World!'); 67 | }); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /config/Dev.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ./tests 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auraphp/Aura.Framework_Project/1f98afdc941098b41ae677b8952419f4888ae241/src/.placeholder -------------------------------------------------------------------------------- /tests/FrameworkProjectTest.php: -------------------------------------------------------------------------------- 1 | assertSame($expect, $actual); 12 | } 13 | 14 | public function testWeb() 15 | { 16 | $url = "http://localhost:8080/index.php"; 17 | $actual = file_get_contents($url); 18 | $expect = 'Hello World!'; 19 | $this->assertSame($expect, $actual); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tmp/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auraphp/Aura.Framework_Project/1f98afdc941098b41ae677b8952419f4888ae241/tmp/.placeholder -------------------------------------------------------------------------------- /tmp/cache/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auraphp/Aura.Framework_Project/1f98afdc941098b41ae677b8952419f4888ae241/tmp/cache/.placeholder -------------------------------------------------------------------------------- /tmp/log/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auraphp/Aura.Framework_Project/1f98afdc941098b41ae677b8952419f4888ae241/tmp/log/.placeholder -------------------------------------------------------------------------------- /web/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | # turn on rewriting 3 | RewriteEngine On 4 | 5 | # turn empty requests into requests for "index.php", 6 | # keeping the query string intact 7 | RewriteRule ^$ index.php [QSA] 8 | 9 | # look for cached versions of files in ./web/cache/ 10 | RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI} -f 11 | RewriteRule ^(.*)$ cache/$1 [L] 12 | 13 | # for all files not found in the file system, 14 | # reroute to "index.php" bootstrap script, 15 | # keeping the query string intact. 16 | RewriteCond %{REQUEST_FILENAME} !-d 17 | RewriteCond %{REQUEST_FILENAME} !-f 18 | RewriteCond %{REQUEST_FILENAME} !favicon.ico$ 19 | RewriteRule ^(.*)$ index.php [QSA,L] 20 | 21 | -------------------------------------------------------------------------------- /web/index.php: -------------------------------------------------------------------------------- 1 | newKernel( 15 | $path, 16 | 'Aura\Web_Kernel\WebKernel' 17 | ); 18 | $kernel(); 19 | --------------------------------------------------------------------------------