Reputation: 19453
I am developing my own package in Laravel and I am developing a huge number of helper to use with my package so that it can be used this way:
MyPackage::myfunc1();
MyPackage::myfunc2();
MyPackage::myfunc3();
....
The problem is MyPackage class (MyPackage.php) is becoming huge and the code is becoming very long. This bring hard maintainability to the file.
Is there anyway that I can split the class into a few files for easier maintaining? Or, is there any other way to do so?
Thank you.
Upvotes: 0
Views: 66
Reputation: 6720
As per request: File: MyPackage/Helpers/FooUtil.php
<?PHP
namespace MyPackage\Helpers;
class FooUtil
{
}
File: MyPackage/Helpers/BarUtil.php
<?PHP
namespace MyPackage\Helpers;
class BarUtil
{
}
Example how to use namespaces to seperate classes and how to use different classes in the same namespace. For more information read:
I generally advice you to read about PSR-0, which is used in Symfony/Laravel to properly support autoloading, composer and packagist: http://petermoulding.com/php/psr PSR in fact defines how to format namespaces in order to be applicable more globally.
In your example a proper namespacing might be:
Author\MyPackage\Helper\FooClass
Upvotes: 1