Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
731d2b4
tidy up - stripped out a lot of depreciated code that has been replac…
jimmyff Sep 14, 2010
7c47981
Merge branch 'master' of git://github.com/atsumi/atsumi
jimmyff Sep 21, 2010
c76d5c9
Merge branch 'master' of github.com:jimmysparkle/atsumi
jimmyff Sep 21, 2010
01516c4
minor fix for an exception name in error handler
jimmyff Sep 26, 2010
47b1a08
minor fox for spelling mistake in memcache handler
jimmyff Sep 26, 2010
e2384fa
Added SSL/HTTPS support to AbstractController
jimmyff Sep 27, 2010
0ecb758
Can now set session life and enable presistent sessions.
jamesoates88 Sep 29, 2010
0c77e5c
Added IP address validator
jimmyff Oct 20, 2010
c5eb004
Added CSS styling options to elements
jimmyff May 6, 2011
fbf7424
Form handler includes elements custom css classes and style
jimmyff May 6, 2011
343c720
Fixed bug with AgeRangeElement value storage
jimmyff May 6, 2011
8416204
Merge pull request #10 from jimmysparkle/master
jimmyff May 6, 2011
b305164
added hooks for js onblur onfocus onkeydown onchange in the widget_Te…
jimmyff May 10, 2011
6c59101
Merge branch 'master' of github.com:jimmysparkle/atsumi
jimmyff May 10, 2011
467f6ac
Added onClick event hook-in to checkbox element
jimmyff May 11, 2011
4e02171
Made the generateUrl method in pagination public rather than private.…
jimmyff May 21, 2011
62c843f
added getResultsPerPage method to paginate. Didn't want to use limit …
jimmyff May 25, 2011
6ab34bd
Registered the class autoloader and made compatible with Smarty 3.x
jimmyff Jun 4, 2011
234b762
Cut down the object formatting in the debug bar as was causing slow d…
jimmyff Jun 5, 2011
628d145
added a has() method to controllers to check if view data has been set
jimmyff Jun 8, 2011
eec2b0e
minor change to inline comments
jimmyff Jun 10, 2011
45f7307
minor var name fix
jimmyff Jun 15, 2011
541247f
added Atsumi::error__listen(Exception ) method. This tells the error …
jimmyff Aug 16, 2011
614bafb
Added content-length header to the text view
jimmyff Aug 19, 2011
e7aba5c
Added a Math utility class
jimmyff Aug 19, 2011
c5154f7
Changes to open framework up to CLI items
Sep 2, 2011
971d739
Support CLI items
Sep 2, 2011
86bbedc
fix bug in db classes still referenced parsers rather than casters
jimmyff Sep 16, 2011
0f46cb2
Started to add row abstraction to database results
jimmyff Sep 16, 2011
5d17d6c
Added castArray and castArraySets to casters, used by DB. Abstract Db…
jimmyff Sep 19, 2011
56ef08a
Db abstraction (postgres) now supports insert() update() select/query…
jimmyff Sep 19, 2011
3f3c471
Added postgresql -> php caster to return values from a db row
jimmyff Sep 19, 2011
0b4e102
Added postgresql support for exists() count() instertOrUpdateOne() tr…
jimmyff Sep 20, 2011
d3d7d16
renamed vender folder to adapter, renamed SQL to Sql in filenames for…
jimmyff Sep 20, 2011
d03629b
Renamed helpers -> utility, added calendar utility subpackage which c…
jimmyff Sep 20, 2011
8355362
Abstract db row now supports quick referencing of casting calls. ->S_…
jimmyff Sep 20, 2011
f0d4cd2
Various fixes for database abstraction layer. Added a JSONP view and …
jimmyff Sep 30, 2011
361826d
A few tweaks to DBL and json views
jimmyff Oct 18, 2011
8d43cb7
Added floats to postgres->php caster
jimmyff Oct 19, 2011
f73fa2a
added a processRequest method to controller which appHandler now call…
jimmyff Nov 22, 2011
cdf7293
Merge branch 'master' of https://github.com/jimmysparkle/atsumi
jimmyff Nov 22, 2011
cbd6335
added intval to integer casting
jimmyff Dec 21, 2011
34e8f90
mysql adaptor & caster classes
chrismou Dec 30, 2011
16499cb
tabindexes + __tostring error handling (and useful errors) in form wi…
chrismou Dec 30, 2011
37f1d06
default tabindex to false for consistency
chrismou Dec 30, 2011
7074fa1
Merge pull request #12 from chrismou/master
jimmyff Jan 3, 2012
42ffd21
Option to change type in text elements
chrismou Jan 11, 2012
f8d9260
Merge pull request #13 from chrismou/master
jimmyff Jan 12, 2012
0200495
Merge branch 'master' of github.com:jimmysparkle/atsumi
Jan 14, 2012
b319284
Fix english
Jan 14, 2012
3b2e4e0
Allow on-the-fly form element removal
Jan 14, 2012
8da01d1
Add delete option to DB API
Jan 14, 2012
724535b
Add empty constructor for atsumi-go support
Jan 15, 2012
5d82ccd
Elaborated on the element exception handling Chris added to forms. It…
jimmyff Jan 19, 2012
b0f6669
added more functionality for setting / getting array data out of post…
jimmyff Jan 20, 2012
a684eb2
Multiples of 'date' function in mysql->php caster removed
Jan 22, 2012
8091280
Add recaptcha form widget and validator
Jan 31, 2012
206ffdc
Check if CLI option exists before trying to get it
Feb 1, 2012
8325a77
Merge pull request #15 from phoenixrises/master
jimmyff Feb 1, 2012
069c520
readded the setCssStyle method
jimmyff Feb 8, 2012
8b45912
Merge branch 'master' of github.com:jimmysparkle/atsumi
jimmyff Feb 8, 2012
e9514ae
Added image picker form element
jimmyff Mar 20, 2012
db759bf
Merge pull request #16 from jimmysparkle/master
jonnixs Apr 6, 2012
42f41b5
minor fixes. Safer postgres casting. Validate max chars supports fore…
jimmyff Jul 3, 2012
4e9507c
Merge branch 'master' of github.com:jimmysparkle/atsumi
jimmyff Jul 3, 2012
d50dc08
Merge pull request #17 from jimmysparkle/master
jimmyff Aug 10, 2012
53facae
Added atsumi_Interval class to the calendar utilities. Useful when do…
jimmyff Aug 30, 2012
51e64cb
Merge pull request #18 from jimmyff/master
jimmyff Aug 30, 2012
e5436aa
added a few useful methods to interval cass, fixed error in caster
jimmyff Aug 30, 2012
a0b2b24
Merge pull request #19 from jimmyff/master
jimmyff Aug 30, 2012
f01c395
added image picker element back in... oops
jimmyff Aug 30, 2012
f5f0fe7
Recaptcha now shows as required and you customise the error message i…
jimmyff Sep 12, 2012
11a759c
Added a validation handler that makes validating outside of form syst…
jimmyff Oct 4, 2012
ddfdd19
Merge branch 'master' of github.com:jimmyff/atsumi
jimmyff Oct 4, 2012
9be9cdc
when formatting an exception it prints the exceptions details member …
jimmyff Oct 17, 2012
d6af459
added pre formatted tag in exception additional details HTML output
jimmyff Oct 17, 2012
935d59d
new simple template - suggested size of 4. couple of css class change…
jimmyff Mar 14, 2013
a8f3857
added an $options param to renderElement so you can disable label fro…
jimmyff Mar 14, 2013
ead9ac3
Added new php template handler, this view handler makes maintaniing U…
jimmyff Mar 14, 2013
438745f
minor changes
jimmyff Mar 26, 2013
314f315
can pass options array to getFormBottom() so can add styles to rows/s…
jimmyff Mar 27, 2013
e7a80d5
added Atsumi::error__recover($e);
jimmyff Mar 31, 2013
4b1257d
Added $supressErrors param to toggle errors
jimmyff Mar 31, 2013
e724413
added getPage() method to pagination
jimmyff Mar 31, 2013
33a6907
added a bit of extra functionality to PHP view handlder, can override…
jimmyff Apr 15, 2013
3fa6442
fix for DBAL, bug resolved by jonny.
jimmyff Apr 15, 2013
65475ee
fix pass by reference changes for php 5.4
jimmyff Apr 16, 2013
0731801
restored essential reference functionality
jimmyff Apr 16, 2013
d5d5770
Merge pull request #21 from jimmyff/master
jimmyff Apr 16, 2013
0e8088b
App Handler returns NotFound exception if cant parse URI
jimmyff Apr 21, 2013
2b3f7c7
set default encoding to UTF8
jimmyff Apr 27, 2013
7fdfd07
added support for cloudfront & proxy IPs
jimmyff Apr 27, 2013
e5806e8
fixed character encoding issue
jimmyff Apr 28, 2013
37a7149
sitemap handler now trys to create the sitemap directories if they do…
jimmyff May 1, 2013
67a6435
now can optionally send tempalte strings - quite dangerous as uses ev…
jimmyff May 1, 2013
399fa25
added numeric type
jimmyff May 13, 2013
e41a0e6
added ->valueOrNull_$elementName method- it returns null if no value …
jimmyff May 13, 2013
72d1eb7
added an abstract model for quick database models read/write - needs …
jimmyff May 13, 2013
fdfd69e
leading 0 int like strings are left as ints
jimmyff Jun 5, 2013
29cc931
added specific exception for file type validator
jimmyff Jun 11, 2013
91b4001
minor fix to error message fomr file validator
jimmyff Jun 11, 2013
47a7c13
added general purpose not found exception, added a white-space trim o…
jimmyff Jul 15, 2013
820953d
moved publishFlashData() before preRender() when processing a page me…
jimmyff Aug 5, 2013
af57ed8
Merge pull request #22 from jimmyff/master
jimmyff Aug 15, 2013
c6f3318
fixed create uri method if controller is on the root of the specifica…
jimmyff Aug 19, 2013
5a6a5cd
added optional parameter logFilePrefix allowing you to better organis…
jimmyff Aug 19, 2013
4c45acf
added whitespace pre-line styling to the description & data blocks in…
jimmyff Aug 19, 2013
af6ba6c
when outputting debug console, if a settings key contains the string …
jimmyff Aug 21, 2013
3098f67
Added support for intervals formatted like: dd:hh:mm:ss
jimmyff Aug 22, 2013
972f248
fleshed out AbstractModel, still needs more work & testing
jimmyff Aug 22, 2013
093add8
Merge branch 'master' of github.com:jimmyff/atsumi
jimmyff Aug 22, 2013
f0eec69
minor fix for setting ID before returning after inserting
jimmyff Aug 28, 2013
3562115
added method for returning the specification from the caster
jimmyff Sep 28, 2013
1840d64
added more useful error handling to abstract model
jimmyff Sep 28, 2013
08397b5
added a date format constant
jimmyff Oct 8, 2013
50d75ad
added %e to postgresql casters - bigint
jimmyff Oct 18, 2013
86e288c
atsumi_ErrorEventArgs->recoverer is NULL if not recovering, listner_a…
jimmyff Oct 18, 2013
8c684f2
error handling for unknown format being passed to caster
jimmyff Oct 22, 2013
7e2e810
added %B (bool or null) to caster
jimmyff Oct 22, 2013
1cfa106
added default format, added static method to format a timestamp
jimmyff Oct 30, 2013
7e997a8
added a static post method and added a HTTP response class, only impl…
jimmyff Nov 15, 2013
d8b28cd
content-type and encoding headers, already declared in abstract view,…
jimmyff Nov 15, 2013
ca277dd
new relic exception listerner
jimmyff Nov 25, 2013
989ee8f
Fixed a few bugs in date/dateTime/interval objects. Added additional …
jimmyff Jan 9, 2014
72689d0
corrected wording slightly
jimmyff Jan 13, 2014
6d7d18b
getRawElement()
chrismou Mar 7, 2014
89a5c0e
getRawElement() -> getElement('xyz', array('elementOnly'=>true))
chrismou Mar 7, 2014
7e84d9f
short tags removed from atsumi debug
chrismou Apr 5, 2014
6914372
Merge pull request #24 from chrismou/master
jonnixs Apr 5, 2014
160ad77
apache 2.4 updates
jimmyff Apr 28, 2014
1fb53a9
Added a temporary storage handler, introduced a default TTL per cache…
jimmyff May 6, 2014
fd9778a
HTTP class much better, now can return headers & body content
jimmyff May 6, 2014
dd0b106
added a disabled state
jimmyff May 6, 2014
1f433c0
Abstract models now dont have concept of data access, db functionalit…
jimmyff May 12, 2014
c4ea8f6
Explosed db queries and times via atsumi_Debug::getDbQueries() - this…
jimmyff May 12, 2014
759bdd9
fixed bug in required validator - should test this
jimmyff May 12, 2014
c57a682
output() now iterates through values including arrays and outputs tho…
jimmyff May 13, 2014
9020186
added json caster, untested. Added an ::getCastName() to the casters …
jimmyff May 15, 2014
c93b967
added basic PHP caster. atsumi PHP accepts a single none-array $field…
jimmyff May 27, 2014
9da3e92
throws a useful error on curl failing
jimmyff May 29, 2014
ed8f043
Added a DynamicModel which is extends AbstractModel, allows to dynami…
jimmyff May 29, 2014
929950e
minor modifications
jimmyff May 30, 2014
2251ea0
added uri parser Matcha, adds localisation handling to the Gyokuro pa…
jimmyff Jun 4, 2014
2c9a901
couple of bux fixes to abstract model.
jimmyff Jun 4, 2014
b287902
fixed timers in atsumi Debug, startTimer and endTimer now accepts a r…
jimmyff Jun 4, 2014
5002287
added a http accepts language parser to locale model
jimmyff Jun 9, 2014
f415cbf
added a setArray method to abstract model
jimmyff Jun 9, 2014
20ca0dc
added a hook to send options to the render method
jimmyff Jun 9, 2014
fa0034c
added a few additional features to LocaleModel - fixed minor bug
jimmyff Jun 10, 2014
f365fbb
added a $httpHeaders parameter that is set directly on the post request
jimmyff Jun 10, 2014
3383035
added total db query time
jimmyff Jun 23, 2014
fce73dd
added timestamp to php caster, abstract model now looks for output() …
jimmyff Jul 8, 2014
7ebb140
added minor debug to template handler
jimmyff Jul 28, 2014
b1d8308
Merge branch 'master' of github.com:jimmyff/atsumi
jimmyff Jul 29, 2014
4177fb6
added more useful exception
jimmyff Jul 31, 2014
e5e8566
Merge remote-tracking branch 'origin' into abstract-models-updated
jimmyff Aug 1, 2014
ee12f6a
added generic duplicate exception
jimmyff Sep 11, 2014
96aaefd
Added Atsumi::store__add($k, $v) and Atsumi::store__get($k) - useful …
jimmyff Sep 15, 2014
87f1376
Merge branch 'master' of bitbucket.org:jimmyff/atsumi
jimmyff Sep 15, 2014
d5980da
added interpolation to the mvc_LocaleModel - might not be the best pl…
jimmyff Sep 22, 2014
3a130ba
Merge branch 'master' of bitbucket.org:jimmyff/atsumi
jimmyff Sep 22, 2014
ef3fdbd
resolved conflict with rocketware branch
jimmyff Oct 16, 2014
9d70a3d
added a security class, currently has a numericCode($ref, $salt, $len…
jimmyff Oct 23, 2014
6018386
minor fix
jimmyff Nov 5, 2014
c372d6c
Email validator accepted "0" as a valid email address due to required…
jimmyff Nov 7, 2014
1025f84
brought in Jonnys namespace loader. Added support for projects/module…
jimmyff Nov 14, 2014
f590499
various minor updates
jimmyff Jan 27, 2015
da4121c
added ::from() and ::fromModel() methods, now can transpose one model…
jimmyff Jan 28, 2015
f1e8c0a
can now populate a request headers var reference
jimmyff Feb 17, 2015
c73ad7d
minor updates
jimmyff Feb 17, 2015
15b4af2
added more useful exception messages - still should add custom except…
jimmyff Mar 2, 2015
4037999
more work on dynamic models
jimmyff Mar 13, 2015
e2fdae9
minor fixes for object auto creation
jimmyff Mar 17, 2015
99d774e
a few minor hooks
jimmyff Mar 27, 2015
0f81ca4
added support for post connection processing. Atsumi::app__dispatchCo…
jimmyff Mar 31, 2015
3e184a3
added Sentry exception listener, minor tweaks to debug to expose cons…
jimmyff Apr 2, 2015
513de12
added session handler that uses a cache handler eg APC or memcache. U…
jimmyff Apr 14, 2015
c72070f
few tweaks
jimmyff Apr 14, 2015
8d72bac
added custom atrributes to text & hidden elements
jimmyff Apr 22, 2015
a488e91
added a few minor tweaks to forms
jimmyff Apr 24, 2015
4d7119d
tweaks to form handling - can now pass html to be used in button
jimmyff Apr 29, 2015
376295e
added onsubmit to form widgets. Added custom curl options to Http
jimmyff May 1, 2015
da3f1d6
added option to not modify uris which is useful if you want your defa…
jimmyff May 4, 2015
eec1515
tweak
jimmyff May 10, 2015
52321fc
fixed bugs in sitemap handler
jimmyff May 13, 2015
1268b0e
onChange hook
jimmyff May 19, 2015
1c3d5f3
uses php.ini to find upload location
jimmyff May 30, 2015
0fe911d
few updates to form elements, can get only errors, and also can clear…
jimmyff Jun 11, 2015
7ac808d
https version of recaptcha
jimmyff Jun 17, 2015
31c64cd
Merge pull request #26 from jimmyff/master
jimmyff Sep 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion classes/cache/cache_AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
abstract class cache_AbstractHandler implements cache_HandlerInterface {

const DEFAULT_TTL = 0;

/**
* Weather or not cache system should throw exceptions
* @var bool
Expand Down Expand Up @@ -60,7 +62,10 @@ final public function get($key, $default = null, $namespace = 'default') {
* @param string $namespace The namespace under which the variable is stored [optional, default: 'default']
* @return boolen True on success or, False on failure
*/
final public function set($key, $data, $ttl = 0, $namespace = 'default') {
final public function set($key, $data, $ttl = null, $namespace = 'default') {

if (is_null($ttl)) $ttl = static::DEFAULT_TTL;

try {
return $this->_set($key, $data, $ttl, $namespace);
} catch (Exception $e) {
Expand Down
3 changes: 3 additions & 0 deletions classes/cache/cache_ApcHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
class cache_ApcHandler extends cache_AbstractHandler {
/* CONSTANTS */

const DEFAULT_TTL = 0;

/* PROPERTIES */
/* CONSTRUCTOR & DESTRUCTOR */

Expand Down
1 change: 1 addition & 0 deletions classes/cache/cache_HandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
interface cache_HandlerInterface {
/* CONSTRUCTOR & DESTRUCTOR */

/* GET METHODS */

/**
Expand Down
13 changes: 11 additions & 2 deletions classes/cache/cache_MemcacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
class cache_MemcacheHandler extends cache_AbstractHandler {
/* CONSTANTS */

const DEFAULT_TTL = 0;

/**
* Constant defining a minite storage duration
* @var integer
Expand Down Expand Up @@ -46,10 +48,17 @@ public function __construct($host, $port, $useExceptions = false) {
$this->useExceptions = $useExceptions;
$this->memcache = new Memcache;

if (is_null($host)) return;

if(!$this->memcache->connect($host, $port))
throw new cache_CouldNotConnectException('Could not connect to Memcache server');
}


// adds a memcached server to the connection pool
public function addServer ($host, $port = 11211) {
$this->memcache->addServer($host, $port);
}

/* GET METHODS */

/**
Expand All @@ -65,7 +74,7 @@ protected function _get($key, $default = null, $namespace = 'default') {

if(!is_array($return)) {
if($this->useExceptions)
throw new cache_NotFoundException(sf('Could not fine \'%s\' variable', $key));
throw new cache_NotFoundException(sf('Could not find \'%s\' variable', $key));

$return = array($default);
}
Expand Down
61 changes: 61 additions & 0 deletions classes/cache/cache_TemporaryStorageHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Created by PhpStorm.
* User: jimmyff
* Date: 30/04/2014
* Time: 14:42
* Description: Storage for settings that need to be passed around but has no persistent back end
* This can be used as a portable settings store that expires at end of the request if not saved elsewhere
*/

class cache_TemporaryStorageHandler extends cache_AbstractHandler {

// null ttl: doesn't expire
const DEFAULT_TTL = null;

private $store = array();

public function __construct() {

}

protected function _get($key, $default = null, $namespace = 'default'){

if (isset($this->store[$namespace][$key]) &&
(is_null($this->store[$namespace][$key]['expires']) || $this->store[$namespace][$key]['expires'] > time()))
return $this->store[$namespace][$key]['value'];

else return $default;

}
protected function _set($key, $data, $ttl = null, $namespace = 'default') {

if (!isset($this->store[$namespace])) {
$this->store[$namespace] = array();
}

$this->store[$namespace][$key] = array(
'value' => $data,
'expires' => is_null($ttl)?null:(time() + $ttl)
);

}
protected function _delete($key, $namespace = 'default') {

if (isset($this->store[$namespace][$key]));
unset($this->store[$namespace][$key]);

}
protected function _exists($key, $namespace = 'default'){

return isset($this->store[$namespace][$key]) &&
(is_null($this->store[$namespace][$key]['expires']) || $this->store[$namespace][$key]['expires'] > time());
}

protected function _flush() {
$this->store = array();
}

}

?>
61 changes: 59 additions & 2 deletions classes/caster/caster_Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ abstract class caster_Abstract {
/* MAGIC METHODS */
/* METHODS */

static public function getSpec() {
$caster = new static;
return $caster->spec;
}

/**
* Checks the given string for the number of caster characters.
* @param string $s The string to parse
*/
protected function numberOfPercents($s) {
if(!is_string($s)) throw new caster_Exception('Parameter $s should be of type string');
if(!is_string($s)) throw new caster_Exception('Caster expecting format string, received '.gettype($s).': '.$s);
$pos = 0;
$count = 0;
while(true) {
Expand Down Expand Up @@ -79,6 +84,46 @@ public function castString($string, $args = null, $_ = null) {
}
return implode('', $ret);
}
/**
* Casts args into a given string/object by the class held caster spec
* @param string $string The string to cast
* @param mixed $args The args to be parsed into the string
* @return string The casted string
*/
public function castObject($string, $args = null, $_ = null) {
// Get args
$args = func_get_args();
if (count($args[0]) !== 2) throw new caster_Exception('Cast object expects two parameters');

$ch = substr($args[0][0], 1);

if(array_key_exists($ch, $this->spec) && method_exists($this,$this->spec[$ch])) {
$methodName = $this->spec[$ch];
return $this->$methodName($args[0][1]);
} elseif($ch == '%') {
return '%';
} else {
throw new caster_Exception("Caster received unexpected format character: %".$ch);
}

}

public function castArray ($params) {
$format = array_shift ($params);
return $this->castReal ($format, $params);
}

public function castArraySets ($args) {
$ret = array ();
for ($i = 0; $i < count ($args); ) {
$format = $args [$i++];
$params = array_slice ($args, $i, $this->numberOfPercents($format));
$i += count ($params);
array_unshift ($params, $format);
$ret[] =$this->castArray ($params);
}
return $ret;
}

/**
* Casts args into a given string by the class held caster spec
Expand Down Expand Up @@ -108,10 +153,14 @@ protected function castReal($format, $args) {
if(array_key_exists($ch, $this->spec) && method_exists($this,$this->spec[$ch])) {
$methodName = $this->spec[$ch];
$ret .= $this->$methodName($args[$i++]);

} elseif(array_key_exists($ch, $this->spec) && method_exists($this,'cast_'.$this->spec[$ch])) {
$methodName = 'cast_'.$this->spec[$ch];
$ret .= $this->$methodName($args[$i++]);
} elseif($ch == '%') {
$ret .= '%';
} else {
throw new caster_Exception("Invalid format string");
throw new caster_Exception("Caster received unexpected format character: %".$ch);
}
$pos0 = $pos1 + 2;
}
Expand Down Expand Up @@ -151,6 +200,14 @@ function formatNewLines($str) {
return $ret;
}

static function getCastName($format) {
$caster = new static;
return $caster->getCastNameReal($format);
}
function getCastNameReal ($format) {
return $this->spec[$format];
}

/* DEPRECATED METHODS */
}

Expand Down
57 changes: 57 additions & 0 deletions classes/caster/caster_Json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/* generic caster for an web project */
class caster_Json extends caster_Abstract {

protected $spec = array (
's' => 'string',
'n' => 'number',

/* these aren't real JSON types, but can validate on them */
'i' => 'integer',
'f' => 'float',

'b' => 'boolean',
'a' => 'array',
'o' => 'object',

't' => 'timestamp'
);

/* annoyance due to PHP scope issue */
static function cast ($args) {
$parser = new self();
return (string) $parser->castString(func_get_args());
}

static function cast_string ($in) {
return sf("'%j'",$in);
}

static function cast_integer ($in) {
return intval($in);
}
static function cast_float ($in) {
return floatval($in);
}
static function cast_number ($in) {
return ($in);
}
static function cast_boolean ($in) {
return boolval($in);
}

static function cast_array ($in) {
return json_encode($in);
}
static function cast_timestamp ($in) {
return intval($in);
}

static function cast_object ($in) {
return json_encode($in);
}

}

?>
63 changes: 63 additions & 0 deletions classes/caster/caster_Php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/* generic caster for an web project */
class caster_Php extends caster_Abstract {

protected $spec = array (
's' => 'string',
'n' => 'number',

/* these aren't real JSON types, but can validate on them */
'i' => 'integer',
'f' => 'float',

'b' => 'boolean',

't' => 'timestamp',

'a' => 'array',
'o' => 'object'
);


/* returns a value */
static function value ($format, $value) {

$parser = new self();

$methodName = 'cast_'.$parser->spec[$format];
return $parser->$methodName($value);

}

static function cast_string ($in) {
return strval($in);
}

static function cast_integer ($in) {
return intval($in);
}
static function cast_float ($in) {
return floatval($in);
}
static function cast_number ($in) {
return ($in);
}
static function cast_boolean ($in) {
return boolval($in);
}
static function cast_timestamp ($in) {
return intval($in);
}

static function cast_array ($in) {
return $in;
}

static function cast_object ($in) {
return $in;
}

}

?>
Loading