承接 tigron/skeleton-core 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tigron/skeleton-core

Composer 安装命令:

composer require tigron/skeleton-core

包简介

Core functionality for Skeleton

README 文档

README

Description

This library contains the core functionality of the skeleton framework. It performs these main tasks:

  • Autoloading
  • Config management
  • Application detection
  • HTTP toolkit

Installation

Installation via composer:

composer require tigron/skeleton-core

After installation you can start a skeleton project.

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.

Autoloading can be configured like this:

	/**
	 * 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:

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.

Include a config directory

\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.

Get a config object

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

Skeleton needs at least these config items to operate properly:

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:

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.

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.

Applications are identified in the $application_path and should respect at least the following directory structure:

- {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:

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:

  • 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.

To run the HTTP handler:

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

It will then pass the request over to the application. The application will be set via:

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

In the lifespan of the request, the application can always be retrieved via:

\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:

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

The asset will be searched for in the following order:

  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.

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.

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:

  • 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.

Example of a Module event class for an application named admin:

<?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.

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.

public function bootstrap(): bool
teardown

The teardown method is called after the application's run is over.

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.

This event should return true in order to proceed with this application.

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

Error context

This context is only available if skeleton-error is installed.

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

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)

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.

public function not_found(): void

tigron/skeleton-core 适用场景与选型建议

tigron/skeleton-core 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.42k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tigron/skeleton-core 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tigron/skeleton-core 我们能提供哪些服务?
定制开发 / 二次开发

基于 tigron/skeleton-core 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 20.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 11
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-14