PHP Classes

File: samples/psr4.php

Recommend this page to a friend!
  Classes of adriano ghezzi   ghz PHP Autoloader   samples/psr4.php   Download  
File: samples/psr4.php
Role: Example script
Content type: text/plain
Description: sample using psr4
Class: ghz PHP Autoloader
Autoload classes scanning files in directories
Author: By
Last change:
Date: 5 years ago
Size: 1,384 bytes
 

Contents

Class file image Download
<?php
/**
 * Created by PhpStorm.
 * User: adriano
 * Date: 25/02/19
 * Time: 18.33
 */


/**
 * suppose to have the folloqing scenario
 * all your classe are in
 ...myPackg/
??? ghzAutoloader.php
??? samples
??? defaultImplementation.php
??? myPckg
?   ??? Core
?   ?   ??? classOne.php
?   ??? Helpers
?   ??? helperOne.php
??? psr4sample.php

 */
require_once "../ghzAutoloader.php";

/* OPTION 1 you can define one top-level namespace -> 'myPckg'
and namespace classes accordingly as in class helperOne
*/
/*$namespacesBasedirs=['myPckg'=>[__DIR__ . DIRECTORY_SEPARATOR . 'myPckg' . DIRECTORY_SEPARATOR]];
ghzAutoloader::Psr4Implementation($namespacesBasedirs,false,true);

$one=new \myPckg\Core\classOne();
$h=new \myPckg\Helpers\helperOne();*/

/* option2 you can define two top-level name spaces
myPckg and Helpers
and namespace classes accordingly as in class helperTwo
*/
$namespacesBasedirs=[
                   
'myPckg'=>[__DIR__ . DIRECTORY_SEPARATOR . 'myPckg' . DIRECTORY_SEPARATOR],
                   
'Helpers'=>[__DIR__ . DIRECTORY_SEPARATOR . 'myPckg' . DIRECTORY_SEPARATOR.'Helpers' . DIRECTORY_SEPARATOR],
    ];
ghzAutoloader::Psr4Implementation($namespacesBasedirs,false,true);

$one=new \myPckg\Core\classOne();
$h=new \myPckg\Helpers\helperOne();
$h2=new \Helpers\helperTwo();