启动swoole服务
@param array $setting 自定义配置
@param string $yiiConfigFile Yii配置文件位置
483996
public function run($setting = [], $yiiConfigFile = false) {
        register_shutdown_function(array($this, 'handleFatal'));
        if (!$yiiConfigFile) {
            $yiiConfigFile = ROOT_DIR . '/config/main.php';
        }
        if (empty($this->config)) exit("Swoole AppServer 未加载任务配置\n");
        if (isset($this->config['setting']['log_file']) && substr($this->config['setting']['log_file'], 0, 1) != '/') {
            $this->config['setting']['log_file'] = ROOT_DIR . '/' . $this->config['setting']['log_file'];
        }
        $this->yiiConfigFile = $yiiConfigFile;
        if (!function_exists('cli_set_process_title')) {
            swoole_set_process_name($this->config['server']['base.process.name'] . 'Master');
        } else {
            cli_set_process_title($this->config['server']['base.process.name'] . 'Master');
        }
        if (!isset($this->config['setting']['worker_num'])) {
            //set worker thread number
            $cpuInfo = @file("/proc/cpuinfo");
            if (false !== $cpuInfo) {
                $cpuInfo = implode("", $cpuInfo);
                @preg_match_all("/model\\s+name\\s{0,}\\:+\\s{0,}([\\w\\s\\)\\(\\@.-]+)([\r\n]+)/s", $cpuInfo, $model);
                if (false !== is_array($model[1])) {
                    $this->config['setting']['worker_num'] = sizeof($model[1]);
                } else {
                    $this->config['setting']['worker_num'] = self::DEFAULT_WORKER_NUMBER;
                }
            } else {
                $this->config['setting']['worker_num'] = self::DEFAULT_WORKER_NUMBER;
            }
        }
        $this->set(array_merge($setting, $this->config['setting']));
        $this->on('ManagerStart', function () {
            if (!function_exists('cli_set_process_title')) {
                swoole_set_process_name($this->config['server']['base.process.name'] . 'Manager');
            } else {
                cli_set_process_title($this->config['server']['base.process.name'] . 'Manager');
            }
        });
        $logPath = dirname($this->config['setting']['log_file']);
        $this->on('Task', function ($serv, $task_id, $from_id, $data) use ($logPath) {

            $args = $data;
            $file = $logPath . DIRECTORY_SEPARATOR . date('Y-m-d') . '.access.log';
            if (!is_dir($logPath)) {
                mkdir($logPath, 0755, TRUE);
            }

            $content = date('Y-m-d H:i:s') . ' worker_id=' . $from_id . ': ';
            if (is_string($args)) {
                $content .= $args . "\n";
            } else {
                foreach ($args as $arg) {
                    $content .= print_r($arg, TRUE) . "\n";
                }
            }
            $fh = fopen($file, 'a+');
            if ($fh) {
                fwrite($fh, $content . "\r\n");
                fclose($fh);
            }
            unset($content);

        });
        $this->on('Finish', function ($serv, $task_id, $data) {
            unset($data);
        });
        $this->on('Start', array($this, 'onStart'));
        $this->on('WorkerStart', [$this, 'onWorkerStart']);
        $this->on('WorkerStop', array($this, 'onWorkerStop'));
        $this->on('WorkerError', array($this, 'onWorkerError'));
        $this->on('Shutdown', array($this, 'onShutdown'));
        $this->start();
    }
780036
public function initBySetting($model, $setting)
    {
        parent::initBySetting($model, $setting);
        if (is_array($setting)) {
            if (isset($setting['remote_class_type'])) {
                $this->remoteModelType = $setting['remote_class_type'];
            }
        }
    }
192341
public function setting($setting = []) {
		
		/*
		 * 指定某一个服务运行仅设置该服务下的配置
		 */
		if (false === empty($this->service) && true === isset($this->config[$this->service])) {
			$setting = $this->config[$this->service];
			unset($setting['host'], $setting['port'], $setting['mode'], $setting['socket']);
			parent::set($setting);
		} else {
			/*
			 * 设置所有配置信息
			 */
			foreach ($this->config as $key => $value) {
				unset($value['host'], $value['port'], $value['mode'], $value['socket']);
				$setting[$key] = $value;
				parent::set($setting[$key]);
			}
		}
		
	}
711864
public static function configure($configFile)
    {
        $configuration = include($configFile);
        if ($configuration === false) {
            throw new PropelException("Unable to open configuration file: " . var_export($configFile, true));
        }
        self::setConfiguration($configuration);
    }
