Skip to content
Snippets Groups Projects
Select Git revision
  • 614c41a1bdf7db81addc99f061c08417de229fff
  • main default protected
  • studip-rector
  • ci-opt
  • course-members-export-as-word
  • data-vue-app
  • pipeline-improvements
  • webpack-optimizations
  • rector
  • icon-renewal
  • http-client-and-factories
  • jsonapi-atomic-operations
  • vueify-messages
  • tic-2341
  • 135-translatable-study-areas
  • extensible-sorm-action-parameters
  • sorm-configuration-trait
  • jsonapi-mvv-routes
  • docblocks-for-magic-methods
19 results

CoreOverview.class.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Factory.php 7.42 KiB
    <?php
    /**
     * Using this factory you can create new Template objects.
     *
     * @copyright 2008 Marcus Lunzenauer <mlunzena@uos.de>
     * @author Marcus Lunzenauer <mlunzena@uos.de>
     * @license MIT
     */
    
    namespace Flexi;
    
    class Factory
    {
        /**
         * mapping of file extensions to supported template classes
         */
        protected array $handlers = [
            'php' => [PhpTemplate::class, []],
        ];
    
        /**
         * Constructor of TemplateFactory.
         *
         * @param string $path the template include path
         */
        public function __construct(protected string $path)
        {
            $this->set_path($path);
        }
    
        /**
         * Sets a new include path for the factory and returns the old one.
         *
         * @param string $path the new path
         *
         * @return string the old path
         */
        public function set_path(string $path): string
        {
            $old_path = $this->get_path();
    
            if (!str_ends_with($path, '/')) {
                $path .= '/';
            }
    
            $this->path = $path;
    
            return $old_path;
        }
    
        /**
         * Returns the include path of the factory
         *
         * @return string the current include path
         */
        public function get_path(): string
        {
            return $this->path;
        }
    
        /**
         * Open a template of the given name using the factory method pattern.
         * If a string was given, the path of the factory is searched for a matching
         * template.
         * If this string starts with a slash or with /\w+:\/\//, the string is
         * interpreted as an absolute path. Otherwise the path of the factory will be
         * prepended.
         * After that the factory searches for a file extension in this string. If
         * there is none, the directory where the template is supposed to live is
         * searched for a file starting with the template string and a supported