$config = [
//others
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
],
//others
]
class yii\base\Application extends yii\base\Module
class yii\base\Module extends yii\di\ServiceLocator
class yii\di\ServiceLocator extends yii\base\Component
class yii\base\Component extends yii\base\Object
public function __construct($config = [])
{
Yii::$app = $this;
//將\yii\base\Application中的所有的屬性和方法交給Yii::$app->loadedModules數(shù)組中
static::setInstance($this);
$this->state = self::STATE_BEGIN;
//加載配置文件的框架信息 如:設(shè)置別名,設(shè)置框架路徑等等最為重要的是給加載默認(rèn)組件
$this->preInit($config);
//加載配置文件中的異常組件
$this->registerErrorHandler($config);
// 調(diào)用父類的 __construct。
// 由于Component類并沒(méi)有__construct函數(shù)
// 這里實(shí)際調(diào)用的是 `yii\base\Object__construct($config)`
Component::__construct($config);
}
Component::__construct($config) 會(huì)調(diào)用 yii\base\Object::__construct() 方法public function __construct($config = [])
{
if (!empty($config)) {
// 將配置文件里面的所有配置信息賦值給Object。
// 由于Object是大部分類的基類,
// 實(shí)際上也就是有配置信息賦值給了yii\web\Application的對(duì)象
Yii::configure($this, $config);
}
$this->init();
}
'components' => [ 'log' => [...]] 從哪來(lái),若不關(guān)心可以直接看 第二步。$this->preInit($config);,即 yii\base\Application::preInit(&$config)
public function preInit(&$config)
{
//others...
// merge core components with custom components
// 合并核心組件和自定義組件
foreach ($this->coreComponents() as $id => $component) {
if (!isset($config['components'][$id])) {
// 若自定義組件中沒(méi)有設(shè)置該核心組件配置信息,直接使用核心組件默認(rèn)配置
$config['components'][$id] = $component;
} elseif (is_array($config['components'][$id]) && !isset($config['components'][$id]['class'])) {
// 若自定義組件有設(shè)置該核心組件配置信息,但是沒(méi)有設(shè)置 'class'屬性,則添加該class屬性
$config['components'][$id]['class'] = $component['class'];
}
}
}
/**
* Returns the configuration of core application components.
* 返回核心應(yīng)用組件的配置
* @see set()
*/
public function coreComponents()
{
return [
// 日志分配器組件
'log' => ['class' => 'yii\log\Dispatcher'],
//others...
];
}
$this->preInit($config);, 我們得到的 $config
$config = [
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
],
'components' => [
'log' => [
'class' => 'yii\\log\\Dispatcher',
],
//others...
]
//others...
]
'components' => [ 'log' => [...]] 從哪來(lái)yii\base\Object::__construct($config = []) 中的 Yii::configure($this, $config);
public static function configure($object, $properties)
{
// 只是遍歷配置信息,賦值給當(dāng)前對(duì)象
foreach ($properties as $name => $value) {
$object->$name = $value;
}
return $object;
}
yii\base\Object::__set($name, $value)
/**
* 為實(shí)例不存在的屬性賦值時(shí)調(diào)用
*
* Do not call this method directly as it is a PHP magic method that
* will be implicitly called when executing `$object->property = $value;`.
* 這個(gè)是PHP的魔術(shù)方法,會(huì)在執(zhí)行 `$object->property = $value;` 的時(shí)候自動(dòng)調(diào)用。
*/
public function __set($name, $value)
{
// setter函數(shù)的函數(shù)名
// 由于php中方法名稱不區(qū)分大小寫,所以setproperty() 等價(jià)于 setProperty()
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
// 調(diào)用setter函數(shù)
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
// 如果只有g(shù)etter沒(méi)有setter 則為只讀屬性
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
當(dāng)前情景下的 $object 我們可以認(rèn)為是 yii\base\Application 的對(duì)象 $app
$app->modules = [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
]
這里會(huì)調(diào)用 yii\base\Module::setModules($modules) 方法
public function setModules($modules)
{
foreach ($modules as $id => $module) {
$this->_modules[$id] = $module;
}
}
這樣便有了問(wèn)題中的
private "_modules" (yiibasemodule)=>
array (size=3)
'backend' =>....
'debug' =>...
'gii'=>...
$app->components = [
'log' => [
'class' => 'yii\\log\\Dispatcher',
],
]
yii\di\ServiceLocator::setComponents($components) 方法public function setComponents($components)
{
foreach ($components as $id => $component) {
$this->set($id, $component);
}
}
public function set($id, $definition)
{
// others ...
if (is_object($definition) || is_callable($definition, true)) {
// an object, a class name, or a PHP callable
$this->_definitions[$id] = $definition;
} elseif (is_array($definition)) {
// 定義如果是個(gè)數(shù)組,要確保數(shù)組中具有 class 元素
// a configuration array
if (isset($definition['class'])) {
// 定義的過(guò)程,只是寫入了 $_definitions 數(shù)組
$this->_definitions[$id] = $definition;
} else {
throw new InvalidConfigException("The configuration for the \"$id\" component must contain a \"class\" element.");
}
} else {
throw new InvalidConfigException("Unexpected configuration type for the \"$id\" component: " . gettype($definition));
}
}
這樣便有了問(wèn)題中的
private "_definitions"(yiidiservicelocator)=>
array (size=7)
...
'log'=>...
...dns劫持, 打電話給運(yùn)營(yíng)商舉報(bào)ip
使用下面的 python 腳本,你可以輕松實(shí)現(xiàn)多開(kāi)
# -*- coding: utf-8 -*-
'''
同時(shí)運(yùn)行多個(gè)進(jìn)程,用法:
python3 xx.py <進(jìn)程數(shù)量> <進(jìn)程啟動(dòng)參數(shù)>
@author: 李毅
'''
import asyncio
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, REMAINDER
async def single(wid, cmd):
p = await asyncio.create_subprocess_exec(*cmd)
print('#{} pid={} 已經(jīng)啟動(dòng)'.format(wid, p.pid))
await p.communicate()
print('#{} pid={}, 代碼={} 已經(jīng)結(jié)束'.format(wid, p.pid, p.returncode))
async def main(loop, args):
if not args.worker or not len(args.cmd):
return
ps = [single(i, args.cmd) for i in range(args.worker)]
return await asyncio.gather(*ps)
if __name__ == '__main__':
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('worker', type=int, help='進(jìn)程數(shù)')
parser.add_argument('cmd', nargs=REMAINDER, help='命令參數(shù),例如: "sleep 30"')
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop, parser.parse_args()))
舉例:同時(shí)開(kāi)啟 10 個(gè) ping -c4 baidu.com 進(jìn)程
python3 a.py 3 ping -c4 baidu.com
輸出如下
PING baidu.com (123.125.115.110) 56(84) bytes of data.
#1 pid=137 已經(jīng)啟動(dòng)
#2 pid=138 已經(jīng)啟動(dòng)
#0 pid=139 已經(jīng)啟動(dòng)
PING baidu.com (220.181.57.216) 56(84) bytes of data.
PING baidu.com (123.125.115.110) 56(84) bytes of data.
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=52 time=38.0 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=1 ttl=55 time=36.3 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=52 time=38.0 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=52 time=37.9 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=2 ttl=55 time=36.2 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=52 time=37.6 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=52 time=37.9 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=3 ttl=55 time=36.1 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=52 time=37.8 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=4 ttl=52 time=37.9 ms
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 37.916/37.955/38.024/0.199 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=4 ttl=55 time=36.1 ms
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 36.113/36.218/36.374/0.254 ms
#1 pid=137, 代碼=0 已經(jīng)結(jié)束
#2 pid=138, 代碼=0 已經(jīng)結(jié)束
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=4 ttl=52 time=37.7 ms
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 37.647/37.818/38.060/0.249 ms
#0 pid=139, 代碼=0 已經(jīng)結(jié)束首先說(shuō)明一下你的標(biāo)題和函數(shù)功能不符,應(yīng)該是:
如何高效把
order.user.name解析為$data['order']['user']['name']
下面的代碼較為
惡心,看看就好,謹(jǐn)慎使用,謹(jǐn)慎使用,謹(jǐn)慎使用
/**
* @param $str
* @param $data
* @return null|mixed
* @throws Exception
*/
function parse($str, &$data)
{
$str = trim($str);
if (empty($str)) {
throw new \Exception("str is empty");
}
$fields= explode('.', $str);
switch (count($fields)) {
case 1:
return $data[$fields[0]] ?? null;
case 2:
return $data[$fields[0]][$fields[1]] ?? null;
case 3:
return $data[$fields[0]][$fields[1]][$fields[2]] ?? null;
case 4:
return $data[$fields[0]][$fields[1]][$fields[2]][$fields[3]] ?? null;
case 5:
return $data[$fields[0]][$fields[1]][$fields[2]][$fields[3]][$fields[4]] ?? null;
case 6:
return $data[$fields[0]][$fields[1]][$fields[2]][$fields[3]][$fields[4]][$fields[5]] ?? null;
default;
// 大仙你的數(shù)組超過(guò)6級(jí)了,是不是考慮優(yōu)化一下代碼 ^_^
throw new \Exception("str key too long");
}
}skip32
laravel 跳轉(zhuǎn)頁(yè)面 應(yīng)該調(diào)用 url route 之類的方法,指向到頁(yè)面對(duì)應(yīng)的路由。類似于
<a href="{{url('/home')}}" class="logo">
/home 路由指向在路由文件定義,指向你的 xxx.blade.php視圖文件。
這個(gè)問(wèn)題我讀書的時(shí)候遇到過(guò):https://www.cnblogs.com/iamzh...
樓主可以看下我當(dāng)時(shí)寫的這個(gè)博客
xx int(11) not null unsigned default 0 comment 'xxx',
tp是thinkphp的簡(jiǎn)寫,你如果覺(jué)得安裝php麻煩,去下載集成包,如wamp,xampp,phpstudy等。
這錯(cuò)誤不是很明顯嗎?
需要先安裝這兩個(gè):libpng和libz
你可以select md5(id) as id查出來(lái)就是id了
一樓說(shuō)的情況針對(duì)同一個(gè)庫(kù)里面可以這樣搞,二樓說(shuō)的我想應(yīng)該可以滿足你的需求。通過(guò)數(shù)據(jù)庫(kù)中間件來(lái)實(shí)現(xiàn)
讀取的時(shí)候再設(shè)一次編碼就行了
建議全部轉(zhuǎn)為utf8mb4編碼。
ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;那是連接查詢的的連接條件啊,怎么能去掉呢?除非你不用連接查詢
Docker的四種網(wǎng)絡(luò)模式:
當(dāng)Docker進(jìn)程啟動(dòng)時(shí),會(huì)在主機(jī)上創(chuàng)建一個(gè)名為docker0的虛擬網(wǎng)橋,此主機(jī)上啟動(dòng)的Docker容器會(huì)連接到這個(gè)虛擬網(wǎng)橋上。虛擬網(wǎng)橋的工作方式和物理交換機(jī)類似,這樣主機(jī)上的所有容器就通過(guò)交換機(jī)連在了一個(gè)二層網(wǎng)絡(luò)中。
從docker0子網(wǎng)中分配一個(gè)IP給容器使用,并設(shè)置docker0的IP地址為容器的默認(rèn)網(wǎng)關(guān)。在主機(jī)上創(chuàng)建一對(duì)虛擬網(wǎng)卡veth pair設(shè)備,Docker將veth pair設(shè)備的一端放在新創(chuàng)建的容器中,并命名為eth0(容器的網(wǎng)卡),另一端放在主機(jī)中,以vethxxx這樣類似的名字命名,并將這個(gè)網(wǎng)絡(luò)設(shè)備加入到docker0網(wǎng)橋中??梢酝ㄟ^(guò)brctl show命令查看。
bridge模式是docker的默認(rèn)網(wǎng)絡(luò)模式,不寫--net參數(shù),就是bridge模式。使用docker run -p時(shí),docker實(shí)際是在iptables做了DNAT規(guī)則,實(shí)現(xiàn)端口轉(zhuǎn)發(fā)功能??梢允褂胕ptables -t nat -vnL查看。
bridge模式如下圖所示:
如果啟動(dòng)容器的時(shí)候使用host模式,那么這個(gè)容器將不會(huì)獲得一個(gè)獨(dú)立的Network Namespace,而是和宿主機(jī)共用一個(gè)Network Namespace。容器將不會(huì)虛擬出自己的網(wǎng)卡,配置自己的IP等,而是使用宿主機(jī)的IP和端口。但是,容器的其他方面,如文件系統(tǒng)、進(jìn)程列表等還是和宿主機(jī)隔離的。
Host模式如下圖所示:
這個(gè)模式指定新創(chuàng)建的容器和已經(jīng)存在的一個(gè)容器共享一個(gè) Network Namespace,而不是和宿主機(jī)共享。新創(chuàng)建的容器不會(huì)創(chuàng)建自己的網(wǎng)卡,配置自己的 IP,而是和一個(gè)指定的容器共享 IP、端口范圍等。同樣,兩個(gè)容器除了網(wǎng)絡(luò)方面,其他的如文件系統(tǒng)、進(jìn)程列表等還是隔離的。兩個(gè)容器的進(jìn)程可以通過(guò) lo 網(wǎng)卡設(shè)備通信。
Container模式示意圖:
使用none模式,Docker容器擁有自己的Network Namespace,但是,并不為Docker容器進(jìn)行任何網(wǎng)絡(luò)配置。也就是說(shuō),這個(gè)Docker容器沒(méi)有網(wǎng)卡、IP、路由等信息。需要我們自己為Docker容器添加網(wǎng)卡、配置IP等。
Node模式示意圖:
更多請(qǐng)自行閱讀: http://www.a-site.cn/article/...
babel 沒(méi)有配置好吧
域名解析改下
因?yàn)?code>getTrace()返回的是函數(shù)調(diào)用堆棧,實(shí)例二沒(méi)有函數(shù)調(diào)用,所以返回空數(shù)組。
不嫌麻煩的話,可以用php-stacktrace查看函數(shù)調(diào)用堆棧。試過(guò)了,php-stacktrace在catch里是看不到test()的,產(chǎn)生異常的時(shí)候就記錄了堆棧,然后就unwind 了。
一般等一會(huì)就好了,這是網(wǎng)站在部署新主題。
如果等十幾分鐘還進(jìn)不去,進(jìn)服務(wù)器重置一下主題就好了
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
北大課工場(chǎng)是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國(guó)家深化產(chǎn)教融合/校企合作的政策,積極推進(jìn)“中國(guó)制造2025”,實(shí)現(xiàn)中華民族偉大復(fù)興的升級(jí)產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國(guó)職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開(kāi)發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_(kāi)發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開(kāi)發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開(kāi)發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開(kāi)發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。