summaryrefslogtreecommitdiff
path: root/src/FilesystemStorageAccess.php
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-05-24 14:55:11 +0200
committerKevin Chabowski <kevin@kch42.de>2014-05-24 14:55:11 +0200
commitd48be01fff31a7a9d611802721aa70532d251c3a (patch)
tree53ac39214a27855a6521f91ea448e39ffcd7866b /src/FilesystemStorageAccess.php
parent3c51baa4167d5a68ff010dc81525b9340c5f1329 (diff)
downloadste-d48be01fff31a7a9d611802721aa70532d251c3a.tar.gz
ste-d48be01fff31a7a9d611802721aa70532d251c3a.tar.bz2
ste-d48be01fff31a7a9d611802721aa70532d251c3a.zip
Moved to src/ste for psr-4 compliance1.0.0
Diffstat (limited to 'src/FilesystemStorageAccess.php')
-rw-r--r--src/FilesystemStorageAccess.php71
1 files changed, 0 insertions, 71 deletions
diff --git a/src/FilesystemStorageAccess.php b/src/FilesystemStorageAccess.php
deleted file mode 100644
index ef29404..0000000
--- a/src/FilesystemStorageAccess.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-// File: FilesystemStorageAccess.php
-
-// Namespace: kch42\ste
-namespace kch42\ste;
-
-/*
- * Class: FilesystemStorageAccess
- * The default <StorageAccess> implementation for loading / saving templates into a directory structure.
- */
-class FilesystemStorageAccess implements StorageAccess {
- protected $sourcedir;
- protected $transcompileddir;
-
- /*
- * Constructor: __construct
- *
- * Parameters:
- * $src - The directory with the sources (Writing permissions are not mandatory, because STE does not save template sources).
- * $transc - The directory with the transcompiled templates (the PHP instance / the HTTP Server needs writing permissions to this directory).
- */
- public function __construct($src, $transc) {
- $this->sourcedir = $src;
- $this->transcompileddir = $transc;
- }
-
- public function load($tpl, &$mode) {
- $src_fn = $this->sourcedir . "/" . $tpl;
- $transc_fn = $this->transcompileddir . "/" . $tpl . ".php";
-
- if($mode == StorageAccess::MODE_SOURCE) {
- $content = @file_get_contents($src_fn);
- if($content === false) {
- throw new CantLoadTemplate("Template not found.");
- }
- return $content;
- }
-
- $src_stat = @stat($src_fn);
- $transc_stat = @stat($transc_fn);
-
- if(($src_stat === false) and ($transc_stat === false)) {
- throw new CantLoadTemplate("Template not found.");
- } else if($transc_stat === false) {
- $mode = StorageAccess::MODE_SOURCE;
- return file_get_contents($src_fn);
- } else if($src_stat === false) {
- include($transc_fn);
- return $transcompile_fx;
- } else {
- if($src_stat["mtime"] > $transc_stat["mtime"]) {
- $mode = StorageAccess::MODE_SOURCE;
- return file_get_contents($src_fn);
- } else {
- include($transc_fn);
- return $transcompile_fx;
- }
- }
- }
-
- public function save($tpl, $data, $mode) {
- $fn = (($mode == StorageAccess::MODE_SOURCE) ? $this->sourcedir : $this->transcompileddir) . "/" . $tpl . (($mode == StorageAccess::MODE_TRANSCOMPILED) ? ".php" : "");
- @mkdir(dirname($fn), 0777, true);
- if(file_put_contents($fn, "<?php
-
-// File: FilesystemStorageAccess.php \$transcompile_fx = $data; ?>") === false) {
- throw new CantSaveTemplate("Unable to save template.");
- }
- }
-}