upcloo/micro-framework

这是一个基于 ZF2 组件构建的简单微框架

0.0.14 2014-02-02 15:56 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:55:40 UTC


README

这是一个基于 ZF2 组件的简单微框架。

许可

本项目遵循 MIT 许可协议发布。

##入门

scenario 文件夹中,你可以找到不仅是一个示例,还是一个典型的起点... 你可以使用你喜欢的项目文件夹,但一个好的起点是

 - src
   - Your
     - Namespace
 - tests
   - Your
     - Namespace
 - web
 - configs

入口点(web/index.php)

<?php
$loader = include __DIR__ . '/vendor/autoload.php';

$loader->add("Your", __DIR__ . '/../src');

$config = new UpCloo\App\Config\ArrayProcessor();
$config->appendConfig(include __DIR__ . '/../configs/app.php');

$engine = new UpCloo\App\Engine();
$boot = new UpCloo\App\Boot($config);

$app = new UpCloo\App($engine, $boot);
$app->run();

以下是一个配置(configs/app.php)

<?php
return array(
    "router" => array(
        "routes" => array(
            "home" => array(
                "type" => "Literal",
                "options" => array(
                    "route" => "/walter",
                    'defaults' => array(
                        'controller' => 'Your\\Controller\\Name',
                        'action' => 'hello'
                    )
                ),
                'may_terminate' => true,
            )
        )
    ),
    "services" => array(
        "invokables" => array(
            "Your\\Controller\\Name" => "Your\\Controller\\Name",
        ),
        "factories" => array(
            "example" => function(\Zend\ServiceManager\ServiceLocatorInterface $sl) {
                return "hello";
            }
        ),
    )
);

从控制器开始(src/Your/Controller/Name.php)

<?php
namespace Your\Controller;

use UpCloo\Controller\ServiceManager;

class Name
{
    use ServiceManager;

    public function hello()
    {
        $hello = $this->services()->get("example");
        return $hello . " " . "world";
    }
}

启动你的网络服务

php -S localhost:8080 -t web/ web/index.php

访问你的页面 -> localhost:8080/walter

构建状态

  • 主分支
    • Build Status
  • 开发分支
    • Build Status