535266
function loadSetting($ini_file)
    {
        if (!is_file($ini_file)) exit("Swoole AppServer配置文件错误($ini_file)\n");
        $config = parse_ini_file($ini_file, true);
        /*--------------Server------------------*/
        //开启http keepalive
        if (!empty($config['server']['keepalive']))
        {
            $this->keepalive = true;
        }
        //是否压缩
        if (!empty($config['server']['gzip_open']) and function_exists('gzdeflate'))
        {
            $this->gzip = true;
            //default level
            if (empty($config['server']['gzip_level']))
            {
                $config['server']['gzip_level'] = 1;
            }
            //level [1, 9]
            elseif ($config['server']['gzip_level'] > 9)
            {
                $config['server']['gzip_level'] = 9;
            }
        }
        //过期控制
        if (!empty($config['server']['expire_open']))
        {
            $this->expire = true;
            if (empty($config['server']['expire_time']))
            {
                $config['server']['expire_time'] = 1800;
            }
        }
        /*--------------Session------------------*/
        if (empty($config['session']['cookie_life'])) $config['session']['cookie_life'] = 86400; //保存SESSION_ID的cookie存活时间
        if (empty($config['session']['session_life'])) $config['session']['session_life'] = 1800; //Session在Cache中的存活时间
        if (empty($config['session']['cache_url'])) $config['session']['cache_url'] = 'file://localhost#sess'; //Session在Cache中的存活时间
        /*--------------Apps------------------*/
        if (empty($config['apps']['url_route'])) $config['apps']['url_route'] = 'url_route_default';
        if (empty($config['apps']['auto_reload'])) $config['apps']['auto_reload'] = 0;
        if (empty($config['apps']['charset'])) $config['apps']['charset'] = 'utf-8';

        if (!empty($config['access']['post_maxsize']))
        {
            $this->config['server']['post_maxsize'] = $config['access']['post_maxsize'];
        }
        if (empty($config['server']['post_maxsize']))
        {
            $config['server']['post_maxsize'] = self::POST_MAXSIZE;
        }
        /*--------------Access------------------*/
        $this->deny_dir = array_flip(explode(',', $config['access']['deny_dir']));
        $this->static_dir = array_flip(explode(',', $config['access']['static_dir']));
        $this->static_ext = array_flip(explode(',', $config['access']['static_ext']));
        $this->dynamic_ext = array_flip(explode(',', $config['access']['dynamic_ext']));
        /*--------------document_root------------*/
        if (empty($this->document_root) and !empty($config['server']['document_root']))
        {
            $this->document_root = $config['server']['document_root'];
        }
        /*-----merge----*/
        if (!is_array($this->config))
        {
            $this->config = array();
        }
        $this->config = array_merge($this->config, $config);
    }
15506
public function init() {

        parent::init();
        $this->registerTranslations();
        
        if(!$this->secure)
            $this->uploadAction = '/uploader/one-file/create';

        // set min & max file sizes
        if(is_null($this->minFileSize))
            $this->minFileSize = isset(\Yii::$app->params['fileSize']['min']) ? \Yii::$app->params['fileSize']['min'] : 0.01;
        if(is_null($this->maxFileSize))
            $this->maxFileSize = isset(\Yii::$app->params['fileSize']['max']) ? \Yii::$app->params['fileSize']['max'] : 2;

        // errors of the file uploading
        $this->errors['size'] = Yii::t('byone', 'File size can be from {minFileSize} to {maxFileSize}Mb', ['minFileSize' => $this->minFileSize, 'maxFileSize' => $this->maxFileSize]);
        $this->errors['type'] = Yii::t('byone', 'There is not right file type! Allowed types - {acceptFileTypes}.', ['acceptFileTypes' => $this->acceptFileTypes]);
        $this->errors['maxFiles'] = Yii::t('byone', 'Only {maxFiles} file(s) can be uploaded.', ['maxFiles' => $this->maxFiles]);

        // captions of the buttons and other strings that should be translated
        self::$defaults['choose']['label'] = Yii::t('byone', 'Photo');
        self::$defaults['choose']['caption'] = Yii::t('byone', 'Choose a file');
        self::$defaults['delete']['question'] = Yii::t('byone', 'Are you shure you want to delete this element?');
        self::$defaults['crop']['caption'] = Yii::t('byone', 'Upload');
        
        // set buttons by widget parameters or defaults
        foreach(self::$defaults as $name => $values) {
            foreach($values as $property => $value)
                if(!isset($this->btns[$name][$property]))
                    $this->btns[$name][$property] = $property == 'action' && !$this->secure 
                        ? str_replace('-secure', '', self::$defaults[$name][$property])
                        : self::$defaults[$name][$property];
        }
        
        // full path server side handlers
        $this->btns['delete']['action'] = Url::toRoute($this->btns['delete']['action']);
        $this->btns['save']['action'] = Url::toRoute($this->btns['save']['action']);
        $this->btns['crop']['action'] = Url::toRoute($this->btns['crop']['action']);
        $this->btns['swap']['action'] = Url::toRoute($this->btns['swap']['action']);
        
        $this->blueimp['url'] = Url::toRoute($this->uploadAction);
        
        $this->blueimp['minFileSize'] = $this->minFileSize;
        $this->blueimp['maxFileSize'] = $this->maxFileSize;
        
        // max files that can be uploaded
        $this->blueimp['maxFiles'] = $this->maxFiles;

        // if model name is not set, set it
        if(!isset($this->modelName))
            $this->modelName = get_class($this->model);
        // parent_id has to exist
        if(is_null($this->model->id))
            $this->model->id = false;
        if(is_null($this->parent_id))
            $this->parent_id = $this->model->id;
        if(is_null($this->subdir))
            $this->subdir = $this->model->id;
        // POST-type data for the handler
        $this->blueimp['formData'] = [
            'model' => $this->modelName,
            'parent_id' => $this->parent_id,
            'subdir' => $this->subdir,
            'cropAllowed' => ($this->cropAllowed ? 1 : 0),
        ];
        
        // min pixels for X and Y when cropping
        $minW = $this->model->getMin();
        $aspectRatio = $this->model->getAspectRatio();
        $minH = $minW * $aspectRatio;

        // send params to JavaScript environment
        $options = [
            'btns' => $this->btns,
            'barClass' => $this->barClass,
            'cropAllowed' => $this->cropAllowed,
            'minW' => $minW,
            'minH' => $minH,
            'aspectRatio' => $aspectRatio,
            'appendixView' => $this->appendixView,
            'acceptFileTypes' => $this->acceptFileTypes,
            'errors' => $this->errors,
        ];
        $this->view->registerJs(
            "editLine.options = " . json_encode($options) . ";", 
            View::POS_READY, 
            'editLineOptions'
        );
        
        // assets 
        BlueimpAsset::register($this->view);
        EditLineAsset::register($this->view);
        if($this->draggable) {
            JQueryUiAsset::register($this->view);
            DraggableAsset::register($this->view);
        }
        if($this->cropAllowed) 
            JcropAsset::register($this->view);
        // plugin
        $selector = $name = $this->blueimp['name'];
        $option = json_encode($this->blueimp);
        $script = "jQuery('#{$selector}').{$name}({$option});";
        $this->view->registerJs($script, View::POS_END, 'byone-plugin');
    }
