celarius/spin-framework

一个超级轻量级的PHP UI/REST框架

dev-master 2024-06-29 11:08 UTC

This package is auto-updated.

Last update: 2024-09-29 11:40:10 UTC


README

Latest Stable Version Total Downloads License PHP8 Ready

SPIN - 一个超级轻量级的PHP UI/REST框架

Latest Unstable Version Build Status

SPIN是一个用于快速有效地使用PHP制作Web UI和REST API的应用程序框架。它大多数使用PSR标准,并允许插入几乎任何PSR兼容组件,如日志记录器、HTTP库等。

    NOTE: This framework is in RC stage - Please contribute to make it complete

1. 功能

  • PHP 8+
  • 平台无关。(Windows, *nix)
  • 路由引擎,带有路由组
  • 中间件
  • 容器
  • 通过Composer在包/扩展中驱动
  • 基于PDO的数据库连接(MySql,PostgreSql,Oracle,CockroachDb,Firebird,Sqlite ...)
  • DAO基类用于数据库实体表示
  • 可与其他框架扩展(ORM、模板等)

1.1. 基于PSR的集成

  • Logger(PSR-3)默认为Monolog
  • HTTP Message(PSR-7)。默认为Guzzle
  • Container(PSR-11)。默认为The League Container
  • SimpleCache(PSR-16)。默认为APCu SimpleCache
  • HTTP Factories(PSR-17)

2. 安装

使用Composer单独安装spin-framework

composer require celarius/spin-framework

2.1. 使用spin-skeleton

要安装和使用spin-framework,强烈建议首先克隆spin-skeleton,然后在文件夹中运行composer update -o。这将下载所有必要的包,并创建一个模板骨架项目,包含示例配置、路由、控制器和其他许多内容。

2.2. 测试

如果已安装PHPUnit,只需在命令提示符中输入

phpunit

所有测试都将执行。

3. 技术细节

3.1. Apache虚拟主机配置

为使用Apache运行应用程序并在Apache下识别域名而设置的虚拟主机。

如果需要基于端口号的应用程序,则需要将<VirtualHost:80>更改为相应的端口,并从配置中删除domain.name

<VirtualHost *:80>

    Define domain.name              mydomain.com
    Define alias.domain.name        www.mydomain.com
    Define path_to_root             C:/Path/Project
    Define environment              DEV

    ServerName ${domain.name}
    ServerAlias ${alias.domain.name}
    ServerAdmin webmaster@${domain.name}

    DocumentRoot "${path_to_root}\src\public"

    ErrorLog "logs/${domain.name}.error.log"
    CustomLog "logs/${domain.name}.access.log" common

    # Default caching headers for static content in /public
    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
      Header set Cache-Control "public, max-age=604800, must-revalidate"
    </FilesMatch>

    <Directory "${path_to_root}\src\public">
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted

        # Set Variables
        SetEnv ENVIRONMENT ${environment}

        # Load files in this order on "/"
        DirectoryIndex bootstrap.php index.php index.html

        # Disable appending a "/" and 301 redirection when a directory
        # matches the requested URL
        DirectorySlash Off

        # Set Rewrite Engine ON to direct all requests to
        # the `bootstrap.php` file
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ bootstrap.php [QSA,L]
    </Directory>
</VirtualHost>