mirror of
https://github.com/Mibew/mibew.git
synced 2024-11-15 08:34:11 +03:00
Use Stash as a cache system
This commit is contained in:
parent
e514b1590b
commit
a2e2f1b194
4
.gitignore
vendored
4
.gitignore
vendored
@ -10,6 +10,10 @@ src/tests/server_side/mibew/libs/config.php
|
|||||||
src/mibew/files/avatar/*
|
src/mibew/files/avatar/*
|
||||||
!src/mibew/files/avatar/.keep
|
!src/mibew/files/avatar/.keep
|
||||||
|
|
||||||
|
# Do not index cache files
|
||||||
|
src/mibew/cache/*
|
||||||
|
!src/mibew/cache/.keep
|
||||||
|
|
||||||
# Do not index plugins
|
# Do not index plugins
|
||||||
src/mibew/plugins/*
|
src/mibew/plugins/*
|
||||||
!src/mibew/plugins/.keep
|
!src/mibew/plugins/.keep
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
"symfony/routing": "2.5.*",
|
"symfony/routing": "2.5.*",
|
||||||
"symfony/config": "2.5.*",
|
"symfony/config": "2.5.*",
|
||||||
"symfony/yaml": "2.5.*",
|
"symfony/yaml": "2.5.*",
|
||||||
"symfony/translation": "2.5.*"
|
"symfony/translation": "2.5.*",
|
||||||
|
"tedivm/stash": "0.12.*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"squizlabs/php_codesniffer": "1.*"
|
"squizlabs/php_codesniffer": "1.*"
|
||||||
|
@ -28,6 +28,7 @@ var config = {
|
|||||||
mibewPath: 'mibew',
|
mibewPath: 'mibew',
|
||||||
phpVendorPath: 'mibew/vendor',
|
phpVendorPath: 'mibew/vendor',
|
||||||
pluginsPath: 'mibew/plugins',
|
pluginsPath: 'mibew/plugins',
|
||||||
|
cachePath: 'mibew/cache',
|
||||||
jsPath: 'mibew/js',
|
jsPath: 'mibew/js',
|
||||||
chatStylesPath: 'mibew/styles/dialogs',
|
chatStylesPath: 'mibew/styles/dialogs',
|
||||||
pageStylesPath: 'mibew/styles/pages',
|
pageStylesPath: 'mibew/styles/pages',
|
||||||
@ -43,8 +44,15 @@ gulp.task('phpcs', ['composer-install-dev'], function() {
|
|||||||
return gulp.src([
|
return gulp.src([
|
||||||
config.mibewPath + '/**/*.php',
|
config.mibewPath + '/**/*.php',
|
||||||
'!' + config.phpVendorPath + '/**/*.*',
|
'!' + config.phpVendorPath + '/**/*.*',
|
||||||
'!' + config.pluginsPath + '/**/*.*'
|
'!' + config.pluginsPath + '/**/*.*',
|
||||||
])
|
'!' + config.cachePath + '/**/*.*'
|
||||||
|
], {
|
||||||
|
// Content of the cache directory is readable only for webserver. Thus
|
||||||
|
// we must to set "strict" option to false to prevent "EACCES" errors.
|
||||||
|
// At the same we need to see all errors that take place.
|
||||||
|
strict: false,
|
||||||
|
silent: false
|
||||||
|
})
|
||||||
.pipe(phpcs({
|
.pipe(phpcs({
|
||||||
bin: config.phpVendorPath + '/bin/phpcs',
|
bin: config.phpVendorPath + '/bin/phpcs',
|
||||||
standard: 'PSR2',
|
standard: 'PSR2',
|
||||||
@ -167,8 +175,15 @@ gulp.task('generate-pot', function() {
|
|||||||
gulp.src([
|
gulp.src([
|
||||||
config.mibewPath + '/**/*.php',
|
config.mibewPath + '/**/*.php',
|
||||||
'!' + config.phpVendorPath + '/**/*.*',
|
'!' + config.phpVendorPath + '/**/*.*',
|
||||||
'!' + config.pluginsPath + '/**/*.*'
|
'!' + config.pluginsPath + '/**/*.*',
|
||||||
])
|
'!' + config.cachePath + '/**/*.*'
|
||||||
|
], {
|
||||||
|
// Content of the cache directory is readable only for webserver.
|
||||||
|
// Thus we must to set "strict" option to false to prevent "EACCES"
|
||||||
|
// errors. At the same we need to see all errors that take place.
|
||||||
|
strict: false,
|
||||||
|
silent: false
|
||||||
|
})
|
||||||
.pipe(xgettext({
|
.pipe(xgettext({
|
||||||
language: 'PHP',
|
language: 'PHP',
|
||||||
keywords: [
|
keywords: [
|
||||||
@ -209,16 +224,27 @@ gulp.task('generate-pot', function() {
|
|||||||
gulp.task('pack-sources', ['composer-install'], function() {
|
gulp.task('pack-sources', ['composer-install'], function() {
|
||||||
var sources = [
|
var sources = [
|
||||||
config.mibewPath + '/**/*',
|
config.mibewPath + '/**/*',
|
||||||
|
// Exclude cache files but include ".keep" file.
|
||||||
|
'!' + config.cachePath + '/**/!(.keep)',
|
||||||
// Exclude Git repositories that can be shipped with third-party libs
|
// Exclude Git repositories that can be shipped with third-party libs
|
||||||
'!' + config.phpVendorPath + '/**/.git',
|
'!' + config.phpVendorPath + '/**/.git',
|
||||||
'!' + config.phpVendorPath + '/**/.git/**/*'
|
'!' + config.phpVendorPath + '/**/.git/**/*'
|
||||||
];
|
];
|
||||||
|
var srcOptions = {
|
||||||
|
// Dot files (.htaccess, .keep, etc.) must be included in the package.
|
||||||
|
dot: true,
|
||||||
|
// Content of the cache directory is readable only for webserver. Thus
|
||||||
|
// we must to set "strict" option to false to prevent "EACCES" errors.
|
||||||
|
// At the same we need to see all errors that take place.
|
||||||
|
strict: false,
|
||||||
|
silent: false
|
||||||
|
}
|
||||||
var version = config.package.version;
|
var version = config.package.version;
|
||||||
|
|
||||||
return eventStream.merge(
|
return eventStream.merge(
|
||||||
gulp.src(sources, {dot: true})
|
gulp.src(sources, srcOptions)
|
||||||
.pipe(zip('mibew-' + version + '.zip')),
|
.pipe(zip('mibew-' + version + '.zip')),
|
||||||
gulp.src(sources, {dot: true})
|
gulp.src(sources, srcOptions)
|
||||||
.pipe(tar('mibew-' + version + '.tar'))
|
.pipe(tar('mibew-' + version + '.tar'))
|
||||||
.pipe(gzip())
|
.pipe(gzip())
|
||||||
)
|
)
|
||||||
|
@ -25,7 +25,8 @@ INSTALLATION
|
|||||||
10. Change your name.
|
10. Change your name.
|
||||||
11. Wait for your visitors on 'Pending users' page.
|
11. Wait for your visitors on 'Pending users' page.
|
||||||
|
|
||||||
On unix/linux platforms change the owner of /mibew/files/avatar folder
|
On unix/linux platforms change the owner of /mibew/files/avatar and
|
||||||
to the user, under which the web server is running (for instance, www).
|
/mibew/cache folders to the user, under which the web server is running
|
||||||
The owner should have all rights on the folder /mibew/files/avatar
|
(for instance, www). The owner should have all rights on the folders
|
||||||
(chmod 700 /mibew/files/avatar).
|
/mibew/files/avatar and /mibew/cache
|
||||||
|
(chmod 700 /mibew/files/avatar && chmod 700 /mibew/cache).
|
||||||
|
0
src/mibew/cache/.keep
vendored
Normal file
0
src/mibew/cache/.keep
vendored
Normal file
@ -82,11 +82,17 @@ class Application implements RouterAwareInterface, AuthenticationManagerAwareInt
|
|||||||
{
|
{
|
||||||
$this->router = $router;
|
$this->router = $router;
|
||||||
$this->authenticationManager = $manager;
|
$this->authenticationManager = $manager;
|
||||||
|
|
||||||
|
$driver = new \Stash\Driver\FileSystem();
|
||||||
|
$driver->setOptions(array('path' => MIBEW_FS_ROOT . '/cache'));
|
||||||
|
$this->cache = new \Stash\Pool($driver);
|
||||||
|
|
||||||
$this->assetUrlGenerator = new AssetUrlGenerator();
|
$this->assetUrlGenerator = new AssetUrlGenerator();
|
||||||
$this->controllerResolver = new ControllerResolver(
|
$this->controllerResolver = new ControllerResolver(
|
||||||
$this->router,
|
$this->router,
|
||||||
$this->authenticationManager,
|
$this->authenticationManager,
|
||||||
$this->assetUrlGenerator
|
$this->assetUrlGenerator,
|
||||||
|
$this->cache
|
||||||
);
|
);
|
||||||
$this->accessCheckResolver = new CheckResolver($this->authenticationManager);
|
$this->accessCheckResolver = new CheckResolver($this->authenticationManager);
|
||||||
}
|
}
|
||||||
|
42
src/mibew/libs/classes/Mibew/Cache/CacheAwareInterface.php
Normal file
42
src/mibew/libs/classes/Mibew/Cache/CacheAwareInterface.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is a part of Mibew Messenger.
|
||||||
|
*
|
||||||
|
* Copyright 2005-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mibew\Cache;
|
||||||
|
|
||||||
|
use Stash\Interfaces\PoolInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A common interface for all classes that works with cache.
|
||||||
|
*/
|
||||||
|
interface CacheAwareInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Gets cache pool instance related with the object.
|
||||||
|
*
|
||||||
|
* @return PoolInterface
|
||||||
|
*/
|
||||||
|
public function getCache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a cache pool instance.
|
||||||
|
*
|
||||||
|
* @param PoolInterface $cache A cache pool instance.
|
||||||
|
*/
|
||||||
|
public function setCache(PoolInterface $cache);
|
||||||
|
}
|
@ -23,6 +23,7 @@ use Mibew\Asset\AssetUrlGeneratorAwareInterface;
|
|||||||
use Mibew\Asset\AssetUrlGeneratorInterface;
|
use Mibew\Asset\AssetUrlGeneratorInterface;
|
||||||
use Mibew\Authentication\AuthenticationManagerAwareInterface;
|
use Mibew\Authentication\AuthenticationManagerAwareInterface;
|
||||||
use Mibew\Authentication\AuthenticationManagerInterface;
|
use Mibew\Authentication\AuthenticationManagerInterface;
|
||||||
|
use Mibew\Cache\CacheAwareInterface;
|
||||||
use Mibew\Handlebars\HandlebarsAwareInterface;
|
use Mibew\Handlebars\HandlebarsAwareInterface;
|
||||||
use Mibew\Handlebars\Helper\AssetHelper;
|
use Mibew\Handlebars\Helper\AssetHelper;
|
||||||
use Mibew\Handlebars\Helper\CsrfProtectedRouteHelper;
|
use Mibew\Handlebars\Helper\CsrfProtectedRouteHelper;
|
||||||
@ -31,6 +32,7 @@ use Mibew\Routing\RouterAwareInterface;
|
|||||||
use Mibew\Routing\RouterInterface;
|
use Mibew\Routing\RouterInterface;
|
||||||
use Mibew\Style\StyleInterface;
|
use Mibew\Style\StyleInterface;
|
||||||
use Mibew\Style\PageStyle;
|
use Mibew\Style\PageStyle;
|
||||||
|
use Stash\Interfaces\PoolInterface;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
|
||||||
@ -40,7 +42,8 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
|||||||
abstract class AbstractController implements
|
abstract class AbstractController implements
|
||||||
RouterAwareInterface,
|
RouterAwareInterface,
|
||||||
AuthenticationManagerAwareInterface,
|
AuthenticationManagerAwareInterface,
|
||||||
AssetUrlGeneratorAwareInterface
|
AssetUrlGeneratorAwareInterface,
|
||||||
|
CacheAwareInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var RouterInterface|null
|
* @var RouterInterface|null
|
||||||
@ -62,6 +65,11 @@ abstract class AbstractController implements
|
|||||||
*/
|
*/
|
||||||
protected $assetUrlGenerator = null;
|
protected $assetUrlGenerator = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PoolInterface|null;
|
||||||
|
*/
|
||||||
|
protected $cache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -129,6 +137,22 @@ abstract class AbstractController implements
|
|||||||
return $this->assetUrlGenerator;
|
return $this->assetUrlGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getCache()
|
||||||
|
{
|
||||||
|
return $this->cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setCache(PoolInterface $cache)
|
||||||
|
{
|
||||||
|
$this->cache = $cache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a URL from the given parameters.
|
* Generates a URL from the given parameters.
|
||||||
*
|
*
|
||||||
|
@ -23,14 +23,17 @@ use Mibew\Asset\AssetUrlGeneratorAwareInterface;
|
|||||||
use Mibew\Asset\AssetUrlGeneratorInterface;
|
use Mibew\Asset\AssetUrlGeneratorInterface;
|
||||||
use Mibew\Authentication\AuthenticationManagerAwareInterface;
|
use Mibew\Authentication\AuthenticationManagerAwareInterface;
|
||||||
use Mibew\Authentication\AuthenticationManagerInterface;
|
use Mibew\Authentication\AuthenticationManagerInterface;
|
||||||
|
use Mibew\Cache\CacheAwareInterface;
|
||||||
use Mibew\Routing\RouterAwareInterface;
|
use Mibew\Routing\RouterAwareInterface;
|
||||||
use Mibew\Routing\RouterInterface;
|
use Mibew\Routing\RouterInterface;
|
||||||
|
use Stash\Interfaces\PoolInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class ControllerResolver implements
|
class ControllerResolver implements
|
||||||
RouterAwareInterface,
|
RouterAwareInterface,
|
||||||
AuthenticationManagerAwareInterface,
|
AuthenticationManagerAwareInterface,
|
||||||
AssetUrlGeneratorAwareInterface
|
AssetUrlGeneratorAwareInterface,
|
||||||
|
CacheAwareInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var RouterInterface|null
|
* @var RouterInterface|null
|
||||||
@ -47,6 +50,11 @@ class ControllerResolver implements
|
|||||||
*/
|
*/
|
||||||
protected $assetUrlGenerator = null;
|
protected $assetUrlGenerator = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PoolInterface|null;
|
||||||
|
*/
|
||||||
|
protected $cache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
@ -54,16 +62,19 @@ class ControllerResolver implements
|
|||||||
* @param AuthenticationManagerInterface $manager Authentication manager
|
* @param AuthenticationManagerInterface $manager Authentication manager
|
||||||
* instance.
|
* instance.
|
||||||
* @param AssetUrlGeneratorInterface $url_generator An instance of Asset
|
* @param AssetUrlGeneratorInterface $url_generator An instance of Asset
|
||||||
* URL generator
|
* URL generator.
|
||||||
|
* @param PoolInterface $cache An instance of Cache pool.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
RouterInterface $router,
|
RouterInterface $router,
|
||||||
AuthenticationManagerInterface $manager,
|
AuthenticationManagerInterface $manager,
|
||||||
AssetUrlGeneratorInterface $url_generator
|
AssetUrlGeneratorInterface $url_generator,
|
||||||
|
PoolInterface $cache
|
||||||
) {
|
) {
|
||||||
$this->router = $router;
|
$this->router = $router;
|
||||||
$this->authenticationManager = $manager;
|
$this->authenticationManager = $manager;
|
||||||
$this->assetUrlGenerator = $url_generator;
|
$this->assetUrlGenerator = $url_generator;
|
||||||
|
$this->cache = $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,6 +125,22 @@ class ControllerResolver implements
|
|||||||
return $this->assetUrlGenerator;
|
return $this->assetUrlGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getCache()
|
||||||
|
{
|
||||||
|
return $this->cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setCache(PoolInterface $cache)
|
||||||
|
{
|
||||||
|
$this->cache = $cache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves controller by request.
|
* Resolves controller by request.
|
||||||
*
|
*
|
||||||
@ -179,6 +206,10 @@ class ControllerResolver implements
|
|||||||
$object->setAssetUrlGenerator($this->getAssetUrlGenerator());
|
$object->setAssetUrlGenerator($this->getAssetUrlGenerator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($object instanceof CacheAwareInterface) {
|
||||||
|
$object->setCache($this->getCache());
|
||||||
|
}
|
||||||
|
|
||||||
return array($object, $method);
|
return array($object, $method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user