示例#1
0
文件: extra.php 项目: vincenttone/daf
<?php

require_once Da\Sys_App::lib_path('class_hooks.trait.php');
class_alias('Module_Translate_Main', 'MT');
示例#2
0
#!/usr/bin/env php
<?php 
require_once dirname(dirname(__FILE__)) . '/init_env.php';
require_once Da\Sys_App::lib_path("CNsHead.class.php");
$opt = getopt('h::p::', ['2json', '2sp']);
$host = isset($opt['h']) ? $opt['h'] : '0.0.0.0';
$port = isset($opt['p']) ? $opt['p'] : '8765';
$socket = stream_socket_server("tcp://{$host}:{$port}", $errno, $errstr);
echo 'Listening at port: ' . $port . PHP_EOL;
if (!$socket) {
    echo "{$errstr} ({$errno})\n";
} else {
    while ($conn = stream_socket_accept($socket, 86400)) {
        $ns = new NsHead();
        $data = $ns->nshead_read($conn);
        $result = mc_pack_pack2array($data['buf']);
        isset($opt['2json']) ? print json_encode($result) : (isset($opt['2sp']) ? print serialize($result) : print_r($result));
        echo PHP_EOL;
        $data = ['errno' => 0, 'data' => 'ok'];
        $body = mc_pack_array2pack($data);
        $hdr = array('body_len' => strlen($body));
        $ns->nshead_write($conn, $hdr, $body);
    }
}
示例#3
0
文件: main.php 项目: vincenttone/daf
 /**
  * @param int $ap_id
  * @param int $mode
  * @param array $options
  * @param string $php_script
  * @return array
  */
 static function exec_task($ap_id, $mode = Module_FlowManager_Main::RUN_MODE_CALLBACK, $options = ['meta' => true], $php_script = 'tools/access_point.php')
 {
     if (empty($ap_id)) {
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_ID_NOT_SET, '没有获取到接入点ID');
     }
     if (php_sapi_name() != 'cli') {
         Lib_Log::info("Run task, user [%s], Ap id:[%d]", [Module_Account_User::get_current_user(), $ap_id]);
     }
     if (Da\Sys_App::run_mode() == DA_RUN_MODE_PRO && $mode == Module_FlowManager_Main::RUN_MODE_CALLBACK && !isset($options['without_ct'])) {
         return Module_ScheduledTask_Main::run_ap_task($ap_id);
     } else {
         self::exec_task_by_cli($ap_id, $mode, $options, $php_script);
     }
     return Lib_Helper::get_return_struct(['msg' => '运行成功']);
 }
示例#4
0
 /**
  * @param string $module_indent
  * @return bool|mixed|string
  */
 static function get_module_entry_class($module_indent)
 {
     $subfix = substr(self::ENTRY_FILE_NAME, 0, strlen(self::ENTRY_FILE_NAME) - 4);
     // prefix 目前只支持一层目录
     $prefix = str_replace(Da\Sys_App::app_path() . '/', '', Da\Sys_App::module_path());
     $matchs = [];
     $r = function ($matchs) {
         return strtoupper($matchs[0][1]);
     };
     $cls = preg_replace_callback('/_\\w/', $r, strtolower($module_indent));
     $cls = ucfirst($prefix) . '_' . ucfirst($cls) . '_' . ucfirst($subfix);
     if (!class_exists($cls)) {
         return false;
     }
     return $cls;
 }
示例#5
0
 static function run_custom_task_action()
 {
     // ap id for run
     $ap_id = Lib_Request::post_int_var('ap_id');
     if (empty($ap_id) && $ap_id != 0) {
         Module_View_Main::view()->output(['errno' => Const_Err_DataAccess::ERR_GET_PARAM, 'data' => '无此接入点']);
     }
     $options = Lib_Request::post_array_vars();
     $options['without_ct'] = true;
     // just run at cmd mode, not use ct to start task
     $mode = Module_FlowManager_Main::RUN_MODE_CALLBACK;
     isset($options['mode']) && ($mode = $options['mode']);
     $result = Da\Sys_App::run_mode() == DA_RUN_MODE_PRO ? Module_ControlCentre_Main::exec_task($ap_id, $mode, $options, 'tools/run_ap.php') : Module_ControlCentre_Main::exec_task($ap_id, $mode, $options);
     $diff = Module_OperationRecord_Main::get_diff([], $options);
     if (Const_Err_Base::ERR_OK !== $diff['errno']) {
         $diff = [];
     }
     $diff = $diff['data'];
     Module_OperationRecord_Main::add_record(Module_OperationRecord_Main::OPCODE_TASK_RUN, $diff, $ap_id);
     Module_View_Main::view()->output($result);
 }
