1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628 |
- <?php
- /**
- * CoreMVC核心模块
- *
- * @version 1.3.2
- * @author Z <602000@gmail.com>
- * @link http://www.coremvc.cn/
- */
- /**
- * 定义(define)
- */
- class core {
- /**
- * 配置文件或配置数组
- *
- * @link http://www.coremvc.cn/api/core/config.php
- */
- private static $config = '';
- private static $connect = '';
- private static $view = '';
- /**
- * 初始化函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/init.php
- * @param mixed $config
- * @param mixed &$variable
- * @return mixed
- */
- public static function init($config = null, &$variable = null) {
- // 引用参数处理
- $self_flag = $variable === null;
- if ($self_flag) {
- $current_config = &self::$config;
- } else {
- $current_config = &$variable;
- }
- // 导入配置文件
- if (is_string($current_config) && $current_config !== '') {
- $current_config = self::_init_file($current_config);
- } elseif ($self_flag && $current_config === '') {
- $current_config = self::_init_file('@' . __CLASS__ . '/config.php');
- }
- if (!is_array($current_config)) {
- $current_config = array();
- }
- // 导入环境变量
- $import_config = self::_init_env('config');
- if ($import_config !== array()) {
- $current_config = array_merge($current_config, $import_config);
- }
- // 配置参数处理
- if (is_bool($config)) {
- if ($config) {
- // 完全清空配置
- $current_config = array();
- } else {
- // 直接返回配置
- return $current_config;
- }
- } elseif (is_array($config)) {
- $count = count($config);
- if ($count > 0 && isset($config [$count - 1])) {
- // 返回多个属性
- $return_config = array();
- for ($i = 0; $i < $count; $i++) {
- $value = $config [$i];
- $return_config [$i] = isset($current_config [$value]) ? $current_config [$value] : '';
- }
- return $return_config;
- } elseif ($count > 0) {
- // 导入参数数组
- $current_config = array_merge($current_config, $config);
- }
- } elseif (is_string($config)) {
- if (strtolower(strrchr($config, '.')) === '.php') {
- // 导入配置文件
- $import_config = self::_init_file($config);
- if ($import_config !== array()) {
- $current_config = array_merge($current_config, $import_config);
- }
- } else {
- // 直接返回属性
- return isset($current_config [$config]) ? $current_config [$config] : '';
- }
- }
- // 需要初始化的函数
- if ($self_flag) {
- self::_init_extension($current_config);
- self::_init_autoload($current_config);
- }
- return $current_config;
- }
- /**
- * 存根函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/stub.php
- * @param bool $autoload_enable
- * @param string $autoload_path
- * @param string $autoload_extensions
- * @param bool $autoload_prepend
- * @return bool
- */
- public static function stub($autoload_enable = null, $autoload_path = null, $autoload_extensions = null, $autoload_prepend = null) {
- // 初始化自动载入功能
- $array = array();
- isset($autoload_enable) and $array ['autoload_enable'] = $autoload_enable;
- isset($autoload_path) and $array ['autoload_path'] = $autoload_path;
- isset($autoload_extensions) and $array ['autoload_extensions'] = $autoload_extensions;
- isset($autoload_prepend) and $array ['autoload_prepend'] = $autoload_prepend;
- self::_stub_autoload($array);
- // 判断访问或者引用
- foreach (debug_backtrace() as $row) {
- switch ($row ['function']) {
- case 'include' :
- case 'require' :
- case 'include_once' :
- case 'require_once' :
- case 'spl_autoload_call' :
- return false;
- }
- }
- return true;
- }
- /**
- * 入口函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/main.php
- * @param bool $framework_enable
- * @param string $framework_require
- * @param string $framework_mdoule
- * @param string $framework_action
- * @param string $framework_parameter
- * @return bool
- */
- public static function main($framework_enable = null, $framework_require = null, $framework_module = null, $framework_action = null, $framework_parameter = null) {
- // 一次跳转功能
- $config = self::init(false);
- if (!empty($config ['framework_function'])) {
- $function = $config ['framework_function'];
- if (!is_array($function)) {
- $function = (array) $function;
- }
- foreach ($function as $function_key => $function_value) {
- unset($function[$function_key]);
- break;
- }
- if ($function === array()) {
- $function = '';
- }
- self::init(array('framework_function' => $function));
- if (is_callable($function_value)) {
- self::_main_framework_first(true);
- return call_user_func($function_value, $framework_enable, $framework_require, $framework_module, $framework_action, $framework_parameter);
- }
- }
- // 入口参数处理
- isset($framework_enable) and $config ['framework_enable'] = $framework_enable;
- if (empty($config ['framework_enable']) || !is_string($config ['framework_enable'])) {
- $return_array = array();
- } else {
- $return_array = explode(',', $config ['framework_enable']);
- }
- // 框架控制功能
- if (!empty($config ['framework_enable'])) {
- isset($framework_require) and $config ['framework_require'] = $framework_require;
- isset($framework_module) and $config ['framework_module'] = $framework_module;
- isset($framework_action) and $config ['framework_action'] = $framework_action;
- isset($framework_parameter) and $config ['framework_parameter'] = $framework_parameter;
- return self::_main_framework($config, $return_array);
- }
- // 模拟文件隐藏效果
- if (!in_array('manual', $return_array)) {
- self::_main_hide($config);
- }
- return false;
- }
- /**
- * 路径函数
- *
- * @link http://www.coremvc.cn/api/core/path.php
- * @param string $filename
- * @param string $filetype
- * @return string
- */
- public static function path($filename, $filetype = null) {
- switch ($filetype) {
- case 'extension' :
- $filepath = self::_path_extension($filename);
- break;
- case 'config' :
- $filepath = self::_path_config($filename);
- break;
- case 'template' :
- $filepath = self::_path_template($filename);
- break;
- default :
- $filepath = self::_path_file($filename);
- if ($filepath === null) {
- $filepath = $filename;
- }
- break;
- }
- return $filepath;
- }
- /**
- * 视图函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/view.php
- * @param mixed $_view_file_global
- * @param array $_view_vars
- * @param string $_view_type
- * @param bool $_view_show
- * @return string
- */
- public static function view($_view_file_global = null, $_view_vars = null, $_view_type = null, $_view_show = null) {
- // 视图全局参数
- self::_view_variable($_view_file_global);
- if (is_string($_view_file_global)) {
- $_view_file = $_view_file_global;
- } else {
- return self::$view;
- }
- // 视图参数处理
- $_view_init = self::init(false);
- $_view_config = array(
- 'template_search' => isset($_view_init ['template_search']) ? $_view_init ['template_search'] : '',
- 'template_replace' => isset($_view_init ['template_replace']) ? $_view_init ['template_replace'] : '',
- 'template_type' => isset($_view_init ['template_type']) ? $_view_init ['template_type'] : '',
- );
- isset($_view_type) and $_view_config ['template_type'] = $_view_type;
- // 视图数据处理
- if ($_view_config ['template_search'] !== '' && $_view_config ['template_search'] !== $_view_config ['template_replace']) {
- $_view_file2 = self::_path_template(str_replace($_view_config ['template_search'], $_view_config ['template_replace'], $_view_file));
- } else {
- $_view_file2 = self::_path_template($_view_file);
- }
- $_view_vars2 = is_array($_view_vars) ? array_merge(self::$view, $_view_vars) : self::$view;
- $_view_type2 = $_view_config ['template_type'] === '' ? 'include' : $_view_config ['template_type'];
- $_view_show2 = $_view_show === null ? true : $_view_show;
- $_view_self2 = __CLASS__;
- // 视图模板处理
- switch ($_view_type2) {
- case 'include' :
- extract($_view_vars2);
- if ($_view_show2) {
- return require $_view_file2;
- } else {
- ob_start();
- require $_view_file2;
- return ob_get_clean();
- }
- case 'string' :
- extract($_view_vars2);
- if ($_view_show2) {
- return eval('echo <<<_END_OF_EVAL' . PHP_EOL . file_get_contents($_view_file2, FILE_USE_INCLUDE_PATH) . PHP_EOL . '_END_OF_EVAL;' . PHP_EOL);
- } else {
- return eval('return <<<_END_OF_EVAL' . PHP_EOL . file_get_contents($_view_file2, FILE_USE_INCLUDE_PATH) . PHP_EOL . '_END_OF_EVAL;' . PHP_EOL);
- }
- default :
- extract($_view_vars2);
- $_view_extension = self::_path_extension($_view_type2 . '.php');
- if (is_file($_view_extension)) {
- return require $_view_extension;
- } else {
- return;
- }
- }
- }
- /**
- * 数据库连接
- *
- * @link http://www.coremvc.cn/api/core/connect.php
- * @param mixed $args
- * @param array &$ref
- * @param array $info
- * @return $dbh
- */
- public static function connect($args = null, &$ref = null, $info = null) {
- // 导入配置文件
- $connect = &self::$connect;
- if (!is_array($connect)) {
- if (empty($connect)) {
- $connect = array();
- } else {
- $connect = self::_init_file($connect);
- if (!is_array($connect)) {
- $connect = array();
- }
- }
- $import_config = self::_init_env('connect');
- if ($import_config !== array()) {
- $connect = array_merge($connect, $import_config);
- }
- } elseif ($args === true && isset($connect ['current']) && isset($connect ['connections']) && isset($connect ['configs'] [$connect ['current']]) && isset($connect ['connections'] [$connect ['current']])) {
- // 返回当前连接
- $pos = $connect ['current'];
- $ref = $connect ['configs'] [$pos];
- $dbh = &$connect ['connections'] [$pos];
- switch ($ref ['connect_provider']) {
- // 【扩展功能】重连数据库
- default :
- $callback = array($ref ['connect_provider'], 'reconnect');
- if (!is_callable($callback)) {
- $provider_file = self::_path_extension($ref ['connect_provider'] . '.php');
- if (is_file($provider_file)) {
- require_once $provider_file;
- }
- }
- if (is_callable($callback)) {
- $dbh = call_user_func($callback, $dbh, $ref, $pos, $info);
- break;
- }
- case '' :
- case 'mysql' :
- if ($dbh === null || !mysql_ping($dbh)) {
- self::connect(false, $ref, $info);
- $dbh = self::connect(true, $ref, $info);
- }
- break;
- }
- return $dbh;
- }
- // 选择指定连接
- if (is_int($args)) {
- $connect ['current'] = $args;
- } elseif (!array_key_exists('current', $connect)) {
- $connect ['current'] = 0;
- } elseif (!is_int($connect ['current'])) {
- $connect ['current'] = (int) $connect ['current'];
- }
- $pos = $connect ['current'];
- if (!array_key_exists('configs', $connect) || !is_array($connect ['configs'])) {
- $connect ['configs'] = array();
- }
- if (!array_key_exists('connections', $connect) || !is_array($connect ['connections'])) {
- $connect ['connections'] = array();
- }
- if (!array_key_exists($pos, $connect ['configs']) || !is_array($connect ['configs'] [$pos])) {
- $connect ['configs'] [$pos] = array();
- }
- if (!array_key_exists($pos, $connect ['connections'])) {
- $connect ['connections'] [$pos] = null;
- }
- $cfg = &$connect ['configs'] [$pos];
- $dbh = &$connect ['connections'] [$pos];
- if (is_int($args)) {
- $ref = $cfg;
- return $dbh;
- }
- if ($args === null) {
- // 返回所有参数
- $ref = $cfg;
- return $connect;
- } elseif (is_array($args)) {
- // 设置参数配置
- foreach ($args as $key => $value) {
- $cfg [$key] = $value;
- }
- $ref = $cfg;
- return $dbh;
- } elseif (is_string($args)) {
- // 导入参数配置
- $ext = strtolower(strrchr($args, '.'));
- if (strtolower(strrchr($args, '.')) === '.php') {
- // 导入参数文件
- $import_config = self::_init_file($args);
- if ($import_config !== array()) {
- $cfg = array_merge($cfg, $import_config);
- }
- $ref = $cfg;
- return $dbh;
- } else {
- // 返回参数配置
- $ref = $cfg;
- return isset($cfg [$args]) ? $cfg [$args] : '';
- }
- }
- // 设置当前连接
- $config = self::init(false);
- $properties = array('connect_provider', 'connect_dsn', 'connect_type', 'connect_server', 'connect_username', 'connect_password',
- 'connect_new_link', 'connect_client_flags', 'connect_dbname', 'connect_charset', 'connect_port', 'connect_socket',
- 'connect_driver_options', 'prefix_search', 'prefix_replace', 'debug_enable', 'debug_file', 'sql_format');
- foreach ($properties as $property) {
- if (!isset($cfg [$property])) {
- if (isset($config [$property])) {
- $cfg [$property] = $config [$property];
- } else {
- $cfg [$property] = '';
- }
- }
- }
- $ref = $cfg;
- // 断开数据库
- if ($args === false) {
- switch ($ref ['connect_provider']) {
- // 【扩展功能】断开数据库
- default :
- $callback = array($ref ['connect_provider'], 'disconnect');
- if (!is_callable($callback)) {
- $provider_file = self::_path_extension($ref ['connect_provider'] . '.php');
- if (is_file($provider_file)) {
- require_once $provider_file;
- }
- }
- if (is_callable($callback)) {
- $return = call_user_func($callback, $dbh, $ref, $pos, $info);
- break;
- }
- case '' :
- case 'mysql' :
- if (is_resource($dbh) && get_resource_type($dbh) == 'mysql link') {
- $return = mysql_close($dbh);
- } else {
- $return = false;
- }
- break;
- }
- $ref = $cfg = array();
- $dbh = null;
- return $dbh;
- }
- // 连接数据库
- if ($args === true) {
- switch ($ref ['connect_provider']) {
- // 【扩展功能】连接数据库
- default :
- $callback = array($ref ['connect_provider'], 'connect');
- if (!is_callable($callback)) {
- $provider_file = self::_path_extension($ref ['connect_provider'] . '.php');
- if (is_file($provider_file)) {
- require_once $provider_file;
- }
- }
- if (is_callable($callback)) {
- $dbh = call_user_func($callback, $ref, $pos, $info);
- break;
- }
- case '' :
- case 'mysql' :
- $type = $ref ['connect_type'];
- $server = $ref ['connect_server'];
- $username = $ref ['connect_username'];
- $password = $ref ['connect_password'];
- $new_link = $ref ['connect_new_link'];
- $client_flags = $ref ['connect_client_flags'];
- $dbname = $ref ['connect_dbname'];
- $charset = $ref ['connect_charset'];
- if ($type === 'persist') {
- $dbh = mysql_pconnect($server, $username, $password, (int) $client_flags);
- } else {
- $dbh = mysql_connect($server, $username, $password, (bool) $new_link, (int) $client_flags);
- }
- if ($dbname) {
- mysql_select_db($dbname, $dbh);
- }
- if ($charset) {
- if (function_exists('mysql_set_charset')) {
- mysql_set_charset($charset, $dbh);
- } else {
- mysql_query('SET NAMES ' . $charset, $dbh);
- }
- }
- break;
- }
- return $dbh;
- }
- }
- /**
- * 执行SQL语句
- *
- * @link http://www.coremvc.cn/api/core/execute.php
- * @param string $sql
- * @param array $param
- * @param array &$ref
- * @return mixed
- */
- public static function execute($sql, $param = null, &$ref = null) {
- // 【基础功能】执行语句
- $ref_flag = (func_num_args() > 2);
- $dbh = self::connect(true, $args, array('execute', $sql, $param, $ref));
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $sql = str_replace($args ['prefix_search'], $args ['prefix_replace'], $sql);
- }
- switch ($args ['connect_provider']) {
- // 【扩展功能】执行语句
- default :
- $callback = array($provider = $args ['connect_provider'], 'execute');
- if (is_callable($callback)) {
- if ($ref_flag) {
- $result = call_user_func_array($callback, array($dbh, $args, __CLASS__, $sql, $param, &$ref));
- } else {
- $result = call_user_func_array($callback, array($dbh, $args, __CLASS__, $sql, $param));
- }
- break;
- }
- case '' :
- case 'mysql' :
- // 是否强制参数转SQL
- if (isset($args ['sql_format']) && $args ['sql_format']) {
- $sql = self::prepare($sql, $param, true);
- $param = null;
- }
- if (is_array($param)) {
- $stmt = 'coremvc_mysql_stmt';
- $var = '@coremvc_mysql_var';
- $sql_set = '';
- $sql_unset = '';
- $using = '';
- $key = 0;
- foreach ($param as $value) {
- if ($value === null) {
- $value = 'NULL';
- } elseif ($value === true) {
- $value = '1';
- } elseif ($value === false) {
- $value = '0';
- } elseif (is_int($value) || is_float($value)) {
-
- } else {
- $value = '\'' . mysqli_real_escape_string($dbh, (string) $value) . '\'';
- }
- $varname = $var . ++$key;
- if ($key === 1) {
- $sql_set = 'SET ' . $varname . '=' . $value;
- $sql_unset = 'SET ' . $varname . '=NULL';
- $using = ' USING ' . $varname;
- } else {
- $sql_set .= ',' . $varname . '=' . $value;
- $sql_unset .= ',' . $varname . '=NULL';
- $using .= ',' . $varname;
- }
- }
- mysql_query('PREPARE ' . $stmt . ' FROM \'' . mysqli_real_escape_string($dbh, $sql) . '\'', $dbh);
- if ($sql_set !== '') {
- mysql_query($sql_set, $dbh);
- }
- $result = mysql_query('EXECUTE ' . $stmt . $using, $dbh);
- } else {
- $result = mysql_query($sql, $dbh);
- }
- // 数据库调试开关
- if (isset($args ['debug_enable']) && $args ['debug_enable']) {
- if ($result === false) {
- $extra = array('errno' => mysql_errno($dbh), 'error' => mysql_error($dbh));
- } else {
- $extra = null;
- }
- self::prepare($sql, $param, null, true, $args ['debug_file'], $extra);
- }
- if ($ref_flag) {
- $ref = array();
- $ref ['insert_id'] = (string) mysql_insert_id($dbh);
- $ref ['affected_rows'] = max(mysql_affected_rows($dbh), 0);
- $ref ['num_fields'] = is_resource($result) ? mysql_num_fields($result) : 0;
- $ref ['num_rows'] = is_resource($result) ? mysql_num_rows($result) : 0;
- }
- if (is_array($param)) {
- if ($sql_unset !== '') {
- mysql_query($sql_unset, $dbh);
- }
- mysql_query('DEALLOCATE PREPARE ' . $stmt, $dbh);
- }
- break;
- }
- return $result;
- }
- /**
- * 准备SQL语句
- *
- * @link http://www.coremvc.cn/api/core/prepare.php
- * @param string $sql
- * @param array $param
- * @param bool $format
- * @param bool $debug
- * @param string $output
- * @param array $extra
- * @return mixed
- */
- public static function prepare($sql, $param = null, $format = null, $debug = null, $output = null, $extra = null) {
- // 【基础功能】准备SQL语句
- $mysql_escape_search = array("\\", "\x00", "\n", "\r", "'", "\"", "\x1a");
- $mysql_escape_replace = array("\\\\", "\\0", "\\n", "\\r", "\\'", "\\\"", "\\Z");
- if (strncmp($sql, 'mysql_escape_', 13) === 0) {
- $debug_provider = 'mysql';
- if ($format) {
- $return_sql = array();
- foreach ($param as $key => $value) {
- if ($value === array() || $key === 'page' && $sql === 'mysql_escape_other') {
- continue;
- }
- if (is_int($key)) {
- switch ($sql) {
- case 'mysql_escape_where' :
- case 'mysql_escape_where2' :
- if (is_array($value)) {
- $escape_sql = $sql === 'mysql_escape_where2' ? 'mysql_where' : 'mysql_where2';
- $return_sql [] = self::prepare($escape_sql, $value, true);
- break;
- }
- default :
- if ($value === null) {
- $value = 'NULL';
- } elseif ($value === true) {
- $value = '1';
- } elseif ($value === false) {
- $value = '0';
- } else {
- $value = (string) $value;
- }
- $return_sql [] = $value;
- break;
- }
- continue;
- }
- if (is_array($value)) {
- foreach ($value as &$value2) {
- if ($value2 === null) {
- $value2 = 'NULL';
- } elseif ($value2 === true) {
- $value2 = '1';
- } elseif ($value2 === false) {
- $value2 = '0';
- } elseif (is_int($value2) || is_float($value2)) {
-
- } else {
- $value2 = '\'' . str_replace($mysql_escape_search, $mysql_escape_replace, $value2) . '\'';
- }
- }
- } elseif ($value === null) {
- $value = 'NULL';
- } elseif ($value === true) {
- $value = '1';
- } elseif ($value === false) {
- $value = '0';
- } elseif (is_int($value) || is_float($value)) {
-
- } else {
- $value = '\'' . str_replace($mysql_escape_search, $mysql_escape_replace, $value) . '\'';
- }
- $pos = strpos($key, '?');
- if ($pos === false) {
- if (is_array($value)) {
- switch ($sql) {
- case 'mysql_escape_set' :
- $sep1 = $key . '=CONCAT_WS(\',\',';
- $sep2 = ')';
- break;
- default :
- case 'mysql_escape_value' :
- $sep1 = 'CONCAT_WS(\',\',';
- $sep2 = ')';
- break;
- case 'mysql_escape_where' :
- case 'mysql_escape_where2' :
- $sep1 = $key . ' IN (';
- $sep2 = ')';
- break;
- case 'mysql_escape_other' :
- $sep1 = $key . ' ';
- $sep2 = '';
- break;
- }
- $return_sql [] = $sep1 . implode(',', $value) . $sep2;
- } else {
- switch ($sql) {
- case 'mysql_escape_set' :
- case 'mysql_escape_where' :
- case 'mysql_escape_where2' :
- $sep = $key . '=';
- break;
- default :
- case 'mysql_escape_value' :
- $sep = '';
- break;
- case 'mysql_escape_other' :
- $sep = $key . ' ';
- break;
- }
- $return_sql [] = $sep . $value;
- }
- } else {
- if (is_array($value)) {
- $key = str_replace(array('%', '?'), array('%%', '%s'), $key);
- $return_sql [] = vsprintf($key, $value);
- } else {
- $return_sql [] = substr_replace($key, $value, $pos, 1);
- }
- }
- }
- $return = $return_sql;
- } else {
- $return_sql = array();
- $return_param = array();
- foreach ($param as $key => $value) {
- if ($value === array() || $key === 'page' && $sql === 'mysql_escape_other') {
- continue;
- }
- if (is_int($key)) {
- switch ($sql) {
- case 'mysql_escape_where' :
- case 'mysql_escape_where2' :
- if (is_array($value)) {
- $escape_sql = $sql === 'mysql_escape_where2' ? 'mysql_where' : 'mysql_where2';
- list ( $list_sql, $list_param ) = self::prepare($escape_sql, $value);
- $return_sql [] = $list_sql;
- foreach ($list_param as &$value2) {
- $return_param [] = $value2;
- }
- break;
- }
- default :
- if ($value === null) {
- $value = 'NULL';
- } elseif ($value === true) {
- $value = '1';
- } elseif ($value === false) {
- $value = '0';
- } else {
- $value = (string) $value;
- }
- $return_sql [] = $value;
- break;
- }
- continue;
- }
- $pos = strpos($key, '?');
- if ($pos === false) {
- if (is_array($value)) {
- switch ($sql) {
- case 'mysql_escape_set' :
- $sep1 = $key . '=CONCAT_WS(\',\',';
- $sep2 = ')';
- break;
- default :
- case 'mysql_escape_value' :
- $sep1 = 'CONCAT_WS(\',\',';
- $sep2 = ')';
- break;
- case 'mysql_escape_where' :
- case 'mysql_escape_where2' :
- $sep1 = $key . ' IN (';
- $sep2 = ')';
- break;
- case 'mysql_escape_other' :
- $sep1 = $key . ' ';
- $sep2 = '';
- break;
- }
- $return_sql [] = $sep1 . implode(',', array_fill(0, count($value), '?')) . $sep2;
- foreach ($value as &$value2) {
- $return_param [] = $value2;
- }
- } else {
- switch ($sql) {
- case 'mysql_escape_set' :
- case 'mysql_escape_where' :
- case 'mysql_escape_where2' :
- $sep = $key . '=';
- break;
- default :
- case 'mysql_escape_value' :
- $sep = '';
- break;
- case 'mysql_escape_other' :
- $sep = $key . ' ';
- break;
- }
- $return_sql [] = $sep . '?';
- $return_param [] = $value;
- }
- } else {
- if (is_array($value)) {
- $return_sql [] = $key;
- foreach ($value as &$value2) {
- $return_param [] = $value2;
- }
- } else {
- $return_sql [] = $key;
- $return_param [] = $value;
- }
- }
- }
- $return = array($return_sql, $return_param);
- }
- } else {
- if (strncmp($sql, 'mysql_', 6) === 0) {
- $mysql = $sql;
- $sql = substr($sql, 6);
- $debug_provider = 'mysql';
- } else {
- $dbh = self::connect(true, $args, array('prepare', $sql, $param, $format, $debug, $output, $extra));
- switch ($args ['connect_provider']) {
- case '' :
- $mysql = 'mysql_' . $sql;
- $debug_provider = 'mysql';
- break;
- case 'mysql' :
- $mysql = 'mysql_' . $sql;
- $debug_provider = 'mysql';
- break;
- default :
- $mysql = false;
- $debug_provider = $args ['connect_provider'];
- break;
- }
- }
- switch ($mysql) {
- case 'mysql_selects' :
- isset($param [0]) or $param [0] = null;
- isset($param [1]) or $param [1] = null;
- isset($param [2]) or $param [2] = null;
- isset($param [3]) or $param [3] = null;
- if ($format) {
- $field_sql = self::prepare('mysql_field', $param [0], true);
- $table_sql = self::prepare('mysql_table', $param [1], true);
- $where_sql = self::prepare('mysql_where', $param [2], true);
- $other_sql = self::prepare('mysql_other', $param [3], true);
- if ($field_sql === '') {
- $field_sql = '*';
- }
- if ($table_sql === '') {
- $return_sql = "SELECT $field_sql $other_sql";
- } elseif ($where_sql === '') {
- $return_sql = "SELECT $field_sql FROM $table_sql $other_sql";
- } else {
- $return_sql = "SELECT $field_sql FROM $table_sql WHERE $where_sql $other_sql";
- }
- $return = rtrim($return_sql);
- } else {
- list ( $field_sql, $field_param ) = self::prepare('field', $param [0]);
- list ( $table_sql, $table_param ) = self::prepare('table', $param [1]);
- list ( $where_sql, $where_param ) = self::prepare('where', $param [2]);
- list ( $other_sql, $other_param ) = self::prepare('other', $param [3]);
- if ($field_sql === '') {
- $field_sql = '*';
- }
- if ($table_sql === '') {
- $return_sql = "SELECT $field_sql $other_sql";
- $return_param = array_merge($field_param, $other_param);
- } elseif ($where_sql === '') {
- $return_sql = "SELECT $field_sql FROM $table_sql $other_sql";
- $return_param = array_merge($field_param, $table_param, $other_param);
- } else {
- $return_sql = "SELECT $field_sql FROM $table_sql WHERE $where_sql $other_sql";
- $return_param = array_merge($field_param, $table_param, $where_param, $other_param);
- }
- $return = array(rtrim($return_sql), $return_param);
- }
- break;
- case 'mysql_inserts' :
- case 'mysql_replaces' :
- isset($param [0]) or $param [0] = null;
- isset($param [1]) or $param [1] = null;
- isset($param [2]) or $param [2] = null;
- isset($param [3]) or $param [3] = null;
- $mysql_sql = strtoupper(substr(substr($mysql, 6), 0, - 1));
- if ($format) {
- $table_sql = self::prepare('mysql_table', $param [0], true);
- $other_sql = self::prepare('mysql_other', $param [3], true);
- if (isset($param [2])) {
- $column_sql = self::prepare('mysql_column', $param [1], true);
- $value_sql = self::prepare('mysql_value', $param [2], true);
- $return_sql = "$mysql_sql $table_sql $column_sql VALUES $value_sql $other_sql";
- } elseif (is_array($param [1]) && count($param [1]) > 0 && !isset($param [1] [count($param [1]) - 1])) {
- $set_sql = self::prepare('mysql_set', $param [1], true);
- $return_sql = "$mysql_sql $table_sql SET $set_sql $other_sql";
- } else {
- $column_sql = self::prepare('mysql_column', $param [1], true);
- $return_sql = "$mysql_sql $table_sql $column_sql $other_sql";
- }
- $return = rtrim($return_sql);
- } else {
- list ( $table_sql, $table_param ) = self::prepare('mysql_table', $param [0]);
- list ( $other_sql, $other_param ) = self::prepare('mysql_other', $param [3]);
- if (isset($param [2])) {
- list ( $column_sql, $column_param ) = self::prepare('mysql_column', $param [1]);
- list ( $value_sql, $value_param ) = self::prepare('mysql_value', $param [2]);
- $return_sql = "$mysql_sql $table_sql $column_sql VALUES $value_sql $other_sql";
- $return_param = array_merge($table_param, $column_param, $value_param, $other_param);
- } elseif (is_array($param [1]) && count($param [1]) > 0 && !isset($param [1] [count($param [1]) - 1])) {
- list ( $set_sql, $set_param ) = self::prepare('mysql_set', $param [1]);
- $return_sql = "$mysql_sql $table_sql SET $set_sql $other_sql";
- $return_param = array_merge($table_param, $set_param, $other_param);
- } else {
- list ( $column_sql, $column_param ) = self::prepare('mysql_column', $param [1]);
- $return_sql = "$mysql_sql $table_sql $column_sql $other_sql";
- $return_param = array_merge($table_param, $column_param, $other_param);
- }
- $return = array(rtrim($return_sql), $return_param);
- }
- break;
- case 'mysql_updates' :
- isset($param [0]) or $param [0] = null;
- isset($param [1]) or $param [1] = null;
- isset($param [2]) or $param [2] = null;
- isset($param [3]) or $param [3] = null;
- if ($format) {
- $table_sql = self::prepare('mysql_table', $param [0], true);
- $set_sql = self::prepare('mysql_set', $param [1], true);
- $where_sql = self::prepare('mysql_where', $param [2], true);
- $other_sql = self::prepare('mysql_other', $param [3], true);
- if ($where_sql === '') {
- $return_sql = "UPDATE $table_sql SET $set_sql $other_sql";
- } else {
- $return_sql = "UPDATE $table_sql SET $set_sql WHERE $where_sql $other_sql";
- }
- $return = rtrim($return_sql);
- } else {
- list ( $table_sql, $table_param ) = self::prepare('mysql_table', $param [0]);
- list ( $set_sql, $set_param ) = self::prepare('mysql_set', $param [1]);
- list ( $where_sql, $where_param ) = self::prepare('mysql_where', $param [2]);
- list ( $other_sql, $other_param ) = self::prepare('mysql_other', $param [3]);
- if ($where_sql === '') {
- $return_sql = "UPDATE $table_sql SET $set_sql $other_sql";
- $return_param = array_merge($table_param, $set_param, $other_param);
- } else {
- $return_sql = "UPDATE $table_sql SET $set_sql WHERE $where_sql $other_sql";
- $return_param = array_merge($table_param, $set_param, $where_param, $other_param);
- }
- $return = array(rtrim($return_sql), $return_param);
- }
- break;
- case 'mysql_deletes' :
- isset($param [0]) or $param [0] = null;
- isset($param [1]) or $param [1] = null;
- isset($param [2]) or $param [2] = null;
- isset($param [3]) or $param [3] = null;
- if ($format) {
- $field_sql = self::prepare('mysql_field', $param [0], true);
- $table_sql = self::prepare('mysql_table', $param [1], true);
- $where_sql = self::prepare('mysql_where', $param [2], true);
- $other_sql = self::prepare('mysql_other', $param [3], true);
- if ($where_sql === '') {
- $return_sql = "DELETE $field_sql FROM $table_sql $other_sql";
- } else {
- $return_sql = "DELETE $field_sql FROM $table_sql WHERE $where_sql $other_sql";
- }
- $return = rtrim($return_sql);
- } else {
- list ( $field_sql, $field_param ) = self::prepare('mysql_field', $param [0]);
- list ( $table_sql, $table_param ) = self::prepare('mysql_table', $param [1]);
- list ( $where_sql, $where_param ) = self::prepare('mysql_where', $param [2]);
- list ( $other_sql, $other_param ) = self::prepare('mysql_other', $param [3]);
- if ($where_sql === '') {
- $return_sql = "DELETE $field_sql FROM $table_sql $other_sql";
- $return_param = array_merge($field_param, $table_param, $other_param);
- } else {
- $return_sql = "DELETE $field_sql FROM $table_sql WHERE $where_sql $other_sql";
- $return_param = array_merge($field_param, $table_param, $where_param, $other_param);
- }
- $return = array(rtrim($return_sql), $return_param);
- }
- break;
- case 'mysql_column' :
- if (is_array($param)) {
- $return_sql = '';
- $expect = '';
- foreach ($param as $key => $value) {
- if ($value === null) {
- $value = 'NULL';
- } elseif ($value === true) {
- $value = '1';
- } elseif ($value === false) {
- $value = '0';
- } else {
- $value = (string) $value;
- }
- $return_sql .= $expect . $value;
- $expect = ',';
- }
- } else {
- $return_sql = (string) $param;
- }
- if ($return_sql !== '') {
- $return_sql = '(' . $return_sql . ')';
- }
- $return = $format ? $return_sql : array($return_sql, array());
- break;
- case 'mysql_field' :
- case 'mysql_table' :
- if (is_array($param)) {
- $return_sql = '';
- $expect = '';
- foreach ($param as $key => $value) {
- if (is_array($value)) {
- foreach ($value as $value2) {
- if ($value2 === null) {
- $value2 = 'NULL';
- } elseif ($value2 === true) {
- $value2 = '1';
- } elseif ($value2 === false) {
- $value2 = '0';
- } else {
- $value2 = (string) $value2;
- }
- $return_sql .= $expect . $value2;
- $expect = ' ';
- }
- } else {
- if ($value === null) {
- $value = 'NULL';
- } elseif ($value === true) {
- $value = '1';
- } elseif ($value === false) {
- $value = '0';
- } else {
- $value = (string) $value;
- }
- if (is_int($key)) {
- $return_sql .= $expect . $value;
- } else {
- $return_sql .= $expect . $value . ' AS ' . $key;
- }
- $expect = ',';
- }
- }
- } else {
- $return_sql = (string) $param;
- }
- $return = $format ? $return_sql : array($return_sql, array());
- break;
- case 'mysql_set' :
- case 'mysql_other' :
- $escape_sql = substr_replace($mysql, 'escape_', 6, 0);
- if (is_array($param)) {
- if ($format) {
- $return_sql = implode(',', self::prepare($escape_sql, $param, true));
- } else {
- list ( $return_sql, $return_param ) = self::prepare($escape_sql, $param);
- $return_sql = implode(',', $return_sql);
- }
- } else {
- $return_sql = (string) $param;
- $return_param = array();
- }
- $return = $format ? $return_sql : array($return_sql, $return_param);
- break;
- case 'mysql_where' :
- case 'mysql_where2' :
- $escape_sql = substr_replace($mysql, 'escape_', 6, 0);
- $escape_sep = $mysql === 'mysql_where2' ? ' OR ' : ' AND ';
- if (is_array($param)) {
- if ($format) {
- $return_sql = implode($escape_sep, self::prepare($escape_sql, $param, true));
- } else {
- list ( $return_sql, $return_param ) = self::prepare($escape_sql, $param);
- $return_sql = implode($escape_sep, $return_sql);
- }
- } else {
- $return_sql = (string) $param;
- $return_param = array();
- }
- if ($mysql === 'mysql_where2' && $return_sql !== '') {
- $return_sql = '(' . $return_sql . ')';
- }
- $return = $format ? $return_sql : array($return_sql, $return_param);
- break;
- case 'mysql_value' :
- if (is_array($param)) {
- if (isset($param [0]) && is_array($param [0])) {
- $return_sql = '';
- $return_param = array();
- $expect = '';
- foreach ($param as $key => $value) {
- if ($format) {
- $value_sql = implode(',', self::prepare('mysql_escape_value', $value, true));
- } else {
- list ( $value_sql, $value_param ) = self::prepare('mysql_escape_value', $value);
- $value_sql = implode(',', $value_sql);
- foreach ($value_param as $value_value) {
- $return_param [] = $value_value;
- }
- }
- if ($value_sql !== '') {
- $return_sql .= $expect . '(' . $value_sql . ')';
- $expect = ',';
- }
- }
- } else {
- if ($format) {
- $return_sql = implode(',', self::prepare('mysql_escape_value', $param, true));
- } else {
- list ( $return_sql, $return_param ) = self::prepare('mysql_escape_value', $param);
- $return_sql = implode(',', $return_sql);
- }
- if ($return_sql !== '') {
- $return_sql = '(' . $return_sql . ')';
- }
- }
- } else {
- $return_sql = (string) $param;
- $return_param = array();
- if ($return_sql !== '') {
- $return_sql = '(' . $return_sql . ')';
- }
- }
- $return = $format ? $return_sql : array($return_sql, $return_param);
- break;
- case false :
- // 【扩展功能】准备SQL语句
- $callback = array($args ['connect_provider'], 'prepare');
- if (!is_callable($callback)) {
- $provider_file = self::_path_extension($args ['connect_provider'] . '.php');
- if (is_file($provider_file)) {
- require_once $provider_file;
- }
- }
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $sql = str_replace($args ['prefix_search'], $args ['prefix_replace'], $sql);
- }
- if (is_callable($callback)) {
- $return = call_user_func($callback, $dbh, $args, __CLASS__, $sql, $param, $format);
- } else {
- $return = self::prepare('mysql_' . $sql, $param, $format);
- }
- break;
- default :
- if ($format) {
- $return_sql = str_replace(array('%', '?'), array('%%', '%s'), $sql);
- if (is_array($param)) {
- $return_param = $param;
- foreach ($return_param as &$value) {
- if ($value === null) {
- $value = 'NULL';
- } elseif ($value === true) {
- $value = '1';
- } elseif ($value === false) {
- $value = '0';
- } elseif (is_int($value) || is_float($value)) {
-
- } else {
- $value = '\'' . str_replace($mysql_escape_search, $mysql_escape_replace, $value) . '\'';
- }
- }
- $return_sql = vsprintf($return_sql, $return_param);
- }
- $return = $return_sql;
- } else {
- $return = array($sql, $param);
- }
- break;
- }
- }
- // 【基础功能】调试SQL语句
- if ($debug) {
- if ($format) {
- $debug_sql = $return;
- $debug_param = null;
- } else {
- list($debug_sql, $debug_param) = $return;
- }
- $echo2 = null;
- if (is_array($debug_param)) {
- $i = 0;
- $echo2 = '';
- foreach ($debug_param as $value) {
- $echo2 .= PHP_EOL . '#' . ($i++) . ': ';
- if ($value === null) {
- $echo2 .= 'NULL';
- } elseif ($value === true) {
- $echo2 .= 'bool(true)';
- } elseif ($value === false) {
- $echo2 .= 'bool(false)';
- } elseif (is_int($value)) {
- $echo2 .= 'int(' . $value . ')';
- } elseif (is_float($value)) {
- $echo2 .= 'float(' . $value . ')';
- } else {
- $echo2 .= 'string(' . strlen($value) . ') ' . $value;
- }
- }
- }
- if (PHP_SAPI == 'cli' || !empty($output)) {
- $echo = PHP_EOL . '(' . $debug_provider . '): ' . $debug_sql;
- if (!empty($echo2)) {
- $echo .= $echo2;
- }
- $echo .= PHP_EOL;
- if (!empty($extra['errno'])) {
- $echo .= $extra['errno'] . ": " . $extra['error'] . PHP_EOL;
- }
- } else {
- $echo = PHP_EOL . '<hr />' . PHP_EOL . '(' . $debug_provider . '): ' . htmlentities($debug_sql) . PHP_EOL;
- if (!empty($echo2)) {
- $echo .= str_replace(PHP_EOL, '<br />' . PHP_EOL, htmlentities($echo2));
- }
- $echo .= '<hr />' . PHP_EOL;
- if (!empty($extra['errno'])) {
- $echo .= $extra['errno'] . ": " . htmlentities($extra['error']) . '<br />' . PHP_EOL;
- }
- }
- if (empty($output)) {
- echo $echo;
- } else {
- file_put_contents(self::path($output), $echo, FILE_APPEND);
- }
- }
- return $return;
- }
- /**
- * 生成自增序列(可继承)
- *
- * @link http://www.coremvc.cn/api/core/sequence.php
- * @param string $tablename
- * @param int $start_index
- * @return int
- */
- public static function sequence($tablename = 'sequence', $start_index = 1) {
- // 【基础功能】生成自增序列
- $dbh = self::connect(true, $args, array('sequence', $tablename, $start_index));
- // 表名
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $tablename = str_replace($args ['prefix_search'], $args ['prefix_replace'], $tablename);
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】生成自增序列
- default :
- $callback = array($args ['connect_provider'], 'sequence');
- if (is_callable($callback)) {
- $return = call_user_func($callback, $dbh, $args, __CLASS__, $tablename, $start_index);
- break;
- }
- case '' :
- case 'mysql' :
- $result = mysql_query('UPDATE ' . $tablename . ' SET id=LAST_INSERT_ID(id+1)', $dbh);
- if ($result === false) {
- mysql_query('CREATE TABLE ' . $tablename . ' (id INT NOT NULL)', $dbh);
- $rs = mysql_query('SELECT COUNT(*) FROM ' . $tablename . ' LIMIT 1', $dbh);
- if (mysql_result($rs, 0) == 0) {
- mysql_query('INSERT INTO ' . $tablename . ' VALUES (' . ($start_index - 1) . ')', $dbh);
- }
- mysql_query('UPDATE ' . $tablename . ' SET id=LAST_INSERT_ID(id+1)', $dbh);
- }
- $return = mysql_insert_id($dbh);
- if ($return === false) {
- return false;
- }
- if ($start_index > $return) {
- mysql_query('UPDATE ' . $tablename . ' SET id=' . $start_index, $dbh);
- $return = $start_index;
- }
- break;
- }
- return $return;
- }
- /**
- * 静态构造函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/structs.php
- * @param array $array
- * @param mixed $struct
- * @return array
- */
- public static function structs($array = null, $struct = null) {
- // 【基础功能】构造对象数组
- // 数组
- if ($array === null || $array === '') {
- $data_arr = array(null);
- } elseif (is_object($array)) {
- $data_arr = array($array);
- } elseif (is_array($array)) {
- $data_arr = $array;
- } else {
- return;
- }
- // 类名
- if ($struct === null || $struct === '') {
- $class_arr = array(null, 'class' => null);
- } elseif (is_string($struct)) {
- $class_arr = array(null, 'class' => $struct);
- } elseif (is_object($struct)) {
- $class_arr = array(null, 'clone' => $struct);
- } elseif (is_array($struct)) {
- if ($struct === array()) {
- return;
- }
- $class_arr = $struct;
- } else {
- return;
- }
- foreach ($class_arr as $classkey => $classname) {
-
- }
- unset($class_arr [$classkey]);
- if (is_int($classkey)) {
- if ($classname === null || $classname === '') {
- $classkey = 'class';
- } elseif (is_int($classname)) {
- $classkey = 'column';
- } elseif (is_string($classname)) {
- $classkey = 'column';
- } elseif (is_object($classname)) {
- $classkey = 'clone';
- } elseif (is_array($classname)) {
- $classkey = 'array';
- } else {
- return;
- }
- }
- if (function_exists('get_called_class')) {
- $calledclass = get_called_class();
- } else {
- $calledclass = __CLASS__;
- }
- // 整理
- $return = array();
- foreach ($data_arr as $data) {
- $data_str = array();
- $data_int = array();
- $data_all = array();
- if (is_object($data) || is_array($data)) {
- $int2 = 0;
- foreach ($data as $key2 => $data2) {
- if (is_int($key2)) {
- $data_int [$key2] = $data2;
- continue;
- }
- $data_str [$key2] = $data2;
- $data_int [$int2] = $data2;
- $data_all [$key2] = $data2;
- $data_all [$int2] = $data2;
- $int2++;
- }
- }
- $point1 = &$return;
- foreach ($class_arr as $class) {
- $point2 = array();
- if ($class === null || $class === '') {
- $point1 [] = &$point2;
- } else {
- if (is_int($class) && isset($data_int [$class])) {
- $point3 = $data_int [$class];
- } elseif (is_string($class) && isset($data_str [$class])) {
- $point3 = $data_str [$class];
- } else {
- $point3 = '';
- }
- if (isset($point1 [$point3])) {
- $point2 = &$point1 [$point3];
- } else {
- $point1 [$point3] = &$point2;
- }
- }
- unset($point1);
- $point1 = &$point2;
- unset($point2);
- }
- switch ($classkey) {
- case 'assoc' :
- $point1 = $data_str;
- break;
- case 'num' :
- $point1 = $data_int;
- break;
- case 'both' :
- $point1 = $data_all;
- break;
- case 'array' :
- if (is_array($classname)) {
- $point1 = $classname;
- foreach ($data_str as $key => $value) {
- if (array_key_exists($key, $point1)) {
- $point1 [$key] = $value;
- }
- }
- foreach ($data_int as $key => $value) {
- if (array_key_exists($key, $point1)) {
- $point1 [$key] = $value;
- }
- }
- } else {
- $point1 = array();
- }
- break;
- case 'column' :
- if (is_int($classname) && isset($data_int [$classname])) {
- $point1 = $data_int [$classname];
- } elseif (is_string($classname) && isset($data_str [$classname])) {
- $point1 = $data_str [$classname];
- } else {
- $point1 = null;
- }
- break;
- default :
- case 'class' :
- if (class_exists($classname)) {
- $point1 = new $classname ( );
- } else {
- $point1 = new $calledclass ( );
- }
- foreach ($data_str as $key => $value) {
- $point1->$key = $value;
- }
- break;
- case 'class|classtype' :
- $i = 0;
- foreach ($data_str as $key => $value) {
- if ($i++ === 0) {
- if (isset($data_int [0]) && preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $data_int [0]) && class_exists($data_int [0])) {
- $point1 = new $data_int [0] ( );
- } elseif (class_exists($classname)) {
- $point1 = new $classname ( );
- } else {
- $point1 = new $calledclass ( );
- }
- continue;
- }
- $point1->$key = $value;
- }
- if ($i === 0) {
- if (isset($data_int [0]) && preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $data_int [0]) && class_exists($data_int [0])) {
- $point1 = new $data_int [0] ( );
- } elseif (class_exists($classname)) {
- $point1 = new $classname ( );
- } else {
- $point1 = new $calledclass ( );
- }
- }
- break;
- case 'clone' :
- if (is_object($classname)) {
- $point1 = clone $classname;
- } else {
- $point1 = new $calledclass ( );
- }
- foreach ($data_str as $key => $value) {
- $point1->$key = $value;
- }
- break;
- }
- }
- return $return;
- }
- /**
- * 静态选择函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/selects.php
- * @param mixed $field_sql
- * @param mixed $table_param
- * @param mixed $where_bool
- * @param mixed $other
- * @param mixed $struct
- * @return array
- */
- public static function selects($field_sql = null, $table_param = null, $where_bool = null, $other = null, $struct = null) {
- // 【基础功能】静态选择数据
- $dbh = self::connect(true, $args, array('selects', $field_sql, $table_param, $where_bool, $other, $struct));
- // 类名
- if ($struct === null || $struct === '') {
- $class_arr = array(null, 'class' => null);
- } elseif (is_string($struct)) {
- $class_arr = array(null, 'class' => $struct);
- } elseif (is_object($struct)) {
- $class_arr = array(null, 'clone' => $struct);
- } elseif (is_array($struct)) {
- if ($struct === array()) {
- return;
- }
- $class_arr = $struct;
- } else {
- return;
- }
- foreach ($class_arr as $classkey => $classname) {
-
- }
- unset($class_arr [$classkey]);
- if (is_int($classkey)) {
- if ($classname === null || $classname === '') {
- $classkey = 'class';
- } elseif (is_int($classname)) {
- $classkey = 'column';
- } elseif (is_string($classname)) {
- $classkey = 'column';
- } elseif (is_object($classname)) {
- $classkey = 'clone';
- } elseif (is_array($classname)) {
- $classkey = 'array';
- } else {
- return;
- }
- }
- if (function_exists('get_called_class')) {
- $calledclass = get_called_class();
- } else {
- $calledclass = __CLASS__;
- }
- $classkey_arr = null;
- if (strpos($classkey, '|') !== false) {
- $classkey_arr = explode('|', $classkey);
- $classkey = array_shift($classkey_arr);
- foreach ($classkey_arr as $classkey_key) {
- if (strncmp($classkey_key, 'table=', 6) === 0) {
- $table_class = substr($classkey_key, 6);
- if ($table_class === '') {
- $table_class = $calledclass;
- }
- }
- }
- }
- // 参数
- if (is_bool($where_bool)) {
- $sql = $field_sql;
- $param = is_array($table_param) ? $table_param : array();
- } else {
- if ($table_param === null) {
- if (isset($table_class)) {
-
- } elseif (is_string($classname)) {
- if (class_exists($classname)) {
- $table_class = $classname;
- } else {
- $table_class = $calledclass;
- }
- } elseif (is_object($classname)) {
- $table_class = get_class($classname);
- } else {
- $table_class = $calledclass;
- }
- if ($args ['prefix_search'] === '') {
- $table = $table_class;
- } else {
- $table = $args ['prefix_search'] . $table_class;
- }
- } else {
- $table = $table_param;
- }
- $field = $field_sql;
- $where = $where_bool;
- list ( $sql, $param ) = self::prepare('selects', array($field, $table, $where, $other));
- }
- // 分页
- if (is_array($other) && isset($other ['page'])) {
- $page = &$other ['page'];
- if (is_array($page)) {
- if (isset($page ['page'])) {
- settype($page ['page'], 'int');
- if ($page ['page'] < 1) {
- $page ['page'] = 1;
- }
- } else {
- $page ['page'] = 1;
- }
- if (isset($page ['size'])) {
- settype($page ['size'], 'int');
- if ($page ['size'] < 1) {
- $page ['size'] = 1;
- }
- } else {
- $page ['size'] = 1;
- }
- if (isset($page ['count'])) {
- settype($page ['count'], 'int');
- if ($page ['count'] < 0) {
- $page ['count'] = null;
- }
- } else {
- $page ['count'] = null;
- }
- if (isset($page ['total'])) {
- settype($page ['total'], 'int');
- if ($page ['total'] < 0) {
- $page ['total'] = null;
- }
- } else {
- $page ['total'] = null;
- }
- } else {
- $page = array('page' => 1, 'size' => 1, 'count' => null, 'total' => null);
- }
- } else {
- $page = null;
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】静态选择数据
- default :
- $callback = array($args ['connect_provider'], 'selects');
- if (is_callable($callback)) {
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $sql = str_replace($args ['prefix_search'], $args ['prefix_replace'], $sql);
- }
- $ref = array('page' => &$page, 'class_arr' => $class_arr, 'classkey' => $classkey, 'classkey_arr' => $classkey_arr, 'classname' => $classname, 'calledclass' => $calledclass);
- list ( $data_arr, $data_all ) = call_user_func($callback, $dbh, $args, __CLASS__, $sql, $param, $ref);
- break;
- }
- case '' :
- case 'mysql' :
- if ($page !== null) {
- if ($page ['count'] === null) {
- $sql = preg_replace('/SELECT/i', 'SELECT SQL_CALC_FOUND_ROWS', $sql, 1);
- }
- $limit = 'LIMIT ' . ($page ['size'] * ($page ['page'] - 1)) . ',' . $page ['size'];
- if (isset($page ['limit'])) {
- $sql = preg_replace('/(.*)' . $page ['limit'] . '/i', '$1' . $limit, $sql, 1);
- } else {
- $sql .= ' ' . $limit;
- }
- }
- $data_key = array();
- foreach ($class_arr as $value) {
- if ($value !== null && $value !== '' && !in_array($value, $data_key, true)) {
- $data_key [] = $value;
- }
- }
- $result = self::execute($sql, $param);
- if ($result === false) {
- return false;
- }
- if ($page !== null) {
- if ($page ['count'] === null) {
- list ( $page ['count'] ) = mysql_fetch_row(mysql_unbuffered_query('SELECT FOUND_ROWS()', $dbh));
- }
- $page ['total'] = (int) ceil($page ['count'] / $page ['size']);
- }
- // 数据
- if (!is_resource($result) || mysql_num_rows($result) === 0) {
- $data_arr = array();
- break;
- }
- $data_all = array();
- if ($data_key !== array()) {
- while ($obj = mysql_fetch_array($result)) {
- $obj_arr = array();
- foreach ($data_key as $value) {
- if (array_key_exists($value, $obj)) {
- $obj_arr [$value] = $obj [$value];
- }
- }
- $data_all [] = $obj_arr;
- }
- mysql_data_seek($result, 0);
- }
- $data_arr = array();
- switch ($classkey) {
- case 'assoc' :
- while ($obj = mysql_fetch_assoc($result)) {
- $data_arr [] = $obj;
- }
- break;
- case 'num' :
- while ($obj = mysql_fetch_row($result)) {
- $data_arr [] = $obj;
- }
- break;
- case 'both' :
- case 'array' :
- while ($obj = mysql_fetch_array($result)) {
- $data_arr [] = $obj;
- }
- break;
- case 'column' :
- while ($obj = mysql_fetch_array($result)) {
- if (isset($obj [$classname])) {
- $data_arr [] = $obj [$classname];
- } else {
- $data_arr [] = null;
- }
- }
- break;
- default :
- case 'class' :
- if (isset($classkey_arr) && in_array('classtype', $classkey_arr)) {
- while ($obj = mysql_fetch_assoc($result)) {
- $obj_classname = $classname;
- foreach ($obj as $key => $obj_classname) {
- unset($obj [$key]);
- break;
- }
- if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $obj_classname) && class_exists($obj_classname)) {
- $clone = new $obj_classname ( );
- } elseif (class_exists($classname)) {
- $clone = new $classname ( );
- } else {
- $clone = new $calledclass ( );
- }
- foreach ($obj as $key => $value) {
- $clone->$key = $value;
- }
- $data_arr [] = $clone;
- }
- } else {
- if (class_exists($classname)) {
- $obj_classname = $classname;
- } else {
- $obj_classname = $calledclass;
- }
- while ($obj = mysql_fetch_object($result, $obj_classname)) {
- $data_arr [] = $obj;
- }
- }
- break;
- case 'clone' :
- if (is_object($classname)) {
- $obj_classname = $classname;
- } else {
- $obj_classname = new $calledclass ( );
- }
- while ($obj = mysql_fetch_assoc($result)) {
- $clone = clone $obj_classname;
- foreach ($obj as $key => $value) {
- $clone->$key = $value;
- }
- $data_arr [] = $clone;
- }
- break;
- }
- break;
- }
- // 整理
- if ($class_arr === array(null) || $class_arr === array('')) {
- return $data_arr;
- }
- $return = array();
- foreach ($data_arr as $key => $data) {
- $point1 = &$return;
- foreach ($class_arr as $struct) {
- $point2 = array();
- if ($struct === null || $struct === '') {
- $point1 [] = &$point2;
- } else {
- if (isset($data_all [$key] [$struct])) {
- $point3 = $data_all [$key] [$struct];
- } else {
- $point3 = '';
- }
- if (isset($point1 [$point3])) {
- $point2 = &$point1 [$point3];
- } else {
- $point1 [$point3] = &$point2;
- }
- }
- unset($point1);
- $point1 = &$point2;
- unset($point2);
- }
- $point1 = $data;
- }
- return $return;
- }
- /**
- * 静态插入函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/inserts.php
- * @param mixed $table_sql
- * @param mixed $column_set_param
- * @param mixed $value_bool
- * @param mixed $other
- * @param string $class
- * @return int
- */
- public static function inserts($table_sql = null, $column_set_param = null, $value_bool = null, $other = null, $class = null) {
- // 【基础功能】静态插入数据
- $dbh = self::connect(true, $args, array('inserts', $table_sql, $column_set_param, $value_bool, $other, $class));
- // 参数
- if (is_bool($value_bool)) {
- $sql = $table_sql;
- $param = $column_set_param;
- } else {
- if ($table_sql === null) {
- if ($class === null) {
- if (function_exists('get_called_class')) {
- $class = get_called_class();
- } else {
- $class = __CLASS__;
- }
- }
- if ($args ['prefix_search'] === '') {
- $table = $class;
- } else {
- $table = $args ['prefix_search'] . $class;
- }
- } else {
- $table = $table_sql;
- }
- $column_set = $column_set_param;
- $value = $value_bool;
- list ( $sql, $param ) = self::prepare('inserts', array($table, $column_set, $value, $other));
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】静态插入数据
- default :
- $callback = array($args ['connect_provider'], 'inserts');
- if (is_callable($callback)) {
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $sql = str_replace($args ['prefix_search'], $args ['prefix_replace'], $sql);
- }
- return call_user_func($callback, $dbh, $args, __CLASS__, $sql, $param);
- }
- case '' :
- case 'mysql' :
- self::execute($sql, $param, $ref);
- return $ref ['affected_rows'];
- }
- }
- /**
- * 静态修改函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/updates.php
- * @param mixed $table_sql
- * @param mixed $set_param
- * @param mixed $where_bool
- * @param mixed $other
- * @param string $class
- * @return int
- */
- public static function updates($table_sql = null, $set_param = null, $where_bool = null, $other = null, $class = null) {
- // 【基础功能】静态修改数据
- $dbh = self::connect(true, $args, array('updates', $table_sql, $set_param, $where_bool, $other, $class));
- // 参数
- if (is_bool($where_bool)) {
- $sql = $table_sql;
- $param = $set_param;
- } else {
- if ($table_sql === null) {
- if ($class === null) {
- if (function_exists('get_called_class')) {
- $class = get_called_class();
- } else {
- $class = __CLASS__;
- }
- }
- if ($args ['prefix_search'] === '') {
- $table = $class;
- } else {
- $table = $args ['prefix_search'] . $class;
- }
- } else {
- $table = $table_sql;
- }
- $set = $set_param;
- $where = $where_bool;
- list ( $sql, $param ) = self::prepare('updates', array($table, $set, $where, $other));
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】静态修改数据
- default :
- $callback = array($args ['connect_provider'], 'updates');
- if (is_callable($callback)) {
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $sql = str_replace($args ['prefix_search'], $args ['prefix_replace'], $sql);
- }
- return call_user_func($callback, $dbh, $args, __CLASS__, $sql, $param);
- }
- case '' :
- case 'mysql' :
- self::execute($sql, $param, $ref);
- return $ref ['affected_rows'];
- }
- }
- /**
- * 静态删除函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/deletes.php
- * @param mixed $field_sql
- * @param mixed $table_param
- * @param mixed $where_bool
- * @param mixed $other
- * @param string $class
- * @return int
- */
- public static function deletes($field_sql = null, $table_param = null, $where_bool = null, $other = null, $class = null) {
- // 【基础功能】静态删除数据
- $dbh = self::connect(true, $args, array('deletes', $field_sql, $table_param, $where_bool, $other, $class));
- // 参数
- if (is_bool($where_bool)) {
- $sql = $field_sql;
- $param = $table_param;
- } else {
- if ($table_param === null) {
- if ($class === null) {
- if (function_exists('get_called_class')) {
- $class = get_called_class();
- } else {
- $class = __CLASS__;
- }
- }
- if ($args ['prefix_search'] === '') {
- $table = $class;
- } else {
- $table = $args ['prefix_search'] . $class;
- }
- } else {
- $table = $table_param;
- }
- $field = $field_sql;
- $where = $where_bool;
- list ( $sql, $param ) = self::prepare('deletes', array($field, $table, $where, $other));
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】静态删除数据
- default :
- $callback = array($args ['connect_provider'], 'deletes');
- if (is_callable($callback)) {
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $sql = str_replace($args ['prefix_search'], $args ['prefix_replace'], $sql);
- }
- return call_user_func($callback, $dbh, $args, __CLASS__, $sql, $param);
- }
- case '' :
- case 'mysql' :
- self::execute($sql, $param, $ref);
- return $ref ['affected_rows'];
- }
- }
- /**
- * 静态更新函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/replaces.php
- * @param mixed $table_sql
- * @param mixed $column_set_param
- * @param mixed $value_bool
- * @param mixed $other
- * @param string $class
- * @return int
- */
- public static function replaces($table_sql = null, $column_set_param = null, $value_bool = null, $other = null, $class = null) {
- // 【基础功能】静态更新数据
- $dbh = self::connect(true, $args, array('replaces', $table_sql, $column_set_param, $value_bool, $other, $class));
- // 参数
- if (is_bool($value_bool)) {
- $sql = $table_sql;
- $param = $column_set_param;
- } else {
- if ($table_sql === null) {
- if ($class === null) {
- if (function_exists('get_called_class')) {
- $class = get_called_class();
- } else {
- $class = __CLASS__;
- }
- }
- if ($args ['prefix_search'] === '') {
- $table = $class;
- } else {
- $table = $args ['prefix_search'] . $class;
- }
- } else {
- $table = $table_sql;
- }
- $column_set = $column_set_param;
- $value = $value_bool;
- list ( $sql, $param ) = self::prepare('replaces', array($table, $column_set, $value, $other));
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】静态更新数据
- default :
- $callback = array($args ['connect_provider'], 'replaces');
- if (is_callable($callback)) {
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $sql = str_replace($args ['prefix_search'], $args ['prefix_replace'], $sql);
- }
- return call_user_func($callback, $dbh, $args, __CLASS__, $sql, $param);
- }
- case '' :
- case 'mysql' :
- self::execute($sql, $param, $ref);
- return $ref ['affected_rows'];
- }
- }
- /**
- * 实例构造函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/struct.php
- * @param mixed $row
- * @return mixed
- */
- public function struct($row = null) {
- // 验证方法名
- if (!isset($this) || !($this instanceof self)) {
- trigger_error('Cannot find the correct object, try ' . __FUNCTION__ . 's method.', E_USER_ERROR);
- return;
- }
- // 【基础功能】返回实例数组
- if ($row === null || $row === '') {
- return get_object_vars($this);
- }
- // 【基础功能】返回实例数据
- if (is_int($row)) {
- $i = 0;
- foreach ($this as $value) {
- if ($row === $i) {
- return $value;
- }
- $i++;
- }
- return;
- } elseif (is_string($row)) {
- foreach ($this as $key => $value) {
- if ($row === $key) {
- return $value;
- }
- }
- return;
- }
- // 【基础功能】载入实例数组
- if (is_object($row)) {
- foreach ($row as $key => $value) {
- $this->$key = $value;
- }
- return get_object_vars($this);
- } elseif (is_array($row)) {
- foreach ($row as $key => $value) {
- if (is_int($key)) {
- $i = 0;
- foreach ($this as $key2 => $value2) {
- if ($key === $i) {
- $this->$key2 = $value;
- break;
- }
- $i++;
- }
- } elseif ($key !== '') {
- $this->$key = $value;
- }
- }
- return get_object_vars($this);
- }
- return;
- }
- /**
- * 实例选择函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/select.php
- * @param string $tablename
- * @param mixed $primary_index
- * @return bool
- */
- public function select($tablename = '', $primary_index = 0) {
- // 验证方法名
- if (!isset($this) || !($this instanceof self)) {
- trigger_error('Cannot find the correct object, try ' . __FUNCTION__ . 's method.', E_USER_ERROR);
- return;
- }
- // 【基础功能】选择实例数据
- $dbh = self::connect(true, $args, array('select', $tablename, $primary_index));
- // 表名
- if (empty($tablename)) {
- $tablename = $args ['prefix_search'] . get_class($this);
- }
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $tablename = str_replace($args ['prefix_search'], $args ['prefix_replace'], $tablename);
- }
- // 字段
- $fieldvars = get_object_vars($this);
- $primary_name = null;
- if (is_int($primary_index) && $primary_index >= 0 && $primary_index < count($fieldvars)) {
- $field_index = 0;
- foreach ($fieldvars as $primary_name => $primary_value) {
- if ($primary_index === $field_index++) {
- break;
- }
- }
- } elseif (is_string($primary_index) && array_key_exists($primary_index, $fieldvars)) {
- $primary_name = $primary_index;
- $primary_value = $fieldvars [$primary_name];
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】选择实例数据
- default :
- $callback = array($args ['connect_provider'], 'select');
- if (is_callable($callback)) {
- $params = compact('primary_name', 'primary_value', 'fieldname', 'valuename', 'paramvars');
- $result = call_user_func($callback, $dbh, $args, $this, $tablename, $primary_index, $params);
- break;
- }
- case '' :
- case 'mysql' :
- if ($primary_name !== null) {
- $sql = 'SELECT * FROM ' . $tablename . ' WHERE ' . $primary_name . '=? LIMIT 1';
- $paramvars = array($primary_value);
- } else {
- $sql = 'SELECT * FROM ' . $tablename . ' LIMIT 1';
- $paramvars = null;
- }
- $result = self::execute($sql, $paramvars);
- if ($result === false) {
- break;
- ;
- }
- if (mysql_num_rows($result) == 0) {
- mysql_free_result($result);
- $result = false;
- break;
- }
- $row = mysql_fetch_assoc($result);
- mysql_free_result($result);
- foreach ($row as $key => $value) {
- $this->$key = $value;
- }
- $result = true;
- break;
- }
- return $result;
- }
- /**
- * 实例插入函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/insert.php
- * @param string $tablename
- * @param mixed $primary_index
- * @return bool
- */
- public function insert($tablename = '', $primary_index = 0) {
- // 验证方法名
- if (!isset($this) || !($this instanceof self)) {
- trigger_error('Cannot find the correct object, try ' . __FUNCTION__ . 's method.', E_USER_ERROR);
- return;
- }
- // 【基础功能】插入实例数据
- $dbh = self::connect(true, $args, array('insert', $tablename, $primary_index));
- // 表名
- if (empty($tablename)) {
- $tablename = $args ['prefix_search'] . get_class($this);
- }
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $tablename = str_replace($args ['prefix_search'], $args ['prefix_replace'], $tablename);
- }
- // 字段
- $fieldvars = get_object_vars($this);
- $primary_name = null;
- if (is_int($primary_index) && $primary_index >= 0 && $primary_index < count($fieldvars)) {
- $field_index = 0;
- foreach ($fieldvars as $primary_name => $primary_value) {
- if ($primary_index === $field_index++) {
- unset($fieldvars [$primary_name]);
- break;
- }
- }
- } elseif (is_string($primary_index) && array_key_exists($primary_index, $fieldvars)) {
- $primary_name = $primary_index;
- $primary_value = $fieldvars [$primary_name];
- unset($fieldvars [$primary_name]);
- }
- // 分析
- $fieldname = implode(',', array_keys($fieldvars));
- $valuename = implode(',', array_fill(0, count($fieldvars), '?'));
- $paramvars = array_values($fieldvars);
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】插入实例数据
- default :
- $callback = array($args ['connect_provider'], 'insert');
- if (is_callable($callback)) {
- $params = compact('primary_name', 'primary_value', 'fieldname', 'valuename', 'paramvars');
- $result = call_user_func($callback, $dbh, $args, $this, $tablename, $primary_index, $params);
- break;
- }
- case '' :
- case 'mysql' :
- $sql = 'INSERT INTO ' . $tablename . ' (' . $fieldname . ') VALUES (' . $valuename . ')';
- if ($primary_name !== null) {
- $result = (bool) self::execute($sql, $paramvars, $ref);
- if ($result) {
- $this->$primary_name = $ref ['insert_id'];
- }
- } else {
- $result = (bool) self::execute($sql, $paramvars);
- }
- break;
- }
- return $result;
- }
- /**
- * 实例修改函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/update.php
- * @param string $tablename
- * @param mixed $primary_index
- * @return bool
- */
- public function update($tablename = '', $primary_index = 0) {
- // 验证方法名
- if (!isset($this) || !($this instanceof self)) {
- trigger_error('Cannot find the correct object, try ' . __FUNCTION__ . 's method.', E_USER_ERROR);
- return;
- }
- // 【基础功能】修改实例数据
- $dbh = self::connect(true, $args, array('update', $tablename, $primary_index));
- // 表名
- if (empty($tablename)) {
- $tablename = $args ['prefix_search'] . get_class($this);
- }
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $tablename = str_replace($args ['prefix_search'], $args ['prefix_replace'], $tablename);
- }
- // 字段
- $fieldvars = get_object_vars($this);
- $primary_name = null;
- if (is_int($primary_index) && $primary_index >= 0 && $primary_index < count($fieldvars)) {
- $field_index = 0;
- foreach ($fieldvars as $primary_name => $primary_value) {
- if ($primary_index === $field_index++) {
- unset($fieldvars [$primary_name]);
- break;
- }
- }
- } elseif (is_string($primary_index) && array_key_exists($primary_index, $fieldvars)) {
- $primary_name = $primary_index;
- $primary_value = $fieldvars [$primary_name];
- unset($fieldvars [$primary_name]);
- }
- // 分析
- $fieldname = array_keys($fieldvars);
- foreach ($fieldname as &$fieldname_value) {
- $fieldname_value = $fieldname_value . '=?';
- }
- $valuename = implode(',', $fieldname);
- $paramvars = array_values($fieldvars);
- if ($primary_name !== null) {
- array_push($paramvars, $primary_value);
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】修改实例数据
- default :
- $callback = array($args ['connect_provider'], 'update');
- if (is_callable($callback)) {
- $params = compact('primary_name', 'primary_value', 'fieldname', 'valuename', 'paramvars');
- $result = call_user_func($callback, $dbh, $args, $this, $tablename, $primary_index, $params);
- break;
- }
- case '' :
- case 'mysql' :
- if ($primary_name !== null) {
- $sql = 'UPDATE ' . $tablename . ' SET ' . $valuename . ' WHERE ' . $primary_name . '=? LIMIT 1';
- } else {
- $sql = 'UPDATE ' . $tablename . ' SET ' . $valuename . ' LIMIT 1';
- }
- $result = (bool) self::execute($sql, $paramvars, $ref);
- if ($result && $ref ['affected_rows'] == 0) {
- return false;
- }
- break;
- }
- return $result;
- }
- /**
- * 实例删除函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/delete.php
- * @param string $tablename
- * @param mixed $primary_index
- * @return bool
- */
- public function delete($tablename = '', $primary_index = 0) {
- // 验证方法名
- if (!isset($this) || !($this instanceof self)) {
- trigger_error('Cannot find the correct object, try ' . __FUNCTION__ . 's method.', E_USER_ERROR);
- return;
- }
- // 【基础功能】删除实例数据
- $dbh = self::connect(true, $args, array('delete', $tablename, $primary_index));
- // 表名
- if (empty($tablename)) {
- $tablename = $args ['prefix_search'] . get_class($this);
- }
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $tablename = str_replace($args ['prefix_search'], $args ['prefix_replace'], $tablename);
- }
- // 字段
- $fieldvars = get_object_vars($this);
- $primary_name = null;
- if (is_int($primary_index) && $primary_index >= 0 && $primary_index < count($fieldvars)) {
- $field_index = 0;
- foreach ($fieldvars as $primary_name => $primary_value) {
- if ($primary_index === $field_index++) {
- break;
- }
- }
- } elseif (is_string($primary_index) && array_key_exists($primary_index, $fieldvars)) {
- $primary_name = $primary_index;
- $primary_value = $fieldvars [$primary_name];
- }
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】删除实例数据
- default :
- $callback = array($args ['connect_provider'], 'delete');
- if (is_callable($callback)) {
- $params = compact('primary_name', 'primary_value', 'fieldname', 'valuename', 'paramvars');
- $result = call_user_func($callback, $dbh, $args, $this, $tablename, $primary_index, $params);
- break;
- }
- case '' :
- case 'mysql' :
- if ($primary_name !== null) {
- $sql = 'DELETE FROM ' . $tablename . ' WHERE ' . $primary_name . '=? LIMIT 1';
- $paramvars = array($primary_value);
- } else {
- $sql = 'DELETE FROM ' . $tablename . ' LIMIT 1';
- $paramvars = null;
- }
- $result = (bool) self::execute($sql, $paramvars, $ref);
- if ($result && $ref['affected_rows'] == 0) {
- $result = false;
- }
- break;
- }
- return $result;
- }
- /**
- * 实例更新函数(可继承)
- *
- * @link http://www.coremvc.cn/api/core/replace.php
- * @param string $tablename
- * @param mixed $primary_index
- * @return bool
- */
- public function replace($tablename = '', $primary_index = 0) {
- // 验证方法名
- if (!isset($this) || !($this instanceof self)) {
- trigger_error('Cannot find the correct object, try ' . __FUNCTION__ . 's method.', E_USER_ERROR);
- return;
- }
- // 【基础功能】更新实例数据
- $dbh = self::connect(true, $args, array('replace', $tablename, $primary_index));
- // 表名
- if (empty($tablename)) {
- $tablename = $args ['prefix_search'] . get_class($this);
- }
- if ($args ['prefix_search'] !== '' && $args ['prefix_search'] !== $args ['prefix_replace']) {
- $tablename = str_replace($args ['prefix_search'], $args ['prefix_replace'], $tablename);
- }
- // 字段
- $fieldvars = get_object_vars($this);
- $primary_name = null;
- if (is_int($primary_index) && $primary_index >= 0 && $primary_index < count($fieldvars)) {
- $field_index = 0;
- foreach ($fieldvars as $primary_name => $primary_value) {
- if ($primary_index === $field_index++) {
- break;
- }
- }
- } elseif (is_string($primary_index) && array_key_exists($primary_index, $fieldvars)) {
- $primary_name = $primary_index;
- $primary_value = $fieldvars [$primary_name];
- }
- // 分析
- $fieldname = implode(',', array_keys($fieldvars));
- $valuename = implode(',', array_fill(0, count($fieldvars), '?'));
- $paramvars = array_values($fieldvars);
- // 执行
- switch ($args ['connect_provider']) {
- // 【扩展功能】更新实例数据
- default :
- $callback = array($args ['connect_provider'], 'replace');
- if (is_callable($callback)) {
- $params = compact('primary_name', 'primary_value', 'fieldname', 'valuename', 'paramvars');
- $result = call_user_func($callback, $dbh, $args, $this, $tablename, $primary_index, $params);
- break;
- }
- case '' :
- case 'mysql' :
- $sql = 'REPLACE INTO ' . $tablename . ' (' . $fieldname . ') VALUES (' . $valuename . ')';
- if ($primary_name !== null) {
- $result = (bool) self::execute($sql, $paramvars, $ref);
- if ($result) {
- $this->$primary_name = $ref ['insert_id'];
- }
- } else {
- $result = (bool) self::execute($sql, $paramvars);
- }
- break;
- }
- return $result;
- }
- /**
- * 载入配置文件
- *
- * @param string $filename
- * @return array
- */
- private static function _init_file($filename) {
- if (strtolower(strrchr($filename, '.')) === '.php') {
- $filepath = self::_path_config($filename);
- if (is_file($filepath)) {
- $return = require $filepath;
- }
- }
- if (!isset($return) || !is_array($return)) {
- $return = array();
- }
- return $return;
- }
- /**
- * 载入配置文件
- *
- * @param string $varname
- * @return array
- */
- private static function _init_env($varname) {
- //导入配置文件
- static $static_htaccess;
- if ($static_htaccess === null) {
- $static_htaccess = array();
- if (!isset($_SERVER[__CLASS__ . '_config']) && !isset($_SERVER[__CLASS__ . '_connect']) && !isset($_SERVER[__CLASS__ . '_view']) && is_file('.htaccess')) {
- $content = file_get_contents('.htaccess');
- if (preg_match_all('/^\s*SetEnv\s+(.+?)\s+(.*?)\s*$/im', $content, $matches)) {
- $static_htaccess = array_combine($matches[1], $matches[2]);
- parse_str(http_build_query($static_htaccess), $array);
- $_SERVER = array_merge($_SERVER, $array);
- }
- }
- }
- //导入环境变量
- static $static_config = array();
- if (!isset($static_config [$varname])) {
- $static_config [$varname] = array();
- if (isset($_SERVER [__CLASS__ . '_' . $varname])) {
- $config = &$static_config [$varname];
- $config = $_SERVER [__CLASS__ . '_' . $varname];
- if (is_string($config) && $config !== '') {
- $config = self::_init_file($config);
- }
- if (!is_array($config)) {
- $config = array();
- }
- }
- }
- return $static_config [$varname];
- }
- /**
- * 类库载入功能
- *
- * @param array $array
- */
- private static function _init_extension($array) {
- // 数组参数处理
- $config = array(
- 'extension_enable' => isset($array ['extension_enable']) ? $array ['extension_enable'] : '',
- 'extension_path' => isset($array ['extension_path']) ? $array ['extension_path'] : '',
- 'extension_prepend' => isset($array ['extension_prepend']) ? $array ['extension_prepend'] : '',
- );
- // 扩展类库功能
- static $static_config = array(
- 'extension_enable' => '',
- 'extension_path' => '',
- 'extension_prepend' => '',
- );
- if ($static_config !== $config) {
- $extension_enable = $config ['extension_enable'];
- $extension_prepend = $config['extension_prepend'];
- // 类库功能启用
- if ($extension_enable) {
- $extension_path = rtrim(self::_path_extension(''), '/\\');
- $include_path_array = explode(PATH_SEPARATOR, get_include_path());
- if ($extension_prepend !== '') {
- if (in_array($extension_path, $include_path_array)) {
- $include_path_array = array_values(array_diff($include_path_array, array($extension_path)));
- }
- if ($extension_prepend) {
- array_unshift($include_path_array, $extension_path);
- } else {
- array_push($include_path_array, $extension_path);
- }
- set_include_path(implode(PATH_SEPARATOR, $include_path_array));
- } elseif (!in_array($extension_path, $include_path_array)) {
- array_push($include_path_array, $extension_path);
- set_include_path(implode(PATH_SEPARATOR, $include_path_array));
- }
- // 自动载入类库
- if (is_string($extension_enable) && $extension_enable !== '1') {
- $extension_array = explode(',', $extension_enable);
- foreach ($extension_array as $extension) {
- $extension_file = self::_path_extension(trim($extension) . '.php');
- if (is_file($extension_file)) {
- require_once $extension_file;
- }
- }
- }
- }
- $static_config = $config;
- }
- }
- /**
- * 自动载入功能
- *
- * @param array $array
- */
- private static function _init_autoload($array) {
- // 数组参数处理
- $config = array(
- 'autoload_enable' => isset($array ['autoload_enable']) ? $array ['autoload_enable'] : '',
- 'autoload_path' => isset($array ['autoload_path']) ? $array ['autoload_path'] : '',
- 'autoload_extensions' => isset($array ['autoload_extensions']) ? $array ['autoload_extensions'] : '',
- 'autoload_prepend' => isset($array ['autoload_prepend']) ? $array ['autoload_prepend'] : '',
- );
- // 自动载入功能
- static $static_config = array(
- 'autoload_enable' => '',
- 'autoload_path' => '',
- 'autoload_extensions' => '',
- 'autoload_prepend' => '',
- );
- static $static_last = array(
- 'autoload_path' => '',
- 'include_path' => '',
- 'autoload_extensions' => '',
- 'spl_autoload_extensions' => '',
- 'autoload_enable' => '',
- 'spl_autoload_functions' => '',
- 'autoload_realname' => '',
- );
- if ($static_config !== $config) {
- // 设置路径
- if ($static_config ['autoload_path'] !== $config ['autoload_path'] || $static_config ['autoload_prepend'] !== $config ['autoload_prepend']) {
- if (empty($static_last ['autoload_path'])) {
- $static_last ['include_path'] = get_include_path();
- }
- if (empty($config ['autoload_path'])) {
- set_include_path($static_last ['include_path']);
- } else {
- $autoload_realpath = self::path($config ['autoload_path']);
- if (empty($config ['autoload_prepend'])) {
- set_include_path($static_last ['include_path'] . PATH_SEPARATOR . $autoload_realpath);
- } else {
- set_include_path($autoload_realpath . PATH_SEPARATOR . $static_last ['include_path']);
- }
- }
- $static_last ['autoload_path'] = $config ['autoload_path'];
- }
- // 设置扩展名
- if ($static_config ['autoload_extensions'] !== $config ['autoload_extensions']) {
- if (empty($static_last ['autoload_extensions'])) {
- $static_last ['spl_autoload_extensions'] = spl_autoload_extensions();
- }
- if (empty($config ['autoload_extensions'])) {
- spl_autoload_extensions($static_last ['spl_autoload_extensions']);
- } else {
- spl_autoload_extensions($config ['autoload_extensions']);
- }
- $static_last ['autoload_extensions'] = $config ['autoload_extensions'];
- }
- // 设置自动载入
- if ($static_config ['autoload_enable'] !== $config ['autoload_enable'] || $static_config ['autoload_prepend'] !== $config ['autoload_prepend']) {
- if (empty($static_last ['autoload_enable'])) {
- $static_last ['spl_autoload_functions'] = spl_autoload_functions();
- }
- if (in_array($static_last ['autoload_realname'], (array) $static_last ['spl_autoload_functions'])) {
- spl_autoload_unregister($static_last ['autoload_realname']);
- }
- if (!empty($config ['autoload_enable'])) {
- if (is_callable($config ['autoload_enable'])) {
- $static_last ['autoload_realname'] = $config ['autoload_enable'];
- } else {
- $static_last ['autoload_realname'] = 'spl_autoload';
- }
- if ($static_last ['spl_autoload_functions'] === array('__autoload')) {
- spl_autoload_register('__autoload');
- }
- if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
- if (empty($config ['autoload_prepend'])) {
- spl_autoload_register($static_last ['autoload_realname'], true, false);
- } else {
- spl_autoload_register($static_last ['autoload_realname'], true, true);
- }
- } else {
- spl_autoload_register($static_last ['autoload_realname']);
- }
- }
- $static_last ['autoload_enable'] = $config ['autoload_enable'];
- }
- $static_config = $config;
- }
- }
- /**
- * 第一次自动载入
- *
- * @param array $array
- */
- private static function _stub_autoload($array) {
- static $static_config;
- if ($static_config === null || $array !== array()) {
- $static_config = $array;
- self::init($array);
- }
- }
- /**
- * 入口函数(可继承)
- *
- * @param array $array
- */
- private static function _main_hide($array) {
- $hide_info = isset($array ['hide_info']) ? $array ['hide_info'] : '';
- $hide_info_cli = isset($array ['hide_info_cli']) ? $array ['hide_info_cli'] : $hide_info;
- $hide_info_web = isset($array ['hide_info_web']) ? $array ['hide_info_web'] : $hide_info;
- if (PHP_SAPI == 'cli') {
- if (empty($hide_info_cli)) {
- echo ('Could not open input file: ' . basename($_SERVER ['SCRIPT_FILENAME']) . PHP_EOL);
- } elseif (is_callable($hide_info_cli)) {
- call_user_func($hide_info_cli);
- echo PHP_EOL;
- } else {
- echo $hide_info_cli . PHP_EOL;
- }
- } else {
- if (empty($hide_info_web)) {
- header('HTTP/1.0 404 Not Found');
- } elseif (is_callable($hide_info_web)) {
- call_user_func($hide_info_web);
- } elseif (filter_var($hide_info_web, FILTER_VALIDATE_URL)) {
- header('Location: ' . $hide_info_web);
- } else {
- header("Content-type:text/html;charset=UTF-8");
- echo $hide_info_web;
- }
- }
- }
- /**
- * 框架控制函数
- *
- * @param array $array
- * @param array $return_array
- * @return mixed
- */
- private static function _main_framework($array, $return_array) {
- // 1. 设置默认值、替换内置宏
- list ($classname_static, $debug_backtrace_file) = self::_main_framework_first();
- if (empty($array ['framework_require'])) {
- $require = '';
- } else {
- $require = $array ['framework_require'];
- if (strpos($require, '(self)') !== false) {
- $require = str_replace('(self)', __CLASS__, $require);
- }
- if (strpos($require, '(static)') !== false) {
- $require = str_replace('(static)', $classname_static, $require);
- }
- }
- if (empty($array ['framework_module'])) {
- $module = $classname_static . '!' . __CLASS__; //默认值:(static)!(self)
- } else {
- $module = $array ['framework_module'];
- if (strpos($module, '(self)') !== false) {
- $module = str_replace('(self)', __CLASS__, $module);
- }
- if (strpos($module, '(static)') !== false) {
- $module = str_replace('(static)', $classname_static, $module);
- }
- }
- if (empty($array ['framework_action'])) {
- $action = '[get:1]|index'; //默认值:[get:1]|index
- } else {
- $action = $array ['framework_action'];
- }
- $action_multi = is_array($action);
- if ($action_multi) {
- $action_array = &$action;
- $action_string = implode(' ', $action);
- } else {
- $action_array = array(&$action);
- $action_string = $action;
- }
- foreach ($action_array as &$action_value) {
- if (strpos($action_value, '(self)') !== false) {
- $action_value = str_replace('(self)', __CLASS__, $action_value);
- }
- if (strpos($action_value, '(static)') !== false) {
- $action_value = str_replace('(static)', $classname_static, $action_value);
- }
- }
- if (empty($array ['framework_parameter'])) {
- $parameter = '';
- } else {
- $parameter = $array ['framework_parameter'];
- }
- $parameter_multi = is_array($parameter);
- if ($parameter_multi) {
- $parameter_array = &$parameter;
- $parameter_string = implode(' ', $parameter);
- } else {
- $parameter_array = array(&$parameter);
- $parameter_string = $parameter;
- }
- foreach ($parameter_array as &$parameter_value) {
- if (strpos($parameter_value, '(self)') !== false) {
- $parameter_value = str_replace('(self)', __CLASS__, $parameter_value);
- }
- if (strpos($parameter_value, '(static)') !== false) {
- $parameter_value = str_replace('(static)', $classname_static, $parameter_value);
- }
- }
- // 2. 生成替换数组
- $value_array = array();
- $string = $require . ' ' . $module . ' ' . $action_string . ' ' . $parameter_string;
- if (stripos($string, '[get:') !== false) {
- $get_array = array_values($_GET) + $_GET;
- array_unshift($get_array, null);
- $value_array ['get'] = $get_array;
- }
- if (stripos($string, '[post:') !== false) {
- $post_array = array_values($_POST) + $_POST;
- array_unshift($post_array, null);
- $value_array ['post'] = $post_array;
- }
- if (stripos($string, '[query:') !== false) {
- $query_array = array();
- if (isset($_SERVER ['QUERY_STRING'])) {
- $query_string = $_SERVER['QUERY_STRING'];
- $query_array = explode('&', $query_string);
- array_unshift($query_array, $query_string);
- }
- $value_array ['query'] = $query_array;
- }
- if (stripos($string, '[path:') !== false) {
- $path_array = array();
- if (isset($_SERVER ['PATH_INFO'])) {
- $path_info = trim($_SERVER ['PATH_INFO'], '/');
- $path_array [] = $path_info;
- $tok = strtok($path_info, '/');
- while ($tok !== false) {
- $path_array [] = $tok;
- $tok = strtok('/');
- }
- }
- $path_array ['path'] = $path_array;
- $value_array ['path'] = $path_array;
- }
- if (stripos($string, '[file:') !== false) {
- $file_array = array();
- if ($debug_backtrace_file === null) {
- list (, $row) = debug_backtrace();
- $debug_backtrace_file = $row ['file'];
- }
- strtok($debug_backtrace_file, '/\\');
- while (($tok = strtok('/\\')) !== false) {
- array_unshift($file_array, $tok);
- }
- $file_array [0] = strtok($file_array [0], '.');
- array_unshift($file_array, strtok('.'));
- $value_array ['file'] = $file_array;
- }
- // 3. 生成返回数组
- $return4_array = array_values(array_intersect($return_array, array('require', 'module', 'action', 'parameter')));
- if (empty($return4_array)) {
- $return4_result = array();
- $return4_final = '';
- } else {
- $return4_result = array_flip($return4_array);
- if (isset($return4_result ['require'])) {
- $return4_result ['require'] = false;
- $return4_final = 'require';
- }
- if (isset($return4_result ['module'])) {
- $return4_result ['module'] = false;
- $return4_final = 'module';
- }
- if (isset($return4_result ['action'])) {
- $return4_result ['action'] = false;
- $return4_final = 'action';
- }
- if (isset($return4_result ['parameter'])) {
- $return4_result ['parameter'] = false;
- $return4_final = 'parameter';
- }
- }
- // 4. 处理引用部份
- $require_now = '';
- if ($require) {
- $result_array = self::_main_framework_resolve($require, $value_array, 'require');
- foreach ($result_array as $value) {
- $value_file = self::_path_file($value);
- if (is_file($value_file)) {
- $require_now = $value;
- $require_name = $value_file;
- break;
- }
- }
- if ($require_now === '') {
- if ($return4_final === '') {
- if (!in_array('manual', $return_array)) {
- self::_main_hide($array);
- }
- return false;
- } elseif (count($return4_array) === 1) {
- return false;
- } else {
- return array_values($return4_result);
- }
- }
- require_once $require_name;
- }
- if (isset($return4_result ['require'])) {
- $return4_result ['require'] = $require_now;
- }
- if ($return4_array === array('require')) {
- return $require_now;
- } elseif ($return4_final === 'require') {
- return array_values($return4_result);
- }
- // 5. 处理模块部份
- $module_now = '';
- $result_array = self::_main_framework_resolve($module, $value_array, 'module');
- foreach ($result_array as $value) {
- if (preg_match('/(^|\\\\)[0-9]/', $value) === 1) {
- continue;
- }
- try {
- if (!class_exists($value)) {
- continue;
- }
- } catch (Exception $e) {
- continue;
- }
- $class = new ReflectionClass($value);
- if ($class->isInternal() || $class->isAbstract() || $class->isInterface()) {
- continue;
- }
- $module_now = $value;
- break;
- }
- if ($module_now === '') {
- if ($return4_final === '') {
- if (!in_array('manual', $return_array)) {
- self::_main_hide($array);
- }
- return false;
- } elseif (count($return4_array) === 1) {
- return false;
- } else {
- return array_values($return4_result);
- }
- } else {
- if (isset($return4_result ['module'])) {
- $return4_result ['module'] = $module_now;
- }
- if ($return4_array === array('module')) {
- return $module_now;
- } elseif ($return4_final === 'module') {
- return array_values($return4_result);
- }
- }
- // 6. 处理动作部份
- if ($action_multi) {
- $action_now = array();
- } else {
- $action_now = false;
- }
- foreach ($action_array as $action_key => &$action_value) {
- $action_now2 = false;
- $action_extra = strncmp($action_value, '*|', 2) === 0;
- if ($action_extra) {
- $action_value2 = substr($action_value, 2);
- $action_now2 = '';
- } else {
- $action_value2 = $action_value;
- }
- $result_array = self::_main_framework_resolve($action_value2, $value_array, 'action', $module_now);
- foreach ($result_array as $value) {
- list ($module_new, $action_new) = $value;
- if ($module_new === '(function)') {
- if (!function_exists($action_new)) {
- continue;
- }
- $module_now2 = '';
- $action_now2 = $action_new;
- break;
- } else {
- if ($module_new !== $module_now) {
- if (preg_match('/(^|\\\\)[0-9]/', $module_new) === 1) {
- continue;
- }
- try {
- if (!class_exists($module_new)) {
- continue;
- }
- } catch (Exception $e) {
- continue;
- }
- $class = new ReflectionClass($module_new);
- if ($class->isAbstract() || $class->isInterface()) {
- continue;
- }
- if (!$action_extra && $class->isInternal()) {
- continue;
- }
- }
- if (!method_exists($module_new, $action_new)) {
- continue;
- }
- $method = new ReflectionMethod($module_new, $action_new);
- if (!$method->isPublic() || $method->isConstructor() || $method->isDestructor()) {
- continue;
- }
- if (!$action_extra && in_array('static', $return_array) && !in_array('object', $return_array)) {
- if (!$method->isStatic()) {
- continue;
- }
- } elseif (!$action_extra && in_array('object', $return_array) && !in_array('static', $return_array)) {
- if ($method->isStatic()) {
- continue;
- }
- }
- if (!$action_extra && in_array('final', $return_array)) {
- if (!$method->isFinal()) {
- continue;
- }
- }
- $module_now2 = $method->isStatic() ? $module_new : new $module_new;
- $action_now2 = $action_new;
- break;
- }
- }
- if ($action_now2 === false) {
- if (!$action_extra) {
- if ($action_multi) {
- $action_now = array();
- } else {
- $action_now = false;
- }
- break;
- }
- } elseif ($action_now2 === '') {
- if ($action_multi) {
- $action_now [$action_key] = '';
- } else {
- $action_now = '';
- }
- } else {
- if ($action_multi) {
- if ($module_now2 === '') {
- $action_now [$action_key] = $action_now2;
- } else {
- $action_now [$action_key] = array($module_now2, $action_now2);
- }
- } else {
- $module_now = $module_now2;
- $action_now = $action_now2;
- if (isset($return4_result ['module'])) {
- $return4_result ['module'] = $module_now;
- }
- }
- }
- }
- if ($action_now === false || $action === array()) {
- if ($return4_final === '') {
- if (!in_array('manual', $return_array)) {
- self::_main_hide($array);
- }
- return false;
- } elseif (count($return4_array) === 1) {
- return false;
- } else {
- return array_values($return4_result);
- }
- } else {
- if (isset($return4_result ['action'])) {
- $return4_result ['action'] = $action_now;
- }
- if ($return4_array === array('action')) {
- return $action_now;
- } elseif ($return4_final === 'action') {
- return array_values($return4_result);
- }
- }
- // 7. 处理参数部份
- $parameter_now = array();
- if ($action_multi) {
- foreach ($action_now as $action_key => &$action_value) {
- $parameter_now [$action_key] = array();
- if ($parameter && is_array($parameter) && isset($parameter [$action_key]) && $action_value !== '') {
- if (!is_array($action_value)) {
- $module_now3 = '';
- $action_now3 = $action_value;
- } elseif (is_object($action_value [0])) {
- $module_now3 = get_class($action_value [0]);
- $action_now3 = $action_value [1];
- } else {
- $module_now3 = $action_value [0];
- $action_now3 = $action_value [1];
- }
- $result_array = self::_main_framework_resolve($parameter [$action_key], $value_array, 'parameter', array($module_now3, $action_now3));
- foreach ($result_array as $value) {
- $parameter_now [$action_key] = array_slice($value, 2);
- break;
- }
- }
- }
- } else {
- if ($parameter && $action_now !== '') {
- $module_now3 = is_object($module_now) ? get_class($module_now) : $module_now;
- $action_now3 = $action_now;
- $result_array = self::_main_framework_resolve($parameter, $value_array, 'parameter', array($module_now3, $action_now3));
- foreach ($result_array as $value) {
- $parameter_now = array_slice($value, 2);
- break;
- }
- }
- }
- if (isset($return4_result ['parameter'])) {
- $return4_result ['parameter'] = $parameter_now;
- }
- if ($return4_array === array('parameter')) {
- return $parameter_now;
- } elseif ($return4_final === 'parameter') {
- return array_values($return4_result);
- }
- // 8. 执行
- if ($action_multi) {
- $return = array();
- foreach ($action_now as $action_key => &$action_value) {
- if ($action_value === '') {
- $return [$action_key] = null;
- } elseif ($action_value [0] === '') {
- $return [$action_key] = call_user_func_array($action_value [1], $parameter_now [$action_key]);
- } else {
- $return [$action_key] = call_user_func_array($action_value, $parameter_now [$action_key]);
- }
- }
- } else {
- // var_dump($action_now);
- // var_dump($module_now);
- // var_dump($parameter_now);
- if ($action_now === '') {
- $return = null;
- } elseif ($module_now === '') {
- $return = call_user_func_array($action_now, $parameter_now);
- } else {
- $return = call_user_func_array(array($module_now, $action_now), $parameter_now);
- }
- }
- if (in_array('return', $return_array)) {
- return $return;
- } else {
- return true;
- }
- }
- /**
- * 框架第一现场
- *
- * @param bool $bool
- * @return array
- */
- private static function _main_framework_first($bool = null) {
- static $class = null;
- static $file = null;
- if ($class === null) {
- if (function_exists('get_called_class')) {
- $class = get_called_class();
- } else {
- $class = '[file:1]';
- }
- }
- if ($bool && $file === null) {
- list (, $row) = debug_backtrace();
- $file = $row ['file'];
- }
- return array($class, $file);
- }
- /**
- * 框架规则解析
- *
- * @param string $string
- * @param array $value_array
- * @param string $flag
- * @param mixed $prefix
- * @return array
- */
- private static function _main_framework_resolve($string, $value_array, $flag, $prefix = null) {
- $result_array = array();
- $length = strlen($string);
- $last_pos = 0;
- $last_bracket = '|';
- $left_pos1 = 0;
- $left_pos2 = 0;
- $left_pos3 = 0;
- while (true) {
- // 寻找“或且非”截断的字符串
- if ($last_pos >= $length) {
- break;
- }
- $left_pos1 === false or $left_pos1 = strpos($string, '|', $last_pos);
- $left_pos2 === false or $left_pos2 = strpos($string, '&', $last_pos);
- $left_pos3 === false or $left_pos3 = strpos($string, '!', $last_pos);
- if ($left_pos1 === false && $left_pos2 === false && $left_pos3 === false) {
- $str = substr($string, $last_pos);
- $left_bracket = '';
- $last_pos = $length + 1;
- } else {
- $left_pos = false;
- if ($left_pos === false || $left_pos1 !== false && $left_pos1 < $left_pos) {
- $left_pos = $left_pos1;
- $left_bracket = '|';
- }
- if ($left_pos === false || $left_pos2 !== false && $left_pos2 < $left_pos) {
- $left_pos = $left_pos2;
- $left_bracket = '&';
- }
- if ($left_pos === false || $left_pos3 !== false && $left_pos3 < $left_pos) {
- $left_pos = $left_pos3;
- $left_bracket = '!';
- }
- $str = substr($string, $last_pos, $left_pos - $last_pos);
- if ($left_bracket === '') {
- break;
- }
- $last_pos = $left_pos + 1;
- }
- $deal_bracket = $last_bracket;
- $last_bracket = $left_bracket;
- if ($str === '') {
- continue;
- }
- if ($flag === 'parameter' && $deal_bracket === '|') {
- $arr = explode(',', $str);
- $str = $prefix;
- foreach ($arr as $value) {
- if (strpos($value, '(comma)') !== false) {
- $value = str_replace('(comma)', ',', $value);
- }
- if (strpos($value, '(module)') !== false) {
- $value = str_replace('(module)', $prefix[0], $value);
- }
- if (strpos($value, '(action)') !== false) {
- $value = str_replace('(action)', $prefix[1], $value);
- }
- if (strpos($value, '(open_paren)') !== false || strpos($value, '(close_paren)') !== false) {
- $value = str_replace(array('(open_paren)', '(close_paren)'), array('(', ')'), $value);
- }
- $str [] = self::_main_framework_replace($value, $value_array, false);
- }
- } else {
- $str = self::_main_framework_replace($str, $value_array, true);
- if ($str === false || $str === '') {
- continue;
- }
- }
- // 处理“或且非”截断的字符串
- switch ($deal_bracket) {
- case '|':
- // “或”的处理
- if ($flag === 'action') {
- if (strpos($str, '::') === false) {
- $result_array [] = array($prefix, $str);
- } else {
- list ($str1, $str2) = explode('::', $str);
- if ($str1 === '' || $str2 === '') {
- continue 2;
- }
- $result_array [] = array($str1, $str2);
- }
- } else {
- $result_array [] = $str;
- }
- break;
- case '&':
- // “且”的处理
- if ($flag === 'action' || $flag === 'parameter') {
- if (strpos($str, '::') === false) {
- $str1 = '';
- $str2 = $str;
- } else {
- list ($str1, $str2) = explode('::', $str);
- }
- $bool_reg1 = strpos($str1, '*') !== false;
- if ($bool_reg1) {
- $str1 = '/' . str_replace('\\*', '.*?', preg_quote($str1, '/')) . '/';
- }
- $bool_reg2 = strpos($str2, '*') !== false;
- if ($bool_reg2) {
- $str2 = '/' . str_replace('\\*', '.*?', preg_quote($str2, '/')) . '/';
- }
- $right_array = array();
- foreach ($result_array as $value) {
- if (($str1 === '' || $bool_reg1 && preg_match($str1, $value[0]) === 1 || $str1 === $value[0]) &&
- ($str2 === '' || $bool_reg2 && preg_match($str2, $value[1]) === 1 || $str2 === $value[1])) {
- $right_array [] = $value;
- }
- }
- $result_array = $right_array;
- } else {
- $bool_reg = strpos($str, '*') !== false;
- if ($bool_reg) {
- $str = '/' . str_replace('\\*', '.*?', preg_quote($str, '/')) . '/';
- }
- $right_array = array();
- foreach ($result_array as $value) {
- if ($bool_reg && preg_match($str, $value) === 1 || !$bool_reg && $str === $value) {
- $right_array [] = $value;
- }
- }
- $result_array = $right_array;
- }
- break;
- case '!':
- // “非”的处理
- if ($flag === 'action' || $flag === 'parameter') {
- if (strpos($str, '::') === false) {
- $str1 = '';
- $str2 = $str;
- } else {
- list ($str1, $str2) = explode('::', $str);
- }
- $bool_reg1 = strpos($str1, '*') !== false;
- if ($bool_reg1) {
- $str1 = '/' . str_replace('\\*', '.*?', preg_quote($str1, '/')) . '/';
- }
- $bool_reg2 = strpos($str2, '*') !== false;
- if ($bool_reg2) {
- $str2 = '/' . str_replace('\\*', '.*?', preg_quote($str2, '/')) . '/';
- }
- $right_array = array();
- foreach ($result_array as $value) {
- if ($str1 !== '' && ($bool_reg1 && preg_match($str1, $value[0]) !== 1 || !$bool_reg1 && $str1 !== $value[0]) ||
- $str2 !== '' && ($bool_reg2 && preg_match($str2, $value[1]) !== 1 || !$bool_reg2 && $str2 !== $value[1])) {
- $right_array [] = $value;
- }
- }
- $result_array = $right_array;
- } else {
- $bool_reg = strpos($str, '*') !== false;
- if ($bool_reg) {
- $str = '/' . str_replace('\\*', '.*?', preg_quote($str, '/')) . '/';
- }
- $right_array = array();
- foreach ($result_array as $value) {
- if ($bool_reg && preg_match($str, $value) !== 1 || !$bool_reg && $str !== $value) {
- $right_array [] = $value;
- }
- }
- $result_array = $right_array;
- }
- break;
- }
- }
- return $result_array;
- }
- /**
- * 框架字串替换
- *
- * @param string $string
- * @param array $value_array
- * @param bool $strict
- * @return array
- */
- private static function _main_framework_replace($string, $value_array, $strict) {
- $result = '';
- $length = strlen($string);
- $last_pos = 0;
- $left_pos1 = 0;
- $left_pos2 = 0;
- while (true) {
- // 寻找需要替换字串
- if ($last_pos >= $length) {
- break;
- }
- $left_pos1 === false or $left_pos1 = strpos($string, '[', $last_pos);
- $left_pos2 === false or $left_pos2 = strpos($string, '{', $last_pos);
- if ($left_pos1 === false && $left_pos2 === false) {
- $result .= substr($string, $last_pos);
- break;
- } elseif ($left_pos1 === false) {
- $left_pos = $left_pos2;
- $right_bracket = '}';
- } elseif ($left_pos2 === false) {
- $left_pos = $left_pos1;
- $right_bracket = ']';
- } elseif ($left_pos1 > $left_pos2) {
- $left_pos = $left_pos2;
- $right_bracket = '}';
- } else {
- $left_pos = $left_pos1;
- $right_bracket = ']';
- }
- $result .= substr($string, $last_pos, $left_pos - $last_pos);
- $last_pos = $left_pos + 1;
- $right_pos = strpos($string, $right_bracket, $last_pos);
- if ($right_pos === false) {
- return false;
- }
- $keyword = substr($string, $last_pos, $right_pos - $last_pos);
- if ($keyword === '') {
- continue;
- }
- $last_pos = $right_pos + 1;
- // 替换成POST值
- if ($right_bracket === '}') {
- if (isset($_POST [$keyword])) {
- $valueword = $_POST [$keyword];
- } else {
- if ($strict) {
- return false;
- }
- continue;
- }
- // 替换成GET值
- } elseif (strpos($keyword, ':') === false) {
- if (isset($_GET [$keyword])) {
- $valueword = $_GET [$keyword];
- } else {
- if ($strict) {
- return false;
- }
- continue;
- }
- // 替换成其他定义值
- } else {
- list ($key, $sub) = explode(':', $keyword);
- if ($key === '' || $sub === '') {
- continue;
- }
- $key_lower = strtolower($key);
- $key_upper = strtoupper($key);
- $key_ucfirst = ucfirst($key_lower);
- $key_lcfirst = $key_upper;
- if (strlen($key_lcfirst) > 0) {
- $key_lcfirst[0] = strtolower($key_lcfirst[0]);
- }
- switch ($key_lower) {
- case 'get':
- case 'post':
- case 'query':
- case 'path':
- case 'file':
- $valueword = isset($value_array [$key_lower] [$sub]) ? $value_array [$key_lower] [$sub] : '';
- break;
- default:
- $valueword = '';
- break;
- }
- switch ($key) {
- case $key_lower:
- break;
- case $key_upper:
- $valueword = strtoupper($valueword);
- break;
- case $key_ucfirst:
- $valueword = ucfirst(strtolower($valueword));
- break;
- case $key_lcfirst:
- $valueword = strtoupper($valueword);
- if (strlen($valueword) > 0) {
- $valueword[0] = strtolower($valueword[0]);
- }
- break;
- default:
- $valueword = strtolower($valueword);
- break;
- }
- }
- // 验证命名规则
- if ($strict && preg_match('/^[a-zA-Z0-9_\x7f-\xff]+$/', $valueword) !== 1) {
- return false;
- }
- $result .= $valueword;
- }
- return $result;
- }
- /**
- * 扩展转义路径
- *
- * @param string $filename
- * @return string
- */
- private static function _path_extension($filename) {
- $filepath = self::_path_file($filename);
- $extension_path = isset(self::$config ['extension_path']) ? self::$config ['extension_path'] : null;
- if ($filepath === null) {
- if (empty($extension_path)) {
- $filepath = dirname(__FILE__) . DIRECTORY_SEPARATOR . __CLASS__ . DIRECTORY_SEPARATOR . $filename;
- } elseif ($extension_path [0] === '@') {
- $filepath = dirname(__FILE__) . DIRECTORY_SEPARATOR . substr($extension_path, 1) . DIRECTORY_SEPARATOR . $filename;
- } else {
- $filepath = $extension_path . DIRECTORY_SEPARATOR . $filename;
- }
- }
- return $filepath;
- }
- /**
- * 模板转义路径
- *
- * @param string $filename
- * @return string
- */
- private static function _path_template($filename) {
- $filepath = self::_path_file($filename);
- $template_path = isset(self::$config ['template_path']) ? self::$config ['template_path'] : null;
- if ($filepath === null) {
- if (empty($template_path)) {
- $filepath = $filename;
- } elseif ($template_path [0] === '@') {
- $filepath = dirname(__FILE__) . DIRECTORY_SEPARATOR . substr($template_path, 1) . DIRECTORY_SEPARATOR . $filename;
- } else {
- $filepath = $template_path . DIRECTORY_SEPARATOR . $filename;
- }
- }
- return $filepath;
- }
- /**
- * 配置转义路径
- *
- * @param string $filename
- * @return string
- */
- private static function _path_config($filename) {
- $filepath = self::_path_file($filename);
- $config_path = isset(self::$config ['config_path']) ? self::$config ['config_path'] : null;
- if ($filepath === null) {
- if (empty($config_path)) {
- $filepath = $filename;
- } elseif ($config_path [0] === '@') {
- $filepath = dirname(__FILE__) . DIRECTORY_SEPARATOR . substr($config_path, 1) . DIRECTORY_SEPARATOR . $filename;
- } else {
- $filepath = $config_path . DIRECTORY_SEPARATOR . $filename;
- }
- }
- return $filepath;
- }
- /**
- * 文件转义路径
- *
- * @param string $filename
- * @return string
- */
- private static function _path_file($filename) {
- $first = strlen($filename) > 0 ? $filename[0] : '';
- if ($first === '@') {
- $filepath = dirname(__FILE__) . DIRECTORY_SEPARATOR . substr($filename, 1);
- } elseif ($first === '\\' || $first === '/' || strncmp($filename, './', 2) === 0 || strncmp($filename, '.\\', 2) === 0 || strpos($filename, ':') !== false) {
- $filepath = $filename;
- } else {
- $filepath = null;
- }
- return $filepath;
- }
- /**
- * 视图全局变量
- *
- * @param array $global
- */
- private static function _view_variable($global = null) {
- $variable = &self::$view;
- if (!is_array($variable)) {
- if (empty($variable)) {
- $variable = array();
- } else {
- $variable = self::_init_file($variable);
- if (!is_array($variable)) {
- $variable = array();
- }
- }
- $import_config = self::_init_env('view');
- if ($import_config !== array()) {
- $variable = array_merge($variable, $import_config);
- }
- }
- if (is_array($global)) {
- $variable = array_merge($variable, $global);
- }
- }
- }
- /**
- * 执行(execute)
- */
- core::stub() and core::main();
|