388587
public static function registerIconFontSet($fontName, $forceCopyAssets = false)
    {
        if (!in_array($fontName, static::getAvailableIconFontSets())) {
            return false;
        }

        $fontPath = \Yii::getPathOfAlias('foundation.fonts.foundation_icons_' . $fontName);
        $fontUrl  = \Yii::app()->assetManager->publish($fontPath, true, -1, $forceCopyAssets);

        \Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons.css");

        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.0')) {
            \Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons_ie7.css");
        }
    }
1122833
public function initSettings(array $settings)
    {
        if (!isset($settings['tcp'])) {
            throw new \InvalidArgumentException('Tcp startup parameter is not configured，settings=' . \json_encode($settings));
        }

        if (!isset($settings['http'])) {
            throw new \InvalidArgumentException('HTTP startup parameters is not configured, settings=' . \json_encode($settings));
        }

        if (!isset($settings['server'])) {
            throw new \InvalidArgumentException('server startup parameters is not configured, settings=' . \json_encode($settings));
        }

        if (!isset($settings['setting'])) {
            throw new \InvalidArgumentException('"setting" parameters is not configured, settings=' . \json_encode($settings));
        }

        foreach ($settings['setting'] as $key => $value) {
            // path alias
            if ($value && \is_string($value) && $value[0] === '@') {
                $settings['setting'][$key] = App::getAlias($value);
            }
        }

        $this->setting = $settings['setting'];
        $this->tcpSetting = $settings['tcp'];
        $this->httpSetting = $settings['http'];
        $this->serverSetting = $settings['server'];

        // fix bug must to int
        if (isset($this->setting['task_ipc_mode'])) {
            $this->setting['task_ipc_mode'] = (int)$this->setting['task_ipc_mode'];
        }
        if (isset($this->setting['message_queue_key'])) {
            $this->setting['message_queue_key'] = (int)$this->setting['message_queue_key'];
        }
    }
728037
public function init()
    {
        $path = Yii::getAlias($this->configFile);
        if (file_exists($path)) {
            $config = (include($path));
            foreach ($config as $name => $closure) {
                if (is_array($closure)) {
                    $this->addElement($name, $closure[0], $closure[1]);
                } else {
                    $this->addElement($name, $closure);
                }
            }
        }
    }
410357
public static function set(string $category, string $setting, $value)
    {
        if (!isset(self::$settings[$category])) {
            self::$settings[$category] = [];
        }

        self::$settings[$category][$setting] = $value;
    }
