arvici/framework

Arvici 框架

2.0.0-rc.2 2018-03-27 08:56 UTC

README

Build Status License Coverage Status Codacy Badge Codacy Badge

Latest Stable Version Latest Unstable Version Dependency Status

Arvici 框架

简介

此包包含 Arvici 框架的核心功能。目前处于开发中!

入门

仅适用于专家使用此包,请点击以下链接获取如何开始使用框架的说明。 入门,使用 composer create-project

组件

路由器

您可以在 Router.php 配置中定义您的路由。使用 Router::define 方法定义您的路由。

示例

Router::define(function(Router $router) {
    $router->get('/',           '\App\Controller\Welcome::index');
    $router->get('/session',    '\App\Controller\Welcome::session');
    $router->get('/json',       '\App\Controller\Welcome::json');
    $router->get('/exception',  '\App\Controller\Welcome::exception');
});

数据库

您的数据库配置位于 Database.php。

示例

Configuration::define('database', function() {
    return [
        /**
         * The default fetch type to use.
         */
        'fetchType' => \Arvici\Heart\Database\Database::FETCH_ASSOC,
        
        /**
         * Database Connection names and configuration values.
         *
         * 'default' is used when no connection name is provided, or using SweetORM.
         */
        'connections' => [
            'default' => [
                'driver'        => 'MySQL',
                'host'          => 'localhost',
                'username'      => 'root',
                'password'      => '',
                'port'          => 3306,
                'database'      => 'arvici_test'
            ],
        ]
    ];
});

模型/ORM

使用 ORM 时,请查阅单独的文档: https://github.com/tomvlk/sweet-orm#defining-entities

缓存

要使用缓存系统,您必须定义缓存配置或默认使用文件系统。

配置文件 Cache.php

Configure::define('cache', function () {
    return [

        /**
         * Enable cache.
         */
        'enabled' => true,

        /**
         * Set to true to enable cache even in non-production mode.
         */
        'forceEnabled' => true,

        /**
         * Cache Pool Configuration.
         */
        'pools' => [
            'default' => [
                'driver' => '\Stash\Driver\FileSystem',
                'options' => [
                    'path' => BASEPATH . 'cache' . DS,
                ]
            ],
        ],

    ];
});

使用缓存池

要检索池(您可以在其中保存和获取项目),您必须使用管理器。

$manager = \Arvici\Component\Cache::getInstance();

在下一步中,您需要获取池。池在您的配置文件中配置。

$pool = $manager->getPool(); // pool name = 'default'
// or with a pool name:
$pool = $manager->getPool('redis-cache'); // pool name = 'redis-cache'

要检索、保存或使用项目,您首先需要获取上下文。使用 Item 实例可以读取和操作内容。

使用示例

$item = $pool->get('test/cachingkey');
$item->set($data);

$expiration = new DateTime('2020-01-21');
$item->expiresAfter($expiration);

$item->save();

$data = $item->get();

$item->isMiss(); // bool

更多信息

使用的缓存库是 Stash。有关使用池的更多信息,请参阅: http://www.stashphp.com/Basics.html

许可证

MIT 许可证,请参阅 LICENSE 文件。