示例#6
0
文件: init.php 项目: vincenttone/daf
<?php

if (!defined('DA_INIT')) {
    // 防止重复初始化
    define("DA_INIT", 1);
    // 版本检查
    if (PHP_VERSION_ID < 50400) {
        exit("Need PHP-5.4.0 or upper." . PHP_EOL);
    }
    ini_set('memory_limit', '30G');
    define('DA_PATH_INIT_FILE', dirname(__FILE__));
    define('DA_PATH_HOME', dirname(DA_PATH_INIT_FILE));
    define('DA_PATH_SYS', DA_PATH_INIT_FILE . '/sys');
    // functions
    require_once DA_PATH_SYS . '/function.php';
    // start app
    require_once DA_PATH_SYS . '/app.php';
    Da\Sys_App::app(DA_PATH_HOME . '/conf/app.ini')->bootstrap();
    file_exists(DA_PATH_INIT_FILE . '/extra.php') && (require_once DA_PATH_INIT_FILE . '/extra.php');
    Lib_Log::DEBUG('Framework(v' . DA_VERSION . ') init ok');
}
// end of if DA_LIB_INIT
示例#7
0
文件: init.php 项目: vincenttone/daf
<?php

if (!defined('DA_UT_PATH')) {
    define('DA_UT_PATH', dirname(__FILE__));
    define('DA_UT_DATA_PATH', DA_UT_PATH . '/data');
    // 版本检查
    if (PHP_VERSION_ID < 50400) {
        exit("Need PHP-5.4.0 or upper." . PHP_EOL);
    }
    ini_set('memory_limit', '10240M');
    //require_once 'PHPUnit/Autoload.php';
    // start app
    defined('DA_PATH_HOME') || define('DA_PATH_HOME', dirname(dirname(DA_UT_PATH)));
    // functions
    if (DA_PATH_HOME) {
        $app = DA_PATH_HOME . '/app/sys/app.php';
        $conf = DA_PATH_HOME . '/conf/unit.ini';
        require_once $app;
        require_once DA_PATH_HOME . '/app/sys/function.php';
        Da\Sys_App::app($conf)->bootstrap();
        Lib_Log::DEBUG('Unit test init ok');
    } else {
        throw new Exception('UT: wrong path.');
    }
    require_once DA_UT_PATH . '/helper.php';
}
// end of if DA_UT_INIT
示例#8
0
文件: index.php 项目: vincenttone/daf
<?php

session_start();
require_once dirname(dirname(__FILE__)) . '/app/init.php';
Module_HttpRequest_Router::get_instance()->register_pre_router_hook(['Module_Account_Manager', 'check_perm']);
Module_View_Main::view()->set_template_dir(Da\Sys_App::template_path());
$router = [Module_HttpRequest_Router::get_instance(), 'route'];
if (Da\Sys_Router::get_instance()->register_router($router)) {
    MT::lang(MT::LANG_ZH_CN);
    $dispatch = Da\Sys_Router::get_instance()->dispatch();
    if ($dispatch['errno'] != Da\Sys_Router::ERRNO_OK) {
        echo $dispatch['data'];
        exit;
    }
} else {
    Lib_Log::error('Route rules ' . json_encode($rules) . ' is not callable!');
}
示例#9
0
文件: main.php 项目: vincenttone/daf
 /**
  * @param string $path
  * @return string
  */
 static function data_path($path = null)
 {
     $dir = Da\Sys_App::data_path() . '/' . self::indentify();
     empty($path) || ($dir .= '/' . $path);
     return $dir;
 }