매우 간단하고 빠른 PHP 라우터
작곡가를 사용하여 Moxrouter를 설치하는 것이 좋습니다.
$ composer require moxxie/moxrouter " ^0.2.0 " 다음 내용이있는 index.php 파일을 만듭니다.
<?php
require ' vendor/autoload.php ' ;
$ router = new Moxxie MoxRouter ();
$ router -> get ( ' /{message} ' , function ( $ message ){
echo " Hello " . $ message . " ! " ;
});
$ router -> run ();PHP와 함께 제공되는 내장 서버를 사용하여이를 테스트 할 수 있습니다.
$ php -S localhost:8000http : // localhost : 8000/world는 이제 "Hello, World!"를 표시합니다.
Moxrouter 지원 Get, Post, Put, Patch 및 Delete HTTP 요청
// Will only match GET HTTP requests
$ router -> get ( ' /product/{id} ' , function ( $ id ){
// Return product with id = $id
});
// Will only match POST HTTP requests
$ router -> post ( ' /product ' , function (){
// Create new a product
});
// Will only match PUT HTTP requests
$ router -> put ( ' /product/{id} ' , function ( $ id ){
// Update product with id = $id
});
// Will only match PATCH HTTP requests
$ router -> patch ( ' /product/{id} ' , function ( $ id ){
// Apply changes made to product with id = $id
});
// Will only match DELETE HTTP requests
$ router -> delete ( ' /product/{id} ' , function ( $ id ){
// Delete product with id = $id
});
<?php
$ router = new Moxxie MoxRouter ();
// Create an empty container
$ container = [];
// Add a service to the container
$ container [ ' service ' ] = function (){
return new Service ();
};
$ router -> get ( ' / ' , function (){
// Use the new Service
$ service = $ this -> service ();
});
// Run the router with the container
$ router -> run ( $ container );경로 전에
$ router -> before ( function (){
// This code will be executed before a route has been executed
});경로 후
$ router -> after ( function (){
// This code will be executed after a route has been executed
});기본 404 핸들러를 무시할 수 있습니다
$ router -> notFound ( function (){
// This code will be executed when a route is not found
});아파치 .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]nginx
try_files $uri /index.php;(MIT 라이센스)
Copyright (C) 2017 Moxxie -https://github.com/moxxie/moxrouter
이에 따라이 소프트웨어 및 관련 문서 파일 ( "소프트웨어")의 사본을 얻는 사람에게는 허가가 부여됩니다. 소프트웨어의 사용, 복사, 수정, 합병, 배포, 배포, 숭고 및/또는 소프트웨어의 사본을 판매 할 권한을 포함하여 제한없이 소프트웨어를 처리 할 수 있도록 소프트웨어를 제공 할 권한이 없습니다.
위의 저작권 통지 및이 권한 통지는 소프트웨어의 모든 사본 또는 실질적인 부분에 포함되어야합니다.
이 소프트웨어는 상업성, 특정 목적에 대한 적합성 및 비 침해에 대한 보증을 포함하여 명시 적 또는 묵시적 보증없이 "그대로"제공됩니다. 어떠한 경우에도 저자 또는 저작권 보유자는 계약, 불법 행위 또는 기타, 소프트웨어 또는 소프트웨어의 사용 또는 기타 거래에서 발생하는 계약, 불법 행위 또는 기타의 행동에 관계없이 청구, 손해 또는 기타 책임에 대해 책임을지지 않습니다.