Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3d51e1d418
Fetching contributors…

Cannot retrieve contributors at this time

file 986 lines (876 sloc) 27.788 kb
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
<?php
/**
* Savvy
*
* PHP version 5
*
* @category Templates
* @package Savvy
* @author Brett Bieber <saltybeagle@php.net>
* @copyright 2010 Brett Bieber
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version SVN: $Id$
* @link http://svn.php.net/repository/pear2/Savvy
*/

/**
* Main class for Savvy
*
* @category Templates
* @package Savvy
* @author Brett Bieber <saltybeagle@php.net>
* @copyright 2010 Brett Bieber
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://svn.php.net/repository/pear2/Savvy
*/
class Savvy
{
    /**
*
* Array of configuration parameters.
*
* @access protected
*
* @var array
*
*/
    
    protected $__config = array(
        'compiler' => null,
        'filters' => array(),
        'escape' => null,
    );
    
    /**
* Parameters for escaping.
*
* @var array
*/
    protected $_escape = array(
        'quotes' => ENT_COMPAT,
        'charset' => 'UTF-8',
        );
    
    /**
* The output template to render using
*
* @var string
*/
    protected $template;

    /**
* stack of templates, so we can access the parent template
*
* @var array
*/
    protected $templateStack = array();

    /**
* To avoid stats on locating templates, populate this array with
* full path => 1 for any existing templates
*
* @var array
*/
    protected $templateMap = array();
    
    /**
* An array of paths to look for template files in.
*
* @var array
*/
    protected $template_path = array('./');

    /**
* The current controller to use
*
* @var string
*/
    protected $selected_controller;
    
    /**
* How class names are translated to templates
*
* @var MapperInterface
*/
    protected $class_to_template;

    /**
* Array of globals available within every template
*
* @var array
*/
    protected $globals = array();
    // -----------------------------------------------------------------
    //
    // Constructor and magic methods
    //
    // -----------------------------------------------------------------
    
    
    /**
*
* Constructor.
*
* @access public
*
* @param array $config An associative array of configuration keys for
* the Main object. Any, or none, of the keys may be set.
*
* @return Savvy A Savvy instance.
*
*/
    
    public function __construct($config = null)
    {
        $savvy = $this;

        $this->selected_controller = 'basic';
        
        // set the default template search path
        if (isset($config['template_path'])) {
            // user-defined dirs
            $this->setTemplatePath($config['template_path']);
        }
        
        // set the output escaping callbacks
        if (isset($config['escape'])) {
            $this->setEscape($config['escape']);
        }
        
        // set the default filter callbacks
        if (isset($config['filters'])) {
            $this->addFilters($config['filters']);
        }
    }

    /**
* Basic output controller
*
* @param mixed $context The context passed to the template
* @param mixed $parent Parent template with context and parents $parent->context
* @param mixed $file The filename to include
* @param Savvy $savvy The Savvy templating system
*
* @return string
*/
    protected static function basicOutputController($context, $parent, $file, $savvy)
    {
        foreach ($savvy->getGlobals() as $__name => $__value) {
            $$__name = $__value;
        }
        unset($__name, $__value);
        ob_start();
        include $file;
        return ob_get_clean();
    }

    /**
* Basic output controller
*
* @param mixed $context The context passed to the template
* @param mixed $parent Parent template with context and parents $parent->context
* @param mixed $file The filename to include
* @param Savvy $savvy The Savvy templating system
*
* @return string
*/
    protected static function filterOutputController($context, $parent, $file, $savvy)
    {
        foreach ($savvy->getGlobals() as $__name => $__value) {
            $$__name = $__value;
        }
        unset($__name, $__value);
        ob_start();
        include $file;
        return $savvy->applyFilters(ob_get_clean());
    }

    /**
* Basic output controller
*
* @param mixed $context The context passed to the template
* @param mixed $parent Parent template with context and parents $parent->context
* @param mixed $file The filename to include
* @param Savvy $savvy The Savvy templating system
*
* @return string
*/
    protected static function basicCompiledOutputController($context, $parent, $file, $savvy)
    {
        foreach ($savvy->getGlobals() as $__name => $__value) {
            $$__name = $__value;
        }
        unset($__name, $__value);
        ob_start();
        include $savvy->template($file);
        return ob_get_clean();
    }

