├── .gitignore ├── README.md ├── app ├── Action │ ├── Action.php │ └── Index │ │ └── PageAction.php ├── Controller │ ├── Controller.php │ ├── Demo │ │ └── IndexController.php │ ├── FooController.php │ ├── FuckController.php │ └── IndexController.php └── Service │ └── AppService.php ├── composer.json ├── composer.lock ├── config ├── app.php └── routes.php ├── phpunit.xml.dist └── public └── index.php /.gitignore: -------------------------------------------------------------------------------- 1 | /test.php 2 | /tests/coverage 3 | 4 | # Cache and logs 5 | /vendor/ 6 | logs/* 7 | # Composer PHAR 8 | /composer.phar 9 | 10 | .DS_Store 11 | /.idea 12 | /.vscode 13 | # tags Files 14 | /.tags 15 | /.tags* 16 | /.tags_sorted_by_file 17 | /resetData.sh 18 | 19 | *.php~ 20 | *.swap 21 | *.swp 22 | *.swo 23 | *.bak 24 | *.ini 25 | *.log 26 | 27 | # Kdevelop IDE 28 | .kdev4 29 | *.kdev4 30 | 31 | #IDE ZEND STUDIO 32 | .buildpath 33 | .project 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The Zim Framework 2 | 3 | ### About 4 | 5 | Zim is a simple framework inspired(copy/paste 😄) by Yaf, Laravel, Symfony, based on Zephir Language. 6 | 7 | Delivered as a C extension for the PHP language via [zim-ext](https://github.com/henter/zim-ext) , or you can choose the pure php implementation [zim-php](https://github.com/henter/zim-php) 8 | 9 | ### Requirements 10 | 11 | 0. PHP >= 7.0 12 | 1. Composer 13 | 14 | ### Install 15 | 16 | build php extension from [zim-ext](https://github.com/henter/zim-ext) 17 | 18 | or 19 | 20 | install php implementation with composer 21 | 22 | `composer require henter/zim` 23 | 24 | ### Usage 25 | 26 | simple demo with php build-in server 27 | 28 | index.php 29 | ```php 30 | 'demo test']); 30 | } 31 | } -------------------------------------------------------------------------------- /app/Controller/FooController.php: -------------------------------------------------------------------------------- 1 | PageAction::class, 19 | ]; 20 | 21 | public function __construct(Config $config) 22 | { 23 | //var_dump('test inject config ', $config); 24 | } 25 | 26 | public function indexAction($x = 'xx') 27 | { 28 | return \Zim\Zim::config('app.name').' '.$x; 29 | } 30 | 31 | public function postAction($page = 2, $x = 'xxx', Config $config) 32 | { 33 | return 'test page '.$page.' '.$x ; 34 | } 35 | 36 | public function testAction(Config $config) 37 | { 38 | return new JsonResponse(['test' => 'ok', 'config' => $config->all()]); 39 | } 40 | 41 | public function test_methodAction(Config $config) 42 | { 43 | return 'test method'; 44 | } 45 | 46 | public function xxxAction() 47 | { 48 | return new JsonResponse(['xx' => 'xxxxxxxxx']); 49 | } 50 | 51 | public function helloAction($world) 52 | { 53 | return 'hello '.$world; 54 | } 55 | 56 | private function privateMethodTestAction() 57 | { 58 | return __FUNCTION__; 59 | } 60 | } -------------------------------------------------------------------------------- /app/Service/AppService.php: -------------------------------------------------------------------------------- 1 | setResponse($resp); 38 | } 39 | 40 | if ($e == ResponseEvent::class && $payload instanceof ResponseEvent) { 41 | $resp = new Response('test response event'); 42 | //$payload->setResponse($resp); 43 | } 44 | if ($e == ExceptionEvent::class && $payload instanceof ExceptionEvent) { 45 | $resp = new Response('test catch exception: '.$payload->getThrowable()->getMessage()); 46 | $payload->setResponse($resp); 47 | } 48 | }); 49 | 50 | Event::on(function(ResponseEvent $e) { 51 | $resp = new JsonResponse([ 52 | 'code' => 0, 53 | 'data' => 'test on event', 54 | 'origin' => $e->getResponse() ? $e->getResponse()->getContent() : 'empty response', 55 | 'callable' => $e->getRequest()->get('callable') 56 | ]); 57 | $e->setResponse($resp); 58 | //return 222; 59 | }); 60 | 61 | } 62 | 63 | public function register() 64 | { 65 | } 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zim", 3 | "type": "project", 4 | "description": "Zim Framework based on Zephir", 5 | "autoload": { 6 | "psr-4": { 7 | "App\\": "app/" 8 | } 9 | }, 10 | "require": { 11 | "php": "^7.1.3", 12 | "henter/zim": "^1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "c79671d00058e45271acff5534f723a1", 8 | "packages": [ 9 | { 10 | "name": "henter/zim", 11 | "version": "1.0.0", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/henter/zim-php.git", 15 | "reference": "05cc8cbde4ec0b5320561d7618fa22937f4b122c" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/henter/zim-php/zipball/05cc8cbde4ec0b5320561d7618fa22937f4b122c", 20 | "reference": "05cc8cbde4ec0b5320561d7618fa22937f4b122c", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": "^7.1.3" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": "^7.5" 28 | }, 29 | "type": "library", 30 | "autoload": { 31 | "psr-4": { 32 | "Zim\\": "Zim/" 33 | } 34 | }, 35 | "notification-url": "https://packagist.org/downloads/", 36 | "description": "The Zim Framework", 37 | "time": "2019-01-11T08:56:06+00:00" 38 | } 39 | ], 40 | "packages-dev": [], 41 | "aliases": [], 42 | "minimum-stability": "stable", 43 | "stability-flags": [], 44 | "prefer-stable": false, 45 | "prefer-lowest": false, 46 | "platform": { 47 | "php": "^7.1.3" 48 | }, 49 | "platform-dev": [] 50 | } 51 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | 'Zim Demo', 11 | 'env' => 'dev', 12 | 13 | //custom services to load 14 | 'services' => [ 15 | //\App\Service\AppService::class, 16 | ], 17 | ]; -------------------------------------------------------------------------------- /config/routes.php: -------------------------------------------------------------------------------- 1 | ?1}', 'Index@test'); 15 | 16 | Route::post('/test_route1/{page<\d+>?123}', function($page) { 17 | return 'test ok'; 18 | }); 19 | 20 | Route::match(['POST', 'PUT', 'GET'], '/put', function() { 21 | return 'test match'; 22 | }); 23 | 24 | return [ 25 | '/' => 'Index@index', 26 | 'closure' => function() { 27 | return 'closure ok'; 28 | }, 29 | '/test' => 'Index@test', 30 | '/demo' => 'Demo/Index@test', 31 | '/post/{page<\d+>?1}' => 'Index@post', 32 | '/foo' => 'Foo@index', 33 | '/foo/test' => 'Foo@foo', 34 | '/hello/{world}' => [ 35 | 'to' => 'Index@hello', 36 | 'methods' => ['GET', 'POST'], 37 | 'requirements' => [ 38 | 'world' => '\d+', 39 | ], 40 | 'defaults' => ['world' => 2], 41 | 'options' => [], 42 | ], 43 | ]; 44 | 45 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ./tests/ 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | ./app/ 30 | ./Zim/ 31 | 32 | vendor 33 | tests 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 |