承接 pixo/outpost 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pixo/outpost

Composer 安装命令:

composer require pixo/outpost

包简介

A PHP Framework for Decoupled Websites

README 文档

README

Outpost is a lightweight web framework, designed for decoupled websites. PHP 5.5+ is required.

What Outpost Does

Routing. Outpost uses Phroute to route an incoming request to the correct responder.

Caching. Each Outpost site has a Stash instance for storing resources between requests.

Logging. Outpost uses Monolog to send status messages to lots of types of logs.

What Outpost Doesn't Do

Templates. Outpost provides no default templating engine.

HTTP. Outpost doesn't provide a client for fetching external resources.

Quickstart

Create a new directory for your Outpost installation. From inside this directory, use Composer to install Outpost:

composer require pixo/outpost

You should now have composer.json and composer.lock files, and a vendor directory containing Outpost and its dependencies.

Create a new directory called public, and in that directory make a new file called index.php with the following contents:

<?php

# Get the Composer autoloader
require_once __DIR__ . '/../vendor/autoload.php';

# Get the incoming request
$request = Symfony\Component\HttpFoundation\Request::createFromGlobals();

# Create a Site object
$site = new Outpost\Site();

# Add an example route
$site->addRoute('GET', '/', function () { print "Hello."; });

# Send a response
$site->respond($request);

Start a local PHP development server and point it at the public directory:

php -S 0.0.0.0:8080 -t public

Once the server is running, you should be able to visit http://localhost:8080/ and see the following:

Hello.

What Just Happened?

Outpost received a request for the home page, and it routed the request to a function that printed "Hello."

When you visited http://localhost:8080/, the server directed you to the index.php script. It included the Composer autoloader, then made a new Request object, using information from the server environment.

The script next created an Outpost Site object, and added one routing instruction: when a visitor asks for the home page, run this function. Functions or other callables used as the targets of routes are called Responders.

Finally, the new Site's respond() method was called. The router used the Request object to find the right Responder: a function that printed "Hello."

Sites

Site objects have two primary purposes:

  • They route each incoming request to the appropriate Responder.
  • They provide Resources needed to create responses.

Responders

Responders act as router callbacks, and are expected to output a response when invoked.

Responder routes can be created using the site's addRoute() method:

$site->addRoute('GET', '/news', new NewsPageResponder());
$site->addRoute('GET', '/news/article/{id}', new ArticlePageResponder());

Responders receive 3 parameters when invoked:

  1. The Site object responding to the request
  2. The Request object
  3. Any parameters extracted from the URL
class ArticlePageResponder
{
  public function __invoke($site, $request, array $params)
  {
    $articleId = list($params);
    print $this->render('about-page.tpl', $this->getArticle($articleId));
  }
}

Resources

An Outpost installation may define any number of Resource classes. Resources are retrieved using the Site's get() method, and they receive the Site object when invoked. The simplest resource is just a callable:

$resource = function ($site) { return 1; }
print $site->get($resource);

The get() method invokes the callable and returns the result, so the output would be:

1

Caching

Resources that implement CacheableInterface can be stored in the site cache, and are only invoked when the cached resource is missing or stale. Cacheable resources have a unique key, and specify the number of seconds they may be cached before a refresh is required.

class ExampleExpensiveResource implements \Outpost\Cache\CacheableInterface {

  public function __invoke($site) {
    # Something that takes a long time, then...
    return $this;
  }
  
  public function getCacheKey() {
    return 'examples/expensive';
  }
  
  public function getCacheLifetime() {
    return 3600; # 1 hour
  }
}

The first time this resource is requested, it is invoked, and the return value is stored in the site cache. For subsequent requests, the cached copy is returned, until the copy is older than the value of getCacheLifetime().

# Nothing in the cache for this call, so Outpost invokes the Resource
# and caches the return value.
$fresh = $site->get(new ExampleExpensiveResource());

# This time the Resource is in the cache, so Outpost returns the cached Resource.
$cached = $site->get(new ExampleExpensiveResource());

# An hour passes...

# Now the cached copy is stale, so Outpost will invoke the Resource again,
# and replace the cached copy.
$fresh = $site->get(new ExampleExpensiveResource());

The Site::getCache() method provides access to the underlying Stash cache object.

# Clear a specific key
$site->getCache()->clear('cache/key');

# Clear a range of keys
$site->getCache()->clear('things/id/*');

# Clear the whole cache
$site->getCache()->clear();

# Flush the cache
$site->getCache()->flush();

pixo/outpost 适用场景与选型建议

pixo/outpost 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 351 次下载、GitHub Stars 达 28, 最近一次更新时间为 2015 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 pixo/outpost 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pixo/outpost 我们能提供哪些服务?
定制开发 / 二次开发

基于 pixo/outpost 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 351
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 28
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 28
  • Watchers: 12
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: NCSA
  • 更新时间: 2015-03-23