almacil/php-core

用于开发Web应用和API的PHP框架。

1.6.0 2023-10-13 08:33 UTC

This package is auto-updated.

Last update: 2024-09-13 10:33:38 UTC


README

GitHub last commit GitHub tag (latest by date) Packagist PHP Version Support GitHub

♥️ Almacil PHP Core

这是一个 简单的MVC框架,用PHP编写,用于快速开发小型项目。


你想贡献吗?
Donate 1€

特性

  • 路由
  • 国际化
  • 数据库
  • 缓存
  • HTTP请求
  • 最小依赖

安装

可以使用Composer进行安装

composer require almacil/php-core

使用

创建 \Almacil\App 的实例

// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';

$rootDir = __DIR__;
$configFile = 'app.config.json';

// Create de instance
$app = new \Almacil\App($rootDir, $configFile);

app.config.json 示例

{
  "display_errors": true,
  "languages": [
    "es_ES",
    "en_GB"
  ],
  "timezone": "Europe/Madrid",

  "spa": {
    "enabled": true
  },
  "cache": {
    "enabled": true,
    "directory": "disk/cache",
    "time": 10
  },
  "database": {
    "enabled": true,
    "directory": "disk/database/",
    "extension": "json"
  },
  "http": { // Developing
    "enabled": true,
    "defaultPrefix": ""
  },
  "translate": {
    "enabled": true,
    "directory": "disk/i18n/",
    "findMissingTranslations": false
  },
  "router": {
    "enabled": true,
    "routesFile": "app.routes.json"
  },

  "environments": {
    "baseFile": "environments/base.json",
    "production": {
      "domain": "id.core.almacil.com",
      "propertiesFile": "environments/production.json"
    },
    "development": {
      "domain": "localhost:8000",
      "propertiesFile": "environments/development.json"
    }
  }
}

display_errors: true | false
当值为 true 时,将显示PHP错误,这对于调试很有用。在生产中建议设置为 false

languages: array
定义一个包含我们应用程序网站有效语言的数组。Almacil Core 会从用户浏览器中获取语言,并在必要时将语言缩写放在URL的第一部分。

timezone: string
定义PHP的时间区域。

spa: object
    enabled: true | false
    此功能允许在不刷新页面的情况下浏览应用程序网站。
    更多信息 请在此处查看

cache: object
    enabled: true | false
    directory: string
    time: number

SPA(单页应用程序)

我们可以使用JavaScript进行以下操作来切换页面

const route = '/contact';
captain.navigate(route);

app.routes.json 示例

{
  "middlewares": [
    "middlewares/variables"
  ],
  "default": {
    "responseType": "html",
    "head": "layout/head",
    "beforeContent": "layout/before-content",
    "afterContent": "layout/after-content",
  },
  "routes": [
    {
      "path": "/contact",
      "component": "pages/contact"
    },
    {
      "path": "/articles",
      "component": "pages/articles",
      "cache": {
        "enabled": false
      },
      "data": {}
    },
    {
      "path": "/articles/{article_id}",
      "component": "pages/article",
      "data": {
          "pageType": "article"
      }
    },
    {
      "path": "/",
      "component": "pages/home",
      "cache": {
        "enabled": true,
        "time": 60, // seconds
      }
    }
  ],
  "notFound": {
    "component": "pages/404"
  }
}


在业余时间编写...



你想贡献吗?
Donate 1€

由开发者为开发者用❤️制作