Part of Firstruner Framework for PHP to allow use Partial function with PHP OOP objects
This project is a part of π οΈ Firstruner Framework for PHP. It contains a little part of the original Framework that allow you to use "partial" DotNet functionality into PHP structure project and also naturally the Framework loader.
To use, it's very simple !
Actually tested on PHP from 7.1.* to 8.3.*
π v1.0 Initial repository
π v1.1 Uses, inheritance and implementations support
π v1.2 Final and Abstract support for classes
π« v2.0 π Features :\
- Interfaces, Enumerations and Trait support
- Conversion Enum files for PHP >= 8.1 to Abstract class files for PHP >= 7.1
- Fix exception on Composer Update (Tested with Symfony and Laravel project)
- Integrate array path for loading and ignored function
- Implement a fluent class for load partial OOP
- Implement log possibilities
- Implement delayed loading possibilities
Create a folder that contains all of your POO Objects (classes, interfaces, enumerations and other).
// The only required dependence for use Loader of Firstruner Framework
require __DIR__ . '/System/Reflection/Dependencies/Loader.php';
// For multiple use of Loader class
use System\Reflection\Dependencies\Loader;
// Load all php POO files in "MyOOP" Folder
Loader::Load(__DIR__ . '/MyOOP');
π° Load function of Loader class can take in 1st argument a single string or an array of string,\
π° The 4th argument is also take a single string or an array of string to ignore some path in the path scanned. Ignored paths must be a physic path like : c:\httpserver\htdocs\myproject\classes\ingoredClasses
π For all other method, go to "All Loader Methods" at the bottom of this documentation π or consult pdf include
This Firstruner Framework contains also a partial loader which is can use in fluent mode.
// The only required dependence for use FluentLoader of Firstruner Framework
require __DIR__ . '/System/Reflection/Dependencies/FluentLoader.php';
// For simplify usage of FluentLoader class
use System\Reflection\Dependencies\FluentLoader;
// Load all php POO files in "MyOOP_Directory/Classes" and "MyOOP" Folders
$fluentLoader = new FluentLoader();
$fluentLoader->SetLogActivation(true)->Load("MyOOP_Directory/Classes")->SetLogActivation(false)->Add_Including_Path(__DIR__ . '/MyOOP')->LoadStoredPaths();
π‘ Pay close attention to the loading order !
π Loading note : it's recommended to load elements in this ordre :
- Enumerations
- Interfaces
- Classes
π File extension note : For standard use, partial file must have "partial_php" extension, but it's possible to use "php" extension if you specify "php_as_partial" attribute to "True" when "Load" method was called. But use "php" are more lazy because it necessary to load the php file before determine if the file is a partial file.
π For better performances, use partial_php extension for your files and DO NOT set php_as_partial argument in Load function as True.
π It recommended if you have a project with multiple target to separate you partial classes of your projects
βοΈ Go in File menu > Preferences > Settings.
In "File editor" section, add "*.partial_php" use like "php" in file association item
\
π‘ To create a php files with partials, create a folder for your OOP object, and create all of your files inside.
To define the file as a partial file, you should reference Partials attributes like this :
use System\Attributes\Partial;
Now define the OOP file as partial with using Partial attribute like this :
#[Partial]
If you need to load OOP file later, you can specify the element with "delayedLoading" at True, like this :\
#[Partial(true)]
Or
#[Partial(delayedLoading: true)]
For load delayed elements, use "LoadStoredPaths" method or specify at True "loadDelayedElements" argument on "Load" method
<?php
namespace System\Printers;
use System\Attributes\Partial;
#[Partial]
class ScreenPrinter
{
public function PrintInstanceMessage()
{
echo "Mon Instance";
}
}
namespace System\Sample;
use System\Attributes\Partial;
use \Exception;
#[Partial]
class Sample extends MainClass
{
}
namespace System\Sample;
use System\Attributes\Partial;
use Symfony\Component\
{
HttpFoundation\Request,
Routing\Annotation\Route
};
#[Partial]
class Sample implements OwnInterface
{
}
namespace System\Sample;
use System\Attributes\Partial;
use \Exception;
#[Partial]
class Sample extends MainClass implements 1stInterface, 2ndInterface
{
}
namespace System\Sample;
use System\Attributes\Partial;
use Symfony\Component\
{
HttpFoundation\Request,
Routing\Annotation\Route
};
#[Partial]
class Sample implements OwnInterface, OtherInterface
{
}
β Load method :\
βΉοΈ Main OOP loading method, it can call directly.
βοΈ included : Specify path(s) who must be load - Can take string or string array - No default value, Required
βοΈ maxTemptatives : Specify the number of loading temptatives - int - default value is 1
βοΈ php_as_partial : Specify if partial class is in php files with php extension - Boolean - default value is False
βοΈ ignored : Specify path(s) who must be ignored during the loading - Can take string or string array - default value is an empty array
βοΈ loadDelayedElements : Specify if the loader load partial class that specified as "delayedLoading" at True - Boolean - default value is Without
OnPost work similar than Without but force loading after non delayed
βοΈ loadDelayedElements : Specify object who the loader must load - Default value is PartialEnumerations_ObjectType::All\
β LoadStoredPaths method :\
βΉοΈ This method try to load OOP paths that specify with Load method or AddIncludePath
βοΈ maxTemptatives : Specify the number of loading temptatives - int - default value is 1
βοΈ php_as_partial : Specify if partial class is in php files with php extension - Boolean - default value is False
βοΈ loadDelayedElements : Specify object who the loader must load - Default value is PartialEnumerations_ObjectType::All\
β LoadDelayedElements method :\
βΉοΈ This method try to load OOP paths that is in delayed mode only
βοΈ php_as_partial : Specify if partial class is in php files with php extension - Boolean - default value is False
βοΈ loadDelayedElements : Specify object who the loader must load - Default value is PartialEnumerations_ObjectType::All\
β AddIncludePath method :\
βΉοΈ This method add OOP paths for Loading. It use before call LoadStoredPaths method
βοΈ paths : Specify path(s) who must be load - Can take string or string array - No default value, Required\
β AddIgnorePath method :\
βΉοΈ This method add OOP paths who must be ignore during Loading. It use before call LoadStoredPaths method
βοΈ paths : Specify path(s) who must be load - Can take string or string array - No default value, Required\
β StandardPHP_LoadDependency method :\
βΉοΈ This method try to load as 'require' a specific php file path
βοΈ paths : Specify path who must be load - String - No default value, Required
π Only available from static class - work also when FluentClass is consume
β SetObjectTypeFilter method :\
βΉοΈ This method defun filter loader
βοΈ objectType : Specify object who the loader must load - Default value is PartialEnumerations_ObjectType::None, Required
π Only available from fluent class
β Clear method :\
βΉοΈ This method clear Loader parameters\
β GetLastDependenciesCount method :\
βΉοΈ This method return dependencies who were well loaded
π Only available from static class - work also when FluentClass is consume
β SetLogActivation method :\
βΉοΈ This method specify if Loader use a log during loading
βοΈ active : Boolean - No default value, Required\
β GetLog method :\
βΉοΈ This method return string array about log events
π Only available from static class - work also when FluentClass is consume
β‘οΈ To solve that, please use partial_php extension for your partial files and use the Firstruner Framework Loader for load these partial files
Solutions :
β‘οΈ Use Firstruner Framework Loader
β‘οΈ Apply partial_php extension on your partial files
β‘οΈ Specify php_as_partial at true on Loader calling