corepine/support
A small collection of Laravel/PHP support utilities from Corepine, providing reusable helpers and common building blocks to simplify everyday application code and package development.
Installation
composer require corepine/support
composer.json for Laravel compatibility (if version-agnostic, test against your Laravel version).Core Features
src/Support/helpers.php (or equivalent) for static utility methods (e.g., str(), arr(), obj() wrappers).SupportServiceProvider in config/support.php (if provided) for bootstrapped bindings or macros.Support::camel_case($string)), alias it in config/app.php.First Use Case
use Corepine\Support\Facades\Support; // or \Corepine\Support\helpers;
// Example: String manipulation
$snakeCase = Support::snake_case('CamelCaseString');
// Example: Array helpers
$flattened = Support::arr()->flatten($nestedArray);
Replacing Native PHP Functions
strtolower() with Support::str()->lower($string) for consistency.$cleaned = Support::str()
->trim($input)
->slugify()
->value();
Collection/Array Manipulation
$result = Support::arr($array)
->pluck('key')
->filter(fn($val) => $val > 10)
->toArray();
Object Utilities
$data = Support::obj($model)->toArray();
$class = Support::obj()->getClass($object);
Macros/Extensions
Support::extend('str', function ($str) {
return $str->append('!');
});
Integration with Laravel
$this->app->bind('custom.helper', function () {
return new \Corepine\Support\CustomHelper();
});
Support::blade()->directive('camel', function ($expr) {
return "<?php echo \\Corepine\Support\\Str::camel({$expr}); ?>";
});
Testing
$mock = $this->partialMock(Support::class, ['snake_case']);
$mock->shouldReceive('snake_case')->andReturn('test');
Static vs. Instance Methods
Support::str()->lower()) and instance (new Support()->lower()) styles, stick to one to avoid confusion.Laravel Version Conflicts
laravel/framework:^10.0). If undocumented, check for:
Illuminate\Support method overrides (e.g., Str::macro() conflicts).--ignore-platform-reqs may hide issues).Performance Overhead
Support::str()->lower()->upper()) may create intermediate objects.->value() early to release memory:
$result = Support::str($input)->lower()->value(); // Force execution
Namespace Collisions
Support as a facade/class name, ensure it doesn’t clash with:
app/Support/ directories.spatie/laravel-support.Undocumented Features
config/support.php).dd(config('support'));
Method Introspection
get_declared_methods() to list available methods:
$methods = get_declared_methods(\Corepine\Support\Str::class);
print_r($methods);
Error Handling
try {
Support::str()->unknownMethod();
} catch (\BadMethodCallException $e) {
Log::error($e->getMessage());
}
Configuration Quirks
config/support.php, merge defaults:
$config = config('support', [
'default_locale' => 'en_US',
]);
Custom Helpers
app/Helpers/Support.php and autoload:
// composer.json
"autoload": {
"files": ["app/Helpers/Support.php"]
}
// app/Helpers/Support.php
if (!function_exists('custom_helper')) {
function custom_helper($input) {
return \Corepine\Support\Str::of($input)->upper();
}
}
Macro System
\Corepine\Support\Str::macro('customMacro', function ($str) {
return $str . ' [custom]';
});
Event Listeners
Event::listen('support.helper.called', function ($payload) {
Log::info('Helper called:', $payload);
});
Testing Extensions
\Corepine\Support\Str::shouldReceive('snake_case')
->once()
->andReturn('overridden');
How can I help you explore Laravel packages today?