repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
yiimaker/yii2-email-templates | src/gii/Generator.php | Generator.init | public function init()
{
parent::init();
if ($this->migrationName === null) {
$this->migrationName = 'm' . \gmdate('ymd_His') . '_add_email_template';
}
$this->hint = 'All tokens wrapped in {} will be replaced by real data';
} | php | public function init()
{
parent::init();
if ($this->migrationName === null) {
$this->migrationName = 'm' . \gmdate('ymd_His') . '_add_email_template';
}
$this->hint = 'All tokens wrapped in {} will be replaced by real data';
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"migrationName",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"migrationName",
"=",
"'m'",
".",
"\\",
"gmdate",
"(",
"'ymd_His'",
")",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/yiimaker/yii2-email-templates/blob/0dbb8611ecbea503ffaa7f0c5166b78afa0a06c8/src/gii/Generator.php#L54-L63 |
yiimaker/yii2-email-templates | src/gii/Generator.php | Generator.generate | public function generate()
{
$params = [
'key' => $this->key,
'subject' => $this->subject,
'body' => $this->body,
'hint' => $this->hint,
];
$templateFile = new CodeFile(
$this->getMigrationAlias(),
$this->render('email-template.php', $params)
);
return [$templateFile];
} | php | public function generate()
{
$params = [
'key' => $this->key,
'subject' => $this->subject,
'body' => $this->body,
'hint' => $this->hint,
];
$templateFile = new CodeFile(
$this->getMigrationAlias(),
$this->render('email-template.php', $params)
);
return [$templateFile];
} | [
"public",
"function",
"generate",
"(",
")",
"{",
"$",
"params",
"=",
"[",
"'key'",
"=>",
"$",
"this",
"->",
"key",
",",
"'subject'",
"=>",
"$",
"this",
"->",
"subject",
",",
"'body'",
"=>",
"$",
"this",
"->",
"body",
",",
"'hint'",
"=>",
"$",
"this... | {@inheritdoc} | [
"{"
] | train | https://github.com/yiimaker/yii2-email-templates/blob/0dbb8611ecbea503ffaa7f0c5166b78afa0a06c8/src/gii/Generator.php#L117-L132 |
yiimaker/yii2-email-templates | src/components/TemplateManager.php | TemplateManager.getTemplate | public function getTemplate($key, $language = null, $default = null)
{
/* @var EmailTemplate $template */
$template = $this->repository->getByKeyWithTranslation(
$key,
$language ?: Yii::$app->language
);
return empty($template->translations[0])
? $default
: EmailTemplate::buildFromEntity($template->translations[0]);
} | php | public function getTemplate($key, $language = null, $default = null)
{
/* @var EmailTemplate $template */
$template = $this->repository->getByKeyWithTranslation(
$key,
$language ?: Yii::$app->language
);
return empty($template->translations[0])
? $default
: EmailTemplate::buildFromEntity($template->translations[0]);
} | [
"public",
"function",
"getTemplate",
"(",
"$",
"key",
",",
"$",
"language",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"/* @var EmailTemplate $template */",
"$",
"template",
"=",
"$",
"this",
"->",
"repository",
"->",
"getByKeyWithTranslation",
"... | Returns template model by key and language.
@see EmailTemplateModel
@param string $key
@param null|string $language Template language.
@param mixed $default Default value.
@return null|EmailTemplate | [
"Returns",
"template",
"model",
"by",
"key",
"and",
"language",
"."
] | train | https://github.com/yiimaker/yii2-email-templates/blob/0dbb8611ecbea503ffaa7f0c5166b78afa0a06c8/src/components/TemplateManager.php#L49-L60 |
yiimaker/yii2-email-templates | src/components/TemplateManager.php | TemplateManager.getAllTemplates | public function getAllTemplates($key, $default = null)
{
$templates = $this->repository->getAll($key);
return null === $templates ? $default : EmailTemplate::buildMultiply($templates);
} | php | public function getAllTemplates($key, $default = null)
{
$templates = $this->repository->getAll($key);
return null === $templates ? $default : EmailTemplate::buildMultiply($templates);
} | [
"public",
"function",
"getAllTemplates",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"templates",
"=",
"$",
"this",
"->",
"repository",
"->",
"getAll",
"(",
"$",
"key",
")",
";",
"return",
"null",
"===",
"$",
"templates",
"?",
"... | Returns email template on all languages.
@param string $key
@param mixed $default Default value.
@return null|EmailTemplate[] | [
"Returns",
"email",
"template",
"on",
"all",
"languages",
"."
] | train | https://github.com/yiimaker/yii2-email-templates/blob/0dbb8611ecbea503ffaa7f0c5166b78afa0a06c8/src/components/TemplateManager.php#L70-L75 |
yiimaker/yii2-email-templates | src/entities/EmailTemplateTranslation.php | EmailTemplateTranslation.attributeLabels | public function attributeLabels()
{
$labels = [
'subject' => Yii::t('email-templates/entity', 'Subject'),
'body' => Yii::t('email-templates/entity', 'Body'),
'hint' => Yii::t('email-templates/entity', 'Hint'),
];
foreach ($labels as $key => $label) {
$labels[$key] = $this->addLabelPostfix($label);
}
return $labels;
} | php | public function attributeLabels()
{
$labels = [
'subject' => Yii::t('email-templates/entity', 'Subject'),
'body' => Yii::t('email-templates/entity', 'Body'),
'hint' => Yii::t('email-templates/entity', 'Hint'),
];
foreach ($labels as $key => $label) {
$labels[$key] = $this->addLabelPostfix($label);
}
return $labels;
} | [
"public",
"function",
"attributeLabels",
"(",
")",
"{",
"$",
"labels",
"=",
"[",
"'subject'",
"=>",
"Yii",
"::",
"t",
"(",
"'email-templates/entity'",
",",
"'Subject'",
")",
",",
"'body'",
"=>",
"Yii",
"::",
"t",
"(",
"'email-templates/entity'",
",",
"'Body'... | {@inheritdoc} | [
"{"
] | train | https://github.com/yiimaker/yii2-email-templates/blob/0dbb8611ecbea503ffaa7f0c5166b78afa0a06c8/src/entities/EmailTemplateTranslation.php#L88-L101 |
yiimaker/yii2-email-templates | src/behaviors/EmailTemplateBehavior.php | EmailTemplateBehavior.fetchEmailTemplate | public function fetchEmailTemplate()
{
if (null !== $this->owner) {
$this->_template = $this->_repository->getByKeyWithTranslation(
$this->generateKey(),
$this->owner->{$this->_languageAttribute}
);
} else {
$this->_template = $this->_repository->create();
}
} | php | public function fetchEmailTemplate()
{
if (null !== $this->owner) {
$this->_template = $this->_repository->getByKeyWithTranslation(
$this->generateKey(),
$this->owner->{$this->_languageAttribute}
);
} else {
$this->_template = $this->_repository->create();
}
} | [
"public",
"function",
"fetchEmailTemplate",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"owner",
")",
"{",
"$",
"this",
"->",
"_template",
"=",
"$",
"this",
"->",
"_repository",
"->",
"getByKeyWithTranslation",
"(",
"$",
"this",
"->",
"ge... | Fetch email template from database. | [
"Fetch",
"email",
"template",
"from",
"database",
"."
] | train | https://github.com/yiimaker/yii2-email-templates/blob/0dbb8611ecbea503ffaa7f0c5166b78afa0a06c8/src/behaviors/EmailTemplateBehavior.php#L148-L158 |
yiimaker/yii2-email-templates | src/behaviors/EmailTemplateBehavior.php | EmailTemplateBehavior.saveEmailTemplate | public function saveEmailTemplate()
{
if (null === $this->_template->key) {
$this->_template->key = $this->generateKey();
}
$this->_repository->save($this->_template);
} | php | public function saveEmailTemplate()
{
if (null === $this->_template->key) {
$this->_template->key = $this->generateKey();
}
$this->_repository->save($this->_template);
} | [
"public",
"function",
"saveEmailTemplate",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"_template",
"->",
"key",
")",
"{",
"$",
"this",
"->",
"_template",
"->",
"key",
"=",
"$",
"this",
"->",
"generateKey",
"(",
")",
";",
"}",
"$",
... | Save email template to database. | [
"Save",
"email",
"template",
"to",
"database",
"."
] | train | https://github.com/yiimaker/yii2-email-templates/blob/0dbb8611ecbea503ffaa7f0c5166b78afa0a06c8/src/behaviors/EmailTemplateBehavior.php#L163-L170 |
yiimaker/yii2-email-templates | src/behaviors/EmailTemplateBehavior.php | EmailTemplateBehavior.generateKey | protected function generateKey()
{
return Json::encode([
'model' => \get_class($this->owner),
'id' => $this->owner->getPrimaryKey(),
'key' => $this->_key,
]);
} | php | protected function generateKey()
{
return Json::encode([
'model' => \get_class($this->owner),
'id' => $this->owner->getPrimaryKey(),
'key' => $this->_key,
]);
} | [
"protected",
"function",
"generateKey",
"(",
")",
"{",
"return",
"Json",
"::",
"encode",
"(",
"[",
"'model'",
"=>",
"\\",
"get_class",
"(",
"$",
"this",
"->",
"owner",
")",
",",
"'id'",
"=>",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",... | Generates key for email template.
@return string | [
"Generates",
"key",
"for",
"email",
"template",
"."
] | train | https://github.com/yiimaker/yii2-email-templates/blob/0dbb8611ecbea503ffaa7f0c5166b78afa0a06c8/src/behaviors/EmailTemplateBehavior.php#L185-L192 |
swoft-cloud/swoft-framework | src/Core/ErrorHandler.php | ErrorHandler.handle | public function handle(\Throwable $throwable)
{
try {
$response = $this->doHandler($throwable);
} catch (\Throwable $e) {
$response = $this->handleThrowtable($e);
}
return $response;
} | php | public function handle(\Throwable $throwable)
{
try {
$response = $this->doHandler($throwable);
} catch (\Throwable $e) {
$response = $this->handleThrowtable($e);
}
return $response;
} | [
"public",
"function",
"handle",
"(",
"\\",
"Throwable",
"$",
"throwable",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"doHandler",
"(",
"$",
"throwable",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"r... | handle exception
@param \Throwable $throwable
@return \Swoft\Http\Message\Server\Response | [
"handle",
"exception"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/ErrorHandler.php#L33-L42 |
swoft-cloud/swoft-framework | src/Core/ErrorHandler.php | ErrorHandler.doHandler | public function doHandler(\Throwable $throwable)
{
$exceptionClass = get_class($throwable);
$collector = ExceptionHandlerCollector::getCollector();
$isNotExistHandler = !isset($collector[$exceptionClass]) && !isset($collector[\Exception::class]);
if (empty($collector) || $isNotExistHandler) {
return $this->handleThrowtable($throwable);
}
if(isset($collector[$exceptionClass])){
list($classBeanName, $methodName) = $collector[$exceptionClass];
}else{
list($classBeanName, $methodName) = $collector[\Exception::class];
}
$handler = App::getBean($classBeanName);
$bindParams = $this->getBindParams($classBeanName, $methodName, $throwable);
$response = PhpHelper::call([$handler, $methodName], $bindParams);
if ($response instanceof ResponseInterface) {
return $response;
}
throw new \Exception("the handler of exception must be return the object of response!");
} | php | public function doHandler(\Throwable $throwable)
{
$exceptionClass = get_class($throwable);
$collector = ExceptionHandlerCollector::getCollector();
$isNotExistHandler = !isset($collector[$exceptionClass]) && !isset($collector[\Exception::class]);
if (empty($collector) || $isNotExistHandler) {
return $this->handleThrowtable($throwable);
}
if(isset($collector[$exceptionClass])){
list($classBeanName, $methodName) = $collector[$exceptionClass];
}else{
list($classBeanName, $methodName) = $collector[\Exception::class];
}
$handler = App::getBean($classBeanName);
$bindParams = $this->getBindParams($classBeanName, $methodName, $throwable);
$response = PhpHelper::call([$handler, $methodName], $bindParams);
if ($response instanceof ResponseInterface) {
return $response;
}
throw new \Exception("the handler of exception must be return the object of response!");
} | [
"public",
"function",
"doHandler",
"(",
"\\",
"Throwable",
"$",
"throwable",
")",
"{",
"$",
"exceptionClass",
"=",
"get_class",
"(",
"$",
"throwable",
")",
";",
"$",
"collector",
"=",
"ExceptionHandlerCollector",
"::",
"getCollector",
"(",
")",
";",
"$",
"is... | do handler
@param \Throwable $throwable
@return mixed|\Swoft\Http\Message\Server\Response
@throws \Exception | [
"do",
"handler"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/ErrorHandler.php#L52-L75 |
swoft-cloud/swoft-framework | src/Core/ErrorHandler.php | ErrorHandler.handleThrowtable | private function handleThrowtable(\Throwable $throwable)
{
$message = sprintf("%s %s %d", $throwable->getFile(), $throwable->getMessage(), $throwable->getLine());
/* @var \Swoft\Http\Message\Server\Response $response */
$response = RequestContext::getResponse();
$response = $response->json([$message]);
return $response;
} | php | private function handleThrowtable(\Throwable $throwable)
{
$message = sprintf("%s %s %d", $throwable->getFile(), $throwable->getMessage(), $throwable->getLine());
/* @var \Swoft\Http\Message\Server\Response $response */
$response = RequestContext::getResponse();
$response = $response->json([$message]);
return $response;
} | [
"private",
"function",
"handleThrowtable",
"(",
"\\",
"Throwable",
"$",
"throwable",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"\"%s %s %d\"",
",",
"$",
"throwable",
"->",
"getFile",
"(",
")",
",",
"$",
"throwable",
"->",
"getMessage",
"(",
")",
",",
... | handler throwable
@param \Throwable $throwable
@return \Swoft\Http\Message\Server\Response | [
"handler",
"throwable"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/ErrorHandler.php#L84-L93 |
swoft-cloud/swoft-framework | src/Core/ErrorHandler.php | ErrorHandler.getBindParams | private function getBindParams(string $className, string $methodName, \Throwable $throwable)
{
$reflectClass = new \ReflectionClass($className);
$reflectMethod = $reflectClass->getMethod($methodName);
$reflectParams = $reflectMethod->getParameters();
$response = RequestContext::getResponse();
$request = RequestContext::getRequest();
// binding params
$bindParams = [];
foreach ($reflectParams as $key => $reflectParam) {
$reflectType = $reflectParam->getType();
// undefined type of the param
if ($reflectType === null) {
$bindParams[$key] = null;
continue;
}
/**
* defined type of the param
* @notice \ReflectType::getName() is not supported in PHP 7.0, that is why use __toString()
*/
$type = $reflectType->__toString();
if ($type === Request::class) {
$bindParams[$key] = $request;
} elseif ($type == Response::class) {
$bindParams[$key] = $response;
} elseif ($type == \Throwable::class) {
$bindParams[$key] = $throwable;
} else {
$bindParams[$key] = null;
}
}
return $bindParams;
} | php | private function getBindParams(string $className, string $methodName, \Throwable $throwable)
{
$reflectClass = new \ReflectionClass($className);
$reflectMethod = $reflectClass->getMethod($methodName);
$reflectParams = $reflectMethod->getParameters();
$response = RequestContext::getResponse();
$request = RequestContext::getRequest();
// binding params
$bindParams = [];
foreach ($reflectParams as $key => $reflectParam) {
$reflectType = $reflectParam->getType();
// undefined type of the param
if ($reflectType === null) {
$bindParams[$key] = null;
continue;
}
/**
* defined type of the param
* @notice \ReflectType::getName() is not supported in PHP 7.0, that is why use __toString()
*/
$type = $reflectType->__toString();
if ($type === Request::class) {
$bindParams[$key] = $request;
} elseif ($type == Response::class) {
$bindParams[$key] = $response;
} elseif ($type == \Throwable::class) {
$bindParams[$key] = $throwable;
} else {
$bindParams[$key] = null;
}
}
return $bindParams;
} | [
"private",
"function",
"getBindParams",
"(",
"string",
"$",
"className",
",",
"string",
"$",
"methodName",
",",
"\\",
"Throwable",
"$",
"throwable",
")",
"{",
"$",
"reflectClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"... | get binded params
@param string $className
@param string $methodName
@param \Throwable $throwable
@return array | [
"get",
"binded",
"params"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/ErrorHandler.php#L104-L140 |
swoft-cloud/swoft-framework | src/Bean/Parser/ValueParser.php | ValueParser.parser | public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
{
$injectValue = $objectAnnotation->getName();
$envValue = $objectAnnotation->getEnv();
if (empty($injectValue) && empty($envValue)) {
throw new \InvalidArgumentException("the name and env of @Value can't be empty! class={$className} property={$propertyName}");
}
$isRef = false;
$injectProperty = null;
if (!empty($injectValue)) {
list($injectProperty, $isRef) = $this->annotationResource->getTransferProperty($injectValue);
}
if (!empty($envValue)) {
$value = $this->getEnvValue($envValue);
$isArray = $this->isEnvArrayValue($className, $propertyName);
$value = $this->getTransferEnvValue($value, $isArray);
$injectProperty = ($value !== null) ? $value : $injectProperty;
$isRef = ($value !== null) ? false : $isRef;
}
return [$injectProperty, $isRef];
} | php | public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
{
$injectValue = $objectAnnotation->getName();
$envValue = $objectAnnotation->getEnv();
if (empty($injectValue) && empty($envValue)) {
throw new \InvalidArgumentException("the name and env of @Value can't be empty! class={$className} property={$propertyName}");
}
$isRef = false;
$injectProperty = null;
if (!empty($injectValue)) {
list($injectProperty, $isRef) = $this->annotationResource->getTransferProperty($injectValue);
}
if (!empty($envValue)) {
$value = $this->getEnvValue($envValue);
$isArray = $this->isEnvArrayValue($className, $propertyName);
$value = $this->getTransferEnvValue($value, $isArray);
$injectProperty = ($value !== null) ? $value : $injectProperty;
$isRef = ($value !== null) ? false : $isRef;
}
return [$injectProperty, $isRef];
} | [
"public",
"function",
"parser",
"(",
"string",
"$",
"className",
",",
"$",
"objectAnnotation",
"=",
"null",
",",
"string",
"$",
"propertyName",
"=",
"\"\"",
",",
"string",
"$",
"methodName",
"=",
"\"\"",
",",
"$",
"propertyValue",
"=",
"null",
")",
"{",
... | Inject注解解析
@param string $className
@param Value $objectAnnotation
@param string $propertyName
@param string $methodName
@param null $propertyValue
@return array | [
"Inject注解解析"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Parser/ValueParser.php#L29-L52 |
swoft-cloud/swoft-framework | src/Bean/Parser/ValueParser.php | ValueParser.getTransferEnvValue | private function getTransferEnvValue($value, bool $isArray)
{
if ($value === null) {
return null;
}
if ($isArray == false) {
return $value;
}
if (empty($value)) {
$value = [];
} else {
$value = explode(",", $value);
}
return $value;
} | php | private function getTransferEnvValue($value, bool $isArray)
{
if ($value === null) {
return null;
}
if ($isArray == false) {
return $value;
}
if (empty($value)) {
$value = [];
} else {
$value = explode(",", $value);
}
return $value;
} | [
"private",
"function",
"getTransferEnvValue",
"(",
"$",
"value",
",",
"bool",
"$",
"isArray",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"isArray",
"==",
"false",
")",
"{",
"return",
"$",
... | transfer the value of env
@param mixed $value
@param bool $isArray
@return mixed | [
"transfer",
"the",
"value",
"of",
"env"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Parser/ValueParser.php#L62-L79 |
swoft-cloud/swoft-framework | src/Bean/Parser/ValueParser.php | ValueParser.isEnvArrayValue | private function isEnvArrayValue(string $className, string $propertyName)
{
$rc = new \ReflectionClass($className);
$rp = $rc->getProperty($propertyName);
$doc = $rp->getDocComment();
$tags = DocumentHelper::tagList($doc);
if (isset($tags['var']) && $tags['var'] == 'array') {
return true;
}
return false;
} | php | private function isEnvArrayValue(string $className, string $propertyName)
{
$rc = new \ReflectionClass($className);
$rp = $rc->getProperty($propertyName);
$doc = $rp->getDocComment();
$tags = DocumentHelper::tagList($doc);
if (isset($tags['var']) && $tags['var'] == 'array') {
return true;
}
return false;
} | [
"private",
"function",
"isEnvArrayValue",
"(",
"string",
"$",
"className",
",",
"string",
"$",
"propertyName",
")",
"{",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"rp",
"=",
"$",
"rc",
"->",
"getProperty",
"(",... | whether the value of env is array
@param string $className
@param string $propertyName
@return bool | [
"whether",
"the",
"value",
"of",
"env",
"is",
"array"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Parser/ValueParser.php#L89-L100 |
swoft-cloud/swoft-framework | src/Bean/Parser/ValueParser.php | ValueParser.getEnvValue | private function getEnvValue(string $envValue)
{
$value = $envValue;
if (preg_match('/^\$\{(.*)\}$/', $envValue, $match)) {
$value = env($match[1]);
}
return $value;
} | php | private function getEnvValue(string $envValue)
{
$value = $envValue;
if (preg_match('/^\$\{(.*)\}$/', $envValue, $match)) {
$value = env($match[1]);
}
return $value;
} | [
"private",
"function",
"getEnvValue",
"(",
"string",
"$",
"envValue",
")",
"{",
"$",
"value",
"=",
"$",
"envValue",
";",
"if",
"(",
"preg_match",
"(",
"'/^\\$\\{(.*)\\}$/'",
",",
"$",
"envValue",
",",
"$",
"match",
")",
")",
"{",
"$",
"value",
"=",
"en... | match env value
@param string $envValue
@return mixed|string | [
"match",
"env",
"value"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Parser/ValueParser.php#L109-L117 |
swoft-cloud/swoft-framework | src/Log/FileHandler.php | FileHandler.handleBatch | public function handleBatch(array $records)
{
$records = $this->recordFilter($records);
if (empty($records)) {
return true;
}
$lines = array_column($records, 'formatted');
$this->write($lines);
} | php | public function handleBatch(array $records)
{
$records = $this->recordFilter($records);
if (empty($records)) {
return true;
}
$lines = array_column($records, 'formatted');
$this->write($lines);
} | [
"public",
"function",
"handleBatch",
"(",
"array",
"$",
"records",
")",
"{",
"$",
"records",
"=",
"$",
"this",
"->",
"recordFilter",
"(",
"$",
"records",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"records",
")",
")",
"{",
"return",
"true",
";",
"}",
... | 批量输出日志
@param array $records 日志记录集合
@return bool | [
"批量输出日志"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/FileHandler.php#L38-L48 |
swoft-cloud/swoft-framework | src/Log/FileHandler.php | FileHandler.write | protected function write(array $records)
{
// 参数
$this->createDir();
$logFile = App::getAlias($this->logFile);
$messageText = implode("\n", $records) . "\n";
if (App::isCoContext()) {
// 协程写
$this->coWrite($logFile, $messageText);
} else {
$this->syncWrite($logFile, $messageText);
}
} | php | protected function write(array $records)
{
// 参数
$this->createDir();
$logFile = App::getAlias($this->logFile);
$messageText = implode("\n", $records) . "\n";
if (App::isCoContext()) {
// 协程写
$this->coWrite($logFile, $messageText);
} else {
$this->syncWrite($logFile, $messageText);
}
} | [
"protected",
"function",
"write",
"(",
"array",
"$",
"records",
")",
"{",
"// 参数",
"$",
"this",
"->",
"createDir",
"(",
")",
";",
"$",
"logFile",
"=",
"App",
"::",
"getAlias",
"(",
"$",
"this",
"->",
"logFile",
")",
";",
"$",
"messageText",
"=",
"imp... | 输出到文件
@param array $records 日志记录集合 | [
"输出到文件"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/FileHandler.php#L55-L68 |
swoft-cloud/swoft-framework | src/Log/FileHandler.php | FileHandler.recordFilter | private function recordFilter(array $records)
{
$messages = [];
foreach ($records as $record) {
if (!isset($record['level'])) {
continue;
}
if (!$this->isHandling($record)) {
continue;
}
$record = $this->processRecord($record);
$record['formatted'] = $this->getFormatter()->format($record);
$messages[] = $record;
}
return $messages;
} | php | private function recordFilter(array $records)
{
$messages = [];
foreach ($records as $record) {
if (!isset($record['level'])) {
continue;
}
if (!$this->isHandling($record)) {
continue;
}
$record = $this->processRecord($record);
$record['formatted'] = $this->getFormatter()->format($record);
$messages[] = $record;
}
return $messages;
} | [
"private",
"function",
"recordFilter",
"(",
"array",
"$",
"records",
")",
"{",
"$",
"messages",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"record",
"[",
"'level'",
"]",
")"... | 记录过滤器
@param array $records 日志记录集合
@return array | [
"记录过滤器"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/FileHandler.php#L111-L128 |
swoft-cloud/swoft-framework | src/Log/FileHandler.php | FileHandler.createDir | private function createDir()
{
$logFile = App::getAlias($this->logFile);
$dir = dirname($logFile);
if ($dir !== null && !is_dir($dir)) {
$status = mkdir($dir, 0777, true);
if ($status === false) {
throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: ', $dir));
}
}
} | php | private function createDir()
{
$logFile = App::getAlias($this->logFile);
$dir = dirname($logFile);
if ($dir !== null && !is_dir($dir)) {
$status = mkdir($dir, 0777, true);
if ($status === false) {
throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: ', $dir));
}
}
} | [
"private",
"function",
"createDir",
"(",
")",
"{",
"$",
"logFile",
"=",
"App",
"::",
"getAlias",
"(",
"$",
"this",
"->",
"logFile",
")",
";",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"logFile",
")",
";",
"if",
"(",
"$",
"dir",
"!==",
"null",
"&&",
"... | 创建目录 | [
"创建目录"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/FileHandler.php#L133-L143 |
swoft-cloud/swoft-framework | src/Log/FileHandler.php | FileHandler.isHandling | public function isHandling(array $record)
{
if (empty($this->levels)) {
return true;
}
return in_array($record['level'], $this->levels);
} | php | public function isHandling(array $record)
{
if (empty($this->levels)) {
return true;
}
return in_array($record['level'], $this->levels);
} | [
"public",
"function",
"isHandling",
"(",
"array",
"$",
"record",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"levels",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"in_array",
"(",
"$",
"record",
"[",
"'level'",
"]",
",",
"$",
"th... | check是否输出日志
@param array $record
@return bool | [
"check是否输出日志"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/FileHandler.php#L152-L159 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.doWrapper | public function doWrapper(string $className, array $annotations)
{
$reflectionClass = new \ReflectionClass($className);
// 解析类级别的注解
$beanDefinition = $this->parseClassAnnotations($className, $annotations['class']);
// 没配置注入bean注解
if (empty($beanDefinition) && !$reflectionClass->isInterface()) {
// 解析属性
$properties = $reflectionClass->getProperties();
// 解析属性
$propertyAnnotations = $annotations['property']??[];
$this->parseProperties($propertyAnnotations, $properties, $className);
// 解析方法
$publicMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
$methodAnnotations = $annotations['method'] ??[];
$this->parseMethods($methodAnnotations, $className, $publicMethods);
return null;
}
// parser bean annotation
list($beanName, $scope, $ref) = $beanDefinition;
// 初始化对象
$objectDefinition = new ObjectDefinition();
$objectDefinition->setName($beanName);
$objectDefinition->setClassName($className);
$objectDefinition->setScope($scope);
$objectDefinition->setRef($ref);
if (!$reflectionClass->isInterface()) {
// 解析属性
$properties = $reflectionClass->getProperties();
// 解析属性
$propertyAnnotations = $annotations['property']??[];
$propertyInjections = $this->parseProperties($propertyAnnotations, $properties, $className);
$objectDefinition->setPropertyInjections($propertyInjections);
}
// 解析方法
$publicMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
$methodAnnotations = $annotations['method'] ??[];
$this->parseMethods($methodAnnotations, $className, $publicMethods);
return [$beanName, $objectDefinition];
} | php | public function doWrapper(string $className, array $annotations)
{
$reflectionClass = new \ReflectionClass($className);
// 解析类级别的注解
$beanDefinition = $this->parseClassAnnotations($className, $annotations['class']);
// 没配置注入bean注解
if (empty($beanDefinition) && !$reflectionClass->isInterface()) {
// 解析属性
$properties = $reflectionClass->getProperties();
// 解析属性
$propertyAnnotations = $annotations['property']??[];
$this->parseProperties($propertyAnnotations, $properties, $className);
// 解析方法
$publicMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
$methodAnnotations = $annotations['method'] ??[];
$this->parseMethods($methodAnnotations, $className, $publicMethods);
return null;
}
// parser bean annotation
list($beanName, $scope, $ref) = $beanDefinition;
// 初始化对象
$objectDefinition = new ObjectDefinition();
$objectDefinition->setName($beanName);
$objectDefinition->setClassName($className);
$objectDefinition->setScope($scope);
$objectDefinition->setRef($ref);
if (!$reflectionClass->isInterface()) {
// 解析属性
$properties = $reflectionClass->getProperties();
// 解析属性
$propertyAnnotations = $annotations['property']??[];
$propertyInjections = $this->parseProperties($propertyAnnotations, $properties, $className);
$objectDefinition->setPropertyInjections($propertyInjections);
}
// 解析方法
$publicMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
$methodAnnotations = $annotations['method'] ??[];
$this->parseMethods($methodAnnotations, $className, $publicMethods);
return [$beanName, $objectDefinition];
} | [
"public",
"function",
"doWrapper",
"(",
"string",
"$",
"className",
",",
"array",
"$",
"annotations",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"// 解析类级别的注解",
"$",
"beanDefinition",
"=",
"$",
"thi... | 封装注解
@param string $className
@param array $annotations
@return array|null | [
"封装注解"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L69-L121 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.parseProperties | private function parseProperties(array $propertyAnnotations, array $properties, string $className)
{
$propertyInjections = [];
/* @var \ReflectionProperty $property */
foreach ($properties as $property) {
if ($property->isStatic()) {
continue;
}
$propertyName = $property->getName();
if (!isset($propertyAnnotations[$propertyName]) || !$this->isParseProperty($propertyAnnotations[$propertyName])) {
continue;
}
$object = new $className();
$property->setAccessible(true);
$propertyValue = $property->getValue($object);
list($injectProperty, $isRef) = $this->parsePropertyAnnotations($propertyAnnotations, $className, $propertyName, $propertyValue);
if ($injectProperty == null) {
continue;
}
$propertyInjection = new PropertyInjection($propertyName, $injectProperty, (bool)$isRef);
$propertyInjections[$propertyName] = $propertyInjection;
}
return $propertyInjections;
} | php | private function parseProperties(array $propertyAnnotations, array $properties, string $className)
{
$propertyInjections = [];
/* @var \ReflectionProperty $property */
foreach ($properties as $property) {
if ($property->isStatic()) {
continue;
}
$propertyName = $property->getName();
if (!isset($propertyAnnotations[$propertyName]) || !$this->isParseProperty($propertyAnnotations[$propertyName])) {
continue;
}
$object = new $className();
$property->setAccessible(true);
$propertyValue = $property->getValue($object);
list($injectProperty, $isRef) = $this->parsePropertyAnnotations($propertyAnnotations, $className, $propertyName, $propertyValue);
if ($injectProperty == null) {
continue;
}
$propertyInjection = new PropertyInjection($propertyName, $injectProperty, (bool)$isRef);
$propertyInjections[$propertyName] = $propertyInjection;
}
return $propertyInjections;
} | [
"private",
"function",
"parseProperties",
"(",
"array",
"$",
"propertyAnnotations",
",",
"array",
"$",
"properties",
",",
"string",
"$",
"className",
")",
"{",
"$",
"propertyInjections",
"=",
"[",
"]",
";",
"/* @var \\ReflectionProperty $property */",
"foreach",
"("... | 解析属性
@param array $propertyAnnotations
@param array $properties
@param string $className
@return array | [
"解析属性"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L132-L160 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.parseMethods | private function parseMethods(array $methodAnnotations, string $className, array $publicMethods)
{
// 循环解析
foreach ($publicMethods as $method) {
/* @var \ReflectionMethod $method*/
if ($method->isStatic()) {
continue;
}
/* @var \ReflectionClass $declaredClass*/
$declaredClass = $method->getDeclaringClass();
$declaredName = $declaredClass->getName();
// 不是当前类方法
if ($declaredName != $className) {
continue;
}
$this->parseMethodAnnotations($className, $method, $methodAnnotations);
}
} | php | private function parseMethods(array $methodAnnotations, string $className, array $publicMethods)
{
// 循环解析
foreach ($publicMethods as $method) {
/* @var \ReflectionMethod $method*/
if ($method->isStatic()) {
continue;
}
/* @var \ReflectionClass $declaredClass*/
$declaredClass = $method->getDeclaringClass();
$declaredName = $declaredClass->getName();
// 不是当前类方法
if ($declaredName != $className) {
continue;
}
$this->parseMethodAnnotations($className, $method, $methodAnnotations);
}
} | [
"private",
"function",
"parseMethods",
"(",
"array",
"$",
"methodAnnotations",
",",
"string",
"$",
"className",
",",
"array",
"$",
"publicMethods",
")",
"{",
"// 循环解析",
"foreach",
"(",
"$",
"publicMethods",
"as",
"$",
"method",
")",
"{",
"/* @var \\ReflectionMet... | 解析方法
@param array $methodAnnotations
@param string $className
@param array $publicMethods | [
"解析方法"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L169-L188 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.parseMethodAnnotations | private function parseMethodAnnotations(string $className, \ReflectionMethod $method, array $methodAnnotations)
{
// 方法没有注解解析
$methodName = $method->getName();
$isWithoutMethodAnnotation = empty($methodAnnotations) || !isset($methodAnnotations[$methodName]);
if ($isWithoutMethodAnnotation || !$this->isParseMethod($methodAnnotations[$methodName])) {
$this->parseMethodWithoutAnnotation($className, $methodName);
return;
}
// 循环方法注解解析
foreach ($methodAnnotations[$methodName] as $methodAnnotationAry) {
foreach ($methodAnnotationAry as $methodAnnotation) {
if (!$this->inMethodAnnotations($methodAnnotation)) {
continue;
}
// 解析器解析
$annotationParser = $this->getAnnotationParser($methodAnnotation);
if ($annotationParser == null) {
$this->parseMethodWithoutAnnotation($className, $methodName);
continue;
}
$annotationParser->parser($className, $methodAnnotation, "", $methodName);
}
}
} | php | private function parseMethodAnnotations(string $className, \ReflectionMethod $method, array $methodAnnotations)
{
// 方法没有注解解析
$methodName = $method->getName();
$isWithoutMethodAnnotation = empty($methodAnnotations) || !isset($methodAnnotations[$methodName]);
if ($isWithoutMethodAnnotation || !$this->isParseMethod($methodAnnotations[$methodName])) {
$this->parseMethodWithoutAnnotation($className, $methodName);
return;
}
// 循环方法注解解析
foreach ($methodAnnotations[$methodName] as $methodAnnotationAry) {
foreach ($methodAnnotationAry as $methodAnnotation) {
if (!$this->inMethodAnnotations($methodAnnotation)) {
continue;
}
// 解析器解析
$annotationParser = $this->getAnnotationParser($methodAnnotation);
if ($annotationParser == null) {
$this->parseMethodWithoutAnnotation($className, $methodName);
continue;
}
$annotationParser->parser($className, $methodAnnotation, "", $methodName);
}
}
} | [
"private",
"function",
"parseMethodAnnotations",
"(",
"string",
"$",
"className",
",",
"\\",
"ReflectionMethod",
"$",
"method",
",",
"array",
"$",
"methodAnnotations",
")",
"{",
"// 方法没有注解解析",
"$",
"methodName",
"=",
"$",
"method",
"->",
"getName",
"(",
")",
"... | 解析方法注解
@param string $className
@param \ReflectionMethod $method
@param array $methodAnnotations | [
"解析方法注解"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L197-L223 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.parseMethodWithoutAnnotation | private function parseMethodWithoutAnnotation(string $className, string $methodName)
{
$parser = new MethodWithoutAnnotationParser($this->annotationResource);
$parser->parser($className, null, "", $methodName);
} | php | private function parseMethodWithoutAnnotation(string $className, string $methodName)
{
$parser = new MethodWithoutAnnotationParser($this->annotationResource);
$parser->parser($className, null, "", $methodName);
} | [
"private",
"function",
"parseMethodWithoutAnnotation",
"(",
"string",
"$",
"className",
",",
"string",
"$",
"methodName",
")",
"{",
"$",
"parser",
"=",
"new",
"MethodWithoutAnnotationParser",
"(",
"$",
"this",
"->",
"annotationResource",
")",
";",
"$",
"parser",
... | 方法没有配置路由注解解析
@param string $className
@param string $methodName | [
"方法没有配置路由注解解析"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L240-L244 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.parsePropertyAnnotations | private function parsePropertyAnnotations(array $propertyAnnotations, string $className, string $propertyName, $propertyValue)
{
$isRef = false;
$injectProperty = "";
// 没有任何注解
if (empty($propertyAnnotations) || !isset($propertyAnnotations[$propertyName])
|| !$this->isParseProperty($propertyAnnotations[$propertyName])
) {
return [null, false];
}
// 属性注解解析
foreach ($propertyAnnotations[$propertyName] as $propertyAnnotation) {
$annotationClass = get_class($propertyAnnotation);
if (!in_array($annotationClass, $this->getPropertyAnnotations())) {
continue;
}
// 解析器
$annotationParser = $this->getAnnotationParser($propertyAnnotation);
if ($annotationParser === null) {
$injectProperty = null;
$isRef = false;
continue;
}
list($injectProperty, $isRef) = $annotationParser->parser($className, $propertyAnnotation, $propertyName, "", $propertyValue);
}
return [$injectProperty, $isRef];
} | php | private function parsePropertyAnnotations(array $propertyAnnotations, string $className, string $propertyName, $propertyValue)
{
$isRef = false;
$injectProperty = "";
// 没有任何注解
if (empty($propertyAnnotations) || !isset($propertyAnnotations[$propertyName])
|| !$this->isParseProperty($propertyAnnotations[$propertyName])
) {
return [null, false];
}
// 属性注解解析
foreach ($propertyAnnotations[$propertyName] as $propertyAnnotation) {
$annotationClass = get_class($propertyAnnotation);
if (!in_array($annotationClass, $this->getPropertyAnnotations())) {
continue;
}
// 解析器
$annotationParser = $this->getAnnotationParser($propertyAnnotation);
if ($annotationParser === null) {
$injectProperty = null;
$isRef = false;
continue;
}
list($injectProperty, $isRef) = $annotationParser->parser($className, $propertyAnnotation, $propertyName, "", $propertyValue);
}
return [$injectProperty, $isRef];
} | [
"private",
"function",
"parsePropertyAnnotations",
"(",
"array",
"$",
"propertyAnnotations",
",",
"string",
"$",
"className",
",",
"string",
"$",
"propertyName",
",",
"$",
"propertyValue",
")",
"{",
"$",
"isRef",
"=",
"false",
";",
"$",
"injectProperty",
"=",
... | 属性解析
@param array $propertyAnnotations
@param string $className
@param string $propertyName
@param mixed $propertyValue
@return array | [
"属性解析"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L256-L286 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.parseClassAnnotations | public function parseClassAnnotations(string $className, array $annotations)
{
if (!$this->isParseClass($annotations)) {
return null;
}
$beanData = null;
foreach ($annotations as $annotation) {
$annotationClass = get_class($annotation);
if (!in_array($annotationClass, $this->getClassAnnotations())) {
continue;
}
// annotation parser
$annotationParser = $this->getAnnotationParser($annotation);
if ($annotationParser == null) {
continue;
}
$annotationData = $annotationParser->parser($className, $annotation);
if ($annotationData != null) {
$beanData = $annotationData;
}
}
return $beanData;
} | php | public function parseClassAnnotations(string $className, array $annotations)
{
if (!$this->isParseClass($annotations)) {
return null;
}
$beanData = null;
foreach ($annotations as $annotation) {
$annotationClass = get_class($annotation);
if (!in_array($annotationClass, $this->getClassAnnotations())) {
continue;
}
// annotation parser
$annotationParser = $this->getAnnotationParser($annotation);
if ($annotationParser == null) {
continue;
}
$annotationData = $annotationParser->parser($className, $annotation);
if ($annotationData != null) {
$beanData = $annotationData;
}
}
return $beanData;
} | [
"public",
"function",
"parseClassAnnotations",
"(",
"string",
"$",
"className",
",",
"array",
"$",
"annotations",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isParseClass",
"(",
"$",
"annotations",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"beanD... | 类注解解析
@param string $className
@param array $annotations
@return array | [
"类注解解析"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L296-L321 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.getExtendAnnotations | private function getExtendAnnotations(int $type = 1): array
{
$annotations = [];
foreach ($this->extends as $extend) {
if ($type == 1) {
$extendAnnoation = $extend->getClassAnnotations();
} elseif ($type == 2) {
$extendAnnoation = $extend->getPropertyAnnotations();
} else {
$extendAnnoation = $extend->getMethodAnnotations();
}
$annotations = array_merge($annotations, $extendAnnoation);
}
return $annotations;
} | php | private function getExtendAnnotations(int $type = 1): array
{
$annotations = [];
foreach ($this->extends as $extend) {
if ($type == 1) {
$extendAnnoation = $extend->getClassAnnotations();
} elseif ($type == 2) {
$extendAnnoation = $extend->getPropertyAnnotations();
} else {
$extendAnnoation = $extend->getMethodAnnotations();
}
$annotations = array_merge($annotations, $extendAnnoation);
}
return $annotations;
} | [
"private",
"function",
"getExtendAnnotations",
"(",
"int",
"$",
"type",
"=",
"1",
")",
":",
"array",
"{",
"$",
"annotations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"extends",
"as",
"$",
"extend",
")",
"{",
"if",
"(",
"$",
"type",
"... | @param int $type
@return array | [
"@param",
"int",
"$type"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L361-L376 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.isParseExtendAnnotations | private function isParseExtendAnnotations(array $annotations, int $type = 1): bool
{
foreach ($this->extends as $extend) {
if ($type == 1) {
$isParse = $extend->isParseClassAnnotations($annotations);
} elseif ($type == 2) {
$isParse = $extend->isParsePropertyAnnotations($annotations);
} else {
$isParse = $extend->isParseMethodAnnotations($annotations);
}
if ($isParse) {
return true;
}
}
return false;
} | php | private function isParseExtendAnnotations(array $annotations, int $type = 1): bool
{
foreach ($this->extends as $extend) {
if ($type == 1) {
$isParse = $extend->isParseClassAnnotations($annotations);
} elseif ($type == 2) {
$isParse = $extend->isParsePropertyAnnotations($annotations);
} else {
$isParse = $extend->isParseMethodAnnotations($annotations);
}
if ($isParse) {
return true;
}
}
return false;
} | [
"private",
"function",
"isParseExtendAnnotations",
"(",
"array",
"$",
"annotations",
",",
"int",
"$",
"type",
"=",
"1",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"extends",
"as",
"$",
"extend",
")",
"{",
"if",
"(",
"$",
"type",
"==",
... | @param array $annotations
@param int $type
@return bool | [
"@param",
"array",
"$annotations",
"@param",
"int",
"$type"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L414-L430 |
swoft-cloud/swoft-framework | src/Bean/Wrapper/AbstractWrapper.php | AbstractWrapper.getAnnotationParser | private function getAnnotationParser($objectAnnotation)
{
$annotationClassName = get_class($objectAnnotation);
$classNameTmp = str_replace('\\', '/', $annotationClassName);
$className = basename($classNameTmp);
$namespaceDir = dirname($classNameTmp, 2);
$namespace = str_replace('/', '\\', $namespaceDir);
// 解析器类名
$annotationParserClassName = "{$namespace}\\Parser\\{$className}Parser";
if (!class_exists($annotationParserClassName)) {
return null;
}
$annotationParser = new $annotationParserClassName($this->annotationResource);
return $annotationParser;
} | php | private function getAnnotationParser($objectAnnotation)
{
$annotationClassName = get_class($objectAnnotation);
$classNameTmp = str_replace('\\', '/', $annotationClassName);
$className = basename($classNameTmp);
$namespaceDir = dirname($classNameTmp, 2);
$namespace = str_replace('/', '\\', $namespaceDir);
// 解析器类名
$annotationParserClassName = "{$namespace}\\Parser\\{$className}Parser";
if (!class_exists($annotationParserClassName)) {
return null;
}
$annotationParser = new $annotationParserClassName($this->annotationResource);
return $annotationParser;
} | [
"private",
"function",
"getAnnotationParser",
"(",
"$",
"objectAnnotation",
")",
"{",
"$",
"annotationClassName",
"=",
"get_class",
"(",
"$",
"objectAnnotation",
")",
";",
"$",
"classNameTmp",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"annotationC... | 获取注解对应解析器
@param $objectAnnotation
@return AbstractParser | [
"获取注解对应解析器"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Wrapper/AbstractWrapper.php#L439-L455 |
swoft-cloud/swoft-framework | src/Core/Timer.php | Timer.addAfterTimer | public function addAfterTimer(string $name, int $time, callable $callback, $params = [])
{
array_unshift($params, $name, $callback);
$tid = \Swoole\Timer::after($time, [$this, 'timerCallback'], $params);
$this->timers[$name][$tid] = $tid;
return $tid;
} | php | public function addAfterTimer(string $name, int $time, callable $callback, $params = [])
{
array_unshift($params, $name, $callback);
$tid = \Swoole\Timer::after($time, [$this, 'timerCallback'], $params);
$this->timers[$name][$tid] = $tid;
return $tid;
} | [
"public",
"function",
"addAfterTimer",
"(",
"string",
"$",
"name",
",",
"int",
"$",
"time",
",",
"callable",
"$",
"callback",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"name",
",",
"$",
"callback",
")... | 添加一个定时器,只执行一次
@param string $name 名称
@param int $time 毫秒
@param callable $callback 回调函数
@param array $params 参数
@return int | [
"添加一个定时器,只执行一次"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/Timer.php#L39-L45 |
swoft-cloud/swoft-framework | src/Core/Timer.php | Timer.addTickTimer | public function addTickTimer(string $name, int $time, $callback, $params = [])
{
array_unshift($params, $name, $callback);
$tid = \Swoole\Timer::tick($time, [$this, 'timerCallback'], $params);
$this->timers[$name][$tid] = $tid;
return $tid;
} | php | public function addTickTimer(string $name, int $time, $callback, $params = [])
{
array_unshift($params, $name, $callback);
$tid = \Swoole\Timer::tick($time, [$this, 'timerCallback'], $params);
$this->timers[$name][$tid] = $tid;
return $tid;
} | [
"public",
"function",
"addTickTimer",
"(",
"string",
"$",
"name",
",",
"int",
"$",
"time",
",",
"$",
"callback",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"name",
",",
"$",
"callback",
")",
";",
"$"... | 添加一个定时器,每隔时间执行
@param string $name 名称
@param int $time 毫秒
@param callable $callback 回调函数
@param array $params 参数
@return int | [
"添加一个定时器,每隔时间执行"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/Timer.php#L57-L66 |
swoft-cloud/swoft-framework | src/Core/Timer.php | Timer.clearTimerByName | public function clearTimerByName(string $name)
{
if (!isset($this->timers[$name])) {
return true;
}
foreach ($this->timers[$name] as $tid => $tidVal) {
\Swoole\Timer::clear($tid);
}
unset($this->timers[$name]);
return true;
} | php | public function clearTimerByName(string $name)
{
if (!isset($this->timers[$name])) {
return true;
}
foreach ($this->timers[$name] as $tid => $tidVal) {
\Swoole\Timer::clear($tid);
}
unset($this->timers[$name]);
return true;
} | [
"public",
"function",
"clearTimerByName",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"timers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"timers"... | 移除一个定时器
@param string $name 定时器名称
@return bool | [
"移除一个定时器"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/Timer.php#L75-L86 |
swoft-cloud/swoft-framework | src/Core/Timer.php | Timer.timerCallback | public function timerCallback($timerId, $params)
{
if (count($params) < 2) {
return;
}
$name = array_shift($params);
$callback = array_shift($params);
$this->beforeTimer($name);
$callbackParams = array_values($params);
if (is_array($callback)) {
list($class, $method) = $callback;
$class->$method(...$callbackParams);
} else {
$callback(...$callbackParams);
}
$this->afterTimer($name);
} | php | public function timerCallback($timerId, $params)
{
if (count($params) < 2) {
return;
}
$name = array_shift($params);
$callback = array_shift($params);
$this->beforeTimer($name);
$callbackParams = array_values($params);
if (is_array($callback)) {
list($class, $method) = $callback;
$class->$method(...$callbackParams);
} else {
$callback(...$callbackParams);
}
$this->afterTimer($name);
} | [
"public",
"function",
"timerCallback",
"(",
"$",
"timerId",
",",
"$",
"params",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"return",
";",
"}",
"$",
"name",
"=",
"array_shift",
"(",
"$",
"params",
")",
";",
"$",
"ca... | 定时器回调函数
@param array $params 参数传递
@param int $timerId 定时器id | [
"定时器回调函数"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/Timer.php#L94-L114 |
swoft-cloud/swoft-framework | src/Core/Timer.php | Timer.beforeTimer | private function beforeTimer(string $name)
{
$contextData = [
'logid' => uniqid(),
'spanid' => 0,
'uri' => $this->getTimerUri($name),
'requestTime' => microtime(true),
];
RequestContext::setContextData($contextData);
} | php | private function beforeTimer(string $name)
{
$contextData = [
'logid' => uniqid(),
'spanid' => 0,
'uri' => $this->getTimerUri($name),
'requestTime' => microtime(true),
];
RequestContext::setContextData($contextData);
} | [
"private",
"function",
"beforeTimer",
"(",
"string",
"$",
"name",
")",
"{",
"$",
"contextData",
"=",
"[",
"'logid'",
"=>",
"uniqid",
"(",
")",
",",
"'spanid'",
"=>",
"0",
",",
"'uri'",
"=>",
"$",
"this",
"->",
"getTimerUri",
"(",
"$",
"name",
")",
",... | 定时器初始化
@param string $name 名称 | [
"定时器初始化"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/Timer.php#L121-L130 |
swoft-cloud/swoft-framework | src/Bean/Resource/DefinitionResource.php | DefinitionResource.getDefinitions | public function getDefinitions()
{
$definitions = [];
foreach ($this->definitions as $beanName => $definition) {
$definitions[$beanName] = $this->resolvedefinitation($beanName, $definition);
}
return $definitions;
} | php | public function getDefinitions()
{
$definitions = [];
foreach ($this->definitions as $beanName => $definition) {
$definitions[$beanName] = $this->resolvedefinitation($beanName, $definition);
}
return $definitions;
} | [
"public",
"function",
"getDefinitions",
"(",
")",
"{",
"$",
"definitions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"definitions",
"as",
"$",
"beanName",
"=>",
"$",
"definition",
")",
"{",
"$",
"definitions",
"[",
"$",
"beanName",
"]",
"=... | 获取已解析的配置beans
@return array
<pre>
[
'beanName' => ObjectDefinition,
...
]
</pre> | [
"获取已解析的配置beans"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Resource/DefinitionResource.php#L50-L58 |
swoft-cloud/swoft-framework | src/Bean/Resource/DefinitionResource.php | DefinitionResource.resolvedefinitation | public function resolvedefinitation(string $beanName, array $definition)
{
if (!isset($definition['class'])) {
throw new \InvalidArgumentException("definitions of bean 初始化失败,class字段没有配置,Data=" . json_encode($definition));
}
$className = $definition['class'];
unset($definition['class']);
// 初始化
$objDefinitation = new ObjectDefinition();
$objDefinitation->setName($beanName);
$objDefinitation->setClassName($className);
// 解析属性和构造函数
list($propertyInjections, $constructorInjection) = $this->resolverPropertiesAndConstructor($definition);
// 设置属性和构造函数
$objDefinitation->setPropertyInjections($propertyInjections);
if ($constructorInjection != null) {
$objDefinitation->setConstructorInjection($constructorInjection);
}
return $objDefinitation;
} | php | public function resolvedefinitation(string $beanName, array $definition)
{
if (!isset($definition['class'])) {
throw new \InvalidArgumentException("definitions of bean 初始化失败,class字段没有配置,Data=" . json_encode($definition));
}
$className = $definition['class'];
unset($definition['class']);
// 初始化
$objDefinitation = new ObjectDefinition();
$objDefinitation->setName($beanName);
$objDefinitation->setClassName($className);
// 解析属性和构造函数
list($propertyInjections, $constructorInjection) = $this->resolverPropertiesAndConstructor($definition);
// 设置属性和构造函数
$objDefinitation->setPropertyInjections($propertyInjections);
if ($constructorInjection != null) {
$objDefinitation->setConstructorInjection($constructorInjection);
}
return $objDefinitation;
} | [
"public",
"function",
"resolvedefinitation",
"(",
"string",
"$",
"beanName",
",",
"array",
"$",
"definition",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"definition",
"[",
"'class'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"... | 解析bean配置
@param string $beanName 名称
@param array $definition 数组定义格式
@return ObjectDefinition | [
"解析bean配置"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Resource/DefinitionResource.php#L68-L92 |
swoft-cloud/swoft-framework | src/Bean/Resource/DefinitionResource.php | DefinitionResource.resolverPropertiesAndConstructor | private function resolverPropertiesAndConstructor(array $definition)
{
$propertyInjections = [];
$constructorInjection = null;
// 循环解析
foreach ($definition as $name => $property) {
// 构造函数
if (is_array($property) && $name === 0) {
$constructorInjection = $this->resolverConstructor($property);
continue;
}
// 数组属性解析
if (is_array($property)) {
$injectProperty = $this->resolverArrayArgs($property);
$propertyInjection = new PropertyInjection($name, $injectProperty, false);
$propertyInjections[$name] = $propertyInjection;
continue;
}
// 普通解析
list($injectProperty, $isRef) = $this->getTransferProperty($property);
$propertyInjection = new PropertyInjection($name, $injectProperty, (bool)$isRef);
$propertyInjections[$name] = $propertyInjection;
}
return [$propertyInjections, $constructorInjection];
} | php | private function resolverPropertiesAndConstructor(array $definition)
{
$propertyInjections = [];
$constructorInjection = null;
// 循环解析
foreach ($definition as $name => $property) {
// 构造函数
if (is_array($property) && $name === 0) {
$constructorInjection = $this->resolverConstructor($property);
continue;
}
// 数组属性解析
if (is_array($property)) {
$injectProperty = $this->resolverArrayArgs($property);
$propertyInjection = new PropertyInjection($name, $injectProperty, false);
$propertyInjections[$name] = $propertyInjection;
continue;
}
// 普通解析
list($injectProperty, $isRef) = $this->getTransferProperty($property);
$propertyInjection = new PropertyInjection($name, $injectProperty, (bool)$isRef);
$propertyInjections[$name] = $propertyInjection;
}
return [$propertyInjections, $constructorInjection];
} | [
"private",
"function",
"resolverPropertiesAndConstructor",
"(",
"array",
"$",
"definition",
")",
"{",
"$",
"propertyInjections",
"=",
"[",
"]",
";",
"$",
"constructorInjection",
"=",
"null",
";",
"// 循环解析",
"foreach",
"(",
"$",
"definition",
"as",
"$",
"name",
... | 解析配置属性和构造函数
@param array $definition
@return array
<pre>
[$propertyInjections, $constructorInjection]
<pre> | [
"解析配置属性和构造函数"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Resource/DefinitionResource.php#L104-L132 |
swoft-cloud/swoft-framework | src/Bean/Resource/DefinitionResource.php | DefinitionResource.resolverArrayArgs | private function resolverArrayArgs(array $propertyValue)
{
$args = [];
foreach ($propertyValue as $key => $subArg) {
// 递归解析
if (is_array($subArg)) {
$args[$key] = $this->resolverArrayArgs($subArg);
continue;
}
// 普通解析
list($injectProperty, $isRef) = $this->getTransferProperty($subArg);
$args[$key] = new ArgsInjection($injectProperty, (bool)$isRef);
}
return $args;
} | php | private function resolverArrayArgs(array $propertyValue)
{
$args = [];
foreach ($propertyValue as $key => $subArg) {
// 递归解析
if (is_array($subArg)) {
$args[$key] = $this->resolverArrayArgs($subArg);
continue;
}
// 普通解析
list($injectProperty, $isRef) = $this->getTransferProperty($subArg);
$args[$key] = new ArgsInjection($injectProperty, (bool)$isRef);
}
return $args;
} | [
"private",
"function",
"resolverArrayArgs",
"(",
"array",
"$",
"propertyValue",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"propertyValue",
"as",
"$",
"key",
"=>",
"$",
"subArg",
")",
"{",
"// 递归解析",
"if",
"(",
"is_array",
"(",
"$"... | 解析数组值属性
@param array $propertyValue
@return array | [
"解析数组值属性"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Resource/DefinitionResource.php#L141-L157 |
swoft-cloud/swoft-framework | src/Bean/Resource/DefinitionResource.php | DefinitionResource.resolverConstructor | private function resolverConstructor(array $args)
{
$methodArgs = [];
foreach ($args as $arg) {
// 数组参数解析
if (is_array($arg)) {
$injectProperty = $this->resolverArrayArgs($arg);
$methodArgs[] = new ArgsInjection($injectProperty, false);
continue;
}
// 普通参数解析
list($injectProperty, $isRef) = $this->getTransferProperty($arg);
$methodArgs[] = new ArgsInjection($injectProperty, (bool)$isRef);
}
$methodInject = new MethodInjection("__construct", $methodArgs);
return $methodInject;
} | php | private function resolverConstructor(array $args)
{
$methodArgs = [];
foreach ($args as $arg) {
// 数组参数解析
if (is_array($arg)) {
$injectProperty = $this->resolverArrayArgs($arg);
$methodArgs[] = new ArgsInjection($injectProperty, false);
continue;
}
// 普通参数解析
list($injectProperty, $isRef) = $this->getTransferProperty($arg);
$methodArgs[] = new ArgsInjection($injectProperty, (bool)$isRef);
}
$methodInject = new MethodInjection("__construct", $methodArgs);
return $methodInject;
} | [
"private",
"function",
"resolverConstructor",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"methodArgs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"// 数组参数解析",
"if",
"(",
"is_array",
"(",
"$",
"arg",
")",
")",
"{",
"... | 解析构造函数
@param array $args
@return MethodInjection | [
"解析构造函数"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Resource/DefinitionResource.php#L166-L184 |
swoft-cloud/swoft-framework | src/Pipe/JsonPipeMessage.php | JsonPipeMessage.pack | public function pack(string $type, array $data): string
{
$data = [
'pipeType' => $type,
'message' => $data,
];
return JsonHelper::encode($data, JSON_UNESCAPED_UNICODE);
} | php | public function pack(string $type, array $data): string
{
$data = [
'pipeType' => $type,
'message' => $data,
];
return JsonHelper::encode($data, JSON_UNESCAPED_UNICODE);
} | [
"public",
"function",
"pack",
"(",
"string",
"$",
"type",
",",
"array",
"$",
"data",
")",
":",
"string",
"{",
"$",
"data",
"=",
"[",
"'pipeType'",
"=>",
"$",
"type",
",",
"'message'",
"=>",
"$",
"data",
",",
"]",
";",
"return",
"JsonHelper",
"::",
... | @param string $type
@param array $data
@return string | [
"@param",
"string",
"$type",
"@param",
"array",
"$data"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Pipe/JsonPipeMessage.php#L21-L29 |
swoft-cloud/swoft-framework | src/Pipe/JsonPipeMessage.php | JsonPipeMessage.unpack | public function unpack(string $message): array
{
$messageAry = json_decode($message, true);
$type = $messageAry['pipeType'];
$data = $messageAry['message'];
return [$type, $data];
} | php | public function unpack(string $message): array
{
$messageAry = json_decode($message, true);
$type = $messageAry['pipeType'];
$data = $messageAry['message'];
return [$type, $data];
} | [
"public",
"function",
"unpack",
"(",
"string",
"$",
"message",
")",
":",
"array",
"{",
"$",
"messageAry",
"=",
"json_decode",
"(",
"$",
"message",
",",
"true",
")",
";",
"$",
"type",
"=",
"$",
"messageAry",
"[",
"'pipeType'",
"]",
";",
"$",
"data",
"... | @param string $message
@return array | [
"@param",
"string",
"$message"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Pipe/JsonPipeMessage.php#L36-L43 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/ServerTrait.php | ServerTrait.onStart | public function onStart(Server $server)
{
\file_put_contents($this->serverSetting['pfile'], $server->master_pid . ',' . $server->manager_pid);
ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' master process (' . $this->scriptFile . ')');
$this->fireServerEvent(SwooleEvent::ON_START, [$server]);
} | php | public function onStart(Server $server)
{
\file_put_contents($this->serverSetting['pfile'], $server->master_pid . ',' . $server->manager_pid);
ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' master process (' . $this->scriptFile . ')');
$this->fireServerEvent(SwooleEvent::ON_START, [$server]);
} | [
"public",
"function",
"onStart",
"(",
"Server",
"$",
"server",
")",
"{",
"\\",
"file_put_contents",
"(",
"$",
"this",
"->",
"serverSetting",
"[",
"'pfile'",
"]",
",",
"$",
"server",
"->",
"master_pid",
".",
"','",
".",
"$",
"server",
"->",
"manager_pid",
... | onStart event callback
@param Server $server
@throws \InvalidArgumentException | [
"onStart",
"event",
"callback"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/ServerTrait.php#L36-L43 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/ServerTrait.php | ServerTrait.onManagerStart | public function onManagerStart(Server $server)
{
$this->fireServerEvent(SwooleEvent::ON_MANAGER_START, [$server]);
ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' manager process');
} | php | public function onManagerStart(Server $server)
{
$this->fireServerEvent(SwooleEvent::ON_MANAGER_START, [$server]);
ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' manager process');
} | [
"public",
"function",
"onManagerStart",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"this",
"->",
"fireServerEvent",
"(",
"SwooleEvent",
"::",
"ON_MANAGER_START",
",",
"[",
"$",
"server",
"]",
")",
";",
"ProcessHelper",
"::",
"setProcessTitle",
"(",
"$",
"t... | onManagerStart event callback
@param Server $server
@throws \InvalidArgumentException | [
"onManagerStart",
"event",
"callback"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/ServerTrait.php#L51-L56 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/ServerTrait.php | ServerTrait.onWorkerStop | public function onWorkerStop(Server $server,int $worker_id)
{
$this->fireServerEvent(SwooleEvent::ON_WORKER_STOP, [$server,$worker_id]);
} | php | public function onWorkerStop(Server $server,int $worker_id)
{
$this->fireServerEvent(SwooleEvent::ON_WORKER_STOP, [$server,$worker_id]);
} | [
"public",
"function",
"onWorkerStop",
"(",
"Server",
"$",
"server",
",",
"int",
"$",
"worker_id",
")",
"{",
"$",
"this",
"->",
"fireServerEvent",
"(",
"SwooleEvent",
"::",
"ON_WORKER_STOP",
",",
"[",
"$",
"server",
",",
"$",
"worker_id",
"]",
")",
";",
"... | onWorkerStop event callback
@param Server $server
@throws \InvalidArgumentException | [
"onWorkerStop",
"event",
"callback"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/ServerTrait.php#L75-L78 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/ServerTrait.php | ServerTrait.onWorkerStart | public function onWorkerStart(Server $server, int $workerId)
{
// Init Worker and TaskWorker
$setting = $server->setting;
$isWorker = false;
if ($workerId >= $setting['worker_num']) {
// TaskWorker
ApplicationContext::setContext(ApplicationContext::TASK);
ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' task process');
} else {
// Worker
$isWorker = true;
ApplicationContext::setContext(ApplicationContext::WORKER);
ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' worker process');
}
$this->beforeWorkerStart($server, $workerId, $isWorker);
$this->fireServerEvent(SwooleEvent::ON_WORKER_START, [$server, $workerId, $isWorker]);
} | php | public function onWorkerStart(Server $server, int $workerId)
{
// Init Worker and TaskWorker
$setting = $server->setting;
$isWorker = false;
if ($workerId >= $setting['worker_num']) {
// TaskWorker
ApplicationContext::setContext(ApplicationContext::TASK);
ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' task process');
} else {
// Worker
$isWorker = true;
ApplicationContext::setContext(ApplicationContext::WORKER);
ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' worker process');
}
$this->beforeWorkerStart($server, $workerId, $isWorker);
$this->fireServerEvent(SwooleEvent::ON_WORKER_START, [$server, $workerId, $isWorker]);
} | [
"public",
"function",
"onWorkerStart",
"(",
"Server",
"$",
"server",
",",
"int",
"$",
"workerId",
")",
"{",
"// Init Worker and TaskWorker",
"$",
"setting",
"=",
"$",
"server",
"->",
"setting",
";",
"$",
"isWorker",
"=",
"false",
";",
"if",
"(",
"$",
"work... | OnWorkerStart event callback
@param Server $server server
@param int $workerId workerId
@throws \InvalidArgumentException
@throws \ReflectionException | [
"OnWorkerStart",
"event",
"callback"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/ServerTrait.php#L99-L119 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/ServerTrait.php | ServerTrait.onPipeMessage | public function onPipeMessage(Server $server, int $srcWorkerId, string $message)
{
/* @var PipeMessageInterface $pipeMessage */
$pipeMessage = App::getBean(PipeMessage::class);
list($type, $data) = $pipeMessage->unpack($message);
App::trigger(AppEvent::PIPE_MESSAGE, null, $type, $data, $srcWorkerId);
} | php | public function onPipeMessage(Server $server, int $srcWorkerId, string $message)
{
/* @var PipeMessageInterface $pipeMessage */
$pipeMessage = App::getBean(PipeMessage::class);
list($type, $data) = $pipeMessage->unpack($message);
App::trigger(AppEvent::PIPE_MESSAGE, null, $type, $data, $srcWorkerId);
} | [
"public",
"function",
"onPipeMessage",
"(",
"Server",
"$",
"server",
",",
"int",
"$",
"srcWorkerId",
",",
"string",
"$",
"message",
")",
"{",
"/* @var PipeMessageInterface $pipeMessage */",
"$",
"pipeMessage",
"=",
"App",
"::",
"getBean",
"(",
"PipeMessage",
"::",... | onPipeMessage event callback
@param \Swoole\Server $server
@param int $srcWorkerId
@param string $message
@return void
@throws \InvalidArgumentException | [
"onPipeMessage",
"event",
"callback"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/ServerTrait.php#L130-L137 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/ServerTrait.php | ServerTrait.fireServerEvent | protected function fireServerEvent(string $event, array $params)
{
/** @var array[] $collector */
$collector = ServerListenerCollector::getCollector();
if (!isset($collector[$event]) || empty($collector[$event])) {
return;
}
foreach ($collector[$event] as $beanClass) {
$listener = App::getBean($beanClass);
$method = SwooleEvent::getHandlerFunction($event);
$listener->$method(...$params);
}
} | php | protected function fireServerEvent(string $event, array $params)
{
/** @var array[] $collector */
$collector = ServerListenerCollector::getCollector();
if (!isset($collector[$event]) || empty($collector[$event])) {
return;
}
foreach ($collector[$event] as $beanClass) {
$listener = App::getBean($beanClass);
$method = SwooleEvent::getHandlerFunction($event);
$listener->$method(...$params);
}
} | [
"protected",
"function",
"fireServerEvent",
"(",
"string",
"$",
"event",
",",
"array",
"$",
"params",
")",
"{",
"/** @var array[] $collector */",
"$",
"collector",
"=",
"ServerListenerCollector",
"::",
"getCollector",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",... | fire server event listeners
@param string $event
@param array $params | [
"fire",
"server",
"event",
"listeners"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/ServerTrait.php#L182-L196 |
swoft-cloud/swoft-framework | src/Bean/Resource/WorkerAnnotationResource.php | WorkerAnnotationResource.registerNamespace | public function registerNamespace()
{
$hostDir = \dirname(__FILE__, 5);
if (\in_array(\basename($hostDir), ['swoft', 'src'])) {
//install by composer
$componentDirs = scandir($hostDir, null);
} else {
//independent
$componentDirs = ['swoft-framework'];
}
foreach ($componentDirs as $component) {
if ($component === '.' || $component === '..') {
continue;
}
$componentDir = $hostDir . DS . $component;
$componentCommandDir = $componentDir . DS . 'src';
if (! is_dir($componentCommandDir)) {
continue;
}
$ns = ComponentHelper::getComponentNamespace($component, $componentDir);
$this->componentNamespaces[] = $ns;
// ignore the comoponent of console
if ($component === $this->consoleName) {
continue;
}
$scanDirs = scandir($componentCommandDir, null);
foreach ($scanDirs as $dir) {
if ($dir == '.' || $dir == '..') {
continue;
}
if (\in_array($dir, $this->serverScan, true)) {
continue;
}
$scanDir = $componentCommandDir . DS . $dir;
if (! is_dir($scanDir)) {
$this->scanFiles[$ns][] = $scanDir;
continue;
}
$scanNs = $ns . '\\' . $dir;
$this->scanNamespaces[$scanNs] = $scanDir;
}
}
$this->registerWorkerNamespace();
} | php | public function registerNamespace()
{
$hostDir = \dirname(__FILE__, 5);
if (\in_array(\basename($hostDir), ['swoft', 'src'])) {
//install by composer
$componentDirs = scandir($hostDir, null);
} else {
//independent
$componentDirs = ['swoft-framework'];
}
foreach ($componentDirs as $component) {
if ($component === '.' || $component === '..') {
continue;
}
$componentDir = $hostDir . DS . $component;
$componentCommandDir = $componentDir . DS . 'src';
if (! is_dir($componentCommandDir)) {
continue;
}
$ns = ComponentHelper::getComponentNamespace($component, $componentDir);
$this->componentNamespaces[] = $ns;
// ignore the comoponent of console
if ($component === $this->consoleName) {
continue;
}
$scanDirs = scandir($componentCommandDir, null);
foreach ($scanDirs as $dir) {
if ($dir == '.' || $dir == '..') {
continue;
}
if (\in_array($dir, $this->serverScan, true)) {
continue;
}
$scanDir = $componentCommandDir . DS . $dir;
if (! is_dir($scanDir)) {
$this->scanFiles[$ns][] = $scanDir;
continue;
}
$scanNs = $ns . '\\' . $dir;
$this->scanNamespaces[$scanNs] = $scanDir;
}
}
$this->registerWorkerNamespace();
} | [
"public",
"function",
"registerNamespace",
"(",
")",
"{",
"$",
"hostDir",
"=",
"\\",
"dirname",
"(",
"__FILE__",
",",
"5",
")",
";",
"if",
"(",
"\\",
"in_array",
"(",
"\\",
"basename",
"(",
"$",
"hostDir",
")",
",",
"[",
"'swoft'",
",",
"'src'",
"]",... | Register the scaned namespace | [
"Register",
"the",
"scaned",
"namespace"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Resource/WorkerAnnotationResource.php#L24-L74 |
swoft-cloud/swoft-framework | src/Helper/ArrayHelper.php | ArrayHelper.isIndexed | public static function isIndexed($array, $consecutive = false)
{
if (!\is_array($array)) {
return false;
}
if (empty($array)) {
return true;
}
if ($consecutive) {
return array_keys($array) === range(0, \count($array) - 1);
} else {
foreach ($array as $key => $value) {
if (!\is_int($key)) {
return false;
}
}
return true;
}
} | php | public static function isIndexed($array, $consecutive = false)
{
if (!\is_array($array)) {
return false;
}
if (empty($array)) {
return true;
}
if ($consecutive) {
return array_keys($array) === range(0, \count($array) - 1);
} else {
foreach ($array as $key => $value) {
if (!\is_int($key)) {
return false;
}
}
return true;
}
} | [
"public",
"static",
"function",
"isIndexed",
"(",
"$",
"array",
",",
"$",
"consecutive",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"array",... | Returns a value indicating whether the given array is an indexed array.
An array is indexed if all its keys are integers. If `$consecutive` is true,
then the array keys must be a consecutive sequence starting from 0.
Note that an empty array will be considered indexed.
@param array $array the array being checked
@param boolean $consecutive whether the array keys must be a consecutive sequence
in order for the array to be treated as indexed.
@return boolean whether the array is associative | [
"Returns",
"a",
"value",
"indicating",
"whether",
"the",
"given",
"array",
"is",
"an",
"indexed",
"array",
"."
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ArrayHelper.php#L649-L670 |
swoft-cloud/swoft-framework | src/Helper/ArrayHelper.php | ArrayHelper.isIn | public static function isIn($needle, $haystack, $strict = false): bool
{
if ($haystack instanceof \Traversable) {
foreach ($haystack as $value) {
if ($needle == $value && (!$strict || $needle === $value)) {
return true;
}
}
} elseif (\is_array($haystack)) {
return \in_array($needle, $haystack, $strict);
} else {
throw new \InvalidArgumentException('Argument $haystack must be an array or implement Traversable');
}
return false;
} | php | public static function isIn($needle, $haystack, $strict = false): bool
{
if ($haystack instanceof \Traversable) {
foreach ($haystack as $value) {
if ($needle == $value && (!$strict || $needle === $value)) {
return true;
}
}
} elseif (\is_array($haystack)) {
return \in_array($needle, $haystack, $strict);
} else {
throw new \InvalidArgumentException('Argument $haystack must be an array or implement Traversable');
}
return false;
} | [
"public",
"static",
"function",
"isIn",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"strict",
"=",
"false",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"haystack",
"instanceof",
"\\",
"Traversable",
")",
"{",
"foreach",
"(",
"$",
"haystack",
"as",
... | Check whether an array or [[\Traversable]] contains an element.
This method does the same as the PHP function [in_array()](http://php.net/manual/en/function.in-array.php)
but additionally works for objects that implement the [[\Traversable]] interface.
@param mixed $needle The value to look for.
@param array|\Traversable $haystack The set of values to search.
@param boolean $strict Whether to enable strict (`===`) comparison.
@return boolean `true` if `$needle` was found in `$haystack`, `false` otherwise.
@throws \InvalidArgumentException if `$haystack` is neither traversable nor an array.
@see http://php.net/manual/en/function.in-array.php | [
"Check",
"whether",
"an",
"array",
"or",
"[[",
"\\",
"Traversable",
"]]",
"contains",
"an",
"element",
"."
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ArrayHelper.php#L686-L701 |
swoft-cloud/swoft-framework | src/Helper/ArrayHelper.php | ArrayHelper.isSubset | public static function isSubset($needles, $haystack, $strict = false)
{
if (\is_array($needles) || $needles instanceof \Traversable) {
foreach ($needles as $needle) {
if (!static::isIn($needle, $haystack, $strict)) {
return false;
}
}
return true;
} else {
throw new \InvalidArgumentException('Argument $needles must be an array or implement Traversable');
}
} | php | public static function isSubset($needles, $haystack, $strict = false)
{
if (\is_array($needles) || $needles instanceof \Traversable) {
foreach ($needles as $needle) {
if (!static::isIn($needle, $haystack, $strict)) {
return false;
}
}
return true;
} else {
throw new \InvalidArgumentException('Argument $needles must be an array or implement Traversable');
}
} | [
"public",
"static",
"function",
"isSubset",
"(",
"$",
"needles",
",",
"$",
"haystack",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"needles",
")",
"||",
"$",
"needles",
"instanceof",
"\\",
"Traversable",
")",
"{",... | Checks whether an array or [[\Traversable]] is a subset of another array or [[\Traversable]].
This method will return `true`, if all elements of `$needles` are contained in
`$haystack`. If at least one element is missing, `false` will be returned.
@param array|\Traversable $needles The values that must **all** be in `$haystack`.
@param array|\Traversable $haystack The set of value to search.
@param boolean $strict Whether to enable strict (`===`) comparison.
@throws \InvalidArgumentException if `$haystack` or `$needles` is neither traversable nor an array.
@return boolean `true` if `$needles` is a subset of `$haystack`, `false` otherwise. | [
"Checks",
"whether",
"an",
"array",
"or",
"[[",
"\\",
"Traversable",
"]]",
"is",
"a",
"subset",
"of",
"another",
"array",
"or",
"[[",
"\\",
"Traversable",
"]]",
"."
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ArrayHelper.php#L732-L745 |
swoft-cloud/swoft-framework | src/Helper/ArrayHelper.php | ArrayHelper.get | public static function get($array, $key, $default = null)
{
if (null === $key) {
return $array;
}
if (isset($array[$key])) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if (static::accessible($array) && static::exists($array, $segment)) {
$array = $array[$segment];
} else {
return value($default);
}
}
return $array;
} | php | public static function get($array, $key, $default = null)
{
if (null === $key) {
return $array;
}
if (isset($array[$key])) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if (static::accessible($array) && static::exists($array, $segment)) {
$array = $array[$segment];
} else {
return value($default);
}
}
return $array;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"return",
"$",
"array",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",... | Get an item from an array using "dot" notation.
@param \ArrayAccess|array $array
@param string $key
@param mixed $default
@return mixed | [
"Get",
"an",
"item",
"from",
"an",
"array",
"using",
"dot",
"notation",
"."
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ArrayHelper.php#L873-L892 |
swoft-cloud/swoft-framework | src/Helper/ArrayHelper.php | ArrayHelper.has | public static function has($array, $key)
{
if (empty($array) || null === $key) {
return false;
}
if (array_key_exists($key, $array)) {
return true;
}
foreach (explode('.', $key) as $segment) {
if ((\is_array($array) && array_key_exists($segment, $array)) || ($array instanceof \ArrayAccess && $array->offsetExists($segment))) {
$array = $array[$segment];
} else {
return false;
}
}
return true;
} | php | public static function has($array, $key)
{
if (empty($array) || null === $key) {
return false;
}
if (array_key_exists($key, $array)) {
return true;
}
foreach (explode('.', $key) as $segment) {
if ((\is_array($array) && array_key_exists($segment, $array)) || ($array instanceof \ArrayAccess && $array->offsetExists($segment))) {
$array = $array[$segment];
} else {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"has",
"(",
"$",
"array",
",",
"$",
"key",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
"||",
"null",
"===",
"$",
"key",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"key... | Check if an item exists in an array using "dot" notation.
@param \ArrayAccess|array $array
@param string $key
@return bool | [
"Check",
"if",
"an",
"item",
"exists",
"in",
"an",
"array",
"using",
"dot",
"notation",
"."
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ArrayHelper.php#L902-L921 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.setRequest | public static function setRequest(RequestInterface $request)
{
$coroutineId = self::getCoroutineId();
self::$context[$coroutineId][self::REQUEST_KEY] = $request;
} | php | public static function setRequest(RequestInterface $request)
{
$coroutineId = self::getCoroutineId();
self::$context[$coroutineId][self::REQUEST_KEY] = $request;
} | [
"public",
"static",
"function",
"setRequest",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"self",
"::",
"$",
"context",
"[",
"$",
"coroutineId",
"]",
"[",
"self",
"::",
"REQUEST... | Set the object of request
@param RequestInterface $request | [
"Set",
"the",
"object",
"of",
"request"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L66-L70 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.setResponse | public static function setResponse(ResponseInterface $response)
{
$coroutineId = self::getCoroutineId();
self::$context[$coroutineId][self::RESPONSE_KEY] = $response;
} | php | public static function setResponse(ResponseInterface $response)
{
$coroutineId = self::getCoroutineId();
self::$context[$coroutineId][self::RESPONSE_KEY] = $response;
} | [
"public",
"static",
"function",
"setResponse",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"self",
"::",
"$",
"context",
"[",
"$",
"coroutineId",
"]",
"[",
"self",
"::",
"RESP... | Set the object of response
@param ResponseInterface $response | [
"Set",
"the",
"object",
"of",
"response"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L77-L81 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.setContextData | public static function setContextData(array $contextData = [])
{
$existContext = [];
$coroutineId = self::getCoroutineId();
if (isset(self::$context[$coroutineId][self::DATA_KEY])) {
$existContext = self::$context[$coroutineId][self::DATA_KEY];
}
self::$context[$coroutineId][self::DATA_KEY] = ArrayHelper::merge($contextData, $existContext);
} | php | public static function setContextData(array $contextData = [])
{
$existContext = [];
$coroutineId = self::getCoroutineId();
if (isset(self::$context[$coroutineId][self::DATA_KEY])) {
$existContext = self::$context[$coroutineId][self::DATA_KEY];
}
self::$context[$coroutineId][self::DATA_KEY] = ArrayHelper::merge($contextData, $existContext);
} | [
"public",
"static",
"function",
"setContextData",
"(",
"array",
"$",
"contextData",
"=",
"[",
"]",
")",
"{",
"$",
"existContext",
"=",
"[",
"]",
";",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self... | Set the context data
@param array $contextData | [
"Set",
"the",
"context",
"data"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L88-L96 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.setContextDataByKey | public static function setContextDataByKey(string $key, $val)
{
$coroutineId = self::getCoroutineId();
self::$context[$coroutineId][self::DATA_KEY][$key] = $val;
} | php | public static function setContextDataByKey(string $key, $val)
{
$coroutineId = self::getCoroutineId();
self::$context[$coroutineId][self::DATA_KEY][$key] = $val;
} | [
"public",
"static",
"function",
"setContextDataByKey",
"(",
"string",
"$",
"key",
",",
"$",
"val",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"self",
"::",
"$",
"context",
"[",
"$",
"coroutineId",
"]",
"[",
"self",
... | Update context data by key
@param string $key
@param mixed $val | [
"Update",
"context",
"data",
"by",
"key"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L104-L108 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.getContextDataByKey | public static function getContextDataByKey(string $key, $default = null)
{
$coroutineId = self::getCoroutineId();
if (isset(self::$context[$coroutineId][self::DATA_KEY][$key])) {
return self::$context[$coroutineId][self::DATA_KEY][$key];
}
return $default;
} | php | public static function getContextDataByKey(string $key, $default = null)
{
$coroutineId = self::getCoroutineId();
if (isset(self::$context[$coroutineId][self::DATA_KEY][$key])) {
return self::$context[$coroutineId][self::DATA_KEY][$key];
}
return $default;
} | [
"public",
"static",
"function",
"getContextDataByKey",
"(",
"string",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"context",
... | Get context data by key
@param string $key
@param mixed $default
@return mixed | [
"Get",
"context",
"data",
"by",
"key"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L117-L125 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.setContextDataByChildKey | public static function setContextDataByChildKey(string $key, string $child, $val)
{
$coroutineId = self::getCoroutineId();
self::$context[$coroutineId][self::DATA_KEY][$key][$child] = $val;
} | php | public static function setContextDataByChildKey(string $key, string $child, $val)
{
$coroutineId = self::getCoroutineId();
self::$context[$coroutineId][self::DATA_KEY][$key][$child] = $val;
} | [
"public",
"static",
"function",
"setContextDataByChildKey",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"child",
",",
"$",
"val",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"self",
"::",
"$",
"context",
"[",
"$",... | Update context data by child key
@param string $key
@param string $child
@param mixed $val | [
"Update",
"context",
"data",
"by",
"child",
"key"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L134-L138 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.getContextDataByChildKey | public static function getContextDataByChildKey(string $key, string $child, $default = null)
{
$coroutineId = self::getCoroutineId();
if (isset(self::$context[$coroutineId][self::DATA_KEY][$key][$child])) {
return self::$context[$coroutineId][self::DATA_KEY][$key][$child];
}
return $default;
} | php | public static function getContextDataByChildKey(string $key, string $child, $default = null)
{
$coroutineId = self::getCoroutineId();
if (isset(self::$context[$coroutineId][self::DATA_KEY][$key][$child])) {
return self::$context[$coroutineId][self::DATA_KEY][$key][$child];
}
return $default;
} | [
"public",
"static",
"function",
"getContextDataByChildKey",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"child",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"if",
"(",
"isset",
"(... | Get context data by child key
@param string $key
@param string $child
@param mixed $default
@return mixed | [
"Get",
"context",
"data",
"by",
"child",
"key"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L148-L156 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.removeContextDataByChildKey | public static function removeContextDataByChildKey(string $key, string $child)
{
$coroutineId = self::getCoroutineId();
unset(self::$context[$coroutineId][self::DATA_KEY][$key][$child]);
} | php | public static function removeContextDataByChildKey(string $key, string $child)
{
$coroutineId = self::getCoroutineId();
unset(self::$context[$coroutineId][self::DATA_KEY][$key][$child]);
} | [
"public",
"static",
"function",
"removeContextDataByChildKey",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"child",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"unset",
"(",
"self",
"::",
"$",
"context",
"[",
"$",
... | Get context data by child key
@param string $key
@param string $child | [
"Get",
"context",
"data",
"by",
"child",
"key"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L164-L168 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.hasContextDataByChildKey | public static function hasContextDataByChildKey(string $key, string $child): bool
{
$coroutineId = self::getCoroutineId();
return isset(self::$context[$coroutineId][self::DATA_KEY][$key][$child]);
} | php | public static function hasContextDataByChildKey(string $key, string $child): bool
{
$coroutineId = self::getCoroutineId();
return isset(self::$context[$coroutineId][self::DATA_KEY][$key][$child]);
} | [
"public",
"static",
"function",
"hasContextDataByChildKey",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"child",
")",
":",
"bool",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"return",
"isset",
"(",
"self",
"::",
"$",
... | has exists child key
@param string $key
@param string $child
@return bool | [
"has",
"exists",
"child",
"key"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L177-L181 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.getLogid | public static function getLogid(): string
{
$contextData = self::getCoroutineContext(self::DATA_KEY);
$logid = $contextData['logid'] ?? '';
return $logid;
} | php | public static function getLogid(): string
{
$contextData = self::getCoroutineContext(self::DATA_KEY);
$logid = $contextData['logid'] ?? '';
return $logid;
} | [
"public",
"static",
"function",
"getLogid",
"(",
")",
":",
"string",
"{",
"$",
"contextData",
"=",
"self",
"::",
"getCoroutineContext",
"(",
"self",
"::",
"DATA_KEY",
")",
";",
"$",
"logid",
"=",
"$",
"contextData",
"[",
"'logid'",
"]",
"??",
"''",
";",
... | Get Current Request Log ID
@return string | [
"Get",
"Current",
"Request",
"Log",
"ID"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L188-L193 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.destroy | public static function destroy()
{
$coroutineId = self::getCoroutineId();
if (isset(self::$context[$coroutineId])) {
unset(self::$context[$coroutineId]);
}
} | php | public static function destroy()
{
$coroutineId = self::getCoroutineId();
if (isset(self::$context[$coroutineId])) {
unset(self::$context[$coroutineId]);
}
} | [
"public",
"static",
"function",
"destroy",
"(",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"context",
"[",
"$",
"coroutineId",
"]",
")",
")",
"{",
"unset",
"(",
"self"... | Destroy all current coroutine context data | [
"Destroy",
"all",
"current",
"coroutine",
"context",
"data"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L210-L216 |
swoft-cloud/swoft-framework | src/Core/RequestContext.php | RequestContext.getCoroutineContext | private static function getCoroutineContext(string $key)
{
$coroutineId = self::getCoroutineId();
if (!isset(self::$context[$coroutineId])) {
return null;
}
$coroutineContext = self::$context[$coroutineId];
if (isset($coroutineContext[$key])) {
return $coroutineContext[$key];
}
return null;
} | php | private static function getCoroutineContext(string $key)
{
$coroutineId = self::getCoroutineId();
if (!isset(self::$context[$coroutineId])) {
return null;
}
$coroutineContext = self::$context[$coroutineId];
if (isset($coroutineContext[$key])) {
return $coroutineContext[$key];
}
return null;
} | [
"private",
"static",
"function",
"getCoroutineContext",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"coroutineId",
"=",
"self",
"::",
"getCoroutineId",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"context",
"[",
"$",
"coroutineId",
"]",... | Get data from coroutine context by key
@param string $key key of context
@return mixed|null | [
"Get",
"data",
"from",
"coroutine",
"context",
"by",
"key"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/RequestContext.php#L224-L236 |
swoft-cloud/swoft-framework | src/Pipe/PipeMessage.php | PipeMessage.pack | public function pack(string $type, array $data): string
{
return $this->getPacker()->pack($type, $data);
} | php | public function pack(string $type, array $data): string
{
return $this->getPacker()->pack($type, $data);
} | [
"public",
"function",
"pack",
"(",
"string",
"$",
"type",
",",
"array",
"$",
"data",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"getPacker",
"(",
")",
"->",
"pack",
"(",
"$",
"type",
",",
"$",
"data",
")",
";",
"}"
] | @param string $type
@param array $data
@return string | [
"@param",
"string",
"$type",
"@param",
"array",
"$data"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Pipe/PipeMessage.php#L43-L46 |
swoft-cloud/swoft-framework | src/Bean/Resource/ServerAnnotationResource.php | ServerAnnotationResource.registerNamespace | public function registerNamespace()
{
$swoftDir = dirname(__FILE__, 5);
$componentDirs = scandir($swoftDir);
foreach ($componentDirs as $component) {
if ($component == '.' || $component == '..') {
continue;
}
$componentDir = $swoftDir . DS . $component;
$componentCommandDir = $componentDir . DS . 'src';
if (! is_dir($componentCommandDir)) {
continue;
}
$ns = ComponentHelper::getComponentNamespace($component, $componentDir);
$this->componentNamespaces[] = $ns;
// console component
if ($component == $this->consoleName) {
$this->scanNamespaces[$ns] = $componentCommandDir;
continue;
}
foreach ($this->serverScan as $dir) {
$scanDir = $componentCommandDir . DS . $dir;
if (!is_dir($scanDir)) {
continue;
}
$scanNs = $ns . "\\" . $dir;
$this->scanNamespaces[$scanNs] = $scanDir;
}
}
$this->registerServerNamespace();
} | php | public function registerNamespace()
{
$swoftDir = dirname(__FILE__, 5);
$componentDirs = scandir($swoftDir);
foreach ($componentDirs as $component) {
if ($component == '.' || $component == '..') {
continue;
}
$componentDir = $swoftDir . DS . $component;
$componentCommandDir = $componentDir . DS . 'src';
if (! is_dir($componentCommandDir)) {
continue;
}
$ns = ComponentHelper::getComponentNamespace($component, $componentDir);
$this->componentNamespaces[] = $ns;
// console component
if ($component == $this->consoleName) {
$this->scanNamespaces[$ns] = $componentCommandDir;
continue;
}
foreach ($this->serverScan as $dir) {
$scanDir = $componentCommandDir . DS . $dir;
if (!is_dir($scanDir)) {
continue;
}
$scanNs = $ns . "\\" . $dir;
$this->scanNamespaces[$scanNs] = $scanDir;
}
}
$this->registerServerNamespace();
} | [
"public",
"function",
"registerNamespace",
"(",
")",
"{",
"$",
"swoftDir",
"=",
"dirname",
"(",
"__FILE__",
",",
"5",
")",
";",
"$",
"componentDirs",
"=",
"scandir",
"(",
"$",
"swoftDir",
")",
";",
"foreach",
"(",
"$",
"componentDirs",
"as",
"$",
"compon... | Register the scaned namespace | [
"Register",
"the",
"scaned",
"namespace"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Resource/ServerAnnotationResource.php#L17-L53 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/AbstractServer.php | AbstractServer.registerSwooleServerEvents | protected function registerSwooleServerEvents()
{
$swooleListeners = SwooleListenerCollector::getCollector();
if (!isset($swooleListeners[SwooleEvent::TYPE_SERVER]) || empty($swooleListeners[SwooleEvent::TYPE_SERVER])) {
return;
}
$swooleServerListeners = $swooleListeners[SwooleEvent::TYPE_SERVER];
$this->registerSwooleEvents($this->server, $swooleServerListeners);
} | php | protected function registerSwooleServerEvents()
{
$swooleListeners = SwooleListenerCollector::getCollector();
if (!isset($swooleListeners[SwooleEvent::TYPE_SERVER]) || empty($swooleListeners[SwooleEvent::TYPE_SERVER])) {
return;
}
$swooleServerListeners = $swooleListeners[SwooleEvent::TYPE_SERVER];
$this->registerSwooleEvents($this->server, $swooleServerListeners);
} | [
"protected",
"function",
"registerSwooleServerEvents",
"(",
")",
"{",
"$",
"swooleListeners",
"=",
"SwooleListenerCollector",
"::",
"getCollector",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"swooleListeners",
"[",
"SwooleEvent",
"::",
"TYPE_SERVER",
"]",
... | Register the event callback of swoole server | [
"Register",
"the",
"event",
"callback",
"of",
"swoole",
"server"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/AbstractServer.php#L88-L98 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/AbstractServer.php | AbstractServer.registerSwooleEvents | protected function registerSwooleEvents($handler, array $events)
{
foreach ($events as $event => $beanName) {
$object = bean($beanName);
$method = SwooleEvent::getHandlerFunction($event);
$handler->on($event, [$object, $method]);
}
} | php | protected function registerSwooleEvents($handler, array $events)
{
foreach ($events as $event => $beanName) {
$object = bean($beanName);
$method = SwooleEvent::getHandlerFunction($event);
$handler->on($event, [$object, $method]);
}
} | [
"protected",
"function",
"registerSwooleEvents",
"(",
"$",
"handler",
",",
"array",
"$",
"events",
")",
"{",
"foreach",
"(",
"$",
"events",
"as",
"$",
"event",
"=>",
"$",
"beanName",
")",
"{",
"$",
"object",
"=",
"bean",
"(",
"$",
"beanName",
")",
";",... | Register swoole server events
@param Server $handler
@param array $events | [
"Register",
"swoole",
"server",
"events"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/AbstractServer.php#L106-L113 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/AbstractServer.php | AbstractServer.reload | public function reload($onlyTask = false)
{
$signal = $onlyTask ? SIGUSR2 : SIGUSR1;
swoole_process::kill($this->serverSetting['managerPid'], $signal);
} | php | public function reload($onlyTask = false)
{
$signal = $onlyTask ? SIGUSR2 : SIGUSR1;
swoole_process::kill($this->serverSetting['managerPid'], $signal);
} | [
"public",
"function",
"reload",
"(",
"$",
"onlyTask",
"=",
"false",
")",
"{",
"$",
"signal",
"=",
"$",
"onlyTask",
"?",
"SIGUSR2",
":",
"SIGUSR1",
";",
"swoole_process",
"::",
"kill",
"(",
"$",
"this",
"->",
"serverSetting",
"[",
"'managerPid'",
"]",
","... | Reload workers
@param bool $onlyTask Only reload TaskWorkers | [
"Reload",
"workers"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/AbstractServer.php#L120-L124 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/AbstractServer.php | AbstractServer.stop | public function stop(): bool
{
// 获取master进程ID
$masterPid = $this->serverSetting['masterPid'];
// 使用swoole_process::kill代替posix_kill
$result = swoole_process::kill($masterPid);
$timeout = 60;
$startTime = time();
while (true) {
// Check the process status
if (swoole_process::kill($masterPid, 0)) {
// 判断是否超时
if (time() - $startTime >= $timeout) {
return false;
}
usleep(10000);
continue;
}
return true;
}
} | php | public function stop(): bool
{
// 获取master进程ID
$masterPid = $this->serverSetting['masterPid'];
// 使用swoole_process::kill代替posix_kill
$result = swoole_process::kill($masterPid);
$timeout = 60;
$startTime = time();
while (true) {
// Check the process status
if (swoole_process::kill($masterPid, 0)) {
// 判断是否超时
if (time() - $startTime >= $timeout) {
return false;
}
usleep(10000);
continue;
}
return true;
}
} | [
"public",
"function",
"stop",
"(",
")",
":",
"bool",
"{",
"// 获取master进程ID",
"$",
"masterPid",
"=",
"$",
"this",
"->",
"serverSetting",
"[",
"'masterPid'",
"]",
";",
"// 使用swoole_process::kill代替posix_kill",
"$",
"result",
"=",
"swoole_process",
"::",
"kill",
"("... | Stop server | [
"Stop",
"server"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/AbstractServer.php#L129-L150 |
swoft-cloud/swoft-framework | src/Bootstrap/Server/AbstractServer.php | AbstractServer.initSettings | 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'];
}
} | php | 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'];
}
} | [
"public",
"function",
"initSettings",
"(",
"array",
"$",
"settings",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"settings",
"[",
"'tcp'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Tcp startup parameter is not configured,setti... | Init settings
@param array[] $settings
@throws \InvalidArgumentException | [
"Init",
"settings"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Server/AbstractServer.php#L238-L275 |
swoft-cloud/swoft-framework | src/Helper/FileHelper.php | FileHelper.getSuffix | public static function getSuffix($filename, $clearPoint = false): string
{
$suffix = strrchr($filename, '.');
return (bool)$clearPoint ? trim($suffix, '.') : $suffix;
} | php | public static function getSuffix($filename, $clearPoint = false): string
{
$suffix = strrchr($filename, '.');
return (bool)$clearPoint ? trim($suffix, '.') : $suffix;
} | [
"public",
"static",
"function",
"getSuffix",
"(",
"$",
"filename",
",",
"$",
"clearPoint",
"=",
"false",
")",
":",
"string",
"{",
"$",
"suffix",
"=",
"strrchr",
"(",
"$",
"filename",
",",
"'.'",
")",
";",
"return",
"(",
"bool",
")",
"$",
"clearPoint",
... | 获得文件扩展名、后缀名
@param $filename
@param bool $clearPoint 是否带点
@return string | [
"获得文件扩展名、后缀名"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/FileHelper.php#L23-L28 |
swoft-cloud/swoft-framework | src/Helper/FileHelper.php | FileHelper.md5File | public static function md5File($dir)
{
if (!is_dir($dir)) {
return '';
}
$md5File = array();
$d = dir($dir);
while (false !== ($entry = $d->read())) {
if ($entry !== '.' && $entry !== '..') {
if (is_dir($dir . '/' . $entry)) {
$md5File[] = self::md5File($dir . '/' . $entry);
} elseif (substr($entry, -4) === '.php') {
$md5File[] = md5_file($dir . '/' . $entry);
}
$md5File[] = $entry;
}
}
$d->close();
return md5(implode('', $md5File));
} | php | public static function md5File($dir)
{
if (!is_dir($dir)) {
return '';
}
$md5File = array();
$d = dir($dir);
while (false !== ($entry = $d->read())) {
if ($entry !== '.' && $entry !== '..') {
if (is_dir($dir . '/' . $entry)) {
$md5File[] = self::md5File($dir . '/' . $entry);
} elseif (substr($entry, -4) === '.php') {
$md5File[] = md5_file($dir . '/' . $entry);
}
$md5File[] = $entry;
}
}
$d->close();
return md5(implode('', $md5File));
} | [
"public",
"static",
"function",
"md5File",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"md5File",
"=",
"array",
"(",
")",
";",
"$",
"d",
"=",
"dir",
"(",
"$",
"dir",
")",... | md5 of dir
@param string $dir
@return bool|string | [
"md5",
"of",
"dir"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/FileHelper.php#L57-L78 |
swoft-cloud/swoft-framework | src/Bootstrap/Bootstrap.php | Bootstrap.bootstrap | public function bootstrap()
{
$bootstraps = BootstrapCollector::getCollector();
$temp = \array_column($bootstraps, 'order');
\array_multisort($temp, SORT_ASC, $bootstraps);
foreach ($bootstraps as $bootstrapBeanName => $name){
/* @var Bootable $bootstrap*/
$bootstrap = App::getBean($bootstrapBeanName);
$bootstrap->bootstrap();
}
} | php | public function bootstrap()
{
$bootstraps = BootstrapCollector::getCollector();
$temp = \array_column($bootstraps, 'order');
\array_multisort($temp, SORT_ASC, $bootstraps);
foreach ($bootstraps as $bootstrapBeanName => $name){
/* @var Bootable $bootstrap*/
$bootstrap = App::getBean($bootstrapBeanName);
$bootstrap->bootstrap();
}
} | [
"public",
"function",
"bootstrap",
"(",
")",
"{",
"$",
"bootstraps",
"=",
"BootstrapCollector",
"::",
"getCollector",
"(",
")",
";",
"$",
"temp",
"=",
"\\",
"array_column",
"(",
"$",
"bootstraps",
",",
"'order'",
")",
";",
"\\",
"array_multisort",
"(",
"$"... | bootstrap | [
"bootstrap"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bootstrap/Bootstrap.php#L20-L32 |
swoft-cloud/swoft-framework | src/Bean/Parser/DefinitionParser.php | DefinitionParser.parser | public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
{
$beanName = $objectAnnotation->getName();
$beanName = empty($beanName) ? $className : $beanName;
$scope = Scope::SINGLETON;
DefinitionCollector::collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
return [$beanName, $scope, ""];
} | php | public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
{
$beanName = $objectAnnotation->getName();
$beanName = empty($beanName) ? $className : $beanName;
$scope = Scope::SINGLETON;
DefinitionCollector::collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
return [$beanName, $scope, ""];
} | [
"public",
"function",
"parser",
"(",
"string",
"$",
"className",
",",
"$",
"objectAnnotation",
"=",
"null",
",",
"string",
"$",
"propertyName",
"=",
"\"\"",
",",
"string",
"$",
"methodName",
"=",
"\"\"",
",",
"$",
"propertyValue",
"=",
"null",
")",
"{",
... | @param string $className
@param Definition $objectAnnotation
@param string $propertyName
@param string $methodName
@param mixed $propertyValue
@return array | [
"@param",
"string",
"$className",
"@param",
"Definition",
"$objectAnnotation",
"@param",
"string",
"$propertyName",
"@param",
"string",
"$methodName",
"@param",
"mixed",
"$propertyValue"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Parser/DefinitionParser.php#L23-L32 |
swoft-cloud/swoft-framework | src/Proxy/Proxy.php | Proxy.newProxyInstance | public static function newProxyInstance(string $className, HandlerInterface $handler)
{
$reflectionClass = new \ReflectionClass($className);
$reflectionMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED);
// Proxy property
$id = \uniqid('', false);
$proxyClassName = \basename(str_replace("\\", '/', $className));
$proxyClassName = $proxyClassName . '_' . $id;
$handlerPropertyName = '__handler_' . $id;
// Base class template
$template = "class $proxyClassName extends $className {
private \$$handlerPropertyName;
public function __construct(\$handler)
{
\$this->{$handlerPropertyName} = \$handler;
}
";
// Methods
$template .= self::getMethodsTemplate($reflectionMethods, $handlerPropertyName);
$template .= '}';
eval($template);
$newRc = new \ReflectionClass($proxyClassName);
return $newRc->newInstance($handler);
} | php | public static function newProxyInstance(string $className, HandlerInterface $handler)
{
$reflectionClass = new \ReflectionClass($className);
$reflectionMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED);
// Proxy property
$id = \uniqid('', false);
$proxyClassName = \basename(str_replace("\\", '/', $className));
$proxyClassName = $proxyClassName . '_' . $id;
$handlerPropertyName = '__handler_' . $id;
// Base class template
$template = "class $proxyClassName extends $className {
private \$$handlerPropertyName;
public function __construct(\$handler)
{
\$this->{$handlerPropertyName} = \$handler;
}
";
// Methods
$template .= self::getMethodsTemplate($reflectionMethods, $handlerPropertyName);
$template .= '}';
eval($template);
$newRc = new \ReflectionClass($proxyClassName);
return $newRc->newInstance($handler);
} | [
"public",
"static",
"function",
"newProxyInstance",
"(",
"string",
"$",
"className",
",",
"HandlerInterface",
"$",
"handler",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"reflectionMethods",
"=",
... | Return a proxy instance
@param string $className
@param HandlerInterface $handler
@return object
@throws \ReflectionException | [
"Return",
"a",
"proxy",
"instance"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Proxy/Proxy.php#L20-L48 |
swoft-cloud/swoft-framework | src/Proxy/Proxy.php | Proxy.getMethodsTemplate | private static function getMethodsTemplate(array $reflectionMethods, string $handlerPropertyName): string
{
$template = '';
foreach ($reflectionMethods as $reflectionMethod) {
$methodName = $reflectionMethod->getName();
// not to override method
if ($reflectionMethod->isConstructor() || $reflectionMethod->isStatic()) {
continue;
}
// define override methodBody
$methodBody = "{
return \$this->{$handlerPropertyName}->invoke('{$methodName}', func_get_args());
}
";
// the template of parameter
$template .= " public function $methodName (";
$template .= self::getParameterTemplate($reflectionMethod);
$template .= ' ) ';
// the template of return type
$reflectionMethodReturn = $reflectionMethod->getReturnType();
if ($reflectionMethodReturn !== null) {
$returnType = $reflectionMethodReturn->__toString();
$returnType = $returnType === 'self' ? $reflectionMethod->getDeclaringClass()->getName() : $returnType;
$template .= " : $returnType";
// if returnType is void
if ($returnType === 'void') {
$methodBody = str_replace('return ', '', $methodBody);
}
}
// append methodBody
$template .= $methodBody;
}
return $template;
} | php | private static function getMethodsTemplate(array $reflectionMethods, string $handlerPropertyName): string
{
$template = '';
foreach ($reflectionMethods as $reflectionMethod) {
$methodName = $reflectionMethod->getName();
// not to override method
if ($reflectionMethod->isConstructor() || $reflectionMethod->isStatic()) {
continue;
}
// define override methodBody
$methodBody = "{
return \$this->{$handlerPropertyName}->invoke('{$methodName}', func_get_args());
}
";
// the template of parameter
$template .= " public function $methodName (";
$template .= self::getParameterTemplate($reflectionMethod);
$template .= ' ) ';
// the template of return type
$reflectionMethodReturn = $reflectionMethod->getReturnType();
if ($reflectionMethodReturn !== null) {
$returnType = $reflectionMethodReturn->__toString();
$returnType = $returnType === 'self' ? $reflectionMethod->getDeclaringClass()->getName() : $returnType;
$template .= " : $returnType";
// if returnType is void
if ($returnType === 'void') {
$methodBody = str_replace('return ', '', $methodBody);
}
}
// append methodBody
$template .= $methodBody;
}
return $template;
} | [
"private",
"static",
"function",
"getMethodsTemplate",
"(",
"array",
"$",
"reflectionMethods",
",",
"string",
"$",
"handlerPropertyName",
")",
":",
"string",
"{",
"$",
"template",
"=",
"''",
";",
"foreach",
"(",
"$",
"reflectionMethods",
"as",
"$",
"reflectionMe... | Return the template of method
@param \ReflectionMethod[] $reflectionMethods
@param string $handlerPropertyName
@return string | [
"Return",
"the",
"template",
"of",
"method"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Proxy/Proxy.php#L57-L96 |
swoft-cloud/swoft-framework | src/Proxy/Proxy.php | Proxy.getParameterTemplate | private static function getParameterTemplate(\ReflectionMethod $reflectionMethod): string
{
$template = '';
$reflectionParameters = $reflectionMethod->getParameters();
$paramCount = \count($reflectionParameters);
foreach ($reflectionParameters as $reflectionParameter) {
$paramCount--;
// Parameter type
$type = $reflectionParameter->getType();
if ($type !== null) {
$type = $type->__toString();
$template .= " $type ";
}
// Parameter name
$paramName = $reflectionParameter->getName();
if ($reflectionParameter->isPassedByReference()) {
$template .= " &\${$paramName} ";
} elseif ($reflectionParameter->isVariadic()) {
$template .= " ...\${$paramName} ";
} else {
$template .= " \${$paramName} ";
}
// Parameter default value
if ($reflectionParameter->isOptional() && $reflectionParameter->isVariadic() === false) {
$template .= self::getParameterDefaultValue($reflectionParameter);
}
if ($paramCount !== 0) {
$template .= ',';
}
}
return $template;
} | php | private static function getParameterTemplate(\ReflectionMethod $reflectionMethod): string
{
$template = '';
$reflectionParameters = $reflectionMethod->getParameters();
$paramCount = \count($reflectionParameters);
foreach ($reflectionParameters as $reflectionParameter) {
$paramCount--;
// Parameter type
$type = $reflectionParameter->getType();
if ($type !== null) {
$type = $type->__toString();
$template .= " $type ";
}
// Parameter name
$paramName = $reflectionParameter->getName();
if ($reflectionParameter->isPassedByReference()) {
$template .= " &\${$paramName} ";
} elseif ($reflectionParameter->isVariadic()) {
$template .= " ...\${$paramName} ";
} else {
$template .= " \${$paramName} ";
}
// Parameter default value
if ($reflectionParameter->isOptional() && $reflectionParameter->isVariadic() === false) {
$template .= self::getParameterDefaultValue($reflectionParameter);
}
if ($paramCount !== 0) {
$template .= ',';
}
}
return $template;
} | [
"private",
"static",
"function",
"getParameterTemplate",
"(",
"\\",
"ReflectionMethod",
"$",
"reflectionMethod",
")",
":",
"string",
"{",
"$",
"template",
"=",
"''",
";",
"$",
"reflectionParameters",
"=",
"$",
"reflectionMethod",
"->",
"getParameters",
"(",
")",
... | Return the template of parameter
@param \ReflectionMethod $reflectionMethod
@return string | [
"Return",
"the",
"template",
"of",
"parameter"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Proxy/Proxy.php#L104-L139 |
swoft-cloud/swoft-framework | src/Proxy/Proxy.php | Proxy.getParameterDefaultValue | private static function getParameterDefaultValue(\ReflectionParameter $reflectionParameter): string
{
$template = '';
$defaultValue = $reflectionParameter->getDefaultValue();
if ($reflectionParameter->isDefaultValueConstant()) {
$defaultConst = $reflectionParameter->getDefaultValueConstantName();
$template = " = {$defaultConst}";
} elseif (\is_bool($defaultValue)) {
$value = $defaultValue ? 'true' : 'false';
$template = " = {$value}";
} elseif (\is_string($defaultValue)) {
$template = " = ''";
} elseif (\is_int($defaultValue)) {
$template = ' = 0';
} elseif (\is_array($defaultValue)) {
$template = ' = []';
} elseif (\is_float($defaultValue)) {
$template = ' = []';
} elseif (\is_object($defaultValue) || null === $defaultValue) {
$template = ' = null';
}
return $template;
} | php | private static function getParameterDefaultValue(\ReflectionParameter $reflectionParameter): string
{
$template = '';
$defaultValue = $reflectionParameter->getDefaultValue();
if ($reflectionParameter->isDefaultValueConstant()) {
$defaultConst = $reflectionParameter->getDefaultValueConstantName();
$template = " = {$defaultConst}";
} elseif (\is_bool($defaultValue)) {
$value = $defaultValue ? 'true' : 'false';
$template = " = {$value}";
} elseif (\is_string($defaultValue)) {
$template = " = ''";
} elseif (\is_int($defaultValue)) {
$template = ' = 0';
} elseif (\is_array($defaultValue)) {
$template = ' = []';
} elseif (\is_float($defaultValue)) {
$template = ' = []';
} elseif (\is_object($defaultValue) || null === $defaultValue) {
$template = ' = null';
}
return $template;
} | [
"private",
"static",
"function",
"getParameterDefaultValue",
"(",
"\\",
"ReflectionParameter",
"$",
"reflectionParameter",
")",
":",
"string",
"{",
"$",
"template",
"=",
"''",
";",
"$",
"defaultValue",
"=",
"$",
"reflectionParameter",
"->",
"getDefaultValue",
"(",
... | Get default value of parameter
@param \ReflectionParameter $reflectionParameter
@return string | [
"Get",
"default",
"value",
"of",
"parameter"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Proxy/Proxy.php#L147-L170 |
swoft-cloud/swoft-framework | src/Helper/ValidatorHelper.php | ValidatorHelper.validateInteger | public static function validateInteger(string $name, $value, $min = null, $max = null, bool $throws = true, string $template = '')
{
$params = [
'name' => $name,
'value' => $value,
'min' => $min,
'max' => $max,
];
$template = self::getTemplate($template, $params);
if ($value === null) {
$template = empty($template) ? sprintf('Parameter %s must be passed', $name) : $template;
return self::validateError($template, $throws);
}
if (!preg_match(self::$integerPattern, (string)$value)) {
$template = empty($template) ? sprintf('Parameter %s is not integer type', $name) : $template;
return self::validateError($template, $throws);
}
$value = (int)$value;
if ($min !== null && $value < $min) {
$template = empty($template) ? sprintf('Parameter %s is too small (minimum is %d)', $name, $min) : $template;
return self::validateError($template, $throws);
}
if ($max !== null && $value > $max) {
$template = empty($template) ? sprintf('Parameter %s is too big (maximum is %d)', $name, $max) : $template;
return self::validateError($template, $throws);
}
return (int)$value;
} | php | public static function validateInteger(string $name, $value, $min = null, $max = null, bool $throws = true, string $template = '')
{
$params = [
'name' => $name,
'value' => $value,
'min' => $min,
'max' => $max,
];
$template = self::getTemplate($template, $params);
if ($value === null) {
$template = empty($template) ? sprintf('Parameter %s must be passed', $name) : $template;
return self::validateError($template, $throws);
}
if (!preg_match(self::$integerPattern, (string)$value)) {
$template = empty($template) ? sprintf('Parameter %s is not integer type', $name) : $template;
return self::validateError($template, $throws);
}
$value = (int)$value;
if ($min !== null && $value < $min) {
$template = empty($template) ? sprintf('Parameter %s is too small (minimum is %d)', $name, $min) : $template;
return self::validateError($template, $throws);
}
if ($max !== null && $value > $max) {
$template = empty($template) ? sprintf('Parameter %s is too big (maximum is %d)', $name, $max) : $template;
return self::validateError($template, $throws);
}
return (int)$value;
} | [
"public",
"static",
"function",
"validateInteger",
"(",
"string",
"$",
"name",
",",
"$",
"value",
",",
"$",
"min",
"=",
"null",
",",
"$",
"max",
"=",
"null",
",",
"bool",
"$",
"throws",
"=",
"true",
",",
"string",
"$",
"template",
"=",
"''",
")",
"... | Validate integer
@param string $name Parameter name
@param mixed $value Parameter value
@param int|null $min Parameter minimun value
@param int|null $max Parameter maximum value
@param bool $throws Determine if throw an ValidatorException when invalid
@param string $template
@return mixed
@throws \Swoft\Exception\ValidatorException | [
"Validate",
"integer"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ValidatorHelper.php#L43-L79 |
swoft-cloud/swoft-framework | src/Helper/ValidatorHelper.php | ValidatorHelper.validateFloat | public static function validateFloat(
string $name,
$value,
float $min = null,
float $max = null,
bool $throws = true,
string $template
) {
$params = [
'name' => $name,
'value' => $value,
'min' => $min,
'max' => $max,
];
$template = self::getTemplate($template, $params);
if ($value === null) {
$template = empty($template) ? sprintf('Parameter %s must be passed', $name) : $template;
return self::validateError($template, $throws);
}
if (!preg_match(self::$floatPattern, (string)$value)) {
$template = empty($template) ? sprintf('Parameter %s is not float type', $name) : $template;
return self::validateError($template, $throws);
}
$value = (float)$value;
if ($min !== null && $value < $min) {
$template = empty($template) ? sprintf('Parameter %s is too short (minimum is %d)', $name, $min) : $template;
return self::validateError($template, $throws);
}
if ($max !== null && $value > $max) {
$template = empty($template) ? sprintf('Parameter %s is too large (maximum is %d)', $name, $max) : $template;
return self::validateError($template, $throws);
}
return (float)$value;
} | php | public static function validateFloat(
string $name,
$value,
float $min = null,
float $max = null,
bool $throws = true,
string $template
) {
$params = [
'name' => $name,
'value' => $value,
'min' => $min,
'max' => $max,
];
$template = self::getTemplate($template, $params);
if ($value === null) {
$template = empty($template) ? sprintf('Parameter %s must be passed', $name) : $template;
return self::validateError($template, $throws);
}
if (!preg_match(self::$floatPattern, (string)$value)) {
$template = empty($template) ? sprintf('Parameter %s is not float type', $name) : $template;
return self::validateError($template, $throws);
}
$value = (float)$value;
if ($min !== null && $value < $min) {
$template = empty($template) ? sprintf('Parameter %s is too short (minimum is %d)', $name, $min) : $template;
return self::validateError($template, $throws);
}
if ($max !== null && $value > $max) {
$template = empty($template) ? sprintf('Parameter %s is too large (maximum is %d)', $name, $max) : $template;
return self::validateError($template, $throws);
}
return (float)$value;
} | [
"public",
"static",
"function",
"validateFloat",
"(",
"string",
"$",
"name",
",",
"$",
"value",
",",
"float",
"$",
"min",
"=",
"null",
",",
"float",
"$",
"max",
"=",
"null",
",",
"bool",
"$",
"throws",
"=",
"true",
",",
"string",
"$",
"template",
")"... | Validate float
@param string $name Parameter name
@param mixed $value Parameter value
@param float|null $min Parameter minimun value
@param float|null $max Parameter maximum value
@param bool $throws Determine if throw an ValidatorException when invalid
@param string $template
@throws ValidatorException
@return mixed | [
"Validate",
"float"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ValidatorHelper.php#L145-L187 |
swoft-cloud/swoft-framework | src/Helper/ValidatorHelper.php | ValidatorHelper.validateString | public static function validateString(string $name, $value, int $min = null, int $max = null, bool $throws = true, string $template)
{
$params = [
'name' => $name,
'value' => $value,
'min' => $min,
'max' => $max,
];
$template = self::getTemplate($template, $params);
if ($value === null) {
$template = empty($template) ? sprintf('Parameter %s must be passed', $name) : $template;
return self::validateError($template, $throws);
}
if (!\is_string($value)) {
$template = empty($template) ? sprintf('Parameter %s is not string type', $name) : $template;
return self::validateError($template, $throws);
}
$length = mb_strlen($value);
if ($min !== null && $length < $min) {
$template = empty($template) ? sprintf('Parameter %s length is too short (minimum is %d)', $name, $min) : $template;
return self::validateError($template, $throws);
}
if ($max !== null && $length > $max) {
$template = empty($template) ? sprintf('Parameter %s length is too long (maximum is %d)', $name, $max) : $template;
return self::validateError($template, $throws);
}
return (string)$value;
} | php | public static function validateString(string $name, $value, int $min = null, int $max = null, bool $throws = true, string $template)
{
$params = [
'name' => $name,
'value' => $value,
'min' => $min,
'max' => $max,
];
$template = self::getTemplate($template, $params);
if ($value === null) {
$template = empty($template) ? sprintf('Parameter %s must be passed', $name) : $template;
return self::validateError($template, $throws);
}
if (!\is_string($value)) {
$template = empty($template) ? sprintf('Parameter %s is not string type', $name) : $template;
return self::validateError($template, $throws);
}
$length = mb_strlen($value);
if ($min !== null && $length < $min) {
$template = empty($template) ? sprintf('Parameter %s length is too short (minimum is %d)', $name, $min) : $template;
return self::validateError($template, $throws);
}
if ($max !== null && $length > $max) {
$template = empty($template) ? sprintf('Parameter %s length is too long (maximum is %d)', $name, $max) : $template;
return self::validateError($template, $throws);
}
return (string)$value;
} | [
"public",
"static",
"function",
"validateString",
"(",
"string",
"$",
"name",
",",
"$",
"value",
",",
"int",
"$",
"min",
"=",
"null",
",",
"int",
"$",
"max",
"=",
"null",
",",
"bool",
"$",
"throws",
"=",
"true",
",",
"string",
"$",
"template",
")",
... | Validate string
@param string $name Parameter name
@param mixed $value Parameter value
@param int|null $min Parameter length minimun value
@param int|null $max Parameter length maximum value
@param bool $throws Determine if throw an ValidatorException when invalid
@param string $template
@return mixed
@throws \Swoft\Exception\ValidatorException | [
"Validate",
"string"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ValidatorHelper.php#L202-L237 |
swoft-cloud/swoft-framework | src/Helper/ValidatorHelper.php | ValidatorHelper.validateEnum | public static function validateEnum(string $name, $value, array $validValues, bool $throws = true, string $template)
{
$params = [
'name' => $name,
'value' => JsonHelper::encode($value, JSON_UNESCAPED_UNICODE),
];
$template = self::getTemplate($template, $params);
if ($value === null) {
$template = empty($template) ? sprintf('Parameter %s must be passed', $name) : $template;
return self::validateError($template, $throws);
}
if (!\in_array($value, $validValues, false)) {
$template = empty($template) ? sprintf('Parameter %s is an invalid enum value', $name) : $template;
return self::validateError($template, $throws);
}
return $value;
} | php | public static function validateEnum(string $name, $value, array $validValues, bool $throws = true, string $template)
{
$params = [
'name' => $name,
'value' => JsonHelper::encode($value, JSON_UNESCAPED_UNICODE),
];
$template = self::getTemplate($template, $params);
if ($value === null) {
$template = empty($template) ? sprintf('Parameter %s must be passed', $name) : $template;
return self::validateError($template, $throws);
}
if (!\in_array($value, $validValues, false)) {
$template = empty($template) ? sprintf('Parameter %s is an invalid enum value', $name) : $template;
return self::validateError($template, $throws);
}
return $value;
} | [
"public",
"static",
"function",
"validateEnum",
"(",
"string",
"$",
"name",
",",
"$",
"value",
",",
"array",
"$",
"validValues",
",",
"bool",
"$",
"throws",
"=",
"true",
",",
"string",
"$",
"template",
")",
"{",
"$",
"params",
"=",
"[",
"'name'",
"=>",... | Validate enum
@param string $name Parameter name
@param mixed $value Parameter value
@param array $validValues Enum values
@param bool $throws Determine if throw an ValidatorException when invalid
@param string $template
@return mixed
@throws \Swoft\Exception\ValidatorException | [
"Validate",
"enum"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ValidatorHelper.php#L251-L271 |
swoft-cloud/swoft-framework | src/Helper/ValidatorHelper.php | ValidatorHelper.getTemplate | private static function getTemplate(string $template, array $params): string
{
if (empty($template)) {
return '';
}
$names = array_keys($params);
$replace = array_values($params);
$search = array_map(function ($v) {
return sprintf('{%s}', $v);
}, $names);
return str_replace($search, $replace, $template);
} | php | private static function getTemplate(string $template, array $params): string
{
if (empty($template)) {
return '';
}
$names = array_keys($params);
$replace = array_values($params);
$search = array_map(function ($v) {
return sprintf('{%s}', $v);
}, $names);
return str_replace($search, $replace, $template);
} | [
"private",
"static",
"function",
"getTemplate",
"(",
"string",
"$",
"template",
",",
"array",
"$",
"params",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"template",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"names",
"=",
"array_keys",
... | @param string $template
@param array $params
@return string | [
"@param",
"string",
"$template",
"@param",
"array",
"$params"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ValidatorHelper.php#L279-L291 |
swoft-cloud/swoft-framework | src/Helper/ValidatorHelper.php | ValidatorHelper.validateError | private static function validateError(string $message, bool $throws): bool
{
if ($throws) {
throw new ValidatorException($message);
}
return false;
} | php | private static function validateError(string $message, bool $throws): bool
{
if ($throws) {
throw new ValidatorException($message);
}
return false;
} | [
"private",
"static",
"function",
"validateError",
"(",
"string",
"$",
"message",
",",
"bool",
"$",
"throws",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"throws",
")",
"{",
"throw",
"new",
"ValidatorException",
"(",
"$",
"message",
")",
";",
"}",
"return",
... | Throw a ValidatorException
@param string $message
@param bool $throws
@return bool
@throws \Swoft\Exception\ValidatorException | [
"Throw",
"a",
"ValidatorException"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/ValidatorHelper.php#L302-L309 |
swoft-cloud/swoft-framework | src/Bean/Parser/MethodWithoutAnnotationParser.php | MethodWithoutAnnotationParser.parser | public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
{
$swoftDir = dirname(__FILE__, 5);
$componentDirs = scandir($swoftDir);
foreach ($componentDirs as $component) {
if ($component == '.' || $component == '..') {
continue;
}
$componentCommandDir = $swoftDir . DS . $component . DS . 'src/Bean/Collector';
if (!is_dir($componentCommandDir)) {
continue;
}
$componentNs = ComponentHelper::getComponentNs($component);
$collectNs = "Swoft{$componentNs}\\Bean\\Collector";
$collectorFiles = scandir($componentCommandDir);
foreach ($collectorFiles as $collectorFile){
$pathInfo = pathinfo($collectorFile);
if(!isset($pathInfo['filename'])){
continue;
}
$fileName = $pathInfo['filename'];
$collectClassName = $collectNs.'\\'.$fileName;
if(!class_exists($collectClassName)){
continue;
}
/* @var \Swoft\Bean\CollectorInterface $collector */
$collector = new $collectClassName();
$collector->collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
}
}
return null;
} | php | public function parser(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null)
{
$swoftDir = dirname(__FILE__, 5);
$componentDirs = scandir($swoftDir);
foreach ($componentDirs as $component) {
if ($component == '.' || $component == '..') {
continue;
}
$componentCommandDir = $swoftDir . DS . $component . DS . 'src/Bean/Collector';
if (!is_dir($componentCommandDir)) {
continue;
}
$componentNs = ComponentHelper::getComponentNs($component);
$collectNs = "Swoft{$componentNs}\\Bean\\Collector";
$collectorFiles = scandir($componentCommandDir);
foreach ($collectorFiles as $collectorFile){
$pathInfo = pathinfo($collectorFile);
if(!isset($pathInfo['filename'])){
continue;
}
$fileName = $pathInfo['filename'];
$collectClassName = $collectNs.'\\'.$fileName;
if(!class_exists($collectClassName)){
continue;
}
/* @var \Swoft\Bean\CollectorInterface $collector */
$collector = new $collectClassName();
$collector->collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
}
}
return null;
} | [
"public",
"function",
"parser",
"(",
"string",
"$",
"className",
",",
"$",
"objectAnnotation",
"=",
"null",
",",
"string",
"$",
"propertyName",
"=",
"\"\"",
",",
"string",
"$",
"methodName",
"=",
"\"\"",
",",
"$",
"propertyValue",
"=",
"null",
")",
"{",
... | 方法没有注解解析
@param string $className
@param null $objectAnnotation
@param string $propertyName
@param string $methodName
@param null $propertyValue
@return mixed | [
"方法没有注解解析"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Parser/MethodWithoutAnnotationParser.php#L29-L64 |
swoft-cloud/swoft-framework | src/Helper/DirHelper.php | DirHelper.glob | public static function glob(string $path, $pattern = null, $strategy = self::SCAN_DFS): array
{
if (! is_dir($path) || ! $pattern) {
throw new \InvalidArgumentException('Invalid $path or $pattern for DirHelper::glob');
}
$files = self::scan($path, $strategy);
$result = [];
foreach ($files as $file) {
if (false === self::matchPattern($pattern, $file)) {
continue;
}
$result[] = $file;
}
return $result;
} | php | public static function glob(string $path, $pattern = null, $strategy = self::SCAN_DFS): array
{
if (! is_dir($path) || ! $pattern) {
throw new \InvalidArgumentException('Invalid $path or $pattern for DirHelper::glob');
}
$files = self::scan($path, $strategy);
$result = [];
foreach ($files as $file) {
if (false === self::matchPattern($pattern, $file)) {
continue;
}
$result[] = $file;
}
return $result;
} | [
"public",
"static",
"function",
"glob",
"(",
"string",
"$",
"path",
",",
"$",
"pattern",
"=",
"null",
",",
"$",
"strategy",
"=",
"self",
"::",
"SCAN_DFS",
")",
":",
"array",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
"||",
"!",
"$",
"p... | 根据规则扫描文件路径
@param string $path 扫描路径
@param null $pattern 扫描匹配规则
@param string $strategy 扫描算法
@return array
@throws \InvalidArgumentException | [
"根据规则扫描文件路径"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/DirHelper.php#L37-L52 |
swoft-cloud/swoft-framework | src/Helper/DirHelper.php | DirHelper.scan | public static function scan(string $path, $strategy = self::SCAN_CURRENT_DIR, $excludeDir = true): array
{
if (! is_dir($path)) {
throw new \InvalidArgumentException('Invalid $path for DirHelper::scan');
}
switch ($strategy) {
case self::SCAN_CURRENT_DIR:
$files = self::scanCurrentDir($path, $excludeDir);
break;
case self::SCAN_BFS:
$files = self::scanBfs($path, $excludeDir);;
break;
case self::SCAN_DFS:
$files = self::scanDfs($path, $excludeDir);
break;
default:
throw new \InvalidArgumentException('Invalid $strategy for DirHelper::glob');
}
return $files;
} | php | public static function scan(string $path, $strategy = self::SCAN_CURRENT_DIR, $excludeDir = true): array
{
if (! is_dir($path)) {
throw new \InvalidArgumentException('Invalid $path for DirHelper::scan');
}
switch ($strategy) {
case self::SCAN_CURRENT_DIR:
$files = self::scanCurrentDir($path, $excludeDir);
break;
case self::SCAN_BFS:
$files = self::scanBfs($path, $excludeDir);;
break;
case self::SCAN_DFS:
$files = self::scanDfs($path, $excludeDir);
break;
default:
throw new \InvalidArgumentException('Invalid $strategy for DirHelper::glob');
}
return $files;
} | [
"public",
"static",
"function",
"scan",
"(",
"string",
"$",
"path",
",",
"$",
"strategy",
"=",
"self",
"::",
"SCAN_CURRENT_DIR",
",",
"$",
"excludeDir",
"=",
"true",
")",
":",
"array",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
... | 扫描路径的所有文件
@param string $path 扫描路径
@param string $strategy 扫描算法
@param bool $excludeDir 是否忽略文件夹
@return array
@throws \InvalidArgumentException | [
"扫描路径的所有文件"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/DirHelper.php#L63-L84 |
swoft-cloud/swoft-framework | src/Helper/DirHelper.php | DirHelper.matchPattern | public static function matchPattern(string $pattern, string $fileName): bool
{
$replaceMap = [
'*' => '.*',
'.' => '\.',
'+' => '.+',
'/' => '\/',
];
$pattern = str_replace(array_keys($replaceMap), array_values($replaceMap), $pattern);
$pattern = '/' . $pattern . '/i';
if (preg_match($pattern, $fileName)) {
return true;
}
return false;
} | php | public static function matchPattern(string $pattern, string $fileName): bool
{
$replaceMap = [
'*' => '.*',
'.' => '\.',
'+' => '.+',
'/' => '\/',
];
$pattern = str_replace(array_keys($replaceMap), array_values($replaceMap), $pattern);
$pattern = '/' . $pattern . '/i';
if (preg_match($pattern, $fileName)) {
return true;
}
return false;
} | [
"public",
"static",
"function",
"matchPattern",
"(",
"string",
"$",
"pattern",
",",
"string",
"$",
"fileName",
")",
":",
"bool",
"{",
"$",
"replaceMap",
"=",
"[",
"'*'",
"=>",
"'.*'",
",",
"'.'",
"=>",
"'\\.'",
",",
"'+'",
"=>",
"'.+'",
",",
"'/'",
"... | $fileName 是否匹配 $pattern 规则
@param string $pattern
@param string $fileName
@return bool | [
"$fileName",
"是否匹配",
"$pattern",
"规则"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/DirHelper.php#L108-L125 |
swoft-cloud/swoft-framework | src/Helper/DirHelper.php | DirHelper.basename | public static function basename(array $pathes, $suffix = ''): array
{
if (! $pathes) {
return [];
}
$ret = [];
foreach ($pathes as $path) {
$ret[] = basename($path, $suffix);
}
return $ret;
} | php | public static function basename(array $pathes, $suffix = ''): array
{
if (! $pathes) {
return [];
}
$ret = [];
foreach ($pathes as $path) {
$ret[] = basename($path, $suffix);
}
return $ret;
} | [
"public",
"static",
"function",
"basename",
"(",
"array",
"$",
"pathes",
",",
"$",
"suffix",
"=",
"''",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"pathes",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(... | 获取路径中的文件名
@param array $pathes
@param string $suffix If the filename ends in suffix this will also be cut off
@return array | [
"获取路径中的文件名"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/DirHelper.php#L134-L146 |
swoft-cloud/swoft-framework | src/Helper/DirHelper.php | DirHelper.scanCurrentDir | private static function scanCurrentDir(string $path, bool $ignoreDir = true): array
{
$path = self::formatPath($path);
$dh = opendir($path);
if (! $dh) {
return [];
}
$files = [];
while (false !== ($file = readdir($dh))) {
if ($file == '.' || $file == '..') {
continue;
}
$fileType = filetype($path . $file);
if ('dir' == $fileType && false === $ignoreDir) {
$files[] = $path . $file . '/';
}
if ('file' == $fileType) {
$files[] = $path . $file;
}
}
closedir($dh);
return $files;
} | php | private static function scanCurrentDir(string $path, bool $ignoreDir = true): array
{
$path = self::formatPath($path);
$dh = opendir($path);
if (! $dh) {
return [];
}
$files = [];
while (false !== ($file = readdir($dh))) {
if ($file == '.' || $file == '..') {
continue;
}
$fileType = filetype($path . $file);
if ('dir' == $fileType && false === $ignoreDir) {
$files[] = $path . $file . '/';
}
if ('file' == $fileType) {
$files[] = $path . $file;
}
}
closedir($dh);
return $files;
} | [
"private",
"static",
"function",
"scanCurrentDir",
"(",
"string",
"$",
"path",
",",
"bool",
"$",
"ignoreDir",
"=",
"true",
")",
":",
"array",
"{",
"$",
"path",
"=",
"self",
"::",
"formatPath",
"(",
"$",
"path",
")",
";",
"$",
"dh",
"=",
"opendir",
"(... | 扫描当前层级文件夹
@param string $path 路径
@param bool $ignoreDir 是否忽略文件夹
@return array | [
"扫描当前层级文件夹"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/DirHelper.php#L155-L178 |
swoft-cloud/swoft-framework | src/Helper/DirHelper.php | DirHelper.scanBfs | private static function scanBfs(string $path, bool $ignoreDir = true): array
{
$files = [];
$queue = new \SplQueue();
$queue->enqueue($path);
while (! $queue->isEmpty()) {
$file = $queue->dequeue();
$fileType = filetype($file);
if ('dir' == $fileType) {
$subFiles = self::scanCurrentDir($file, false);
foreach ($subFiles as $subFile) {
$queue->enqueue($subFile);
}
if (false === $ignoreDir && $file !== $path) {
$files[] = $file;
}
}
if ('file' == $fileType) {
$files[] = $file;
}
}
return $files;
} | php | private static function scanBfs(string $path, bool $ignoreDir = true): array
{
$files = [];
$queue = new \SplQueue();
$queue->enqueue($path);
while (! $queue->isEmpty()) {
$file = $queue->dequeue();
$fileType = filetype($file);
if ('dir' == $fileType) {
$subFiles = self::scanCurrentDir($file, false);
foreach ($subFiles as $subFile) {
$queue->enqueue($subFile);
}
if (false === $ignoreDir && $file !== $path) {
$files[] = $file;
}
}
if ('file' == $fileType) {
$files[] = $file;
}
}
return $files;
} | [
"private",
"static",
"function",
"scanBfs",
"(",
"string",
"$",
"path",
",",
"bool",
"$",
"ignoreDir",
"=",
"true",
")",
":",
"array",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"queue",
"=",
"new",
"\\",
"SplQueue",
"(",
")",
";",
"$",
"queue",
... | 以广度优先搜索扫描路径
@param string $path 路径
@param bool $ignoreDir 是否忽略文件夹
@return array | [
"以广度优先搜索扫描路径"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/DirHelper.php#L187-L210 |
swoft-cloud/swoft-framework | src/Helper/DirHelper.php | DirHelper.scanDfs | private static function scanDfs(string $path, bool $excludeDir = true): array
{
$files = [];
$subFiles = self::scanCurrentDir($path, false);
foreach ($subFiles as $subFile) {
$fileType = filetype($subFile);
if ('dir' == $fileType) {
$innerFiles = self::scanDfs($subFile, $excludeDir);
$files = ArrayHelper::merge($files, $innerFiles);
if (false === $excludeDir) {
$files[] = $subFile;
}
}
if ('file' == $fileType) {
$files[] = $subFile;
}
}
return $files;
} | php | private static function scanDfs(string $path, bool $excludeDir = true): array
{
$files = [];
$subFiles = self::scanCurrentDir($path, false);
foreach ($subFiles as $subFile) {
$fileType = filetype($subFile);
if ('dir' == $fileType) {
$innerFiles = self::scanDfs($subFile, $excludeDir);
$files = ArrayHelper::merge($files, $innerFiles);
if (false === $excludeDir) {
$files[] = $subFile;
}
}
if ('file' == $fileType) {
$files[] = $subFile;
}
}
return $files;
} | [
"private",
"static",
"function",
"scanDfs",
"(",
"string",
"$",
"path",
",",
"bool",
"$",
"excludeDir",
"=",
"true",
")",
":",
"array",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"subFiles",
"=",
"self",
"::",
"scanCurrentDir",
"(",
"$",
"path",
","... | 以深度优先搜索扫描路径
@param string $path 路径
@param bool $excludeDir 是否忽略文件夹
@return array | [
"以深度优先搜索扫描路径"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Helper/DirHelper.php#L219-L238 |
swoft-cloud/swoft-framework | src/Log/Logger.php | Logger.addRecord | public function addRecord($level, $message, array $context = array())
{
if (! $this->enable) {
return true;
}
$levelName = static::getLevelName($level);
if (! static::$timezone) {
static::$timezone = new \DateTimeZone(date_default_timezone_get() ? : 'UTC');
}
// php7.1+ always has microseconds enabled, so we do not need this hack
if ($this->microsecondTimestamps && PHP_VERSION_ID < 70100) {
$ts = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone);
} else {
$ts = new \DateTime(null, static::$timezone);
}
$ts->setTimezone(static::$timezone);
$message = $this->formatMessage($message);
$message = $this->getTrace($message);
$record = $this->formateRecord($message, $context, $level, $levelName, $ts, []);
foreach ($this->processors as $processor) {
$record = \Swoole\Coroutine::call_user_func($processor, $record);
}
$this->messages[] = $record;
if (App::$isInTest || \count($this->messages) >= $this->flushInterval) {
$this->flushLog();
}
return true;
} | php | public function addRecord($level, $message, array $context = array())
{
if (! $this->enable) {
return true;
}
$levelName = static::getLevelName($level);
if (! static::$timezone) {
static::$timezone = new \DateTimeZone(date_default_timezone_get() ? : 'UTC');
}
// php7.1+ always has microseconds enabled, so we do not need this hack
if ($this->microsecondTimestamps && PHP_VERSION_ID < 70100) {
$ts = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone);
} else {
$ts = new \DateTime(null, static::$timezone);
}
$ts->setTimezone(static::$timezone);
$message = $this->formatMessage($message);
$message = $this->getTrace($message);
$record = $this->formateRecord($message, $context, $level, $levelName, $ts, []);
foreach ($this->processors as $processor) {
$record = \Swoole\Coroutine::call_user_func($processor, $record);
}
$this->messages[] = $record;
if (App::$isInTest || \count($this->messages) >= $this->flushInterval) {
$this->flushLog();
}
return true;
} | [
"public",
"function",
"addRecord",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enable",
")",
"{",
"return",
"true",
";",
"}",
"$",
"levelName",
"=",
"... | 记录日志
@param int $level 日志级别
@param mixed $message 信息
@param array $context 附加信息
@return bool | [
"记录日志"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/Logger.php#L105-L141 |
swoft-cloud/swoft-framework | src/Log/Logger.php | Logger.formateRecord | public function formateRecord($message, $context, $level, $levelName, $ts, $extra)
{
$record = array(
'logid' => RequestContext::getLogid(),
'spanid' => RequestContext::getSpanid(),
'messages' => $message,
'context' => $context,
'level' => $level,
'level_name' => $levelName,
'channel' => $this->name,
'datetime' => $ts,
'extra' => $extra,
);
return $record;
} | php | public function formateRecord($message, $context, $level, $levelName, $ts, $extra)
{
$record = array(
'logid' => RequestContext::getLogid(),
'spanid' => RequestContext::getSpanid(),
'messages' => $message,
'context' => $context,
'level' => $level,
'level_name' => $levelName,
'channel' => $this->name,
'datetime' => $ts,
'extra' => $extra,
);
return $record;
} | [
"public",
"function",
"formateRecord",
"(",
"$",
"message",
",",
"$",
"context",
",",
"$",
"level",
",",
"$",
"levelName",
",",
"$",
"ts",
",",
"$",
"extra",
")",
"{",
"$",
"record",
"=",
"array",
"(",
"'logid'",
"=>",
"RequestContext",
"::",
"getLogid... | 格式化一条日志记录
@param string $message 信息
@param array $context 上下文信息
@param int $level 级别
@param string $levelName 级别名
@param \DateTime $ts 时间
@param array $extra 附加信息
@return array | [
"格式化一条日志记录"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/Logger.php#L154-L169 |
swoft-cloud/swoft-framework | src/Log/Logger.php | Logger.pushLog | public function pushLog($key, $val)
{
if (! $this->enable || ! (\is_string($key) || is_numeric($key))) {
return;
}
$key = urlencode($key);
$cid = Coroutine::tid();
if (\is_array($val)) {
$this->pushlogs[$cid][] = "$key=" . json_encode($val);
} elseif (\is_bool($val)) {
$this->pushlogs[$cid][] = "$key=" . var_export($val, true);
} elseif (\is_string($val) || is_numeric($val)) {
$this->pushlogs[$cid][] = "$key=" . urlencode($val);
} elseif (null === $val) {
$this->pushlogs[$cid][] = "$key=";
}
} | php | public function pushLog($key, $val)
{
if (! $this->enable || ! (\is_string($key) || is_numeric($key))) {
return;
}
$key = urlencode($key);
$cid = Coroutine::tid();
if (\is_array($val)) {
$this->pushlogs[$cid][] = "$key=" . json_encode($val);
} elseif (\is_bool($val)) {
$this->pushlogs[$cid][] = "$key=" . var_export($val, true);
} elseif (\is_string($val) || is_numeric($val)) {
$this->pushlogs[$cid][] = "$key=" . urlencode($val);
} elseif (null === $val) {
$this->pushlogs[$cid][] = "$key=";
}
} | [
"public",
"function",
"pushLog",
"(",
"$",
"key",
",",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enable",
"||",
"!",
"(",
"\\",
"is_string",
"(",
"$",
"key",
")",
"||",
"is_numeric",
"(",
"$",
"key",
")",
")",
")",
"{",
"return"... | pushlog日志
@param string $key 记录KEY
@param mixed $val 记录值 | [
"pushlog日志"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/Logger.php#L177-L194 |
swoft-cloud/swoft-framework | src/Log/Logger.php | Logger.profileStart | public function profileStart($name)
{
if (! $this->enable || \is_string($name) === false || empty($name)) {
return;
}
$cid = Coroutine::tid();
$this->profileStacks[$cid][$name]['start'] = microtime(true);
} | php | public function profileStart($name)
{
if (! $this->enable || \is_string($name) === false || empty($name)) {
return;
}
$cid = Coroutine::tid();
$this->profileStacks[$cid][$name]['start'] = microtime(true);
} | [
"public",
"function",
"profileStart",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enable",
"||",
"\\",
"is_string",
"(",
"$",
"name",
")",
"===",
"false",
"||",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
";",
"}",
"$"... | 标记开始
@param string $name 标记名称 | [
"标记开始"
] | train | https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Log/Logger.php#L201-L208 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.