2017 © Pedro Peláez
 

library skeleton-core

Core functionality for Skeleton

image

tigron/skeleton-core

Core functionality for Skeleton

  • Tuesday, July 17, 2018
  • by tigron
  • Repository
  • 2 Watchers
  • 0 Stars
  • 4,294 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 23 Versions
  • 8 % Grown

The README.md

skeleton-core

Description

This library contains the core functionality of the skeleton framework. It performs these main tasks:, (*1)

  • Autoloading
  • Config management
  • Application detection
  • HTTP toolkit

Installation

Installation via composer:, (*2)

composer require tigron/skeleton-core

After installation you can start a skeleton project., (*3)

Features

Autoloading

Skeleton doesn't enforce you to use a specific file structure. This means that skeleton can adapt itself to your structure. In order to do so, you need to configure the skeleton autoloader., (*4)

Autoloading can be configured like this:, (*5)

    /**
     * Register the autoloader
     */
    $autoloader = new \Skeleton\Core\Autoloader();
    $autoloader->add_include_path($root_path . '/lib/model/');
    $autoloader->add_include_path($root_path . '/lib/base/');
    $autoloader->add_include_path($root_path . '/lib/component/');
    $autoloader->add_include_path($root_path . '/tests');
    $autoloader->register();

Skeleton autoloader will include the given include paths in its search for the requested class. An optional parameter 'class_prefix' can be given. This will prepend all classes for a given path with the given prefix:, (*6)

Config management

Skeleton core offers a Config object that is populated from a given config directory. The Config object automatically includes all php files which are stored in the config directory. Each php file should return a php array. Each key/value pair will be available in your project., (*7)

Include a config directory, (*8)

\Skeleton\Core\Config::include_path('/config');

PHP files stored in the config directory will be evaluated in alphabetical order. In case you have environment-specific configuration, you can create a file environment.php in your config directory which will be evaluated last., (*9)

Get a config object, (*10)

$config = \Skeleton\Core\Config::get();

Skeleton needs at least these config items to operate properly:, (*11)

Configuration Description Default value Example values
application_path Sets the directory where skeleton-core can find Applications 'app/'
asset_paths An array containing optional paths to search for assets [] [ 'lib/external/assets' ]

Application detection

The package will automatically detect "applications", which are separate parts of your project. The following application types are available:, (*12)

Based on the Host-header in the request, the correct application will be started. This is where the hostnames array in the application's configuration file (shown above) will come into play., (*13)

If skeleton-core could find a matching application based on the Host-header. It is the responsibility of the application to finish the HTTP request., (*14)

Applications are identified in the $application_path and should respect at least the following directory structure:, (*15)

- {application_path}
  - {APP_NAME}
    - config
    - event

The application config directory should contain the application-specific configuration files. The following configuration directives should at least be set: , (*16)