1115475
public function reload($defaultSettingsFiles = array(), $userSettingsFile = null)
    {
        if (!empty($defaultSettingsFiles)
            || !empty($userSettingsFile)
        ) {
            $this->resetSettingsChain($defaultSettingsFiles, $userSettingsFile);
        }

        $reader = new IniReader();
        foreach ($this->settingsChain as $file => $ignore) {
            if (is_readable($file)) {
                try {
                    $contents = $reader->readFile($file);
                    $this->settingsChain[$file] = $this->decodeValues($contents);
                } catch (IniReadingException $ex) {
                    throw new IniReadingException('Unable to read INI file {' . $file . '}: ' . $ex->getMessage() . "\n Your host may have disabled parse_ini_file().");
                }

                $this->decodeValues($this->settingsChain[$file]);
            }
        }

        $merged = $this->mergeFileSettings();
        // remove reference to $this->settingsChain... otherwise dump() or compareElements() will never notice a difference
        // on PHP 7+ as they would be always equal
        $this->mergedSettings = $this->copy($merged);
    }
66668
public function setSettings(array $settings)
    {
        $this->settings = array_merge($this->settings, $settings);
        
        if (isset($settings['templates_path'])) {
            $this->view->templatesPath = $this->settings['templates_path'];
        }
        
        return $this;
    }
644243
public function initBySetting($model, $setting)
    {
        parent::initBySetting($model, $setting);
        if (is_array($setting)) {
            $setting = new \Stack\Util\ArrayObject($setting);
            $this->options = $setting->getAsArray('options');
            $this->allowNull = $setting->getAsBoolean('allowNull', TRUE);
        }
        if (!$this->allowNull && empty($this->options)) {
            throw new \Exception('No options defined for the selection attribute');
        }
    }
233228
public static function overload(array $settings)
    {
        if (!self::loaded()) return false;
        foreach ($settings as $var=>$val) {
            self::set($var, $val);
        }
    }
130589
public function setLinkDefaults(array $Settings = [])
    {
        if (isset($Settings["R"])) {
            $this->Default["LinkR"] = $Settings["R"];
        }
        if (isset($Settings["G"])) {
            $this->Default["LinkG"] = $Settings["G"];
        }
        if (isset($Settings["B"])) {
            $this->Default["LinkB"] = $Settings["B"];
        }
        if (isset($Settings["Alpha"])) {
            $this->Default["LinkAlpha"] = $Settings["Alpha"];
        }
    }
718812
function appendMIMETypeSetting( $settings )
    {
        $this->MIMETypeSettings[] = $settings;
        if ( !isset( $this->MIMETypeSettingsMap[$settings['mime_type']] ) )
            $this->MIMETypeSettingsMap[$settings['mime_type']] = array();
        $this->MIMETypeSettingsMap[$settings['mime_type']][] = $settings;
    }
1202293
public function init($ini) {
		/*
		 * 是否使用自定义配置
		 */
		$config = parse_ini_file(false === $ini ? __DIR__ . '/../etc/client.ini' : $ini, true);

		$config[$this->service] = array_merge($config['global'], $config[$this->service]);
		unset($config['global']);
		
		/*
		 * 设置运行模式与socket方式
		 */
		foreach ($config as $key => $value) {
			if (true === empty($value)) {
				continue 1;
			}
			if (self::SWOOLE_SOCKET_SYNC == $value['sync']) {
				$value['sync'] = SWOOLE_SOCK_SYNC;
			} else {
				$value['sync'] = SWOOLE_SOCK_ASYNC;
				$value['timeout'] = 0;
			}
			
			switch ($value['socket']) {
				case self::SWOOLE_SOCKET_TCP6:
					$value['socket'] = SWOOLE_TCP6;
					break;
				case self::SWOOLE_SOCKET_UDP:
					$value['socket'] = SWOOLE_UDP;
					break;
				case self::SWOOLE_SOCKET_UDP6:
					$value['socket'] = SWOOLE_UDP6;
					break;
				case self::SWOOLE_SOCKET_TCP:
				default:
					$value['socket'] = SWOOLE_TCP;
					break;
			}
			
			/*
			 * 设置连接的key
			 */
			if (self::SWOOLE_RANDOM_KEY == $value[$key . '.key']) {
				$value['key'] = uniqId(self::SWOOLE_KEY_PREFIX, true);
			} else {
				$value['key'] = $value['host'] . ':' . $value['port'];
			}
			
			/*
			 * 设置on off
			 */
			
			array_walk($value, function (& $item, $key) {
				$item = strtolower($item);
				if (self::SWOOLE_CONFIG_ON == $item) {
					$item = true;
				} else if (self::SWOOLE_CONFIG_OFF == $item) {
					$item = false;
				}
			});
			
			$this->config[$key] = $value;
		}
	}