ASISG
Gy - php framework/CMS | Documentation | Class autoloading
Class autoloading
Psr0 is implemented for the gy/classes/
, section, also under the customDir/classes/
.
For modules, psr0 is not implemented, to refer to the module you need to use the fictitious namespace Gy\Modules\<имя модуля>\Classes\<имя класса>
.
Example (a piece of code, from a file gy\modules\filemodule\component\work_page_site\controller.php
):
<?php
use Gy\Modules\filemodule\Classes\SitePages;
$sitePage = new SitePages($APP->urlProject.'/');
PSR-4
PSR-4 - in gy kernel does not use.
Implemented class for PSR-4 (\gy\classes\Psr\Psr4\Psr4AutoloaderClass.php
) which can be used in their projects by a developer using gy. (this has been tested)
Example how to use PSR-4
You need to create a file \customDir\gy\afterGyCore.php
, and add PSR-4 autoloading classes to it, indicating the user section where to get the classes from.
For example (file \customDir\gy\afterGyCore.php
):
<?php if (!defined("GY_CORE") && (GY_CORE !== true)) die( "gy: err include core" );
global $APP;
// connect psr4 autoloading classes
$autoloadPsr4 = new \Psr\Psr4\Psr4AutoloaderClass;
$autoloadPsr4->register();
$autoloadPsr4->addNamespace('Aqw\\', $APP->urlProject.DIRECTORY_SEPARATOR.'testPsr4'.DIRECTORY_SEPARATOR.'Aqw'.DIRECTORY_SEPARATOR);
File \testPsr4\Aqw\Asd\Asd1.php
:
<?php
namespace Aqw\Asd;
class Asd1
{
public function test(){
echo '
'.'12345';
}
}
File \testPsr4.php
, using class:
<? include "./gy/gy.php"; // include core
$asd = new Aqw\Asd\Asd1();
$asd->test();