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

Daypia Bundle Laravel Package

dayploy/daypia-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require dayploy/daypia-bundle
    

    Register the bundle in config/app.php under providers:

    Dayploy\DaypiaBundle\DaypiaServiceProvider::class,
    
  2. Publish Config Publish the default configuration:

    php artisan vendor:publish --provider="Dayploy\DaypiaBundle\DaypiaServiceProvider" --tag="config"
    

    This generates config/daypia.php. Review and customize as needed.

  3. First Use Case: Basic API Integration Inject the DaypiaClient into a service or controller:

    use Dayploy\DaypiaBundle\Services\DaypiaClient;
    
    class MyController extends Controller
    {
        protected $daypia;
    
        public function __construct(DaypiaClient $daypia)
        {
            $this->daypia = $daypia;
        }
    
        public function fetchData()
        {
            $response = $this->daypia->get('/endpoint');
            return response()->json($response);
        }
    }
    
  4. Environment Configuration Ensure your .env includes:

    DAYPIA_API_KEY=your_api_key_here
    DAYPIA_BASE_URL=https://api.daypia.example
    

Implementation Patterns

Common Workflows

  1. API Requests with Error Handling Use the client for standard HTTP methods with automatic error handling:

    try {
        $data = $this->daypia->post('/resource', [
            'param1' => 'value1',
            'param2' => 'value2'
        ]);
    } catch (\Dayploy\DaypiaBundle\Exceptions\DaypiaException $e) {
        Log::error('Daypia API Error: ' . $e->getMessage());
        return response()->json(['error' => 'Service unavailable'], 503);
    }
    
  2. Authentication Attach authentication tokens dynamically:

    $this->daypia->withAuthToken('custom_token')->get('/secure-endpoint');
    
  3. Middleware Integration Create middleware to inject the client or transform responses:

    namespace App\Http\Middleware;
    
    use Dayploy\DaypiaBundle\Services\DaypiaClient;
    
    class DaypiaMiddleware
    {
        public function __construct(DaypiaClient $daypia)
        {
            $this->daypia = $daypia;
        }
    
        public function handle($request, Closure $next)
        {
            $request->merge(['daypia_data' => $this->daypia->get('/data')]);
            return $next($request);
        }
    }
    
  4. Event Listeners Listen for Daypia-specific events (e.g., daypia.request.sent or daypia.response.received):

    namespace App\Listeners;
    
    use Dayploy\DaypiaBundle\Events\DaypiaResponseEvent;
    
    class LogDaypiaResponse
    {
        public function handle(DaypiaResponseEvent $event)
        {
            Log::info('Daypia Response', ['data' => $event->getData()]);
        }
    }
    
  5. Service Container Binding Extend or bind custom clients:

    $this->app->bind('custom.daypia.client', function ($app) {
        return new \Dayploy\DaypiaBundle\Services\CustomDaypiaClient(
            $app->make('config')['daypia']
        );
    });
    

Integration Tips

  1. Laravel HTTP Client Use Laravel’s HTTP client for advanced features (e.g., retries, middleware):

    $this->daypia->withHttpClient(function (\Illuminate\Http\Client\PendingRequest $request) {
        return $request->withOptions(['timeout' => 30]);
    });
    
  2. Queue Jobs Offload API calls to queues:

    Dispatch(new FetchDaypiaData($this->daypia))->onQueue('daypia');
    
  3. Testing Mock the DaypiaClient in tests:

    $mock = Mockery::mock(DaypiaClient::class);
    $mock->shouldReceive('get')->andReturn(['data' => 'test']);
    $this->app->instance(DaypiaClient::class, $mock);
    
  4. Caching Responses Cache API responses using Laravel’s cache:

    $cachedData = Cache::remember('daypia_resource', now()->addHours(1), function () {
        return $this->daypia->get('/resource');
    });
    

Gotchas and Tips

Pitfalls

  1. Configuration Overrides Avoid overriding config/daypia.php directly in production. Use environment variables or Laravel’s config caching:

    'api_key' => env('DAYPIA_API_KEY', config('daypia.default_api_key')),
    
  2. Rate Limiting Daypia may enforce rate limits. Implement exponential backoff:

    use Symfony\Component\HttpClient\Retry\RetryStrategy;
    
    $this->daypia->withRetryStrategy(
        RetryStrategy::fromConfig([
            'max_retries' => 3,
            'delay' => 1000,
            'multiplier' => 2,
            'max_delay' => 10000,
        ])
    );
    
  3. Deprecated Methods Check for deprecated methods in the package (if any) and update your codebase proactively. Example:

    // Deprecated (if applicable)
    $this->daypia->oldMethod();
    
    // Use instead
    $this->daypia->newMethod();
    
  4. SSL Verification Disable SSL verification only in development (never in production):

    $this->daypia->withOptions(['verify_peer' => false]); // ⚠️ Avoid in prod
    
  5. Event Dispatching Ensure events are properly bound in EventServiceProvider:

    protected $listen = [
        \Dayploy\DaypiaBundle\Events\DaypiaResponseEvent::class => [
            \App\Listeners\LogDaypiaResponse::class,
        ],
    ];
    

Debugging Tips

  1. Enable Debug Mode Toggle debug mode in config:

    'debug' => env('APP_DEBUG', false),
    

    This may log additional request/response details.

  2. Log Raw Responses Use Laravel’s logging to inspect raw responses:

    $response = $this->daypia->get('/endpoint');
    Log::debug('Daypia Raw Response', [
        'status' => $response['status'],
        'data' => $response['data'] ?? null,
        'headers' => $response['headers'] ?? null,
    ]);
    
  3. Check HTTP Status Codes Handle specific status codes explicitly:

    $response = $this->daypia->get('/endpoint');
    if ($response['status'] === 404) {
        abort(404, 'Resource not found on Daypia');
    }
    
  4. Validate API Keys Ensure your API key is correct and hasn’t been revoked:

    try {
        $this->daypia->validateApiKey();
    } catch (\Dayploy\DaypiaBundle\Exceptions\InvalidApiKeyException $e) {
        // Handle invalid key (e.g., notify admin)
    }
    

Extension Points

  1. Custom Request Transformers Extend the client to transform requests/responses:

    namespace App\Services;
    
    use Dayploy\DaypiaBundle\Services\DaypiaClient;
    
    class CustomDaypiaClient extends DaypiaClient
    {
        protected function transformRequest(array $data)
        {
            $data['custom_field'] = 'value';
            return parent::transformRequest($data);
        }
    }
    
  2. Add Middleware Attach middleware to the HTTP client:

    $this->daypia->withMiddleware(function ($handler) {
        return function ($request, $options) use ($handler) {
            // Pre-process request
            $response = $handler($request, $options);
            // Post-process response
            return $response;
        };
    });
    
  3. Create Custom Commands Build Artisan commands for Daypia-specific tasks:

    php artisan make:command FetchDaypiaData
    

    Example:

    namespace App\Console\Commands;
    
    use Dayploy\DaypiaBundle\Services\DaypiaClient;
    use Illuminate\Console\Command;
    
    class FetchDaypiaData extends Command
    {
        protected $signature = 'daypia:fetch {endpoint}';
        protected $description = 'Fetch data from Daypia API';
    
        public function handle(DaypiaClient $daypia)
        {
            $data = $daypia->get($this->argument('endpoint'));
            $this->info($data);
        }
    }
    
  4. Override Default Config Extend the config in config/daypia.php:

    return [
        'defaults' => [
    
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle