inspira/application 问题修复 & 功能扩展

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

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

inspira/application

Composer 安装命令:

composer require inspira/application

包简介

The Inspira application setup

README 文档

README

A simple PHP MVC framework inspired from Laravel.

DISCLAIMER !!!

This project is for fun and educational purposes only.

How to use?

Create a project via composer.

composer create-project inspira/application -s dev <project-name>

Note:

  • You can change the project name to your desired name

Start the application.

php wizard run

Note:

  • You can set a custom port by providing the port option in the command
  • You can also set a custom host by providing the host option in the command. Just make sure that this host is added in your host file.
  • To see all available commands, run php wizard.

Features

⭐Router

You can register your web routes at routes.php located in app directory.

Router's supported methods are get, post, put, and delete.

The parameters are as follows:

Uri
  • string
  • required
Handler
  • array | Closure
  • required
  • The shape of array handler should be [controller, method]
Middlewares
  • array | string
  • optional
  • Default is empty array
Name
  • string
  • optional

use App\Controllers\HomeController;

/** @var Inspira\Http\Router\Router $router */
$router->get('/user/:id/posts/:post?', [HomeController::class, 'index'], \App\Middlewares\AuthMiddleware::class, 'home');

Router also supports dynamic route parameters, both required and optional.

To indicate a route parameter, just prefix it with a colon :, and to indicate an optional route parameter, just suffix it with a question mark ?.

You can access these parameters from the request object via property access or get method. For example, you register the following route /users/:id/posts/:post?


use Inspira\Http\Request;

class HomeController
{
	public function index(Request $request)
	{
		echo $request->id;
		// post is optional and might be null so you can use get() and provide a default value
		echo $request->get('post', 1);
	}
}

⭐Middlewares

You can create your own middlewares inside of app/Middlewares directory. The middleware should extend the Middleware abstract class as it implements PSR's MiddlewareInterface.

After creating your middleware, you can modify the boolean $global property to indicate whether this middleware should run on all requests. If you wish to only run the middleware on specific route, then you should set $global to false and attach the middleware from route registration.


namespace App\Middlewares;

use Inspira\Http\Middlewares\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class AuthMiddleware extends Middleware
{
	// Change the value based on your needs
	public bool $global = false;
  
	public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
	{
		// Do something with the request object and pass to the next handler or immediately return a response
		return $handler->handle($request);
	}
}

⭐Service Container

Service Container is the heart of this framework. It handles the dependency injection and automatically resolve these dependencies through the use of PHP's Reflection API.

Service Container can be used to

  • Bind a concrete class to an abstract class
  • Bind a singleton class
  • Make an instance of a class with deep dependency

Currently, container can only resolve injected dependencies that are a valid class, enum, or interface. However, you can still bind an implementation to any word you want and use the make method to resolve it.


// Example of binding
container()->bind(StorageInterface::class, LocalStorage::class);

// In controller method
public function upload(StorageInterface $storage) {
    print_f($storage instanceof LocalStorage::class); // prints out true
}

// Example of singleton binding
// You will get only one instance of Database class throughout the request
container()->singleton(DatabaseInterface::class, Database::class); // or container()->singleton(Database::class) if you don't need to bind it to an interface

// In controller method
public function create(Database $database) {
    $database->table(...); // you will get the same instance throughout the request
}

// Example of making an instance
// Let's say that request class has a lot of dependencies, and it's dependencies also have dependencies
// Service Container will do all the work for you to make an instance of it
container()->make(Request::class); // or container()->make('auth') if for example you bound an Auth class to the word `auth`

inspira/application 适用场景与选型建议

inspira/application 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 inspira/application 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 inspira/application 我们能提供哪些服务?
定制开发 / 二次开发

基于 inspira/application 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: CSS

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-03