andrewscaya/statuslib-example
Composer 安装命令:
composer require andrewscaya/statuslib-example
包简介
Library for use with Apigility documentation examples
关键字:
README 文档
README
This is a library designed to demonstrate an Apigility "Code-Connected" REST API, and has been written in parallel with the Apigility documentation.
It uses the following components:
- rhumsaa/uuid, a library for generating and validating UUIDs.
- zfcampus/zf-configuration, used for providing PHP files as one possible backend for reading/writing status messages.
- zendframework/zend-config for the actual configuration writer used
by the
zf-configurationmodule. - zendframework/zend-db, used for providing a database table as a backend for reading/writing status messages.
- zendframework/zend-stdlib, specifically the Hydrator subcomponent,
for casting data from arrays to objects, and for the
ArrayUtilsclass, which provides advanced array merging capabilities. - zendframework/zend-paginator for providing pagination.
It is written as a Zend Framework module, but could potentially be dropped into other
applications; use the StatusLib\*Factory classes to see how dependencies might be injected.
Installation
Use Composer to install the library in your application:
$ composer require zfcampus/statuslib-example
If you are using this as part of a Zend Framework or Apigility application, you
may need to enable the module in your config/application.config.php file, if
you are not using the zend-component-installer:
return [ /* ... */ 'modules' => [ /* ... */ 'StatusLib', ], /* ... */ ];
Configuration
When used as a Zend Framework module, you may define the following configuration values in order to tell the library which adapter to use, and what options to pass to that adapter.
[
'statuslib' => [
'db' => 'Name of service providing DB adapter',
'table' => 'Name of database table within db to use',
'array_mapper_path' => 'path to PHP file returning an array for use with ArrayMapper',
],
'service_manager' => [
'aliases' => [
// Set to either StatusLib\ArrayMapper or StatusLib\TableGatewayMapper
\StatusLib\Mapper::class => \StatusLib\ArrayMapper::class,
],
],
]
For purposes of the Apigility examples, we suggest the following:
-
Create a PHP file in your application's
data/directory namedstatuslib.phpthat returns an array:<?php return [];
-
Edit your application's
config/autoload/local.phpfile to set thearray_mapper_pathconfiguration value todata/statuslib.php:<?php return [ /* ... */ 'statuslib' => [ 'array_mapper_path' => 'data/statuslib.php', ], ];
The above will provide the minimum necessary requirements for experimenting with the library in order to test an API.
Using a database
The file data/statuslib.sqlite.sql contains a SQLite schema. You can
create a SQLite database using:
$ sqlite3 statuslib.db < path/to/data/statuslib.sqlite.sql
The schema can be either used directly by other databases, or easily modified to work with other databases.
StatusLib in a New Zend Framework Project
- Create a new Zend Framework project from scratch; we'll use
my-projectas our project folder:
$ composer create-project zendframework/skeleton-application my-project
- Install the StatusLib module:
$ composer require zfcampus/statuslib-example
-
Build a DataSource
-
Option A: Array data source:
First, copy the sample array to the
datadirectory of thet application:$ cp vendor/zfcampus/statuslib-example/data/sample-data/array-data.php data/status.data.phpThen, configure this datasource by setting up a
local.phpconfiguration file:$ cp config/autoload/local.php.dist config/autoload/local.phpNext, add the StatusLib specific configuration for an array based data source:
'statuslib' => [ 'array_mapper_path' => 'data/status.data.php', ], 'service_manager' => [ 'aliases' => [ \StatusLib\Mapper::class => \StatusLib\ArrayMapper::class, ], ],
-
Option B: Sqlite data source:
First, create a sqlite3 database, and fill it with the sample data:
$ sqlite3 data/status.db < vendor/zfcampus/statuslib-example/data/statuslib.sqlite.sql $ sqlite3 data/status.db < vendor/zfcampus/statuslib-example/data/sample-data/db-sqlite-insert.sql
Then, configure this datasource by setting up a
local.phpconfiguration file:$ cp config/autoload/local.php.dist config/autoload/local.phpNext, add the StatusLib specific configuration for a sqlite database based data source:
'db' => [ 'adapters' => [ 'MyDb' => [ 'driver' => 'pdo_sqlite', 'database' => __DIR__ . '/../../data/status.db' ], ], ], 'statuslib' => [ 'db' => 'MyDb', 'table' => 'status', ], 'service_manager' => [ 'aliases' => [ \StatusLib\Mapper::class => \StatusLib\TableGatewayMapper::class, ], ],
-
-
Create a test script to prove the data source is working:
// test.php namespace StatusLib; use Zend\Mvc\Application; use Zend\Stdlib\ArrayUtils; include 'vendor/autoload.php'; $appConfig = include 'config/application.config.php'; if (file_exists('config/development.config.php')) { $appConfig = ArrayUtils::merge( $appConfig, include 'config/development.config.php' ); } $app = Application::init($appConfig); $services = $app->getServiceManager(); $statusMapper = $services->get(Mapper::class); foreach ($statusMapper->fetchAll() as $status) { printf( "[%d] [%s] %s (by %s)\n", $status->timestamp, $status->id, $status->message, $status->user ); }
andrewscaya/statuslib-example 适用场景与选型建议
andrewscaya/statuslib-example 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「zf2」 「apigility」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 andrewscaya/statuslib-example 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 andrewscaya/statuslib-example 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 andrewscaya/statuslib-example 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
LosLog provides some log utility
EdpModuleLayouts is very simple Laminas module for making module-specific layouts insanely easy.
Apigility Doctrine module which enables POST-ing collections
Zend Framework module to leverage the symfony dependency injection container
RCM User HTML views/pages
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-04-21