    /**
* Basic output controller
*
* @param mixed $context The context passed to the template
* @param mixed $parent Parent template with context and parents $parent->context
* @param mixed $file The filename to include
* @param Savvy $savvy The Savvy templating system
*
* @return string
*/
    protected static function filterCompiledOutputController($context, $parent, $file, $savvy)
    {
        foreach ($savvy->getGlobals() as $__name => $__value) {
            $$__name = $__value;
        }
        unset($__name, $__value);
        ob_start();
        include $savvy->template($file);
        return $savvy->applyFilters(ob_get_clean());
    }

    /**
* Basic output controller
*
* @param mixed $context The context passed to the template
* @param mixed $parent Parent template with context and parents $parent->context
* @param mixed $file The filename to include
* @param Savvy $savvy The Savvy templating system
*
* @return string
*/
    protected static function basicFastCompiledOutputController($context, $parent, $file, $savvy)
    {
        return include $savvy->template($file);
    }

    /**
* Basic output controller
*
* @param mixed $context The context passed to the template
* @param mixed $parent Parent template with context and parents $parent->context
* @param mixed $file The filename to include
* @param Savvy $savvy The Savvy templating system
*
* @return string
*/
    protected static function filterFastCompiledOutputController($context, $parent, $file, $savvy)
    {
        return $savvy->applyFilters(include $savvy->template($file));
    }

    /**
* Add a global variable which will be available inside every template
*
* @param string $var The global variable name
* @param mixed $value The value
*
* @return void
*/
    function addGlobal($name, $value)
    {
        switch ($name) {
            case 'context':
            case 'parent':
            case 'template':
            case 'savvy':
            case 'this':
                throw new Savvy_BadMethodCallException('Invalid global variable name');
        }

        if ($this->__config['escape']) {
            switch (gettype($value)) {
                case 'object':
                    if (!$value instanceof Savvy_ObjectProxy) {
                        $value = Savvy_ObjectProxy::factory($value, $this);
                    }
                    break;
                case 'string':
                case 'int':
                case 'double':
                    $value = $this->escape($value);
                    break;
                case 'array':
                    $value = new Savvy_ObjectProxy_ArrayIterator($value, $this);
                    break;
            }
        }

        $this->globals[$name] = $value;
    }

    /**
* Get the array of assigned globals
*
* @return array
*/
    function getGlobals()
    {
        return $this->globals;
    }

    /**
* Return the current template set (if any)
*
* @return string
*/
    function getTemplate()
    {
        return $this->template;
    }
    
    
    // -----------------------------------------------------------------
    //
    // Public configuration management (getters and setters).
    //
    // -----------------------------------------------------------------
    
    
    /**
*
* Returns a copy of the Savvy configuration parameters.
*
* @access public
*
* @param string $key The specific configuration key to return. If null,
* returns the entire configuration array.
*
* @return mixed A copy of the $this->__config array.
*
*/
    
    public function getConfig($key = null)
    {
        if (is_null($key)) {
            // no key requested, return the entire config array
            return $this->__config;
        } elseif (empty($this->__config[$key])) {
            // no such key
            return null;
        } else {
            // return the requested key
            return $this->__config[$key];
        }
    }
    
    
    /**
*
* Sets a custom compiler/pre-processor callback for template sources.
*
* By default, Savvy does not use a compiler; use this to set your
* own custom compiler (pre-processor) for template sources.
*
* @access public
*
* @param mixed $compiler A compiler callback value suitable for the
* first parameter of call_user_func(). Set to null/false/empty to
* use PHP itself as the template markup (i.e., no compiling).
*
* @return void
*
*/
    
    public function setCompiler(Savvy_CompilerInterface $compiler)
    {
        $this->__config['compiler'] = $compiler;
        if ($compiler instanceof Savvy_FastCompilerInterface) {
            switch ($this->selected_controller) {
                case 'basic' :
                case 'basiccompiled';
                    $this->selected_controller = 'basicfastcompiled';
                    break;
                case 'filter' :
                case 'filtercompiled' :
                    $this->selected_controller = 'filterfastcompiled';
                    break;
            }
            return;
        }
        if (!strpos($this->selected_controller, 'compiled')) {
            $this->selected_controller .= 'compiled';
        }
    }
    
