aufa/enproject

Enproject 简易 PHP 框架库

dev-master 2016-06-03 08:59 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:58:59 UTC


README

[ALPHA 开发] Enproject 简易 PHP 框架库 - 仅用于我的项目 这里有一些错误 ... 但我在本地存储中已经完成了一些,没有时间定期更新此脚本 使用 Enproject 简易框架轻松创建应用程序。

基于 MWYS (Models Whatever You Say)

对于像 Hook 这样的类,使用 WordPress 插件方法,还有一些方法使用了其他库,并受到 CMS / PHP 框架的启发。使用内置的模板引用助手,默认模板目录基于

{root_directory}/templates

扫描子模板目录容器。

/**
 * Run Instance Easily Create Default View
 * will be render templates/Default/default.php
 * or on template directory
 */
\Aufa\Enproject\Enproject::Run();

致敬

添加路由

添加路由就像 Code Igniter 一样,但效率更高,您还可以通过位置确定默认返回值,也可以确定您设置了方法。

/**
 * Set Route To any
 * - main as position of route, `main` means Route Group that will be execute as main priority
 *      if you set and empty value will be use as default route and execute second.
 * - '/' mean the regex as accessing URL Route access as '/' or empty url
 *      The regex like CI(Code Igniter use) :any as [^/]+ and :num as [0-9]+
 * by default returning  of callback use 3 arguments
 *  1. \Aufa\Enproject\Enproject::Singleton() // as main application
 *  2. \Aufa\Enproject\Response::Singleton() // as response application
 *  3. \Aufa\Enproject\Route::getCurrent() // as current route
 *
 * @return object \Aufa\Enproject\Route Singleton
 */
\Aufa\Enproject\Route('main', '/', function ($a, $b, $c) {
    // doing some thing here   
})
// as request by any Request method
->all()
// set default value
->defaultValue(
    'a' => null, // @param $a as null default
    'b' => true, // @param $b as boolean true default
    'c' => new stdClass() // @param $c as object stdClass
)
// protecting route being overide
->protect();

// and more ...

默认配置

Enproject 的配置使用

/**
 * Set Config
 */
\Aufa\Enproject\Config::set('config name', ([mixed] value));

/**
 * If want to protect last config just set
 * protecting config prevent configuration being overide
 */
\Aufa\Enproject\Config::protect();

// or use
\Aufa\Enproject\Config::set('config name', ([mixed] value))->protect();
/**
 * Or protecting configs using value
 */
\Aufa\Enproject\Config::protect('keyname_config');

// or use array as keyname multiple protect
\Aufa\Enproject\Config::protect(['keyname_config', 'keyname_config_1', 'keyname_config_2']);
  • uri_sufix (字符串) 默认空字符串

  • templates_directory (字符串) 默认 templates 从网站的根目录获取

  • debug (布尔值) 如果渲染调试信息则为 true(即使有通知)

  • security_salt (字符串) 用于加密和 cookie 加密的随机字符串,默认空字符串

  • security_key (字符串) 用于加密 cookie 的随机字符串,默认空字符串

  • session_hash (字符串) 用于加密会话 cookie 的随机字符串,默认空字符串

  • cookie_lifetime (整数) Cookie 生命周期默认 null

  • cookie_domain (字符串) 作为 cookie 域的域名默认 null

  • cookie_secure (布尔值) 如果仅允许安全连接则为 true,默认 false

  • cookie_httponly (布尔值) 如果使用 http-only 则为 true,默认 false

  • safe_output (布尔值) 如果使用多字节字符串的实体则为 true,默认 false

  • force_tag (布尔值) 如果使用强制平衡的 HTML 输出标签则为 true,默认 false

  • http_version (字符串) HTTP 版本默认 1.1

  • show_error_count (整数) 如果存在最大错误数将显示(仅在调试模式下受影响),默认 3 和最大 30。设置为空值(0/false/null/''/'0'),则不显示错误。或将设置为 -1 以显示 30 个错误。

核心钩子

使用 WordPress 钩子模型的 Hook 类,您可以使用的方法类似于 WordPress 使用

Enproject 上的钩子使用

Hook::Apply('fn_name', 'return1', 'arg1', etc...);

类似于 WordPress 使用

apply_filters('fn_name', 'return1', 'arg1', etc...);
  • x_before_route (void) 在执行路由之前调用钩子

  • x_after_route (void) 在路由运行后调用钩子

  • x_headers (数组) 列出头信息(必须在非致命错误中)

  • x_header_status (整数) HTTP 状态码头信息(必须在非致命错误中)

  • x_before_output (字符串) 在输出渲染之前调用此钩子,这将结果作为输出内容

  • x_force_tag_output (字符串) 在输出渲染之前调用此钩子,这将结果作为 body 内容强制平衡标签的结果(必须在非致命错误中)

  • x_safe_output (字符串) 在输出渲染之前调用此钩子,这将结果作为 body 内容实体结果(必须在非致命错误中)

  • x_error_output (字符串) 在输出渲染之前调用此钩子,这将结果作为返回错误输出的 body 内容(如果出错)

  • x_after_output (字符串) 在输出渲染之后调用此钩子,这将结果作为返回输出的 body 内容

  • x_after_all(字符串)所有处理完成后

基准短码

* %[benchmark]%      as benchmark total time application execute
* %[memory]%         as benchmark total memory application use
* %[real_memory]%    as benchmark total real memory application use

为了避免被替换,使用转义符\,例如

%[\benchmark\]% 将变为 %[benchmark]%

%[\\benchmark\\]% 将变为 %[\benchmark\]%

一些功能

  • 简单添加和获取应用对象到单例
    /**
     * Set Application
     */
    \Aufa\Enproject\Enproject::set('applicationName', new ObjectClass());
    /**
     * Then call
     */
    \Aufa\Enproject\Enproject::get('applicationName');
    /**
     * Or if you have variable to set application
     */
    $application = \Aufa\Enproject\Enproject::Singleton(); // call instance
    /**
     * Call your set application
     */
    $yourapp = $application->applicationName;
  • 设置后可以轻松保护它
    /**
     * Set Application and protect it, to prevent application being override
     * nb:
     * if application has exists and protected , user warning has been logged.
     * and if you have set debug to true it will be insert on your html
     */
    \Aufa\Enproject\Enproject::set('applicationName', new ObjectClass())->protect();
  • 轻松调用Enproject核心
    /**
     * Example call Helper
     */
    $application = \Aufa\Enproject\Enproject::Singleton(); // call instance
    $helper = $application->helper; // get object Helper
    /**
     * Or example if want call string helper
     */
    $string_helper = $application->helper->string;
    /**
     * Or wanna call Request Class
     */
    $request = $application->request;
    /**
     * Or calling class using another method?
     * just like :
     * $application->helper->string
     */
    $string_helper = $application->helper_string;
    // or
    $string_helper = $application->get("Helper\\StringHelper");
    // or
    $string_helper = $application->get("Helper_String");
  • 模板类已准备好,通过调用 \Aufa\Enproject\Helper\Template::init(),确保在调用init之前已经设置了模板配置参数。请参阅 src/Enproject/Helper/Template.php。文档在文件中(请参阅类的属性部分)。

  • PasswordHash 由openwall提供,具有自定义结构,返回值保持不变且不作为单例包含。因此,如果想要将其用作核心应用,只需将其添加到应用中。

要求

  • PHP 5.3.2x或更高版本