AthenaeumAthenaeum
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
  • Version 5.x

    • Release Notes
    • Upgrade Guide
    • New to this...
    • Origin
  • ACL

    • Introduction
    • How to install
    • Setup
    • Permissions
    • Roles
    • Users
    • Cached Permissions
  • Circuits

    • Circuits
    • How to install
    • Setup
    • Usage
    • Events
  • Collections

    • Collections
    • How to install
    • Summation

      • Summation Collection
      • Items Processor
  • Config

    • Configuration Loader
    • How to install
    • Setup
    • Load Configuration Files
    • Custom File Parsers
  • Console

    • Command and Schedule Registration
    • How to install
    • Setup
    • Commands
    • Schedules
  • Container

    • IoC Service Container
    • How to install
    • Container
    • List Resolver
  • Core

    • Athenaeum Core Application
    • Prerequisite
    • How to install
    • Integration
    • Usage

      • Configuration
      • Service Providers
      • Service Container
      • Events
      • Caching
      • Logging
      • Console
      • Task Scheduling
      • Exception Handling
      • Extending Core Application
      • Testing
  • Database

    • Introduction
    • How to install
    • Models

      • Instantiatable
      • Sluggable
    • Query

      • Criteria (Query Filter)
  • Dto

    • Data Transfer Object (DTO)
    • How to install
    • Create Interface
    • Implement DTO
    • How to use
    • Populate
    • Export
    • Json
    • Serialization
    • Nested DTOs
    • Array DTO
  • Events

    • Register Listeners and Subscribers
    • How to install
    • Setup
    • Listeners
    • Subscribers
  • Filters

    • Search Filter Utilities
    • Prerequisites
    • How to install
    • Setup
    • Processor
    • Filters Builder
    • Predefined Resources

      • Search Processor
      • Sorting Processor
      • Constraints Processor
      • Matching Processor
    • Tip: Create a base builder
  • Http

    • Clients

      • Http Clients
      • How to install
      • Setup
      • Basic Usage
      • Available Methods

        • Fluent Api
        • Protocol Version
        • Base Uri
        • Http Method and Uri
        • Headers
        • Accept & Content-Type
        • Authentication
        • Http Query
        • Payload Format
        • Payload
        • Attachments
        • Cookies
        • Response Expectations
        • Middleware
        • Conditions
        • Criteria
        • Redirects
        • Timeout
        • Debugging
        • Logging
        • Driver Options
        • Driver
      • Http Query Builder

        • Introduction
        • Select
        • Where
        • Dates
        • Include
        • Pagination
        • Sorting
        • Raw Expressions
        • Custom Grammar
    • Cookies

      • Http Cookies
      • How to install
      • Usage
    • Messages

      • Http Messages
      • How to install
      • Serializers
  • Properties

    • Properties Overload
    • How to install
    • Usage
    • Naming Convention
    • Properties Visibility
  • Redmine

    • Redmine Api Client
    • How to install
    • Setup
    • General Usage

      • Supported Operations
      • Fetch list of resources
      • Find
      • Fetch
      • Create new record
      • Update existing record
      • Delete existing record
      • Relations
    • Available Resources

      • Predefined Resources
      • Attachments
      • Enumerations
      • Issue Relations
      • Users
      • User Groups
      • Roles
      • Project Memberships
      • Versions (Milestones)
      • Issue Categories
      • Trackers
  • Service

    • Service Registrar
    • How to install
    • How to use
  • Support

    • Introduction
    • How to install
    • Laravel Aware-of Helpers

      • How to use
      • Enforce Via Interface
      • Custom Default
      • Pros and Cons
      • Available Helpers
    • Aware-of Properties

      • Generator
      • Available Aware-of Helpers
    • Live Templates
  • Testing

    • Introduction
    • How to install
    • Test Cases
    • Testing Aware-of Helpers
  • Utils

    • Introduction
    • How to install
    • Array
    • Duration
    • Json
    • Math
    • Method Helper
    • Populatable
    • Version
  • Validation

    • Introduction
    • How to install
    • Setup
    • Rules

      • Alpha-Dash-Dot
You are viewing documentation for an outdated version. It is no longer supported!

Extending Core Application

Every application serves a different purpose. If would not be too surprising, if the Athenaeum Core Application wouldn't be able to satisfy your evey need, when attempting to integrate it with your legacy application. Perhaps, you could extend the Core Application, to overcome your challenges. In this chapter, a few important concepts are briefly introduced, in hopes that it may help, when considering extending the Core Application.

  • Core Service Providers
  • Core Bootstrappers
    • Create Custom Bootstrapper
    • Overwrite Core Bootstrappers
  • Application is a Service Container

Core Service Providers

As soon as you instantiate a new Application instance, it's core service providers are registered - but NOT booted! Some of these service providers are very essential and the application might not work as expected, without them. Should you wish to adapt the list of core service providers, overwrite the getCoreServiceProviders() method.

// In your extended Athenaeum Core Application
public function getCoreServiceProviders(): array
{
    return [
        CoreServiceProvider::class,
        ExceptionHandlerServiceProvider::class,
        NativeFilesystemServiceProvider::class,
        EventServiceProvider::class,
        ListenersViaConfigServiceProvider::class,
        ConfigServiceProvider::class,
        ConfigLoaderServiceProvider::class,

        // ... etc
    ];
} 

Core Bootstrappers

In this context, a bootstrapper is a component that is able to perform some kind of "initial startup" logic. It is what sets the entire application in motion. Bootstrappers are processed when you invoke the bootstrapWith() method (automatically invoked by the run() method). Furthermore, they are processed after the core service providers have registered.

$app->run(); // All bootstrappers are processed...

Create Custom Bootstrapper

To create your own custom bootstrapper, you need to implement the CanBeBootstrapped interface. The following examples shows a very simple bootstrapper, which is used to set the default timezone.

<?php

namespace Aedart\Core\Bootstrappers;

use Aedart\Contracts\Core\Application;
use Aedart\Contracts\Core\Helpers\CanBeBootstrapped;
use Aedart\Support\Helpers\Config\ConfigTrait;

class SetDefaultTimezone implements CanBeBootstrapped
{
    use ConfigTrait;

    public function bootstrap(Application $application): void
    {
        date_default_timezone_set($this->getConfig()->get('app.timezone', 'UTC'));
    }
}

Overwrite Core Bootstrappers

To use your custom bootstrappers, you need to overwrite the getCoreBootstrappers() method. Similar to the getCoreServiceProviders() method, this method returns an order list of class paths to the application's bootstrappers.

public function getCoreBootstrappers(): array
{
    return [
        DetectAndLoadEnvironment::class,
        LoadConfiguration::class,
        SetDefaultTimezone::class,
        SetExceptionHandling::class,

        // ... etc
    ];
}

Application is a Service Container

Just like Laravel's Foundation Application, the Athenaeum Core Application extends the Service Container. This means that, you can gain access to services and components. But not before those service have been registered!

// Somewhere inside your extended Core Application
$config = $this->make('config'); // Might fail, if Config Service hasn't registered!

It is advisable that you keep your logic simple. If possible, try to encapsulate your needs into either service providers or bootstrappers. Otherwise you potentially risk of addition too much complexity, inside the actual application.

Edit page
Last Updated: 05/04/2022, 21:01
Contributors: Alin Eugen Deac
Prev
Exception Handling
Next
Testing