    /**
* Set the class to template mapper.
*
* @see MapperInterface
*
* @param MapperInterface $mapper The mapper interface to use
*
* @return Main
*/
    function setClassToTemplateMapper(Savvy_MapperInterface $mapper)
    {
        $this->class_to_template = $mapper;
        return $this;
    }
    
    /**
* Get the class to template mapper.
*
* @return MapperInterface
*/
    function getClassToTemplateMapper()
    {
        if (!isset($this->class_to_template)) {
            $this->setClassToTemplateMapper(new Savvy_ClassToTemplateMapper());
        }
        return $this->class_to_template;
    }
    
    
    // -----------------------------------------------------------------
    //
    // Output escaping and management.
    //
    // -----------------------------------------------------------------
    
    
    /**
*
* Clears then sets the callbacks to use when calling $this->escape().
*
* Each parameter passed to this function is treated as a separate
* callback. For example:
*
* <code>
* $savvy->setEscape(
* 'stripslashes',
* 'htmlspecialchars',
* array('StaticClass', 'method'),
* array($object, $method)
* );
* </code>
*
* @access public
*
* @return Main
*
*/
    
    public function setEscape()
    {
        $this->__config['escape'] = @func_get_args();
        return $this;
    }
    
    
    /**
*
* Gets the array of output-escaping callbacks.
*
* @access public
*
* @return array The array of output-escaping callbacks.
*
*/
    
    public function getEscape()
    {
        return $this->__config['escape'];
    }
    
    
    /**
* Escapes a value for output in a view script.
*
* If escaping mechanism is one of htmlspecialchars or htmlentities, uses
* {@link $_encoding} setting.
*
* @param mixed $var The output to escape.
*
* @return mixed The escaped value.
*/
    public function escape($var)
    {
        foreach ($this->__config['escape'] as $escape) {
            if (in_array($escape,
                    array('htmlspecialchars', 'htmlentities'), true)) {
                $var = call_user_func($escape,
                                      $var,
                                      $this->_escape['quotes'],
                                      $this->_escape['charset']);
            } else {
                $var = call_user_func($escape, $var);
            }
        }
        return $var;
    }
    
    
    // -----------------------------------------------------------------
    //
    // File management
    //
    // -----------------------------------------------------------------
    
    /**
* Get the template path.
*
* @return array
*/
    function getTemplatePath()
    {
        return $this->template_path;
    }
    
    /**
*
* Sets an entire array of search paths for templates or resources.
*
* @access public
*
* @param string|array $path The new set of search paths. If null or
* false, resets to the current directory only.
*
* @return Main
*
*/
    
    public function setTemplatePath($path = null)
    {
        // clear out the prior search dirs, add default
        $this->template_path = array('./');
        
        // actually add the user-specified directories
        $this->addTemplatePath($path);
        return $this;
    }
    
    
    /**
*
* Adds to the search path for templates and resources.
*
* @access public
*
* @param string|array $path The directory or stream to search.
*
* @return Main
*
*/
    
    public function addTemplatePath($path)
    {
        // convert from path string to array of directories
        if (is_string($path) && !strpos($path, '://')) {
        
            // the path config is a string, and it's not a stream
            // identifier (the "://" piece). add it as a path string.
            $path = explode(PATH_SEPARATOR, $path);
            
            // typically in path strings, the first one is expected
            // to be searched first. however, Savvy uses a stack,
            // so the first would be last. reverse the path string
            // so that it behaves as expected with path strings.
            $path = array_reverse($path);
            
        } else {
        
            // just force to array
            settype($path, 'array');
            
        }
        
        // loop through the path directories
        foreach ($path as $dir) {
        
            // no surrounding spaces allowed!
            $dir = trim($dir);
            
            // add trailing separators as needed
            if (strpos($dir, '://')) {
                if (substr($dir, -1) != '/') {
                    // stream
                    $dir .= '/';
                }
            } elseif (substr($dir, -1) != DIRECTORY_SEPARATOR) {
                if (false !== strpos($dir, '..')) {
                    // checking for weird paths here removes directory traversal threat
                    throw new Savvy_UnexpectedValueException('upper directory reference .. cannot be used in template path');
                }
                // directory
                $dir .= DIRECTORY_SEPARATOR;
            }

            // add to the top of the search dirs
            array_unshift(
                $this->template_path,
                $dir
            );
        }
    }
    
    
    /**
*
* Searches the directory paths for a given file.
*
* @param string $file The file name to look for.
*
* @return string|bool The full path and file name for the target file,
* or boolean false if the file is not found in any of the paths.
*
*/
    
