This repository has been archived by the owner on May 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Class.php
1509 lines (1395 loc) · 38.3 KB
/
Class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* OPEN POWER LIBS <http://www.invenzzia.org>
*
* This file is subject to the new BSD license that is bundled
* with this package in the file LICENSE. It is also available through
* WWW at this URL: <http://www.invenzzia.org/license/new-bsd>
*
* Copyright (c) Invenzzia Group <http://www.invenzzia.org>
* and other contributors. See website for details.
*
*/
/**
* The interface for writing caching systems for OPT.
*
* @author Tomasz Jędrzejewski
* @copyright Invenzzia Group <http://www.invenzzia.org/> and contributors.
* @license http://www.invenzzia.org/license/new-bsd New BSD License
* @package Interfaces
* @subpackage Public
*/
interface Opt_Caching_Interface
{
/**
* The method executed during the template execution initialization.
* It is supposed to return false in order to regenerate the cache
* or the cached result.
*
* @param Opt_View $view The cached view
* @return boolean|string
*/
public function templateCacheStart(Opt_View $view);
/**
* Executed during the cache rebuilding process. It must finish the
* capturing and store the result in a persistent storage.
*
* @param Opt_View $view The cached view
*/
public function templateCacheStop(Opt_View $view);
} // end Opt_Caching_Interface;
/**
* The interface for writing output systems
*
* @author Tomasz Jędrzejewski
* @copyright Invenzzia Group <http://www.invenzzia.org/> and contributors.
* @license http://www.invenzzia.org/license/new-bsd New BSD License
* @package Interfaces
* @subpackage Public
*/
interface Opt_Output_Interface
{
/**
* Returns the output interface name
*
* @return string
*/
public function getName();
/**
* Renders the specified view.
*
* @param Opt_View $view The view to render
*/
public function render(Opt_View $view);
} // end Opt_Output_Interface;
/**
* The interface for writing inflectors.
*
* @author Tomasz Jędrzejewski
* @copyright Invenzzia Group <http://www.invenzzia.org/> and contributors.
* @license http://www.invenzzia.org/license/new-bsd New BSD License
* @package Interfaces
* @subpackage Public
*/
interface Opt_Inflector_Interface
{
/**
* Returns the actual path to the source template suitable to use with
* the PHP filesystem functions.
*
* @param string $file The template file
* @return string
*/
public function getSourcePath($file);
/**
* Returns the actual path to the compiled template suitable to use
* with the PHP filesystem functions.
*
* @param string $file The template file
* @param array $inheritance The dynamic template inheritance list
* @return string
*/
public function getCompiledPath($file, array $inheritance);
} // end Opt_Inflector_Interface;
/**
* The main OPT class. It manages the configuration, initialization
* and plugin loading issues. Usually, there is no need to create more
* than one object of this class, and OPT assumes there is only one
* object of Opt_Class at given time.
*
* @author Tomasz Jędrzejewski
* @copyright Invenzzia Group <http://www.invenzzia.org/> and contributors.
* @license http://www.invenzzia.org/license/new-bsd New BSD License
* @package Public
*/
class Opt_Class extends Opl_Class
{
// Constants
const CM_DEFAULT = 0;
const CM_REBUILD = 1;
const CM_PERFORMANCE = 2;
const CHOOSE_MODE = 'Opt_Parser_Html';
const XML_MODE = 'Opt_Parser_Xml';
const QUIRKS_MODE = 'Opt_Parser_Quirks';
const HTML_MODE = 'Opt_Parser_Html';
const OPT_INSTRUCTION = 1;
const OPT_NAMESPACE = 2;
const OPT_FORMAT = 3;
const OPT_COMPONENT = 4;
const OPT_BLOCK = 5;
const PHP_FUNCTION = 6;
const PHP_CLASS = 7;
const XML_ENTITY = 8;
const EXPR_ENGINE = 9;
const MODIFIER = 10;
const VERSION = '2.1-beta1';
const ERR_STANDARD = 6135; // E_ALL^E_NOTICE
// Directory configuration
public $sourceDir = NULL;
public $compileDir = NULL;
public $cacheDir = NULL;
// Template configuration
public $compileId = NULL;
// Front-end configuration
public $compileMode = self::CM_DEFAULT;
public $charset = 'utf-8';
public $contentType = 0;
public $gzipCompression = true;
public $headerBuffering = false;
public $errorReporting = self::ERR_STANDARD;
public $stdStream = 'file';
public $debugConsole = false;
public $allowRelativePaths = false;
// Function configuration
public $moneyFormat;
public $numberDecimals;
public $numberDecPoint;
public $numberThousandSep;
// Template language configuration
public $parser = 'Opt_Parser_Xml';
public $expressionEngine = 'parse';
public $attributeModifier = 'a';
public $defaultModifier = 'e';
// Compiler configuration
public $backwardCompatibility = false;
public $unicodeNames = false;
public $htmlAttributes = false;
public $printComments = false;
public $prologRequired = true;
public $stripWhitespaces = true;
public $singleRootNode = true;
public $allowArrays = false;
public $allowObjects = false;
public $allowObjectCreation = false;
public $backticks = null;
public $translate = null;
public $strictCallbacks = true;
public $htmlEntities = true;
public $escape = true;
public $defaultFormat = 'Array';
public $containerFormat = 'Container';
public $treeFormat = 'DepthTree';
public $componentFormat = 'Component';
public $blockFormat = 'Block';
/**
* The compiler object
* @var Opt_Compiler_Class
*/
protected $_compiler;
/**
* The inflector object
* @var Opt_Inflector_Interface
*/
protected $_inflector;
/**
* The translation interface
* @var Opl_Translation_Interface
*/
protected $_tf = NULL;
/**
* The cache object
* @var Opt_Caching_Interface
*/
protected $_cache;
/**
* The list of registered instruction processors.
* @var array
*/
protected $_instructions = array('Opt_Instruction_Section', 'Opt_Instruction_Tree',
'Opt_Instruction_Grid', 'Opt_Instruction_Selector', 'Opt_Instruction_Repeat',
'Opt_Instruction_Snippet', 'Opt_Instruction_Extend',
'Opt_Instruction_For', 'Opt_Instruction_Foreach', 'Opt_Instruction_If',
'Opt_Instruction_Put', 'Opt_Instruction_Capture', 'Opt_Instruction_Attribute',
'Opt_Instruction_Tag', 'Opt_Instruction_Root', 'Opt_Instruction_Prolog',
'Opt_Instruction_Dtd', 'Opt_Instruction_Literal', 'Opt_Instruction_Include',
'Opt_Instruction_Dynamic', 'Opt_Instruction_Component', 'Opt_Instruction_Block',
'Opt_Instruction_Switch', 'Opt_Instruction_Procedure'
);
/**
* The list of registered functions: assotiative parray of pairs:
* template function name => php function name
* @var array
*/
protected $_functions = array(
'money' => 'Opt_Function::money', 'number' => 'Opt_Function::number', 'spacify' => 'Opt_Function::spacify',
'firstof' => 'Opt_Function::firstof', 'indent' => 'Opt_Function::indent', 'strip' => 'Opt_Function::strip',
'stripTags' => 'Opt_Function::stripTags', 'upper' => 'Opt_Function::upper', 'lower' => 'Opt_Function::lower',
'capitalize' => 'Opt_Function::capitalize', 'countWords' => 'str_word_count', 'countChars' => 'strlen',
'replace' => '#3,1,2#str_replace', 'repeat' => 'str_repeat', 'nl2br' => 'Opt_Function::nl2br', 'date' => 'date',
'regexReplace' => '#3,1,2#preg_replace', 'truncate' => 'Opt_Function::truncate', 'wordWrap' => 'Opt_Function::wordwrap',
'count' => 'sizeof', 'sum' => 'Opt_Function::sum', 'average' => 'Opt_Function::average',
'absolute' => 'Opt_Function::absolute', 'stddev' => 'Opt_Function::stddev', 'range' => 'Opt_Function::range',
'isUrl' => 'Opt_Function::isUrl', 'isImage' => 'Opt_Function::isImage', 'stddev' => 'Opt_Function::stddev',
'entity' => 'Opt_Function::entity', 'scalar' => 'is_scalar', 'cycle' => 'Opt_Function::cycle',
'containsKey' => 'Opt_Function::containsKey', 'autoLink' => 'Opt_Function::autoLink', 'pluralize' => 'Opt_Function::pluralize',
'countSubstring' => 'Opt_Function::countSubstring', 'pad' => 'Opt_Function::pad', 'autoLink' => 'Opt_Function::autoLink',
'position' => 'strpos'
);
/**
* The list of registered classes: assotiative array of pairs:
* template class name => php class name
* @var array
*/
protected $_classes = array();
/**
* The list of registered components: assotiative array of
* pairs: XML tag => component class
* @var array
*/
protected $_components = array();
/**
* The list of registered blocks: assotiative array of
* pairs: XML tag => component class
* @var array
*/
protected $_blocks = array();
/**
* The list of recognized OPT namespaces
* @var array
*/
protected $_namespaces = array(1 => 'opt', 'com', 'parse');
/**
* The list of recognized expression engines.
* @var array
*/
protected $_exprEngines = array(
'parse' => 'Opt_Expression_Standard',
'str' => 'Opt_Expression_String',
);
protected $_modifiers = array(
'a' => 'htmlspecialchars',
'e' => 'htmlspecialchars',
'u' => null
);
/**
* The list of data formats: associative array of pairs:
* format name => format class
* @var array
*/
protected $_formats = array(
'Array' => 'Opt_Format_Array',
'AssociativeArray' => 'Opt_Format_AssociativeArray',
'Objective' => 'Opt_Format_Objective',
'Global' => 'Opt_Format_Global',
'SingleArray' => 'Opt_Format_SingleArray',
'SplDatastructure' => 'Opt_Format_SplDatastructure',
'StaticGenerator' => 'Opt_Format_StaticGenerator',
'RuntimeGenerator' => 'Opt_Format_RuntimeGenerator',
'System' => 'Opt_Format_System',
'SwitchEquals' => 'Opt_Format_SwitchEquals',
'SwitchContains' => 'Opt_Format_SwitchContains',
'Container' => 'Opt_Format_Container',
'DepthTree' => 'Opt_Format_DepthTree',
'NestedTree' => 'Opt_Format_NestedTree',
'Component' => 'Opt_Format_Component',
'Block' => 'Opt_Format_Block'
);
/**
* The extra entities replaced by OPT
* @var array
*/
protected $_entities = array('lb' => '{', 'rb' => '}');
/**
* The output buffers for advisory output buffering information.
* @var array
*/
protected $_buffers = array();
/**
* Was the library initialized?
* @var boolean
*/
protected $_init = false;
/*
* Template parsing
*/
/**
* Returns the compiler object and optionally loads the necessary classes. Unless
* you develop instructions or reimplement various core features you do not have
* to use this method.
*
* @return Opt_Compiler_Class The compiler
*/
public function getCompiler()
{
if(!is_object($this->_compiler))
{
$this->_compiler = new Opt_Compiler_Class($this);
}
return $this->_compiler;
} // end getCompiler();
/*
* Extensions and configuration
*/
/**
* Performs the main initialization of OPT. If the optional argument `$config` is
* specified, it is transparently sent to Opt_Class::loadConfig(). Before using this
* method, we are obligated to configure the library and load the necessary extensions.
*
* @param mixed $config = null The optional configuration to be loaded
*/
public function setup($config = null)
{
if(is_array($config))
{
$this->loadConfig($config);
}
if($this->pluginDir !== null)
{
$this->loadPlugins();
}
if(Opl_Registry::exists('opl_translate'))
{
$this->setTranslationInterface(Opl_Registry::get('opl_translate'));
}
if(Opl_Registry::getValue('opl_debug_console') || $this->debugConsole)
{
$this->debugConsole = true;
Opt_Support::initDebugConsole($this);
}
// Register a default inflector, if the programmer didn't set any.
if(!$this->_inflector instanceof Opt_Inflector_Interface)
{
$this->_inflector = new Opt_Inflector_Standard($this);
}
$this->_securePath($this->compileDir);
$this->_init = true;
return true;
} // end setup();
/**
* Registers a new add-on in OPT identified by `$type`. The type is identified
* by the appropriate Opt_Class constant. The semantics of the next arguments
* depends on the registered add-on.
*
* Note that you may register several add-ons at the same time by passing an
* array as the second argument.
*
* @throws Opt_Exception
* @param int $type The type of registered item(s).
* @param mixed $item The item or a list of items to be registered
* @param mixed $addon = null Used in several types of add-ons
* @return void
*/
public function register($type, $item, $addon = null)
{
if($this->_init)
{
throw new Opt_Exception('Cannot register an item in OPT: the library has already been initialized.');
}
$map = array(1 => '_instructions', '_namespaces', '_formats', '_components', '_blocks', '_functions', '_classes', '_entities', '_exprEngines', '_modifiers');
$whereto = $map[$type];
// Massive registration
if(is_array($item))
{
$this->$whereto = array_merge($this->$whereto, $item);
return;
}
switch($type)
{
case self::OPT_FORMAT:
if($addon === null)
{
$addon = 'Opt_Format_'.$item;
}
$a = &$this->$whereto;
$a[$item] = $addon;
break;
case self::OPT_INSTRUCTION:
if($addon === null)
{
$addon = 'Opt_Instruction_'.$item;
}
$a = &$this->$whereto;
$a[$item] = $addon;
break;
case self::OPT_NAMESPACE:
$a = &$this->$whereto;
$a[] = $item;
break;
case self::MODIFIER:
$a = &$this->$whereto;
$a[$item] = $addon;
break;
default:
if($addon === null)
{
throw new BadMethodCallException('Missing argument 3 for Opt_Class::register()');
}
$a = &$this->$whereto;
$a[$item] = $addon;
}
} // end register();
/**
* Registers a new translation interface to be used in templates. The translation
* interface must implement Opl_Translation_Interface. If the specified parameter
* is not a valid translation interface, the method unregisters the already set one
* and returns false.
*
* @param Opl_Translation_Interface $tf The translation interface or "null".
* @return boolean True, if the translation interface was properly set.
*/
public function setTranslationInterface($tf)
{
if(!$tf instanceof Opl_Translation_Interface)
{
$this->_tf = null;
return false;
}
$this->_tf = $tf;
return true;
} // end setTranslationInterface();
/**
* Returns the current translation interface assigned to OPT.
*
* @return Opl_Translation_Interface The translation interface.
*/
public function getTranslationInterface()
{
return $this->_tf;
} // end getTranslationInterface();
/**
* Sets a new inflector for the OPT.
* @param Opt_Inflector_Interface $inflector The new inflector.
*/
public function setInflector(Opt_Inflector_Interface $inflector)
{
$this->_inflector = $inflector;
} // end setInflector();
/**
* Returns the current inflector. Note that before calling setup()
* this method may return NULL.
* @return Opt_Inflector_Interface
*/
public function getInflector()
{
return $this->_inflector;
} // end getInflector();
/**
* Sets the global caching system to use in all the views.
*
* @param Opt_Caching_Interface $cache=null The caching interface
*/
public function setCache(Opt_Caching_Interface $cache = null)
{
$this->_cache = $cache;
} // end setCache();
/**
* Returns the current global caching system.
*
* @return Opt_Caching_Interface
*/
public function getCache()
{
return $this->_cache;
} // end getCache();
/**
* An implementation of advisory output buffering which allows us
* to tell us, whether another part of the script opened the requested
* buffer.
*
* @param String $buffer The buffer name
* @param Boolean $state The new buffer state: true to open, false to close.
*/
public function setBufferState($buffer, $state)
{
if($state)
{
if(!isset($this->_buffers[$buffer]))
{
$this->_buffers[$buffer] = 1;
}
else
{
$this->_buffers[$buffer]++;
}
}
else
{
if(isset($this->_buffers[$buffer]) && $this->_buffers[$buffer] > 0)
{
$this->_buffers[$buffer]--;
}
}
} // end setBufferState();
/**
* Returns the state of the specified output buffer.
*
* @param String $buffer Buffer name
* @return Boolean
*/
public function getBufferState($buffer)
{
if(!isset($this->_buffers[$buffer]))
{
return false;
}
return ($this->_buffers[$buffer] > 0);
} // end getBufferState();
/*
* Internal use
*/
/**
* Allows the read access to some of the internal structures for the
* template compiler.
*
* @internal
* @param string $name The structure to be returned.
* @return array The returned structure.
*/
public function _getList($name)
{
static $list;
if($list === null)
{
$list = array('_instructions', '_namespaces', '_formats', '_components', '_blocks', '_functions', '_classes', '_tf', '_entities', '_exprEngines', '_modifiers');
}
if(in_array($name, $list))
{
return $this->$name;
}
return NULL;
} // end _getList();
/**
* The helper function for the plugin subsystem. It returns the
* PHP code that loads the specified plugin.
*
* @internal
* @param String $directory The plugin directory
* @param SplFileInfo $file The loaded file
* @return String
*/
protected function _pluginLoader($directory, SplFileInfo $file)
{
$ns = explode('.', $file->getFilename());
$filename = $file->getFilename();
if(strpos($filename, '.php') === (strlen($filename) - 4))
{
return ' require(\''.$directory.$filename.'\'); ';
}
} // end _pluginLoader();
/**
* Loads the template source code. Returns the template body or
* the array with two (false) values in case of problems.
*
* @internal
* @throws Opl_Filesystem_Exception
* @param string $filename The template filename
* @param boolean $exception Do we inform about the problems with exception?
* @return string|array
*/
public function _getSource($filename, $exception = true)
{
$item = $this->_inflector->getSourcePath($filename);
if(!file_exists($item))
{
if(!$exception)
{
return array(false, false);
}
throw new Opl_Filesystem_Exception('The specified template: '.$item.' has not been found.');
}
return file_get_contents($item);
} // end _getSource();
/**
* The class constructor - registers the main object in the
* OPL registry.
*/
public function __construct()
{
Opl_Registry::set('opt', $this);
} // end __construct();
/**
* The destructor. Clears the output buffers and optionally
* displays the debug console.
*/
public function __destruct()
{
if($this->debugConsole)
{
try
{
Opt_Support::updateTimers();
Opl_Debug_Console::display();
}
catch(Opl_Exception $e)
{
die('<div style="background: #f77777;">Opt_Class destructor exception: '.$e->getMessage().'</div>');
}
}
} // end __destruct();
/**
* Frees the memory etc.
*/
public function dispose()
{
if($this->_compiler !== null)
{
$this->_compiler->dispose();
}
$this->_compiler = null;
$this->_tf = null;
} // end dispose();
} // end Opt_Class;
/**
* The main view class.
*
* @author Tomasz Jędrzejewski
* @copyright Invenzzia Group <http://www.invenzzia.org/> and contributors.
* @license http://www.invenzzia.org/license/new-bsd New BSD License
* @package Public
*/
class Opt_View
{
const VAR_LOCAL = false;
const VAR_GLOBAL = true;
/**
* A reference to the main class object.
* @var Opt_Class
*/
private $_tpl;
/**
* The template name
* @var string
*/
private $_template;
/**
* Data format information storage
* @var array
*/
private $_formatInfo = array('system' => 'System', 'opt' => 'System');
/**
* Template inheritance storage for the inflectors
* @var array
*/
private $_inheritance = array();
/**
* View data
* @var array
*/
private $_data = array();
/**
* Translation interface
* @var Opl_Translation_Interface
*/
private $_tf;
/**
* The information for the debugger: processing time
* @var integer
*/
private $_processingTime = null;
/**
* The branch name for the template inheritance.
* @var string
*/
private $_branch = null;
/**
* The caching system used in the view.
* @var Opt_Caching_Interface
*/
private $_cache = null;
/**
* The used parser.
* @var string
*/
private $_parser;
/**
* Part of the caching system to integrate with opt:dynamic instruction.
* @var array
*/
private $_outputBuffer = array();
/**
* The template variable storage
* @static
* @var array
*/
static private $_vars = array();
/**
* The template procedures
* @static
* @var array
*/
static private $_procedures = array();
/**
* The list of the captured content.
* @static
* @var array
*/
static private $_capture = array();
/**
* The global template data
* @static
* @var array
*/
static private $_global = array();
/**
* The global data format information
* @static
* @var array
*/
static private $_globalFormatInfo = array();
/**
* Creates a new view object. The optional argument, $template
* may specify the template to be associated with this view.
* Please note that if you do not specify the template here,
* you have to do this manually later using Opt_View::setTemplate()
* method.
*
* @param string $template The template file.
*/
public function __construct($template = '')
{
$this->_tpl = Opl_Registry::get('opt');
$this->_template = $template;
$this->_parser = $this->_tpl->parser;
$this->_cache = $this->_tpl->getCache();
$this->_formatInfo['#container'] = $this->_tpl->containerFormat;
} // end __construct();
/**
* Associates a template file to the view.
*
* @param string $file The template file.
*/
public function setTemplate($file)
{
$this->_template = $file;
} // end setTemplate();
/**
* Returns a template associated with this view.
*
* @return string The template filename.
*/
public function getTemplate()
{
return $this->_template;
} // end getTemplate();
/**
* Sets the template mode (XML, Quirks, etc...)
*
* @deprecated
* @param int|string $mode The new mode
*/
public function setMode($mode)
{
$this->_parser = $mode;
} // end setMode();
/**
* Gets the current template mode.
*
* @deprecated
* @return int|string
*/
public function getMode()
{
return $this->_parser;
} // end getMode();
/**
* Sets the name of the parser used to compile the template.
*
* @param string $parser The parser name
*/
public function setParser($parser)
{
$this->_parser = (string)$parser;
} // end setParser();
/**
* Returns the name of the parsed used to compile the view template.
*
* @return string
*/
public function getParser()
{
return $this->_parser;
} // end getParser();
/**
* Sets a template inheritance branch that will be used
* in this view. If you want to disable branching, set
* the argument to NULL.
*
* @param string $branch The branch name.
*/
public function setBranch($branch)
{
$this->_branch = $branch;
} // end setBranch();
/**
* Returns a branch used in the template inheritance.
*
* @return string The branch name.
*/
public function getBranch()
{
return $this->_branch;
} // end getBranch();
/**
* Returns the view processing time for the debug purposes.
* The processing time is calculated only if the debug mode
* is enabled.
*
* @return float The processing time.
*/
public function getTime()
{
return $this->_processingTime;
} // end getTime();
/*
* Data management
*/
/**
* Creates a new local template variable.
*
* @param string $name The variable name.
* @param mixed $value The variable value.
*/
public function __set($name, $value)
{
$this->_data[(string)$name] = $value;
} // end __set();
/**
* Creates a new local template variable.
*
* @param string $name The variable name.
* @param mixed $value The variable value.
*/
public function assign($name, $value)
{
$this->_data[(string)$name] = $value;
} // end assign();
/**
* Creates a group of local template variables
* using an associative array, where the keys are
* the variable names.
*
* @param array $vars A list of variables.
*/
public function assignGroup($values)
{
$this->_data = array_merge($this->_data, $values);
} // end assignGroup();
/**
* Creates a new local template variable with
* the value assigned by reference.
*
* @param string $name The variable name.
* @param mixed &$value The variable value.
*/
public function assignRef($name, &$value)
{
$this->_data[(string)$name] = &$value;
} // end assignRef();
/**
* Returns the value of a template variable or
* null, if the variable does not exist.
*
* @param string $name The variable name.
* @return mixed The variable value or NULL.
*/
public function get($name)
{
if(!isset($this->_data[(string)$name]))
{
return null;
}
return $this->_data[(string)$name];
} // end read();
/**
* Returns the value of a local template variable or
* null, if the variable does not exist.
*
* @param string $name The variable name.
* @return mixed The variable value or NULL.
*/
public function &__get($name)
{
if(!isset($this->_data[(string)$name]))
{
// For returning by reference...
$empty = null;
return $empty;
}
return $this->_data[(string)$name];
} // end __get();
/**
* Returns TRUE, if the local template variable with the
* specified name is defined.
*
* @param string $name The variable name.
* @return boolean True, if the variable is defined.
*/
public function defined($name)
{
return isset($this->_data[(string)$name]);
} // end defined();