1: <?php
2: /**
3: * DataTables PHP libraries.
4: *
5: * PHP libraries for DataTables and DataTables Editor, utilising PHP 5.3+.
6: *
7: * @author SpryMedia
8: * @copyright 2012 SpryMedia ( http://sprymedia.co.uk )
9: * @license http://editor.datatables.net/license DataTables Editor
10: * @link http://editor.datatables.net
11: */
12:
13: namespace DataTables;
14: if (!defined('DATATABLES')) exit();
15:
16:
17: /**
18: * Base class for DataTables classes.
19: */
20: class Ext {
21: /**
22: * Static method to instantiate a new instance of a class.
23: *
24: * A factory method that will create a new instance of the class
25: * that has extended 'Ext'. This allows classes to be instantiated
26: * and then chained - which otherwise isn't available until PHP 5.4.
27: * If using PHP 5.4 or later, simply create a 'new' instance of the
28: * target class and chain methods as normal.
29: * @return \DataTables\Editor|\DataTables\Editor\Field|\DataTables\Editor\Join|\DataTables\Editor\Upload Instantiated class
30: * @static
31: */
32: public static function instantiate ()
33: {
34: $rc = new \ReflectionClass( get_called_class() );
35: return $rc->newInstanceArgs( func_get_args() );
36: }
37:
38: /**
39: * Static method to instantiate a new instance of a class (shorthand of
40: * 'instantiate').
41: *
42: * This method performs exactly the same actions as the 'instantiate'
43: * static method, but is simply shorter and easier to type!
44: * @return \DataTables\Editor|\DataTables\Editor\Field|\DataTables\Editor\Join|\DataTables\Editor\Upload class
45: * @static
46: */
47: public static function inst ()
48: {
49: $rc = new \ReflectionClass( get_called_class() );
50: return $rc->newInstanceArgs( func_get_args() );
51: }
52:
53: /**
54: * Common getter / setter function for DataTables classes.
55: *
56: * This getter / setter method makes building getter / setting methods
57: * easier, by abstracting everything to a single function call.
58: * @param mixed &$prop The property to set
59: * @param mixed $val The value to set - if given as null, then we assume
60: * that the function is being used as a getter.
61: * @param boolean $array Treat the target property as an array or not
62: * (default false). If used as an array, then values passed in are added
63: * to the $prop array.
64: * @return self|* Class instance if setting (allowing chaining), or
65: * the value requested if getting.
66: */
67: protected function _getSet( &$prop, $val, $array=false )
68: {
69: // Get
70: if ( $val === null ) {
71: return $prop;
72: }
73:
74: // Set
75: if ( $array ) {
76: // Property is an array, merge or add to array
77: is_array( $val ) ?
78: $prop = array_merge( $prop, $val ) :
79: $prop[] = $val;
80: }
81: else {
82: // Property is just a value
83: $prop = $val;
84: }
85:
86: return $this;
87: }
88: }
89:
90: