PHP code example of kanekescom / laravel-helperia

1. Go to this page and download the library: Download kanekescom/laravel-helperia library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kanekescom / laravel-helperia example snippets


// Get all public methods (excluding constructor, destructor, internal)
method_public(MyClass::class); // Collection of method names

// Get all protected methods
method_protected(MyClass::class);

// Get all private methods
method_private(MyClass::class);

// Get all methods (public, protected, private)
method_all(MyClass::class);

// Also works with object instances
$obj = new MyClass();
method_public($obj); // Same result as using class name

// Convert date from one format to another
convert_date_format('01-01-2024', 'd-m-Y', 'Y-m-d'); // "2024-01-01"
convert_date_format('01-01-2024 10:30:00', 'd-m-Y H:i:s', 'Y-m-d H:i:s');

// Parse date string to specified format
parse_date_format('2024-01-01', 'd M Y'); // "01 Jan 2024"
parse_date_format('2024-01-01 10:30:00', 'd M Y H:i:s');

// With default value for invalid/null input
convert_date_format(null, 'd-m-Y', 'Y-m-d', 'N/A'); // "N/A"
convert_date_format('invalid-date', 'd-m-Y', 'Y-m-d', 'fallback'); // "fallback"
parse_date_format('not-a-date', 'Y-m-d', 'default'); // "default"

use Kanekescom\Helperia\Support\ClassExtender;

class MyWrapper extends ClassExtender
{
    public function __construct()
    {
        $this->class = new SomeOtherClass();
    }
}

$wrapper = new MyWrapper();
$wrapper->someMethod(); // Calls SomeOtherClass::someMethod()

use Kanekescom\Helperia\Traits\HasMethodCaller;

class MyClass
{
    use HasMethodCaller;

    protected $class;

    public function __construct($wrappedClass)
    {
        $this->class = $wrappedClass;
    }
}

// Usage
$wrapper = new MyClass(new SomeService());
$wrapper->serviceMethod(); // Forwards to SomeService::serviceMethod()

// Static method calls are also supported
MyClass::staticMethod(); // Forwards static calls