-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continued integration into HTTP Kernel environment
- Loading branch information
Cameron Manderson
committed
Sep 15, 2014
1 parent
e289016
commit 832baf2
Showing
5 changed files
with
181 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,81 @@ | ||
<?php | ||
namespace Phruts\Util\ModuleProvider; | ||
|
||
use Phruts\Config\ModuleConfig; | ||
use Phruts\Utils\ModuleProviderInterface; | ||
use Phigester\Digester; | ||
|
||
class FileCacheModuleProvider implements ModuleProviderInterface | ||
{ | ||
/** | ||
* @var Digester | ||
*/ | ||
protected $application; | ||
|
||
protected $cachePath; | ||
|
||
public function __construct(\Silex\Application $application) | ||
{ | ||
$this->application = $application; | ||
} | ||
|
||
public function getModuleConfig($prefix = '', $config) | ||
{ | ||
$rebuild = false; | ||
|
||
// Determine if a cache file is present | ||
$cacheFile = $this->cachePath . '/' . $prefix . '.data'; | ||
$mtime = filemtime($cacheFile); | ||
|
||
// Check the ages of the config paths against the age of the cache file | ||
if($mtime !== false) { | ||
foreach($configPaths as $path) { | ||
$cmtime = filemtime($path); | ||
if($cmtime == false) { | ||
throw new \Phruts\Exception('Unable to locate the specified Phruts configuration file'); | ||
} | ||
if($cmtime > $mtime) { | ||
$rebuild = true; | ||
break; | ||
} | ||
} | ||
} else { | ||
// We couldn't find the modified time on the cache file | ||
$rebuild = true; | ||
} | ||
|
||
// Get the module config | ||
if($rebuild == true) { | ||
// (re)Build the cache | ||
if(!is_writable($cacheFile)) { | ||
throw new \Phruts\Exception('Unable to write to the cache'); | ||
} | ||
|
||
// Digest the config | ||
$moduleConfig = new ModuleConfig($prefix); | ||
$digester = $this->application[\Phruts\Util\Globals::DIGESTER]; | ||
if(empty($digester)) { | ||
throw new \Phruts\Exception('Digester is not present in the application, unable to process the configruation file'); | ||
} | ||
$digester->push($moduleConfig); | ||
foreach($configPaths as $path) { | ||
$digester->parse($path); | ||
} | ||
|
||
// Write out the cache | ||
file_put_contents($cacheFile, serialize($moduleConfig)); | ||
} else { | ||
// Obtain from the cache | ||
$serialised = file_get_contents($cacheFile); | ||
$moduleConfig = unserialize($serialised); | ||
} | ||
|
||
return $moduleConfig; | ||
} | ||
|
||
public function setCachePath($path) | ||
{ | ||
$this->cachePath = $path; | ||
} | ||
} | ||
|
This file contains 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,7 @@ | ||
<?php | ||
namespace Phruts\Utils; | ||
|
||
interface ModuleProviderInterface | ||
{ | ||
public function getModuleConfig($prefix = '', $config); | ||
} |