File code/class/OldPackage.php

class Lia\OldPackage

Encaspulate multiple components, views, routes & other bits in a single directory as a package.

@featured
See source code at /code/class/OldPackage.php

Constants

Properties

  • public $name; The configured name of this package or uniqid() if not specified

  • public $dir; The root dir for the package
    @featured

  • public $lia; the liaison instance
    @featured

  • protected $compos = []; All compos added. ['name'=>$compoObject, 'name2'=>$otherCompo]
    @featured

  • protected $lifecycleCompos = []; Components implementing LiaisonInterface\PackageLifeCycle

  • `protected $config = [
    'namespace'=>'',
    'dir'=>
    [
    'component' => 'core',
    'autoload'=> 'class',
    'view' => 'view',
    'cache' => 'cache',
    'package_lifecycle' => 'package_lifecycle',
    'public'=>[ 'dir' => 'public',
    'baseUrl'=> '',
    ]
    ],

      'route'=>  
          [  
              'force_trail_slash'=>true,  
              'index_names'=>  
              [  
                  'index'  
              ],  
              'hidden_extensions'=>  
              [  
                  'php'  
              ],  
          ],  
      'class'=>  
          [  
              'view' => '\\Lia\\Obj\\View'  
          ],  
      'views'=>  
          [  
                          ]  
    

    ];` Configurations for the package
    This implementation is going to change, but I don't know how that's gonna work yet. I just know I don't like it.

Methods

  • public function __construct( $lia, string $dir=null, array $configs []) Initialize package.

  • Configs are loaded from a config file in the package. Any keys set in the $config array will replace values set in the config file

  • Setup is only performed if dir is non-null

  • public function setup(array $configs, string $dir = null) Setup the package.

  • public function onComponentsLoaded() @override

  • public function onPrePackageReady() @override

  • public function onPackageReady() @override

  • protected function lifecycle($name) Execute the given lifecycle method on each component in this package
    Execute same-named php file in the package's package_lifecycle dir

  • public function addComponent($name, $component) Add a component to the package.

  • protected function setup_config_file(string $configFile) Load Config file. Currently $package->dir.'/config.json'.

  • public function fileToPattern($relFile) Convert a relative file path into a pattern for the Router component

  • public function set($key, $value) Set a config on the package (Does NOT propagate to Liaison)

  • public function get($key) Get a config from the package (NOT from Liaison)
    @featured

  • public function class($forKey) Get the configured class for the given key.
    Shorthand for get('class.$key');
    @featured

  • public function compo($name) Get the named component from the package

  • public function dir($forKey=null) Get the path to a directory in this package, or the package root dir if $forKey==null

  • public function url($path, $getParams=null) Prepends base url to the given path & sets $getparams as querystring. Replaces all double shashes (//) with single (/)

  • public function setup_autoload($dir) Adds configured 'autoload' dir to the Autoloader component

  • protected function setup_components(string $dir) Load all components from the configured 'component' dir

  • public function setup_public_routes($dir, $prefix=null) Add all files in configured 'public' dir to the Router component

  • public function setup_views(string $dir, array $args) Add all views in configured 'view' dir to the View Component