    public function findTemplateFile($file)
    {
        if (false !== strpos($file, '..')) {
            // checking for weird path here removes directory traversal threat
            throw new Savvy_UnexpectedValueException('upper directory reference .. cannot be used in template filename');
        }
        
        // start looping through the path set
        foreach ($this->template_path as $path) {
            // get the path to the file
            $fullname = $path . $file;

            if (isset($this->templateMap[$fullname])) {
                return $fullname;
            }

            if (!@is_readable($fullname)) {
                continue;
            }

            return $fullname;
        }

        // could not find the file in the set of paths
        throw new Savvy_TemplateException('Could not find the template ' . $file);
    }
    
    
    // -----------------------------------------------------------------
    //
    // Template processing
    //
    // -----------------------------------------------------------------
    
    /**
* Render context data through a template.
*
* This method allows you to render data through a template. Typically one
* will pass the model they wish to display through an optional template.
* If no template is specified, the ClassToTemplateMapper::map() method
* will be called which should return the name of a template to render.
*
* Arrays will be looped over and rendered through the template specified.
*
* Strings, ints, and doubles will returned if no template parameter is
* present.
*
* Within templates, two variables will be available, $context and $savvy.
* The $context variable will contain the data passed to the render method,
* the $savvy object will be an instance of the Main class with which you
* can render nested data through partial templates.
*
* @param mixed $mixed Data to display through the template.
* @param string $template A template to display data in.
*
* @return string The template output
*/
    function render($mixed = null, $template = null)
    {
        $method = 'render'.gettype($mixed);
        return $this->$method($mixed, $template);
    }
    
    /**
* Called when a resource is rendered
*
* @param resource $resouce The resources
* @param string $template Template
*
* @return void
*
* @throws UnexpectedValueException
*/
    protected function renderResource($resouce, $template = null)
    {
        throw new Savvy_UnexpectedValueException('No way to render a resource!');
    }
    
    protected function renderBoolean($bool, $template = null)
    {
        return $this->renderString((string)$bool, $template);
    }
    
    protected function renderDouble($double, $template = null)
    {
        return $this->renderString($double, $template);
    }
    
    protected function renderInteger($int, $template = null)
    {
        return $this->renderString($int, $template);
    }
    
    /**
* Render string of data
*
* @param string $string String of data
* @param string $template A template to display the string in
*
* @return string
*/
    protected function renderString($string, $template = null)
    {
        if ($this->__config['escape']) {
            $string = $this->escape($string);
        }
        
        if ($template) {
            return $this->fetch($string, $template);
        }

        if (!$this->__config['filters']) {
            return $string;
        }
        return $this->applyFilters($string);
    }
    
    /**
* Used to render context array
*
* @param array $array Data to render
* @param string $template Template to render
*
* @return string Rendered output
*/
    protected function renderArray(array $array, $template = null)
    {
        $output = '';
        foreach ($array as $mixed) {
            $output .= $this->render($mixed, $template);
        }
        return $output;
    }

    /**
* Render an associative array of data through a template.
*
* Three parameters will be passed to the closure, the array key, value,
* and selective third parameter.
*
* @param array $array Associative array of data
* @param mixed $selected Optional parameter to pass
* @param Closure $template A closure that will be called
*
* @return string
*/
    public function renderAssocArray(array $array, $selected = false, Closure $template)
    {
        $ret = '';
        foreach ($array as $key => $element) {
            $ret .= $template($key, $element, $selected);
        }
        return $ret;
    }

    protected function renderArrayAccess(ArrayAccess $array, $template = null)
    {
        $ret = '';
        foreach ($array as $key => $element) {
            $ret .= $this->render($element, $template);
        }
        return $ret;
    }

    /**
* Render an if else conditional template output.
*
* @param mixed $condition The conditional to evaluate
* @param mixed $render Context data to render if condition is true
* @param mixed $else Context data to render if condition is false
* @param string $rendertemplate If true, render using this template
* @param string $elsetemplate If false, render using this template
*
* @return string
*/
    public function renderElse($condition, $render, $else, $rendertemplate = null, $elsetemplate = null)
    {
        if ($condition) {
            $this->render($render, $rendertemplate);
        } else {
            $this->render($else, $elsetemplate);
        }
    }
    
