topsitemakers/superglue

关于此包的最新版本(dev-master)没有可用的许可信息。

dev-master 2013-11-10 14:21 UTC

This package is not auto-updated.

Last update: 2024-09-28 12:33:04 UTC


README

PHP "微型框架",用于快速原型设计

这基本上是对现有Glue类的修改版本,用于映射URL到类。其主要目的是快速且简单地进行原型设计,尽可能减少开销。
它不使用PHP 5.3+的任何特性,并且应该可以在安装了PHP 5.x+的任何地方运行。

此版本与原始类之间的差异包括

  • 匹配类和方法而不是直接函数。这允许更好的应用程序组织。
  • 使用正则表达式标记参数(例如,<alpha|case-insensitive><alphanumeric|case-insensitive>)。
  • 删除了协议函数(GET()POST())。

附带一个非常简单的 .htaccess 文件,以便进行可读的URL。

用法

您首先需要定义可访问的URL

require 'superglue.php';

// Define URLs
$urls = array(
  
  // This will be binded to class "sample" and method "index"
  '/' => 'sample',
  // This will be binded to class "sample" and method "page"
  '/sample' => array('sample', 'page'),

  // RESTful example
  // If we do not pass an array here, superglue will check if the class has
  // method named as the request method (GET, POST, DELETE, PUSH)
  '/restful' => 'restful',

);

定义在适当的路由上将被调用的类

// Our sample class
// Classes are better than direct functions for code organization and for
// avoiding name clashes.
class sample {
  function index() {
    print 'home page';
  }
  function page() {
    print 'sample page';
  }
}

// Example RESTful class
// Each method corresponds with the request method.
class restful {
  function GET() {
    print 'GET method.';
  }
  function POST() {
    print 'POST method.';
  }
  function PUSH() {
    print 'PUSH method.';
  }
  function DELETE() {
    print 'DELETE method.';
  }
}

就这样 - 启动应用程序!

superglue::stick($urls);

致谢

Glue

作者:topsitemakers.com