https://github.com/firstruner/framework_php_partialsclass
Part of Firstruner Framework for PHP to allow use Partial function with PHP class
https://github.com/firstruner/framework_php_partialsclass
attributes class firstruner framework loader partial partials php trait traits
Last synced: 18 days ago
JSON representation
Part of Firstruner Framework for PHP to allow use Partial function with PHP class
- Host: GitHub
- URL: https://github.com/firstruner/framework_php_partialsclass
- Owner: firstruner
- License: other
- Created: 2024-01-15T12:18:41.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-16T12:34:23.000Z (about 1 year ago)
- Last Synced: 2025-04-14T17:36:34.124Z (10 months ago)
- Topics: attributes, class, firstruner, framework, loader, partial, partials, php, trait, traits
- Language: PHP
- Homepage:
- Size: 137 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# đ ī¸ Framework PHP - Partials functions
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 !
## âī¸ PHP version
Actually tested on PHP from 7.1.* to 8.3.*
## Partials versions
\
đ v1.0 Initial repository\
đ v1.1 Uses, inheritance and implementations support\
đ v1.2 Final and Abstract support for classes\
đ v2.0 đ Features :\
1. Interfaces, Enumerations and Trait support
2. Conversion Enum files for PHP >= 8.1 to Abstract class files for PHP >= 7.1
3. Fix exception on Composer Update (Tested with Symfony and Laravel project)
4. Integrate array path for loading and ignored function
5. Implement a fluent class for load partial OOP
6. Implement log possibilities
7. Implement delayed loading possibilities
đĢ v2.1 đ Features :\
1. Loading bugs
2. Allow array of path
3. Auto-manage slash and backslash char for container usages
## đ§ââī¸ Loader (main method)
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
## đ§ââī¸ Load with FluentLoader
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();
## Notes
đĄ Pay close attention to the loading order !
đ Loading note : it's recommended to load elements in this ordre :
1. Enumerations
2. Interfaces
3. 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.
## Performances
đ 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
## IDE integration
### VS Code
âī¸ Go in File menu > Preferences > Settings.\
In "File editor" section, add "*.partial_php" use like "php" in file association item
[](https://postimg.cc/14p2wShT)\
[](https://postimg.cc/wtC4RfWg)\
## How use Partials on OOP object
đĄ To create a php files with partials, create a folder for your OOP object, and create all of your files inside.
### đ¨âđ Define a OOP file as partial
#### Call attributes
To define the file as a partial file, you should reference Partials attributes like this :
use System\Attributes\Partial;
#### Define as partial file
Now define the OOP file as partial with using Partial attribute like this :
#[Partial]
#### Delayed loading
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
#### đ Full main partial sample
âšī¸ 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
## Know exceptions
### During Composer Update
â ī¸ Name is allready in use\
[](https://postimg.cc/MM34cgh4)
âĄī¸ To solve that, please use partial_php extension for your partial files and use the Firstruner Framework Loader for load these partial files
### PHP
â ī¸ Name is allready in use\
[](https://postimg.cc/kBjmRCWC)
Solutions :\
âĄī¸ Use Firstruner Framework Loader\
âĄī¸ Apply partial_php extension on your partial files\
âĄī¸ Specify php_as_partial at true on Loader calling