    /**
* Used to render an object through a template.
*
* @param object $object Model containing data
* @param string $template Template to render data through
*
* @return string Rendered output
*/
    protected function renderObject($object, $template = null)
    {
        if ($this->__config['escape']) {

            if (!$object instanceof Savvy_ObjectProxy) {
                $object = Savvy_ObjectProxy::factory($object, $this);
            }

            if ($object instanceof Savvy_ObjectProxy_ArrayIterator) {
                return $this->renderArrayAccess($object);
            }
        }
        return $this->fetch($object, $template);
    }
    
    /**
* Used to render null through an optional template
*
* @param null $null The null var
* @param string $template Template to render null through
*
* @return string Rendered output
*/
    protected function renderNULL($null, $template = null)
    {
        if ($template) {
            return $this->fetch(null, $template);
        }
    }
    
    protected function fetch($mixed, $template = null)
    {
        if ($template) {
            $this->template = $template;
        } else {
            if ($mixed instanceof Savvy_ObjectProxy) {
                $class = $mixed->__getClass();
            } else {
                $class = get_class($mixed);
            }
            $this->template = $this->getClassToTemplateMapper()->map($class);
        }
        $current = new stdClass;
        $current->file = $this->findTemplateFile($this->template);
        $current->context = $mixed;
        $current->parent = null;
        if (count($this->templateStack)) {
            $current->parent = $this->templateStack[count($this->templateStack)-1];
        }
        $this->templateStack[] = $current;
        $ret = call_user_func(array($this, $this->selected_controller.'OutputController'), $current->context, $current->parent, $current->file, $this);
        array_pop($this->templateStack);
        return $ret;
    }
    
    /**
*
* Compiles a template and returns path to compiled script.
*
* By default, Savvy does not compile templates, it uses PHP as the
* markup language, so the "compiled" template is the same as the source
* template.
*
* If a compiler is specific, this method is used to look up the compiled
* template script name
*
* @param string $tpl The template source name to look for.
*
* @return string The full path to the compiled template script.
*
* @throws Savvy_UnexpectedValueException
* @throws Savvy_Exception
*
*/
    
    public function template($tpl = null)
    {
        // find the template source.
        $file = $this->findTemplateFile($tpl);
        
        // are we compiling source into a script?
        if ($this->__config['compiler']) {
            // compile the template source and get the path to the
            // compiled script (will be returned instead of the
            // source path)
            $result = $this->__config['compiler']->compile($file, $this);
        } else {
            // no compiling requested, use the source path
            $result = $file;
        }
        
        // is there a script from the compiler?
        if (!$result) {
            // return an error, along with any error info
            // generated by the compiler.
            throw new Savvy_TemplateException('Compiler error for template '.$tpl.'. '.$result );
            
        } else {
            // no errors, the result is a path to a script
            return $result;
        }
    }
    
    
    // -----------------------------------------------------------------
    //
    // Filter management and processing
    //
    // -----------------------------------------------------------------
    
    
    /**
*
* Resets the filter stack to the provided list of callbacks.
*
* @access protected
*
* @param array An array of filter callbacks.
*
* @return void
*
*/
    
    public function setFilters()
    {
        $this->__config['filters'] = (array) @func_get_args();
        if (!$this->__config['filters']) {
            $this->selected_controller = 'basic';
        } else {
            $this->selected_controller = 'filter';
        }
    }
    
    
    /**
*
* Adds filter callbacks to the stack of filters.
*
* @access protected
*
* @param array An array of filter callbacks.
*
* @return void
*
*/
    
    public function addFilters()
    {
        // add the new filters to the static config variable
        // via the reference
        foreach ((array) @func_get_args() as $callback) {
            $this->__config['filters'][] = $callback;
            $this->selected_controller = 'filter';
        }
    }
    
    
    /**
*
* Runs all filter callbacks on buffered output.
*
* @access protected
*
* @param string The template output.
*
* @return void
*
*/
    
    public function applyFilters($buffer)
    {
        foreach ($this->__config['filters'] as $callback) {
            $buffer = call_user_func($callback, $buffer);
        }
        return $buffer;
    }
    
}
Something went wrong with that request. Please try again.