承接 grobmeier/cicada 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

grobmeier/cicada

Composer 安装命令:

composer require grobmeier/cicada

包简介

Tiny PHP framework for quickly creating webapps, inspired by Rubys Sinatra

关键字:

README 文档

README

A micro framework for creating traditional or REST-like web applications.

Latest Stable Version Total Downloads Build Status Coverage Status License

Installation

Add Cicada as a requirement for your project via Composer:

composer require "cicada/cicada=@stable"

Usage

Minimal application:

require '../vendor/autoload.php';

use Cicada\Application;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$app = new Application();

// Add a route
$app->get('/hello/{name}', function (Application $app, Request $request, $name) {
    return new Response("Hello $name");
});

$app->run();

This application has one route which will match GET requests starting with /hello/ and will forward the matched {name} into the callback function as $name.

The callback function should return a Response object. If it returns a string, it will implicitly be converted into a Response.

Handling exceptions

It is possible that route callbacks throw an exception. By default, Cicada will in this case return a HTTP 500 response (Internal Server Error). However, it is possible to add exception handlers which will intercept specific exceptions and return an appropriate response.

For example, if you want to catch a custom NotImplementedException and return a custom error message:

$app->exception(function (NotImplementedException $ex) {
    $msg = "Dreadfully sorry, old chap, but tis' not implemented yet.";
    return new Response($msg, Response::HTTP_INTERNAL_SERVER_ERROR);
});

The callback function passed to $app->exception() must have a single argument and that argument must have a class type hint which denotes the exception class which it will handle.

It's possible to specify multiple exception handlers and they will be tried in order in which they were specified:

$app->exception(function (SomeException $ex) {
    return new Response("Arrrghhhhh", Response::HTTP_INTERNAL_SERVER_ERROR);
});


$app->exception(function (OtherException $ex) {
    return new Response("FFFFUUUUUUU...", Response::HTTP_INTERNAL_SERVER_ERROR);
});

// If all else fails, this will catch any exceptions
$app->exception(function (Exception $ex) {
    $msg ="Something went wrong. The incident has been logged and our code monkeys are on it.";
    return new Response($msg, Response::HTTP_INTERNAL_SERVER_ERROR);
});

统计信息

  • 总下载量: 203
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2013-06-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固