-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix PSR-2 coding standards and PHPDoc blocks #452
- Loading branch information
Showing
13 changed files
with
1,063 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
title = Welcome to Smarty! | ||
cutoff_size = 40 | ||
|
||
[setup] | ||
bold = true |
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,34 @@ | ||
<?php | ||
/** | ||
* Example Application | ||
* | ||
* @package Example-application | ||
*/ | ||
|
||
require '../libs/Smarty.class.php'; | ||
|
||
$smarty = new Smarty; | ||
|
||
//$smarty->force_compile = true; | ||
$smarty->debugging = true; | ||
$smarty->caching = true; | ||
$smarty->cache_lifetime = 120; | ||
|
||
$smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true); | ||
$smarty->assign("FirstName", array("John", "Mary", "James", "Henry")); | ||
$smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case")); | ||
$smarty->assign( | ||
"Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"), | ||
array("M", "N", "O", "P")) | ||
); | ||
|
||
$smarty->assign( | ||
"contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), | ||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")) | ||
); | ||
|
||
$smarty->assign("option_values", array("NY", "NE", "KS", "IA", "OK", "TX")); | ||
$smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas")); | ||
$smarty->assign("option_selected", "NE"); | ||
|
||
$smarty->display('index.tpl'); |
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,88 @@ | ||
<?php | ||
|
||
/** | ||
* APC CacheResource | ||
* CacheResource Implementation based on the KeyValueStore API to use | ||
* memcache as the storage resource for Smarty's output caching. | ||
* * | ||
* | ||
* @package CacheResource-examples | ||
* @author Uwe Tews | ||
*/ | ||
class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore | ||
{ | ||
/** | ||
* Smarty_CacheResource_Apc constructor. | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function __construct() | ||
{ | ||
// test if APC is present | ||
if (!function_exists('apc_cache_info')) { | ||
throw new Exception('APC Template Caching Error: APC is not installed'); | ||
} | ||
} | ||
|
||
/** | ||
* Read values for a set of keys from cache | ||
* | ||
* @param array $keys list of keys to fetch | ||
* | ||
* @return array list of values with the given keys used as indexes | ||
* @return boolean true on success, false on failure | ||
*/ | ||
protected function read(array $keys) | ||
{ | ||
$_res = array(); | ||
$res = apc_fetch($keys); | ||
foreach ($res as $k => $v) { | ||
$_res[ $k ] = $v; | ||
} | ||
|
||
return $_res; | ||
} | ||
|
||
/** | ||
* Save values for a set of keys to cache | ||
* | ||
* @param array $keys list of values to save | ||
* @param int $expire expiration time | ||
* | ||
* @return boolean true on success, false on failure | ||
*/ | ||
protected function write(array $keys, $expire = null) | ||
{ | ||
foreach ($keys as $k => $v) { | ||
apc_store($k, $v, $expire); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Remove values from cache | ||
* | ||
* @param array $keys list of keys to delete | ||
* | ||
* @return boolean true on success, false on failure | ||
*/ | ||
protected function delete(array $keys) | ||
{ | ||
foreach ($keys as $k) { | ||
apc_delete($k); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Remove *all* values from cache | ||
* | ||
* @return boolean true on success, false on failure | ||
*/ | ||
protected function purge() | ||
{ | ||
return apc_clear_cache('user'); | ||
} | ||
} |
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,101 @@ | ||
<?php | ||
|
||
/** | ||
* Memcache CacheResource | ||
* CacheResource Implementation based on the KeyValueStore API to use | ||
* memcache as the storage resource for Smarty's output caching. | ||
* Note that memcache has a limitation of 256 characters per cache-key. | ||
* To avoid complications all cache-keys are translated to a sha1 hash. | ||
* | ||
* @package CacheResource-examples | ||
* @author Rodney Rehm | ||
*/ | ||
class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore | ||
{ | ||
/** | ||
* memcache instance | ||
* | ||
* @var Memcache | ||
*/ | ||
protected $memcache = null; | ||
|
||
public function __construct() | ||
{ | ||
if (class_exists('Memcached')) { | ||
$this->memcache = new Memcached(); | ||
} else { | ||
$this->memcache = new Memcache(); | ||
} | ||
$this->memcache->addServer('127.0.0.1', 11211); | ||
} | ||
|
||
/** | ||
* Read values for a set of keys from cache | ||
* | ||
* @param array $keys list of keys to fetch | ||
* | ||
* @return array list of values with the given keys used as indexes | ||
* @return boolean true on success, false on failure | ||
*/ | ||
protected function read(array $keys) | ||
{ | ||
$_keys = $lookup = array(); | ||
foreach ($keys as $k) { | ||
$_k = sha1($k); | ||
$_keys[] = $_k; | ||
$lookup[ $_k ] = $k; | ||
} | ||
$_res = array(); | ||
$res = $this->memcache->get($_keys); | ||
foreach ($res as $k => $v) { | ||
$_res[ $lookup[ $k ] ] = $v; | ||
} | ||
|
||
return $_res; | ||
} | ||
|
||
/** | ||
* Save values for a set of keys to cache | ||
* | ||
* @param array $keys list of values to save | ||
* @param int $expire expiration time | ||
* | ||
* @return boolean true on success, false on failure | ||
*/ | ||
protected function write(array $keys, $expire = null) | ||
{ | ||
foreach ($keys as $k => $v) { | ||
$k = sha1($k); | ||
$this->memcache->set($k, $v, 0, $expire); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Remove values from cache | ||
* | ||
* @param array $keys list of keys to delete | ||
* | ||
* @return boolean true on success, false on failure | ||
*/ | ||
protected function delete(array $keys) | ||
{ | ||
foreach ($keys as $k) { | ||
$k = sha1($k); | ||
$this->memcache->delete($k); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Remove *all* values from cache | ||
* | ||
* @return boolean true on success, false on failure | ||
*/ | ||
protected function purge() | ||
{ | ||
return $this->memcache->flush(); | ||
} | ||
} |
Oops, something went wrong.