Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Core Laravel Package

cakephp/core

Core framework utilities for CakePHP: shared classes for configuration, routing, events, cache/logging, error handling, and common helpers used across CakePHP applications and plugins. Provides the foundational building blocks that other CakePHP packages depend on.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to Begin

  1. Installation Add the package via Composer (though note this is a read-only split of CakePHP core; use cakephp/cakephp for full functionality):

    composer require cakephp/core
    

    For Laravel integration, focus on standalone utilities (e.g., Collection, Utility, I18n) rather than full framework features.

  2. First Use Case: Collections Leverage CakePHP’s Collection for array manipulation (similar to Laravel’s Collection but with additional methods):

    use Cake\Collection\Collection;
    use Cake\Collection\CollectionObject;
    
    $data = [['id' => 1, 'name' => 'Alice'], ['id' => 2, 'name' => 'Bob']];
    $collection = new Collection(new CollectionObject($data));
    
    // Filter and map like Laravel's Collection
    $names = $collection->filter(fn($item) => $item['id'] > 1)
                        ->pluck('name')
                        ->toArray();
    
  3. Key Entry Points

    • Cake\Utility\Inflector: For string manipulation (e.g., pluralization, slugs).
      use Cake\Utility\Inflector;
      echo Inflector::slug('Hello World'); // "hello-world"
      
    • Cake\I18n\I18n: For localization (if integrating with Laravel’s translator).
    • Cake\ORM\TableRegistry: Not recommended for Laravel (use Eloquent). Focus on utility classes.

Implementation Patterns

1. Utility-First Workflows

  • String/Date Handling Replace Laravel’s Str:: or Carbon with CakePHP’s utilities where needed:
    use Cake\Utility\Text;
    use Cake\I18n\Time;
    
    // Truncate text
    Text::truncate('Long string', 10); // "Long strin..."
    
    // Parse dates
    Time::parse('2023-12-31'); // Carbon-like object
    
  • Data Transformation Use Cake\Collection for complex array operations in service layers:
    $users = $collection->combine('id', 'name')->toArray();
    

2. Integration with Laravel

  • Service Providers Register CakePHP utilities as Laravel bindings in AppServiceProvider:

    public function register()
    {
        $this->app->singleton('cake.inflector', fn() => new \Cake\Utility\Inflector());
    }
    

    Access via:

    app('cake.inflector')->slug('Test');
    
  • Middleware/Helpers Create a helper trait for reusable CakePHP logic:

    trait CakeHelpers
    {
        public function cakeSlug(string $string): string
        {
            return app('cake.inflector')->slug($string);
        }
    }
    

3. ORM Alternatives

  • Avoid TableRegistry: Use Eloquent or Laravel’s query builder.
  • For DTOs/Value Objects: Use CakePHP’s Cake\Utility\Hash for nested data extraction:
    use Cake\Utility\Hash;
    $value = Hash::get($array, 'user.profile.name');
    

Gotchas and Tips

Pitfalls

  1. Framework Lock-In

    • This package is not a drop-in replacement for CakePHP. Avoid using ORM, routing, or MVC components.
    • Example: TableRegistry::get('Users') will fail in Laravel.
  2. Namespace Collisions

    • CakePHP uses Cake\ namespace; ensure no conflicts with Laravel’s Cake\ (unlikely, but check autoloading).
  3. Performance Overhead

    • CakePHP’s Collection is optimized for CakePHP’s ORM. For large datasets, prefer Laravel’s Collection or raw PHP arrays.

Debugging

  • Method Not Found? Verify the class exists in vendor/cakephp/core/src/. Example:

    // Works:
    use Cake\Utility\Inflector;
    // Fails (not in this package):
    use Cake\ORM\Table;
    
  • Localization Issues CakePHP’s I18n expects a different config structure than Laravel’s. Use a wrapper:

    $translator = new \Cake\I18n\Translator([
        'defaultLocale' => 'en_US',
        'locale' => 'es_ES',
        'sourceLocale' => 'en_US',
    ]);
    

Extension Points

  1. Custom Collection Macros Extend Cake\Collection\Collection with Laravel’s macro system:

    \Cake\Collection\Collection::macro('customMethod', function () {
        return $this->filter(...);
    });
    
  2. Inflector Rules Add custom pluralization rules:

    \Cake\Utility\Inflector::rules('custom', [
        'plural' => ['ox' => 'oxen'],
    ]);
    
  3. Time Zone Handling Configure CakePHP’s Time class to use Laravel’s timezone:

    \Cake\I18n\Time::setDefaultTimeZone(config('app.timezone'));
    

Pro Tips

  • Hybrid Projects: Use CakePHP’s utilities in Laravel’s console commands or artisan commands for string/date logic.
  • Testing: Mock CakePHP classes in PHPUnit:
    $this->partialMock(\Cake\Utility\Inflector::class, [], [], '', false);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor