eric-chau/jarvis 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eric-chau/jarvis

最新稳定版本:v2.0.0

Composer 安装命令:

composer require eric-chau/jarvis

包简介

Jarvis is a PHP 7.1 micro-framework

README 文档

README

Code Climate Test Coverage Build Status SensioLabsInsight Scrutinizer Code Quality

Jarvis is a PHP 7.1 micro framework. It is designed to be simple and lightweight.

Note that if you want to use Jarvis with PHP 5.6, please switch on 0.1 branch or use the v0.1.* tag.

Jarvis requires php >= 7.1. it's based on its own dependency injection container, http foundation component from Symfony and nikic's fast route.

Usage

<?php

require_once __DIR__ . '/vendor/autoload.php';

$jarvis = new Jarvis\Jarvis();

$jarvis->router
    ->beginRoute('default')
        ->setMethod('get')
        ->setPattern('/')
        ->setHandler(function () {
            return 'Hello world!';
        })
    ->end()
;

$response = $jarvis->run();

$response->send();

How Jarvis process incoming request

The schema below will sum up how Jarvis\Jarvis::run() treats any incoming request:

INPUT: an instance of Request

|
|__ Step 1: broadcast RunEvent.
|
|__ Step 2: check if RunEvent has a response?
|_______
| NO    | YES
|       |
|       |_ RETURN Response
|
|__ Step 3: resolve URI
|
|__ Step 4: does request match any route?
|_______
| NO*   | YES
|       |
|       |_ Step 4a: broadcast ControllerEvent
|       |
|       |_ Step 4b: invoke callback to process the request
|       |
|<------
|
|_ Step 5: broadcast ResponseEvent
|
|_ RETURN Response

OUT: an instance of Response

*: note that if provided URI does not match any route run() will return an instance of Response with 404 or 406 status code.

Router skill

Jarvis' Router can handle anonymous and named routes. By default, a route is type of HTTP GET method and the pattern setted to /. You can find some example below:

Anonymous route, GET HTTP method, / as pattern

<?php

require_once __DIR__ . '/vendor/autoload.php';

$jarvis = new Jarvis\Jarvis();

$jarvis->router
    ->beginRoute()
        ->setHandler(function () {
            return 'foobar!';
        })
    ->end()
;

Named route, name: user_edit , http method: PUT, pattern: /user/{id}

Note that id must be a number. Let's see how to do so.

<?php

require_once __DIR__ . '/vendor/autoload.php';

$jarvis = new Jarvis\Jarvis();

$jarvis->router
    ->beginRoute('user_edit')
        ->setMethod('PUT')
        ->setPattern('/user/{id:\d+}')
        ->setHandler(function ($id) {
            // Do some stuff

            return "User $id informations are now up-to-date!";
        })
    ->end()
;

echo $jarvis->router->uri('user_edit', ['id' => 123]); // print '/user/123'

Dependency injection container skill

Container::alias()

Jarvis' DIC (dependency injection container) can deal with alias:

<?php

$jarvis = new Jarvis\Jarvis();

$jarvis['foo'] = 'hello world';
$jarvis->alias('bar', 'foo');

$jarvis['foo'] === $jarvis['bar']; // = true

Container::find()

::find() is an another useful method provided by Jarvis' DIC:

<?php

$jarvis = new Jarvis\Jarvis();

$jarvis['dicaprio_movie_1997'] = 'Titanic';
$jarvis['dicaprio_movie_2010'] = 'Inception';
$jarvis['dicaprio_movie_2014'] = 'The Wolf of Wall Street';

$jarvis->find('dicaprio_movie_*'); // = ['Titanic', 'Inception', 'The Wolf of Wall Street']
$jarvis->find('dicaprio_movie_19*'); // = ['Titanic']
$jarvis->find('dicaprio_movie_2015'); // = []

统计信息

  • 总下载量: 254
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 3
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固