Permalink
Browse files

Make many improvements / bug fixes

  • Loading branch information...
winzou committed Jun 20, 2011
1 parent d2b50d7 commit 7fb69efb1a75440ea63c91936b3d6450960f2db1
View
@@ -57,7 +57,10 @@ public function setCacheDir($cacheDir)
*/
private function getFileName($id)
{
- return $this->cacheDir.str_replace(DIRECTORY_SEPARATOR, $this->separator, $id).'.php';
+ return $this->cacheDir
+ .DIRECTORY_SEPARATOR
+ .str_replace(DIRECTORY_SEPARATOR, $this->separator, $id)
+ .'.php';
}
/**
@@ -102,7 +105,7 @@ protected function _doContains($id)
*/
protected function _doSave($id, $data, $lifeTime = 0)
{
- return (bool) file_put_contents($this->getFileName($id), '<?php return '.var_export($data));
+ return (bool) file_put_contents($this->getFileName($id), '<?php return '.var_export($data, true).';');
}
/**
View
@@ -40,6 +40,7 @@ public function __construct(array $options = array())
*
* @param string $driver The cache driver to use
* @param array $options Options to pass to the driver
+ * @return Cache\AbstractCache
*/
public function build($driver, array $options = array(), $byPassCheck = true)
{
@@ -51,13 +52,15 @@ public function build($driver, array $options = array(), $byPassCheck = true)
throw new \InvalidArgumentException('The cache driver "'.$driver.'" is not supported by your current configuration.');
}
- $cache = new $driver;
+ $class = 'Cache\\'.$driver.'Cache';
+ $cache = new Cache\FileCache;
+ //$cache = new $class;
if ($driver == 'File') {
$options = array_merge($this->options, $options);
if (!isset($options['cacheDir'])) {
- throw new \InvalidArgumentException('The parameter "cacheDir" must be defined when using the File driver.');
+ throw new \Exception('The parameter "cacheDir" must be defined when using the File driver.');
}
$cache->setCacheDir($options['cacheDir']);
}
@@ -1 +1 @@
-<?php/* * This file is part of winzouCacheBundle. * * winzouCacheBundle is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * winzouCacheBundle is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */namespace winzou\CacheBundle\DependencyInjection;use Symfony\Component\Config\Definition\Builder\TreeBuilder;/** * Configuration builder for final dev app/config/config.yml * @author winzou */class Configuration{ public function getConfigTree() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('winzou_cache'); $rootNode ->children() ->arrayNode('factory') ->children() ->scalarNode('class')->defaultValue('winzou\\CacheBundle\\CacheFactory')->cannotBeEmpty()->end() ->end() ->end() ->arrayNode('driver') ->children() ->scalarNode('default')->defaultValue('File')->cannotBeEmpty()->end() ->scalarNode('abstract_class')->defaultValue('winzou\\CacheBundle\\Cache\\AbstractCache')->cannotBeEmpty()->end() ->end() ->end() ->end(); return $treeBuilder->buildTree(); }}
+<?php/* * This file is part of winzouCacheBundle. * * winzouCacheBundle is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * winzouCacheBundle is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */namespace winzou\CacheBundle\DependencyInjection;use Symfony\Component\Config\Definition\Builder\TreeBuilder;/** * Configuration builder for final dev app/config/config.yml * @author winzou */class Configuration{ public function getConfigTree() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('winzou_cache'); $rootNode ->children() ->arrayNode('factory') ->children() ->scalarNode('class')->defaultValue('winzou\\CacheBundle\\CacheFactory')->end() ->end() ->end() ->arrayNode('driver') ->children() ->scalarNode('default')->defaultValue('File')->end() ->scalarNode('abstract_class')->defaultValue('winzou\\CacheBundle\\Cache\\AbstractCache')->end() ->end() ->end() ->arrayNode('options') ->children() ->scalarNode('cache_dir')->defaultValue('winzou_cache')->end() ->end() ->end() ->end(); return $treeBuilder->buildTree(); }}
@@ -41,6 +41,10 @@ public function load(array $configs, ContainerBuilder $container)
$config = $processor->process($configuration->getConfigTree(), $configs);
+ if (!isset($config['options']['cache_dir'])) {
+ $config['options']['cache_dir'] = $container->getParameter('kernel.root_dir').'/cache/'.$container->getParameter('kernel.environment').'/winzou_cache';
+ }
+
$this->bindParameter($container, 'winzou_cache', $config);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
@@ -1 +1 @@
-services: winzou_cache.factory: class: %winzou_cache.factory.class% arguments: [ {'cacheDir': %winzou_cache.options.cacheDir% } ] winzou_cache.cache: factory-service: @winzou_cache.factory factory-method: build class: %winzou_cache.driver.abstract_class% argument: %winzou_cache.driver.default%
+parameters: winzou_cache.factory.class: winzou\CacheBundle\CacheFactory winzou_cache.driver.abstract_class: winzou\CacheBundle\Cache\AbstractCache winzou_cache.driver.default: Fileservices: winzou_cache.factory: class: %winzou_cache.factory.class% arguments: [ {'cacheDir': %winzou_cache.options.cache_dir% } ] winzou_cache.cache: factory_service: winzou_cache.factory factory_method: build class: winzou\CacheBundle\Cache\FileCache arguments: - %winzou_cache.driver.default%
View
@@ -1,26 +1,26 @@
-<?php
-
-/*
- * This file is part of winzouCacheBundle.
- *
- * winzouCacheBundle is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * winzouCacheBundle is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace winzou\CacheBundle;
-
-use Symfony\Component\HttpKernel\Bundle\Bundle;
-
-class winzouCacheBundle extends Bundle
-{
+<?php
+
+/*
+ * This file is part of winzouCacheBundle.
+ *
+ * winzouCacheBundle is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * winzouCacheBundle is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace winzou\CacheBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class winzouCacheBundle extends Bundle
+{
}

0 comments on commit 7fb69ef

Please sign in to comment.