1. Go to this page and download the library: Download pixo/outpost library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pixo / outpost example snippets
# Get the Composer autoloader
= 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);
$site->addRoute('GET', '/news', new NewsPageResponder());
$site->addRoute('GET', '/news/article/{id}', new ArticlePageResponder());
class ArticlePageResponder
{
public function __invoke($site, $request, array $params)
{
$articleId = list($params);
print $this->render('about-page.tpl', $this->getArticle($articleId));
}
}
$resource = function ($site) { return 1; }
print $site->get($resource);
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
}
}
# 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());
# 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();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.