Configuration Description Default value Example values
application_type (optional)Sets the application to the required type \Skeleton\Application\Web
hostnames (required)an array containing the hostnames to listen for. Wildcards can be used via *. [] [ 'www.example.be, '*.example.be' ]
session_name The name given to your session 'App' any string
sticky_session_name The key in your session where sticky session information is stored 'sys_sticky_session' any string

HTTP toolkit

Altough skeleton can be used for a console application, it has an HTTP toolkit available. It can:, (*17)

  • accept an HTTP request and pass it to the correct application
  • serve media files
  • session management

HTTP handler

The HTTP handler will accept an incoming HTTP request and searches for the correct application based on the HTTP host header., (*18)

To run the HTTP handler:, (*19)

\Skeleton\Core\Http\Handler::Run();

It will then pass the request over to the application. The application will be set via:, (*20)

\Skeleton\Core\Application::set();

In the lifespan of the request, the application can always be retrieved via:, (*21)

\Skeleton\Core\Application::get();

Serve media

Media serving is only done for known filetypes. The known filetypes are: css, map, pdf, txt, woff, woff2, ttf, otf, eot, gif, jpg, jpeg, png, ico, svg, js, html, htm, mp4, mkv Any other file extensions will be ignored. Media serving can be requested via:, (*22)

\Skeleton\Core\Http\Media::detect($request_uri);

The asset will be searched for in the following order:, (*23)

  1. The media directory of the current Application
  2. The configured asset_paths
  3. The media directory of other skeleton packages

Events

Events can be created to perform a task at specific key points during the application's execution., (*24)

Events are defined in Event context classes. These classes are optional, but when they are used, they should be located in the event directory of your application. The filename should be in the form of Context_name.php, for example Application.php., (*25)

The class should extend from Skeleton\Core\Application\Event\{Context} and the classname should be within the namespace \App\APP_NAME\Event\{Context}, where APP_NAME is the name of your application, and Context is one of the available contexts:, (*26)

  • Application
  • Error
  • Media

Depending on the type of Application you are running, additional events could be available. Please read the application-type Readme for more information., (*27)

Example of a Module event class for an application named admin:, (*28)

<?php
/**
 * Module events for the "admin" application
 */

namespace App\Admin\Event;

class Module extends \Skeleton\Core\Application\Event\Module {

    /**
     * Access denied
     *
     * @access public
     */
    public function access_denied() {
        \Skeleton\Core\Web\Session::redirect('/reset');
    }

}

The different contexts and their events are described below., (*29)

Application context

bootstrap

The bootstrap method is called before loading the application. The event should return a boolean to indicate if skeleton should proceed running the application. If false is returned, the application stops execution and triggers the teardown() event., (*30)

public function bootstrap(): bool
teardown

The teardown method is called after the application's run is over., (*31)

public function teardown(): void
detect

The detect method is called on every request to determine if the application should handle the request, or if it should be skipped based on, for example, the requested hostname and the request's URI., (*32)

This event should return true in order to proceed with this application., (*33)

public function detect($hostname, $request_uri): bool

Error context

This context is only available if skeleton-error is installed., (*34)

exception

The exception method is called on every exeption/error. The method should return a boolean, indicating if skeleton-error should proceed to other error handlers, (*35)

public function exception(\Throwable $exception): bool
sentry_before_send

The sentry_before_send method can be used to enrich the data that will be sent to Sentry with application-specific data (ex the user that logged in), (*36)

public function sentry_before_send(\Sentry\Event $event)

Media context

not_found

The not_found method is called whenever a media file is requested which could not be found., (*37)

public function not_found(): void

The Versions

17/07 2018

dev-master

9999999-dev

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

17/07 2018

v0.1.16

0.1.16.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

10/07 2018

v0.1.15

0.1.15.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

16/03 2018

v0.1.14

0.1.14.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

04/12 2017

v0.1.13

0.1.13.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

30/08 2017

v0.1.12

0.1.12.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

21/03 2017

0.1.11

0.1.11.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

24/01 2017

v0.1.10

0.1.10.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

19/12 2016

v0.1.9

0.1.9.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

19/12 2016

v0.1.8

0.1.8.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

19/12 2016

v0.1.7

0.1.7.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

01/12 2016

v0.1.6

0.1.6.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

30/11 2016

v0.1.5

0.1.5.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

16/11 2016

v0.1.4

0.1.4.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

25/10 2016

v0.1.2

0.1.2.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

25/10 2016

0.1.3

0.1.3.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

18/10 2016

v0.1.1

0.1.1.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

05/07 2016

v0.1.0

0.1.0.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

15/02 2016

v0.0.5

0.0.5.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

28/01 2016

v0.0.4

0.0.4.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

26/11 2015

v0.0.3

0.0.3.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

16/10 2015

v0.0.2

0.0.2.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA

18/08 2015

v0.0.1

0.0.1.0

Core functionality for Skeleton

  Sources   Download

MIT

by Tigron BVBA