-
Notifications
You must be signed in to change notification settings - Fork 16
Support for simple cache #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d86e4c
Support for simple cache
Nyholm 6cb33db
Applied changes from StyleCI
Nyholm dbcea78
Fixed stuff
Nyholm 9b7ba2e
Minor
Nyholm 39c706b
Fixes
Nyholm 2db53dc
Moved template to a separate class
Nyholm 93f3e9f
typo
Nyholm 88d5e01
Applied changes from StyleCI
Nyholm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\cache-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\CacheBundle\DataCollector; | ||
|
||
use Nyholm\NSA; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
/** | ||
* A factory that decorates another factory to be able to use the proxy cache. | ||
* | ||
* @author Tobias Nyholm <tobias.nyholm@gmail.com> | ||
*/ | ||
class DecoratingFactory | ||
{ | ||
/** | ||
* @type ProxyFactory | ||
*/ | ||
private $proxyFactory; | ||
|
||
/** | ||
* @param ProxyFactory $proxyFactory | ||
*/ | ||
public function __construct(ProxyFactory $proxyFactory) | ||
{ | ||
$this->proxyFactory = $proxyFactory; | ||
} | ||
|
||
/** | ||
* @param CacheItemPoolInterface $originalObject original class | ||
* | ||
* @return CacheProxy|CacheItemPoolInterface | ||
*/ | ||
public function create($originalObject) | ||
{ | ||
$proxyClass = $this->proxyFactory->createProxy(get_class($originalObject)); | ||
$rc = new \ReflectionClass($proxyClass); | ||
$pool = $rc->newInstanceWithoutConstructor(); | ||
|
||
// Copy properties from original pool to new | ||
foreach (NSA::getProperties($originalObject) as $property) { | ||
NSA::setProperty($pool, $property, NSA::getProperty($originalObject, $property)); | ||
} | ||
|
||
return $pool; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache\cache-bundle package. | ||
* | ||
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\CacheBundle\DataCollector; | ||
|
||
/** | ||
* Generate proxies over your cache pool. This should only be used in development. | ||
* | ||
* @author Tobias Nyholm <tobias.nyholm@gmail.com> | ||
*/ | ||
class ProxyFactory | ||
{ | ||
/** | ||
* @type string | ||
*/ | ||
private $proxyDirectory; | ||
|
||
/** | ||
* @param string $proxyDirectory | ||
*/ | ||
public function __construct($proxyDirectory) | ||
{ | ||
$this->proxyDirectory = $proxyDirectory; | ||
} | ||
|
||
/** | ||
* Create a proxy that handles data collecting better. | ||
* | ||
* @param string $class | ||
* @param string &$proxyFile where we store the proxy class | ||
* | ||
* @return string the name of a much much better class | ||
*/ | ||
public function createProxy($class, &$proxyFile = null) | ||
{ | ||
$proxyClass = $this->getProxyClass($class); | ||
$class = '\\'.rtrim($class, '\\'); | ||
$proxyFile = $this->proxyDirectory.'/'.$proxyClass.'.php'; | ||
|
||
if (class_exists($proxyClass)) { | ||
return $proxyClass; | ||
} | ||
|
||
$content = file_get_contents(dirname(__DIR__).'/Resources/proxy/template.php'); | ||
$content = str_replace('__TPL_CLASS__', $proxyClass, $content); | ||
$content = str_replace('__TPL_EXTENDS__', $class, $content); | ||
|
||
$this->checkProxyDirectory(); | ||
file_put_contents($proxyFile, $content); | ||
require $proxyFile; | ||
|
||
return $proxyClass; | ||
} | ||
|
||
private function checkProxyDirectory() | ||
{ | ||
if (!is_dir($this->proxyDirectory)) { | ||
@mkdir($this->proxyDirectory, 0777, true); | ||
} | ||
} | ||
|
||
private function getProxyClass($namespace) | ||
{ | ||
return 'php_cache_proxy_'.str_replace('\\', '_', $namespace); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have stable version, why dont use them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not a part of this PR.
But here: #76