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
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
lootils/archiver | src/Lootils/Archiver/TarArchive.php | TarArchive.contents | public function contents()
{
$files = array();
foreach ($this->tar->listContent() as $data) {
$files[$data['filename']] = $data;
}
return $files;
} | php | public function contents()
{
$files = array();
foreach ($this->tar->listContent() as $data) {
$files[$data['filename']] = $data;
}
return $files;
} | [
"public",
"function",
"contents",
"(",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"tar",
"->",
"listContent",
"(",
")",
"as",
"$",
"data",
")",
"{",
"$",
"files",
"[",
"$",
"data",
"[",
"'filename'",
"]",
"]",
"=",
"$",
"data",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Retrieve an array of the archive contents. | [
"Retrieve",
"an",
"array",
"of",
"the",
"archive",
"contents",
"."
] | train | https://github.com/lootils/archiver/blob/5b801bddfe15f7378a118c4094f04b37abb5a53e/src/Lootils/Archiver/TarArchive.php#L72-L80 |
yuncms/framework | src/sms/captcha/CaptchaAction.php | CaptchaAction.init | public function init()
{
parent::init();
$this->sessionKey = $this->getSessionKey();
$this->cache = Instance::ensure($this->cache, Cache::class);
} | php | public function init()
{
parent::init();
$this->sessionKey = $this->getSessionKey();
$this->cache = Instance::ensure($this->cache, Cache::class);
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"$",
"this",
"->",
"sessionKey",
"=",
"$",
"this",
"->",
"getSessionKey",
"(",
")",
";",
"$",
"this",
"->",
"cache",
"=",
"Instance",
"::",
"ensure",
"(",
"$",
"this",
"->",
"cache",
",",
"Cache",
"::",
"class",
")",
";",
"}"
] | 初始化组件
@throws \yii\base\InvalidConfigException | [
"初始化组件"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sms/captcha/CaptchaAction.php#L85-L90 |
yuncms/framework | src/sms/captcha/CaptchaAction.php | CaptchaAction.getVerifyCode | public function getVerifyCode($regenerate = false)
{
if ($this->fixedVerifyCode !== null) {
return $this->fixedVerifyCode;
}
$verifyCode = $this->cache->get($this->sessionKey);
if ($verifyCode === null || $regenerate) {
$verifyCode = $this->generateVerifyCode();
Yii::$app->cache->multiSet([
$this->sessionKey => $verifyCode,
$this->sessionKey . 'time' => time(),
], $this->waitTime);
Yii::$app->cache->multiSet([
$this->sessionKey . 'mobile' => $this->mobile,
$this->sessionKey . 'count' => 1,
], $this->duration);
}
return $verifyCode;
} | php | public function getVerifyCode($regenerate = false)
{
if ($this->fixedVerifyCode !== null) {
return $this->fixedVerifyCode;
}
$verifyCode = $this->cache->get($this->sessionKey);
if ($verifyCode === null || $regenerate) {
$verifyCode = $this->generateVerifyCode();
Yii::$app->cache->multiSet([
$this->sessionKey => $verifyCode,
$this->sessionKey . 'time' => time(),
], $this->waitTime);
Yii::$app->cache->multiSet([
$this->sessionKey . 'mobile' => $this->mobile,
$this->sessionKey . 'count' => 1,
], $this->duration);
}
return $verifyCode;
} | [
"public",
"function",
"getVerifyCode",
"(",
"$",
"regenerate",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fixedVerifyCode",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"fixedVerifyCode",
";",
"}",
"$",
"verifyCode",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"this",
"->",
"sessionKey",
")",
";",
"if",
"(",
"$",
"verifyCode",
"===",
"null",
"||",
"$",
"regenerate",
")",
"{",
"$",
"verifyCode",
"=",
"$",
"this",
"->",
"generateVerifyCode",
"(",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"cache",
"->",
"multiSet",
"(",
"[",
"$",
"this",
"->",
"sessionKey",
"=>",
"$",
"verifyCode",
",",
"$",
"this",
"->",
"sessionKey",
".",
"'time'",
"=>",
"time",
"(",
")",
",",
"]",
",",
"$",
"this",
"->",
"waitTime",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"cache",
"->",
"multiSet",
"(",
"[",
"$",
"this",
"->",
"sessionKey",
".",
"'mobile'",
"=>",
"$",
"this",
"->",
"mobile",
",",
"$",
"this",
"->",
"sessionKey",
".",
"'count'",
"=>",
"1",
",",
"]",
",",
"$",
"this",
"->",
"duration",
")",
";",
"}",
"return",
"$",
"verifyCode",
";",
"}"
] | 获取验证码
@param boolean $regenerate 是否重新生成验证码
@return string 验证码 | [
"获取验证码"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sms/captcha/CaptchaAction.php#L139-L158 |
yuncms/framework | src/sms/captcha/CaptchaAction.php | CaptchaAction.validate | public function validate($input, $caseSensitive)
{
$code = $this->getVerifyCode();
$valid = $caseSensitive ? ($input === $code) : strcasecmp($input, $code) === 0;
$count = $this->cache->get($this->sessionKey . 'count');
$count = $count + 1;
if ($valid || $count > $this->testLimit && $this->testLimit > 0) {
$this->getVerifyCode(true);
}
//更新计数器
$this->cache->set($this->sessionKey . 'count', $count, $this->duration);
return $valid;
} | php | public function validate($input, $caseSensitive)
{
$code = $this->getVerifyCode();
$valid = $caseSensitive ? ($input === $code) : strcasecmp($input, $code) === 0;
$count = $this->cache->get($this->sessionKey . 'count');
$count = $count + 1;
if ($valid || $count > $this->testLimit && $this->testLimit > 0) {
$this->getVerifyCode(true);
}
//更新计数器
$this->cache->set($this->sessionKey . 'count', $count, $this->duration);
return $valid;
} | [
"public",
"function",
"validate",
"(",
"$",
"input",
",",
"$",
"caseSensitive",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"getVerifyCode",
"(",
")",
";",
"$",
"valid",
"=",
"$",
"caseSensitive",
"?",
"(",
"$",
"input",
"===",
"$",
"code",
")",
":",
"strcasecmp",
"(",
"$",
"input",
",",
"$",
"code",
")",
"===",
"0",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"this",
"->",
"sessionKey",
".",
"'count'",
")",
";",
"$",
"count",
"=",
"$",
"count",
"+",
"1",
";",
"if",
"(",
"$",
"valid",
"||",
"$",
"count",
">",
"$",
"this",
"->",
"testLimit",
"&&",
"$",
"this",
"->",
"testLimit",
">",
"0",
")",
"{",
"$",
"this",
"->",
"getVerifyCode",
"(",
"true",
")",
";",
"}",
"//更新计数器",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"this",
"->",
"sessionKey",
".",
"'count'",
",",
"$",
"count",
",",
"$",
"this",
"->",
"duration",
")",
";",
"return",
"$",
"valid",
";",
"}"
] | 验证输入,看看它是否与生成的代码相匹配
@param string $input user input
@param boolean $caseSensitive whether the comparison should be case-sensitive
@return boolean whether the input is valid | [
"验证输入,看看它是否与生成的代码相匹配"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sms/captcha/CaptchaAction.php#L166-L179 |
yuncms/framework | src/sms/captcha/CaptchaAction.php | CaptchaAction.validateMobile | public function validateMobile($input)
{
$mobile = $this->cache->get($this->sessionKey . 'mobile');
$valid = strcasecmp($mobile, $input) === 0;
return $valid;
} | php | public function validateMobile($input)
{
$mobile = $this->cache->get($this->sessionKey . 'mobile');
$valid = strcasecmp($mobile, $input) === 0;
return $valid;
} | [
"public",
"function",
"validateMobile",
"(",
"$",
"input",
")",
"{",
"$",
"mobile",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"this",
"->",
"sessionKey",
".",
"'mobile'",
")",
";",
"$",
"valid",
"=",
"strcasecmp",
"(",
"$",
"mobile",
",",
"$",
"input",
")",
"===",
"0",
";",
"return",
"$",
"valid",
";",
"}"
] | 验证提交的手机号时候和接收验证码的手机号一致
@param string $input user input
@return boolean whether the input is valid | [
"验证提交的手机号时候和接收验证码的手机号一致"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sms/captcha/CaptchaAction.php#L186-L191 |
atkrad/data-tables | src/Request.php | Request.setColumns | public function setColumns(array $columns)
{
foreach ($columns as $column) {
$this->columns[] = new Request\Column($column);
}
return $this;
} | php | public function setColumns(array $columns)
{
foreach ($columns as $column) {
$this->columns[] = new Request\Column($column);
}
return $this;
} | [
"public",
"function",
"setColumns",
"(",
"array",
"$",
"columns",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"columns",
"[",
"]",
"=",
"new",
"Request",
"\\",
"Column",
"(",
"$",
"column",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set Columns
@param array $columns
@return Request | [
"Set",
"Columns"
] | train | https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Request.php#L73-L80 |
atkrad/data-tables | src/Request.php | Request.setOrder | public function setOrder(array $orders)
{
foreach ($orders as $order) {
$this->order[] = new Order($order);
}
return $this;
} | php | public function setOrder(array $orders)
{
foreach ($orders as $order) {
$this->order[] = new Order($order);
}
return $this;
} | [
"public",
"function",
"setOrder",
"(",
"array",
"$",
"orders",
")",
"{",
"foreach",
"(",
"$",
"orders",
"as",
"$",
"order",
")",
"{",
"$",
"this",
"->",
"order",
"[",
"]",
"=",
"new",
"Order",
"(",
"$",
"order",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set Order
@param array $orders
@return Request | [
"Set",
"Order"
] | train | https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Request.php#L89-L96 |
nexusnetsoftgmbh/nexuscli | src/Nexus/Dumper/DumperDependencyProvider.php | DumperDependencyProvider.addDockerFacade | private function addDockerFacade(DependencyContainerInterface $container): DependencyContainerInterface
{
$container[self::DOCKER_FACADE] = function(DependencyContainerInterface $container) {
return $container->getLocator()->dockerClient()->facade();
};
return $container;
} | php | private function addDockerFacade(DependencyContainerInterface $container): DependencyContainerInterface
{
$container[self::DOCKER_FACADE] = function(DependencyContainerInterface $container) {
return $container->getLocator()->dockerClient()->facade();
};
return $container;
} | [
"private",
"function",
"addDockerFacade",
"(",
"DependencyContainerInterface",
"$",
"container",
")",
":",
"DependencyContainerInterface",
"{",
"$",
"container",
"[",
"self",
"::",
"DOCKER_FACADE",
"]",
"=",
"function",
"(",
"DependencyContainerInterface",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"->",
"getLocator",
"(",
")",
"->",
"dockerClient",
"(",
")",
"->",
"facade",
"(",
")",
";",
"}",
";",
"return",
"$",
"container",
";",
"}"
] | @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container
@return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface | [
"@param",
"\\",
"Xervice",
"\\",
"Core",
"\\",
"Business",
"\\",
"Model",
"\\",
"Dependency",
"\\",
"DependencyContainerInterface",
"$container"
] | train | https://github.com/nexusnetsoftgmbh/nexuscli/blob/8416b43d31ad56ea379ae2b0bf85d456e78ba67a/src/Nexus/Dumper/DumperDependencyProvider.php#L65-L72 |
picamator/CacheManager | src/ObjectManager.php | ObjectManager.create | public function create(string $className, array $arguments = [])
{
if (empty($arguments)) {
return new $className();
}
// construction does not available
if (method_exists($className, '__construct') === false) {
throw new RuntimeException(sprintf('Class "%s" does not have __construct', $className));
}
return $this->getReflection($className)
->newInstanceArgs($arguments);
} | php | public function create(string $className, array $arguments = [])
{
if (empty($arguments)) {
return new $className();
}
// construction does not available
if (method_exists($className, '__construct') === false) {
throw new RuntimeException(sprintf('Class "%s" does not have __construct', $className));
}
return $this->getReflection($className)
->newInstanceArgs($arguments);
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"className",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"arguments",
")",
")",
"{",
"return",
"new",
"$",
"className",
"(",
")",
";",
"}",
"// construction does not available",
"if",
"(",
"method_exists",
"(",
"$",
"className",
",",
"'__construct'",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Class \"%s\" does not have __construct'",
",",
"$",
"className",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getReflection",
"(",
"$",
"className",
")",
"->",
"newInstanceArgs",
"(",
"$",
"arguments",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/ObjectManager.php#L25-L38 |
picamator/CacheManager | src/ObjectManager.php | ObjectManager.getReflection | private function getReflection(string $className) : \ReflectionClass
{
if (empty($this->reflectionContainer[$className])) {
$this->reflectionContainer[$className] = new \ReflectionClass($className);
}
return $this->reflectionContainer[$className];
} | php | private function getReflection(string $className) : \ReflectionClass
{
if (empty($this->reflectionContainer[$className])) {
$this->reflectionContainer[$className] = new \ReflectionClass($className);
}
return $this->reflectionContainer[$className];
} | [
"private",
"function",
"getReflection",
"(",
"string",
"$",
"className",
")",
":",
"\\",
"ReflectionClass",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"reflectionContainer",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"this",
"->",
"reflectionContainer",
"[",
"$",
"className",
"]",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"}",
"return",
"$",
"this",
"->",
"reflectionContainer",
"[",
"$",
"className",
"]",
";",
"}"
] | Retrieve reflection.
@param string $className
@return \ReflectionClass | [
"Retrieve",
"reflection",
"."
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/ObjectManager.php#L47-L54 |
dashifen/wordpress-php7-plugin-boilerplate | src/Loader/Loader.php | Loader.addAction | public function addAction(string $hook, ComponentInterface $component, string $handler, int $priority = 10, int $argCount = 1): void {
$this->actions[] = new Hook($hook, $component, $handler, $priority, $argCount);
} | php | public function addAction(string $hook, ComponentInterface $component, string $handler, int $priority = 10, int $argCount = 1): void {
$this->actions[] = new Hook($hook, $component, $handler, $priority, $argCount);
} | [
"public",
"function",
"addAction",
"(",
"string",
"$",
"hook",
",",
"ComponentInterface",
"$",
"component",
",",
"string",
"$",
"handler",
",",
"int",
"$",
"priority",
"=",
"10",
",",
"int",
"$",
"argCount",
"=",
"1",
")",
":",
"void",
"{",
"$",
"this",
"->",
"actions",
"[",
"]",
"=",
"new",
"Hook",
"(",
"$",
"hook",
",",
"$",
"component",
",",
"$",
"handler",
",",
"$",
"priority",
",",
"$",
"argCount",
")",
";",
"}"
] | @param string $hook
@param ComponentInterface $component
@param string $handler
@param int $priority
@param int $argCount
@return void | [
"@param",
"string",
"$hook",
"@param",
"ComponentInterface",
"$component",
"@param",
"string",
"$handler",
"@param",
"int",
"$priority",
"@param",
"int",
"$argCount"
] | train | https://github.com/dashifen/wordpress-php7-plugin-boilerplate/blob/c7875deb403d311efca72dc3c8beb566972a56cb/src/Loader/Loader.php#L39-L41 |
dashifen/wordpress-php7-plugin-boilerplate | src/Loader/Loader.php | Loader.getAttachmentArguments | protected function getAttachmentArguments(HookInterface $hook, bool $isShortcode): array {
// both shortcodes and non-shortcodes are attached using a hook and a
// callback to start. then, non-shortcodes also get a priority and an
// argument count. we can build that array as follows and return it
// to the calling scope.
$arguments[] = $hook->getHook();
$arguments[] = [
$hook->getComponent(),
$hook->getHandler(),
];
if (!$isShortcode) {
// if this isn't a shortcode, then we want to add our
// priority and argument count to our list of arguments,
// too.
$arguments[] = $hook->getPriority();
$arguments[] = $hook->getArgCount();
}
return $arguments;
} | php | protected function getAttachmentArguments(HookInterface $hook, bool $isShortcode): array {
// both shortcodes and non-shortcodes are attached using a hook and a
// callback to start. then, non-shortcodes also get a priority and an
// argument count. we can build that array as follows and return it
// to the calling scope.
$arguments[] = $hook->getHook();
$arguments[] = [
$hook->getComponent(),
$hook->getHandler(),
];
if (!$isShortcode) {
// if this isn't a shortcode, then we want to add our
// priority and argument count to our list of arguments,
// too.
$arguments[] = $hook->getPriority();
$arguments[] = $hook->getArgCount();
}
return $arguments;
} | [
"protected",
"function",
"getAttachmentArguments",
"(",
"HookInterface",
"$",
"hook",
",",
"bool",
"$",
"isShortcode",
")",
":",
"array",
"{",
"// both shortcodes and non-shortcodes are attached using a hook and a",
"// callback to start. then, non-shortcodes also get a priority and an",
"// argument count. we can build that array as follows and return it",
"// to the calling scope.",
"$",
"arguments",
"[",
"]",
"=",
"$",
"hook",
"->",
"getHook",
"(",
")",
";",
"$",
"arguments",
"[",
"]",
"=",
"[",
"$",
"hook",
"->",
"getComponent",
"(",
")",
",",
"$",
"hook",
"->",
"getHandler",
"(",
")",
",",
"]",
";",
"if",
"(",
"!",
"$",
"isShortcode",
")",
"{",
"// if this isn't a shortcode, then we want to add our",
"// priority and argument count to our list of arguments,",
"// too.",
"$",
"arguments",
"[",
"]",
"=",
"$",
"hook",
"->",
"getPriority",
"(",
")",
";",
"$",
"arguments",
"[",
"]",
"=",
"$",
"hook",
"->",
"getArgCount",
"(",
")",
";",
"}",
"return",
"$",
"arguments",
";",
"}"
] | @param HookInterface $hook
@param bool $isShortcode
@return array | [
"@param",
"HookInterface",
"$hook",
"@param",
"bool",
"$isShortcode"
] | train | https://github.com/dashifen/wordpress-php7-plugin-boilerplate/blob/c7875deb403d311efca72dc3c8beb566972a56cb/src/Loader/Loader.php#L121-L145 |
Chill-project/Main | Form/Type/DataTransformer/MultipleObjectsToIdTransformer.php | MultipleObjectsToIdTransformer.reverseTransform | public function reverseTransform($array)
{
$ret = new ArrayCollection();
foreach ($array as $el) {
$ret->add(
$this->em
->getRepository($this->class)
->find($el)
);
}
return $ret;
} | php | public function reverseTransform($array)
{
$ret = new ArrayCollection();
foreach ($array as $el) {
$ret->add(
$this->em
->getRepository($this->class)
->find($el)
);
}
return $ret;
} | [
"public",
"function",
"reverseTransform",
"(",
"$",
"array",
")",
"{",
"$",
"ret",
"=",
"new",
"ArrayCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"el",
")",
"{",
"$",
"ret",
"->",
"add",
"(",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"class",
")",
"->",
"find",
"(",
"$",
"el",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Transforms a string (id) to an object (item).
@param string $id
@return ArrayCollection | [
"Transforms",
"a",
"string",
"(",
"id",
")",
"to",
"an",
"object",
"(",
"item",
")",
"."
] | train | https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Form/Type/DataTransformer/MultipleObjectsToIdTransformer.php#L72-L84 |
yuncms/framework | src/helpers/ArrayHelper.php | ArrayHelper.filterByValue | public static function filterByValue($array, $key, $value, bool $strict = false): array
{
$result = [];
foreach ($array as $i => $element) {
$elementValue = static::getValue($element, $key);
/** @noinspection TypeUnsafeComparisonInspection */
if (($strict && $elementValue === $value) || (!$strict && $elementValue == $value)) {
$result[$i] = $element;
}
}
return $result;
} | php | public static function filterByValue($array, $key, $value, bool $strict = false): array
{
$result = [];
foreach ($array as $i => $element) {
$elementValue = static::getValue($element, $key);
/** @noinspection TypeUnsafeComparisonInspection */
if (($strict && $elementValue === $value) || (!$strict && $elementValue == $value)) {
$result[$i] = $element;
}
}
return $result;
} | [
"public",
"static",
"function",
"filterByValue",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"value",
",",
"bool",
"$",
"strict",
"=",
"false",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"i",
"=>",
"$",
"element",
")",
"{",
"$",
"elementValue",
"=",
"static",
"::",
"getValue",
"(",
"$",
"element",
",",
"$",
"key",
")",
";",
"/** @noinspection TypeUnsafeComparisonInspection */",
"if",
"(",
"(",
"$",
"strict",
"&&",
"$",
"elementValue",
"===",
"$",
"value",
")",
"||",
"(",
"!",
"$",
"strict",
"&&",
"$",
"elementValue",
"==",
"$",
"value",
")",
")",
"{",
"$",
"result",
"[",
"$",
"i",
"]",
"=",
"$",
"element",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Filters an array to only the values where a given key (the name of a
sub-array key or sub-object property) is set to a given value.
Array keys are preserved.
@param array|\Traversable $array the array that needs to be indexed or grouped
@param string|\Closure $key the column name or anonymous function which result will be used to index the array
@param mixed $value the value that $key should be compared with
@param bool $strict 是否严格比较
@return array the filtered array | [
"Filters",
"an",
"array",
"to",
"only",
"the",
"values",
"where",
"a",
"given",
"key",
"(",
"the",
"name",
"of",
"a",
"sub",
"-",
"array",
"key",
"or",
"sub",
"-",
"object",
"property",
")",
"is",
"set",
"to",
"a",
"given",
"value",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/ArrayHelper.php#L484-L497 |
yuncms/framework | src/helpers/ArrayHelper.php | ArrayHelper.rename | public static function rename(array &$array, string $oldKey, string $newKey, $default = null)
{
if (!array_key_exists($newKey, $array) || array_key_exists($oldKey, $array)) {
$array[$newKey] = static::remove($array, $oldKey, $default);
}
} | php | public static function rename(array &$array, string $oldKey, string $newKey, $default = null)
{
if (!array_key_exists($newKey, $array) || array_key_exists($oldKey, $array)) {
$array[$newKey] = static::remove($array, $oldKey, $default);
}
} | [
"public",
"static",
"function",
"rename",
"(",
"array",
"&",
"$",
"array",
",",
"string",
"$",
"oldKey",
",",
"string",
"$",
"newKey",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"newKey",
",",
"$",
"array",
")",
"||",
"array_key_exists",
"(",
"$",
"oldKey",
",",
"$",
"array",
")",
")",
"{",
"$",
"array",
"[",
"$",
"newKey",
"]",
"=",
"static",
"::",
"remove",
"(",
"$",
"array",
",",
"$",
"oldKey",
",",
"$",
"default",
")",
";",
"}",
"}"
] | 重命名数组中的项目。如果新Key已经存在于数组中,并且旧Key不存在,数组将保持不变。
@param array $array the array to extract value from
@param string $oldKey old key name of the array element
@param string $newKey new key name of the array element
@param mixed $default the default value to be set if the specified old key does not exist
@return void | [
"重命名数组中的项目。如果新Key已经存在于数组中,并且旧Key不存在,数组将保持不变。"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/ArrayHelper.php#L548-L553 |
steeffeen/FancyManiaLinks | FML/Elements/Dico.php | Dico.getEntry | public function getEntry($language, $entryId)
{
if (isset($this->entries[$language]) && isset($this->entries[$language][$entryId])) {
return $this->entries[$language][$entryId];
}
return null;
} | php | public function getEntry($language, $entryId)
{
if (isset($this->entries[$language]) && isset($this->entries[$language][$entryId])) {
return $this->entries[$language][$entryId];
}
return null;
} | [
"public",
"function",
"getEntry",
"(",
"$",
"language",
",",
"$",
"entryId",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
"[",
"$",
"entryId",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
"[",
"$",
"entryId",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Get the translatable entry
@api
@param string $language Language id
@param string $entryId Entry id
@return string | [
"Get",
"the",
"translatable",
"entry"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Elements/Dico.php#L179-L185 |
steeffeen/FancyManiaLinks | FML/Elements/Dico.php | Dico.setEntry | public function setEntry($language, $entryId, $entryValue)
{
$language = (string)$language;
$entryId = (string)$entryId;
$entryValue = (string)$entryValue;
if (!isset($this->entries[$language]) && $entryValue) {
$this->entries[$language] = array();
}
if ($entryValue) {
$this->entries[$language][$entryId] = $entryValue;
} else {
if (isset($this->entries[$language][$entryId])) {
unset($this->entries[$language][$entryId]);
}
}
return $this;
} | php | public function setEntry($language, $entryId, $entryValue)
{
$language = (string)$language;
$entryId = (string)$entryId;
$entryValue = (string)$entryValue;
if (!isset($this->entries[$language]) && $entryValue) {
$this->entries[$language] = array();
}
if ($entryValue) {
$this->entries[$language][$entryId] = $entryValue;
} else {
if (isset($this->entries[$language][$entryId])) {
unset($this->entries[$language][$entryId]);
}
}
return $this;
} | [
"public",
"function",
"setEntry",
"(",
"$",
"language",
",",
"$",
"entryId",
",",
"$",
"entryValue",
")",
"{",
"$",
"language",
"=",
"(",
"string",
")",
"$",
"language",
";",
"$",
"entryId",
"=",
"(",
"string",
")",
"$",
"entryId",
";",
"$",
"entryValue",
"=",
"(",
"string",
")",
"$",
"entryValue",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
")",
"&&",
"$",
"entryValue",
")",
"{",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"entryValue",
")",
"{",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
"[",
"$",
"entryId",
"]",
"=",
"$",
"entryValue",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
"[",
"$",
"entryId",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
"[",
"$",
"entryId",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the translatable entry for the specific language
@api
@param string $language Language id
@param string $entryId Entry id
@param string $entryValue Translated entry value
@return static | [
"Set",
"the",
"translatable",
"entry",
"for",
"the",
"specific",
"language"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Elements/Dico.php#L196-L212 |
steeffeen/FancyManiaLinks | FML/Elements/Dico.php | Dico.removeEntry | public function removeEntry($entryId, $language = null)
{
$entryId = (string)$entryId;
foreach ($this->entries as $languageKey => $entries) {
if ($language && $language !== $languageKey) {
continue;
}
if (isset($this->entries[$languageKey][$entryId])) {
unset($this->entries[$languageKey][$entryId]);
}
}
return $this;
} | php | public function removeEntry($entryId, $language = null)
{
$entryId = (string)$entryId;
foreach ($this->entries as $languageKey => $entries) {
if ($language && $language !== $languageKey) {
continue;
}
if (isset($this->entries[$languageKey][$entryId])) {
unset($this->entries[$languageKey][$entryId]);
}
}
return $this;
} | [
"public",
"function",
"removeEntry",
"(",
"$",
"entryId",
",",
"$",
"language",
"=",
"null",
")",
"{",
"$",
"entryId",
"=",
"(",
"string",
")",
"$",
"entryId",
";",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"languageKey",
"=>",
"$",
"entries",
")",
"{",
"if",
"(",
"$",
"language",
"&&",
"$",
"language",
"!==",
"$",
"languageKey",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"languageKey",
"]",
"[",
"$",
"entryId",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"languageKey",
"]",
"[",
"$",
"entryId",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove entries of the given id
@api
@param string $entryId Entry id that should be removed
@param string $language (optional) Only remove entry from the given language
@return static | [
"Remove",
"entries",
"of",
"the",
"given",
"id"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Elements/Dico.php#L222-L234 |
steeffeen/FancyManiaLinks | FML/Elements/Dico.php | Dico.removeLanguage | public function removeLanguage($language)
{
$language = (string)$language;
if (isset($this->entries[$language])) {
unset($this->entries[$language]);
}
return $this;
} | php | public function removeLanguage($language)
{
$language = (string)$language;
if (isset($this->entries[$language])) {
unset($this->entries[$language]);
}
return $this;
} | [
"public",
"function",
"removeLanguage",
"(",
"$",
"language",
")",
"{",
"$",
"language",
"=",
"(",
"string",
")",
"$",
"language",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"language",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove entries of the given language
@api
@param string $language Language which entries should be removed
@return static | [
"Remove",
"entries",
"of",
"the",
"given",
"language"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Elements/Dico.php#L243-L250 |
steeffeen/FancyManiaLinks | FML/Elements/Dico.php | Dico.render | public function render(\DOMDocument $domDocument)
{
$domElement = $domDocument->createElement("dico");
foreach ($this->entries as $language => $entries) {
$languageElement = $domDocument->createElement("language");
$languageElement->setAttribute("id", $language);
foreach ($entries as $entryId => $entryValue) {
$entryElement = $domDocument->createElement($entryId, $entryValue);
$languageElement->appendChild($entryElement);
}
$domElement->appendChild($languageElement);
}
return $domElement;
} | php | public function render(\DOMDocument $domDocument)
{
$domElement = $domDocument->createElement("dico");
foreach ($this->entries as $language => $entries) {
$languageElement = $domDocument->createElement("language");
$languageElement->setAttribute("id", $language);
foreach ($entries as $entryId => $entryValue) {
$entryElement = $domDocument->createElement($entryId, $entryValue);
$languageElement->appendChild($entryElement);
}
$domElement->appendChild($languageElement);
}
return $domElement;
} | [
"public",
"function",
"render",
"(",
"\\",
"DOMDocument",
"$",
"domDocument",
")",
"{",
"$",
"domElement",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"\"dico\"",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"language",
"=>",
"$",
"entries",
")",
"{",
"$",
"languageElement",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"\"language\"",
")",
";",
"$",
"languageElement",
"->",
"setAttribute",
"(",
"\"id\"",
",",
"$",
"language",
")",
";",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"entryId",
"=>",
"$",
"entryValue",
")",
"{",
"$",
"entryElement",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"$",
"entryId",
",",
"$",
"entryValue",
")",
";",
"$",
"languageElement",
"->",
"appendChild",
"(",
"$",
"entryElement",
")",
";",
"}",
"$",
"domElement",
"->",
"appendChild",
"(",
"$",
"languageElement",
")",
";",
"}",
"return",
"$",
"domElement",
";",
"}"
] | Render the Dico
@param \DOMDocument $domDocument DOMDocument for which the Dico should be rendered
@return \DOMElement | [
"Render",
"the",
"Dico"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Elements/Dico.php#L283-L296 |
gries/rcon | src/ConnectionFactory.php | ConnectionFactory.create | public static function create($host, $port, $password)
{
$factory = new \Socket\Raw\Factory();
$socket = $factory->createClient(sprintf('%s:%s', $host, $port));
return new \gries\Rcon\Connection($socket, $password);
} | php | public static function create($host, $port, $password)
{
$factory = new \Socket\Raw\Factory();
$socket = $factory->createClient(sprintf('%s:%s', $host, $port));
return new \gries\Rcon\Connection($socket, $password);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"password",
")",
"{",
"$",
"factory",
"=",
"new",
"\\",
"Socket",
"\\",
"Raw",
"\\",
"Factory",
"(",
")",
";",
"$",
"socket",
"=",
"$",
"factory",
"->",
"createClient",
"(",
"sprintf",
"(",
"'%s:%s'",
",",
"$",
"host",
",",
"$",
"port",
")",
")",
";",
"return",
"new",
"\\",
"gries",
"\\",
"Rcon",
"\\",
"Connection",
"(",
"$",
"socket",
",",
"$",
"password",
")",
";",
"}"
] | Create a new RconConnection
@param $host
@param $port
@param $password
@return \gries\Rcon\Connection | [
"Create",
"a",
"new",
"RconConnection"
] | train | https://github.com/gries/rcon/blob/7fada05b329d89542692af00ab80db02ad59d45d/src/ConnectionFactory.php#L21-L27 |
periaptio/empress-generator | src/Commands/FactoryMakeCommand.php | FactoryMakeCommand.handle | public function handle()
{
parent::handle();
$this->comment('\nGenerating factory for : '. implode(',', $this->tables));
if ($this->option('models')) {
$this->models = explode(',', $this->option('models'));
}
$configData = $this->getConfigData();
$factoryGenerator = new FactoryGenerator($this);
foreach ($this->tables as $idx => $tableName) {
if (isset($this->models[$idx])) {
$modelName = $this->models[$idx];
} else {
$modelName = str_singular(studly_case($tableName));
}
$data = array_merge([
'TABLE_NAME' => $tableName,
'MODEL_NAME' => $modelName
], $configData);
$factoryGenerator->generate($data);
}
} | php | public function handle()
{
parent::handle();
$this->comment('\nGenerating factory for : '. implode(',', $this->tables));
if ($this->option('models')) {
$this->models = explode(',', $this->option('models'));
}
$configData = $this->getConfigData();
$factoryGenerator = new FactoryGenerator($this);
foreach ($this->tables as $idx => $tableName) {
if (isset($this->models[$idx])) {
$modelName = $this->models[$idx];
} else {
$modelName = str_singular(studly_case($tableName));
}
$data = array_merge([
'TABLE_NAME' => $tableName,
'MODEL_NAME' => $modelName
], $configData);
$factoryGenerator->generate($data);
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"parent",
"::",
"handle",
"(",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'\\nGenerating factory for : '",
".",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"tables",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'models'",
")",
")",
"{",
"$",
"this",
"->",
"models",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"option",
"(",
"'models'",
")",
")",
";",
"}",
"$",
"configData",
"=",
"$",
"this",
"->",
"getConfigData",
"(",
")",
";",
"$",
"factoryGenerator",
"=",
"new",
"FactoryGenerator",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"tables",
"as",
"$",
"idx",
"=>",
"$",
"tableName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"models",
"[",
"$",
"idx",
"]",
")",
")",
"{",
"$",
"modelName",
"=",
"$",
"this",
"->",
"models",
"[",
"$",
"idx",
"]",
";",
"}",
"else",
"{",
"$",
"modelName",
"=",
"str_singular",
"(",
"studly_case",
"(",
"$",
"tableName",
")",
")",
";",
"}",
"$",
"data",
"=",
"array_merge",
"(",
"[",
"'TABLE_NAME'",
"=>",
"$",
"tableName",
",",
"'MODEL_NAME'",
"=>",
"$",
"modelName",
"]",
",",
"$",
"configData",
")",
";",
"$",
"factoryGenerator",
"->",
"generate",
"(",
"$",
"data",
")",
";",
"}",
"}"
] | Execute the command.
@return void | [
"Execute",
"the",
"command",
"."
] | train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Commands/FactoryMakeCommand.php#L47-L75 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/UserController.php | UserController.createAction | public function createAction(Request $request)
{
$oUser = new User();
$form = $this->createCreateForm($oUser);
$form->handleRequest($request);
if ($form->isValid()) {
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($oUser);
$password = $encoder->encodePassword($oUser->getPassword(), $oUser->getSalt());
$oUser->setPassword($password);
$oUser->save();
return $this->redirect($this->generateUrl('backend_system_user'));
}
return $this->render('SlashworksBackendBundle:User:new.html.twig', array(
'entity' => $oUser,
'form' => $form->createView(),
));
} | php | public function createAction(Request $request)
{
$oUser = new User();
$form = $this->createCreateForm($oUser);
$form->handleRequest($request);
if ($form->isValid()) {
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($oUser);
$password = $encoder->encodePassword($oUser->getPassword(), $oUser->getSalt());
$oUser->setPassword($password);
$oUser->save();
return $this->redirect($this->generateUrl('backend_system_user'));
}
return $this->render('SlashworksBackendBundle:User:new.html.twig', array(
'entity' => $oUser,
'form' => $form->createView(),
));
} | [
"public",
"function",
"createAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"oUser",
"=",
"new",
"User",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"oUser",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.encoder_factory'",
")",
";",
"$",
"encoder",
"=",
"$",
"factory",
"->",
"getEncoder",
"(",
"$",
"oUser",
")",
";",
"$",
"password",
"=",
"$",
"encoder",
"->",
"encodePassword",
"(",
"$",
"oUser",
"->",
"getPassword",
"(",
")",
",",
"$",
"oUser",
"->",
"getSalt",
"(",
")",
")",
";",
"$",
"oUser",
"->",
"setPassword",
"(",
"$",
"password",
")",
";",
"$",
"oUser",
"->",
"save",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_user'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksBackendBundle:User:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"oUser",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Creates a new User entity.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
@throws \Exception
@throws \PropelException | [
"Creates",
"a",
"new",
"User",
"entity",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/UserController.php#L65-L86 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/UserController.php | UserController.newAction | public function newAction()
{
$oUser = new User();
$form = $this->createCreateForm($oUser);
return $this->render('SlashworksBackendBundle:User:new.html.twig', array(
'entity' => $oUser,
'form' => $form->createView(),
));
} | php | public function newAction()
{
$oUser = new User();
$form = $this->createCreateForm($oUser);
return $this->render('SlashworksBackendBundle:User:new.html.twig', array(
'entity' => $oUser,
'form' => $form->createView(),
));
} | [
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"oUser",
"=",
"new",
"User",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"oUser",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksBackendBundle:User:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"oUser",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Displays a form to create a new User entity.
@return \Symfony\Component\HttpFoundation\Response | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"User",
"entity",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/UserController.php#L94-L103 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/UserController.php | UserController.editAction | public function editAction($id)
{
/** @var User $oUser */
$oUser = UserQuery::create()->findOneById($id);
if (count($oUser) === 0) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createEditForm($oUser);
$deleteForm = $this->createDeleteForm($id);
// preselect Role
$editForm->get('roles')->setData($oUser->getRole());
return $this->render('SlashworksBackendBundle:User:edit.html.twig', array(
'entity' => $oUser,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | php | public function editAction($id)
{
/** @var User $oUser */
$oUser = UserQuery::create()->findOneById($id);
if (count($oUser) === 0) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createEditForm($oUser);
$deleteForm = $this->createDeleteForm($id);
// preselect Role
$editForm->get('roles')->setData($oUser->getRole());
return $this->render('SlashworksBackendBundle:User:edit.html.twig', array(
'entity' => $oUser,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"editAction",
"(",
"$",
"id",
")",
"{",
"/** @var User $oUser */",
"$",
"oUser",
"=",
"UserQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"count",
"(",
"$",
"oUser",
")",
"===",
"0",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find User entity.'",
")",
";",
"}",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createEditForm",
"(",
"$",
"oUser",
")",
";",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"// preselect Role",
"$",
"editForm",
"->",
"get",
"(",
"'roles'",
")",
"->",
"setData",
"(",
"$",
"oUser",
"->",
"getRole",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksBackendBundle:User:edit.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"oUser",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Displays a form to edit an existing User entity.
@param $id
@return \Symfony\Component\HttpFoundation\Response | [
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"User",
"entity",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/UserController.php#L113-L133 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/UserController.php | UserController.updateAction | public function updateAction(Request $request, $id)
{
/** @var User $oUser */
$oUser = UserQuery::create()->findOneById($id);
if (count($oUser) === 0) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($oUser);
$editForm->handleRequest($request);
$aUserRoles = UserRoleQuery::create()->findByUserId($oUser->getId());
if ($editForm->isValid()) {
foreach($aUserRoles as $oUserRole){
$oUserRole->setUserId($oUser->getId());
$oUserRole->delete();
}
$aFormData =$request->request->get('slashworks_backendbundle_user');
$sPassword = $aFormData['password'];
$sPasswordRepeat = $aFormData['password_repeat'];
if(!empty($sPassword) && !empty($sPasswordRepeat)){
if($sPassword === $sPasswordRepeat){
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($oUser);
$sPassword = $encoder->encodePassword($sPassword, $oUser->getSalt());
$oUser->setPassword($sPassword);
}else{
}
}elseif(!empty($sPassword) && empty($sPasswordReqpeat)){
}
$oUser->save();
return $this->redirect($this->generateUrl('backend_system_user'));
}
return $this->render('SlashworksBackendBundle:User:edit.html.twig', array(
'entity' => $oUser,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | php | public function updateAction(Request $request, $id)
{
/** @var User $oUser */
$oUser = UserQuery::create()->findOneById($id);
if (count($oUser) === 0) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($oUser);
$editForm->handleRequest($request);
$aUserRoles = UserRoleQuery::create()->findByUserId($oUser->getId());
if ($editForm->isValid()) {
foreach($aUserRoles as $oUserRole){
$oUserRole->setUserId($oUser->getId());
$oUserRole->delete();
}
$aFormData =$request->request->get('slashworks_backendbundle_user');
$sPassword = $aFormData['password'];
$sPasswordRepeat = $aFormData['password_repeat'];
if(!empty($sPassword) && !empty($sPasswordRepeat)){
if($sPassword === $sPasswordRepeat){
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($oUser);
$sPassword = $encoder->encodePassword($sPassword, $oUser->getSalt());
$oUser->setPassword($sPassword);
}else{
}
}elseif(!empty($sPassword) && empty($sPasswordReqpeat)){
}
$oUser->save();
return $this->redirect($this->generateUrl('backend_system_user'));
}
return $this->render('SlashworksBackendBundle:User:edit.html.twig', array(
'entity' => $oUser,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"updateAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"/** @var User $oUser */",
"$",
"oUser",
"=",
"UserQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"count",
"(",
"$",
"oUser",
")",
"===",
"0",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find User entity.'",
")",
";",
"}",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createEditForm",
"(",
"$",
"oUser",
")",
";",
"$",
"editForm",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"$",
"aUserRoles",
"=",
"UserRoleQuery",
"::",
"create",
"(",
")",
"->",
"findByUserId",
"(",
"$",
"oUser",
"->",
"getId",
"(",
")",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"isValid",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"aUserRoles",
"as",
"$",
"oUserRole",
")",
"{",
"$",
"oUserRole",
"->",
"setUserId",
"(",
"$",
"oUser",
"->",
"getId",
"(",
")",
")",
";",
"$",
"oUserRole",
"->",
"delete",
"(",
")",
";",
"}",
"$",
"aFormData",
"=",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'slashworks_backendbundle_user'",
")",
";",
"$",
"sPassword",
"=",
"$",
"aFormData",
"[",
"'password'",
"]",
";",
"$",
"sPasswordRepeat",
"=",
"$",
"aFormData",
"[",
"'password_repeat'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sPassword",
")",
"&&",
"!",
"empty",
"(",
"$",
"sPasswordRepeat",
")",
")",
"{",
"if",
"(",
"$",
"sPassword",
"===",
"$",
"sPasswordRepeat",
")",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.encoder_factory'",
")",
";",
"$",
"encoder",
"=",
"$",
"factory",
"->",
"getEncoder",
"(",
"$",
"oUser",
")",
";",
"$",
"sPassword",
"=",
"$",
"encoder",
"->",
"encodePassword",
"(",
"$",
"sPassword",
",",
"$",
"oUser",
"->",
"getSalt",
"(",
")",
")",
";",
"$",
"oUser",
"->",
"setPassword",
"(",
"$",
"sPassword",
")",
";",
"}",
"else",
"{",
"}",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"sPassword",
")",
"&&",
"empty",
"(",
"$",
"sPasswordReqpeat",
")",
")",
"{",
"}",
"$",
"oUser",
"->",
"save",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_user'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksBackendBundle:User:edit.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"oUser",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Edits an existing User entity.
@param \Symfony\Component\HttpFoundation\Request $request
@param $id
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response | [
"Edits",
"an",
"existing",
"User",
"entity",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/UserController.php#L144-L193 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/UserController.php | UserController.deleteAction | public function deleteAction(Request $request, $id)
{
/** @var User $oUser */
$oUser = UserQuery::create()->findOneById($id);
if (count($oUser) === 0) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$oUser->delete();
return $this->redirect($this->generateUrl('backend_system_user'));
} | php | public function deleteAction(Request $request, $id)
{
/** @var User $oUser */
$oUser = UserQuery::create()->findOneById($id);
if (count($oUser) === 0) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$oUser->delete();
return $this->redirect($this->generateUrl('backend_system_user'));
} | [
"public",
"function",
"deleteAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"/** @var User $oUser */",
"$",
"oUser",
"=",
"UserQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"count",
"(",
"$",
"oUser",
")",
"===",
"0",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find User entity.'",
")",
";",
"}",
"$",
"oUser",
"->",
"delete",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_user'",
")",
")",
";",
"}"
] | Deletes a User entity.
@param \Symfony\Component\HttpFoundation\Request $request
@param $id
@return \Symfony\Component\HttpFoundation\RedirectResponse
@throws \Exception
@throws \PropelException | [
"Deletes",
"a",
"User",
"entity",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/UserController.php#L206-L218 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/UserController.php | UserController.createEditForm | private function createEditForm(User $oUser)
{
$form = $this->createForm(new UserType(), $oUser, array(
'action' => $this->generateUrl('backend_system_user_update', array('id' => $oUser->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
} | php | private function createEditForm(User $oUser)
{
$form = $this->createForm(new UserType(), $oUser, array(
'action' => $this->generateUrl('backend_system_user_update', array('id' => $oUser->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
} | [
"private",
"function",
"createEditForm",
"(",
"User",
"$",
"oUser",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"UserType",
"(",
")",
",",
"$",
"oUser",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_user_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"oUser",
"->",
"getId",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'Update'",
")",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Creates a form to edit a User entity.
@param User $entity The entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"edit",
"a",
"User",
"entity",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/UserController.php#L248-L258 |
Ocramius/OcraDiCompiler | src/OcraDiCompiler/Mvc/Service/ControllerLoaderFactory.php | ControllerLoaderFactory.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
$controllerLoader = new ControllerManager();
$controllerLoader->setServiceLocator($serviceLocator);
$controllerLoader->addPeeringServiceManager($serviceLocator);
$config = $serviceLocator->get('Config');
if (isset($config['di']) && isset($config['di']['allowed_controllers']) && $serviceLocator->has('Di')) {
$diAbstractFactory = new DiStrictAbstractServiceFactory(
$serviceLocator->get('Di'),
DiStrictAbstractServiceFactory::USE_SL_BEFORE_DI
);
$diAbstractFactory->setAllowedServiceNames($config['di']['allowed_controllers']);
$controllerLoader->addAbstractFactory($diAbstractFactory);
}
return $controllerLoader;
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
$controllerLoader = new ControllerManager();
$controllerLoader->setServiceLocator($serviceLocator);
$controllerLoader->addPeeringServiceManager($serviceLocator);
$config = $serviceLocator->get('Config');
if (isset($config['di']) && isset($config['di']['allowed_controllers']) && $serviceLocator->has('Di')) {
$diAbstractFactory = new DiStrictAbstractServiceFactory(
$serviceLocator->get('Di'),
DiStrictAbstractServiceFactory::USE_SL_BEFORE_DI
);
$diAbstractFactory->setAllowedServiceNames($config['di']['allowed_controllers']);
$controllerLoader->addAbstractFactory($diAbstractFactory);
}
return $controllerLoader;
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"controllerLoader",
"=",
"new",
"ControllerManager",
"(",
")",
";",
"$",
"controllerLoader",
"->",
"setServiceLocator",
"(",
"$",
"serviceLocator",
")",
";",
"$",
"controllerLoader",
"->",
"addPeeringServiceManager",
"(",
"$",
"serviceLocator",
")",
";",
"$",
"config",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Config'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'di'",
"]",
")",
"&&",
"isset",
"(",
"$",
"config",
"[",
"'di'",
"]",
"[",
"'allowed_controllers'",
"]",
")",
"&&",
"$",
"serviceLocator",
"->",
"has",
"(",
"'Di'",
")",
")",
"{",
"$",
"diAbstractFactory",
"=",
"new",
"DiStrictAbstractServiceFactory",
"(",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Di'",
")",
",",
"DiStrictAbstractServiceFactory",
"::",
"USE_SL_BEFORE_DI",
")",
";",
"$",
"diAbstractFactory",
"->",
"setAllowedServiceNames",
"(",
"$",
"config",
"[",
"'di'",
"]",
"[",
"'allowed_controllers'",
"]",
")",
";",
"$",
"controllerLoader",
"->",
"addAbstractFactory",
"(",
"$",
"diAbstractFactory",
")",
";",
"}",
"return",
"$",
"controllerLoader",
";",
"}"
] | Create the controller loader service
Creates and returns an instance of Controller\ControllerManager. The
only controllers this manager will allow are those defined in the
application configuration's "controllers" array. If a controller is
matched, the scoped manager will attempt to load the controller.
Finally, it will attempt to inject the controller plugin manager
if the controller implements a setPluginManager() method.
This plugin manager is _not_ peered against DI, and as such, will
not load unknown classes.
@param ServiceLocatorInterface $serviceLocator
@return ControllerManager | [
"Create",
"the",
"controller",
"loader",
"service"
] | train | https://github.com/Ocramius/OcraDiCompiler/blob/667f4b24771f27fb9c8d6c38ffaf72d9cd55ca4a/src/OcraDiCompiler/Mvc/Service/ControllerLoaderFactory.php#L51-L70 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaConnect/Client.php | Client.getLoginURL | function getLoginURL($scope = null, $redirectURI = null)
{
$redirectURI = $redirectURI ? : $this->getCurrentURI();
self::$persistance->setVariable('redirect_uri', $redirectURI);
return $this->getAuthorizationURL($redirectURI, $scope);
} | php | function getLoginURL($scope = null, $redirectURI = null)
{
$redirectURI = $redirectURI ? : $this->getCurrentURI();
self::$persistance->setVariable('redirect_uri', $redirectURI);
return $this->getAuthorizationURL($redirectURI, $scope);
} | [
"function",
"getLoginURL",
"(",
"$",
"scope",
"=",
"null",
",",
"$",
"redirectURI",
"=",
"null",
")",
"{",
"$",
"redirectURI",
"=",
"$",
"redirectURI",
"?",
":",
"$",
"this",
"->",
"getCurrentURI",
"(",
")",
";",
"self",
"::",
"$",
"persistance",
"->",
"setVariable",
"(",
"'redirect_uri'",
",",
"$",
"redirectURI",
")",
";",
"return",
"$",
"this",
"->",
"getAuthorizationURL",
"(",
"$",
"redirectURI",
",",
"$",
"scope",
")",
";",
"}"
] | When a user is not authentified, you need to create a link to the URL
returned by this method.
@param string $scope Space-separated list of scopes. Leave empty if you just need the basic one
@param string $redirectURI Where to redirect the user after auth. Leave empty for the current URI
@return string Login URL | [
"When",
"a",
"user",
"is",
"not",
"authentified",
"you",
"need",
"to",
"create",
"a",
"link",
"to",
"the",
"URL",
"returned",
"by",
"this",
"method",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaConnect/Client.php#L72-L77 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaConnect/Client.php | Client.getLogoutURL | function getLogoutURL($redirectURI = null)
{
$redirectURI = $redirectURI ? : $this->getCurrentURI();
return $this->logoutURL.'?'.http_build_query(array('redirect_uri' => $redirectURI),
'', '&');
} | php | function getLogoutURL($redirectURI = null)
{
$redirectURI = $redirectURI ? : $this->getCurrentURI();
return $this->logoutURL.'?'.http_build_query(array('redirect_uri' => $redirectURI),
'', '&');
} | [
"function",
"getLogoutURL",
"(",
"$",
"redirectURI",
"=",
"null",
")",
"{",
"$",
"redirectURI",
"=",
"$",
"redirectURI",
"?",
":",
"$",
"this",
"->",
"getCurrentURI",
"(",
")",
";",
"return",
"$",
"this",
"->",
"logoutURL",
".",
"'?'",
".",
"http_build_query",
"(",
"array",
"(",
"'redirect_uri'",
"=>",
"$",
"redirectURI",
")",
",",
"''",
",",
"'&'",
")",
";",
"}"
] | If you want to place a "logout" button, you can use this link to log the
user out of the player page too. Don't forget to empty your sessions .
@see \Maniaplanet\WebServices\ManiaConnect\Client::logout()
@param string $redirectURI Where to redirect the user after he logged out. Leave empty for current URI
@return string Logout URL | [
"If",
"you",
"want",
"to",
"place",
"a",
"logout",
"button",
"you",
"can",
"use",
"this",
"link",
"to",
"log",
"the",
"user",
"out",
"of",
"the",
"player",
"page",
"too",
".",
"Don",
"t",
"forget",
"to",
"empty",
"your",
"sessions",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaConnect/Client.php#L87-L92 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaConnect/Client.php | Client.getCurrentURI | protected function getCurrentURI()
{
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$current_uri = $protocol.$_SERVER['HTTP_HOST'].$this->getRequestURI();
$parts = parse_url($current_uri);
$query = '';
if(!empty($parts['query']))
{
$params = array();
parse_str($parts['query'], $params);
$params = array_filter($params);
if(!empty($params))
{
$query = '?'.http_build_query($params, '', '&');
}
}
// Use port if non default.
$port = isset($parts['port']) &&
(($protocol === 'http://' && $parts['port'] !== 80) || ($protocol === 'https://' && $parts['port'] !== 443)) ? ':'.$parts['port']
: '';
// Rebuild.
return $protocol.$parts['host'].$port.$parts['path'].$query;
} | php | protected function getCurrentURI()
{
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$current_uri = $protocol.$_SERVER['HTTP_HOST'].$this->getRequestURI();
$parts = parse_url($current_uri);
$query = '';
if(!empty($parts['query']))
{
$params = array();
parse_str($parts['query'], $params);
$params = array_filter($params);
if(!empty($params))
{
$query = '?'.http_build_query($params, '', '&');
}
}
// Use port if non default.
$port = isset($parts['port']) &&
(($protocol === 'http://' && $parts['port'] !== 80) || ($protocol === 'https://' && $parts['port'] !== 443)) ? ':'.$parts['port']
: '';
// Rebuild.
return $protocol.$parts['host'].$port.$parts['path'].$query;
} | [
"protected",
"function",
"getCurrentURI",
"(",
")",
"{",
"$",
"protocol",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"&&",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
"==",
"'on'",
"?",
"'https://'",
":",
"'http://'",
";",
"$",
"current_uri",
"=",
"$",
"protocol",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
".",
"$",
"this",
"->",
"getRequestURI",
"(",
")",
";",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"current_uri",
")",
";",
"$",
"query",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"parse_str",
"(",
"$",
"parts",
"[",
"'query'",
"]",
",",
"$",
"params",
")",
";",
"$",
"params",
"=",
"array_filter",
"(",
"$",
"params",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"$",
"query",
"=",
"'?'",
".",
"http_build_query",
"(",
"$",
"params",
",",
"''",
",",
"'&'",
")",
";",
"}",
"}",
"// Use port if non default.",
"$",
"port",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'port'",
"]",
")",
"&&",
"(",
"(",
"$",
"protocol",
"===",
"'http://'",
"&&",
"$",
"parts",
"[",
"'port'",
"]",
"!==",
"80",
")",
"||",
"(",
"$",
"protocol",
"===",
"'https://'",
"&&",
"$",
"parts",
"[",
"'port'",
"]",
"!==",
"443",
")",
")",
"?",
"':'",
".",
"$",
"parts",
"[",
"'port'",
"]",
":",
"''",
";",
"// Rebuild.",
"return",
"$",
"protocol",
".",
"$",
"parts",
"[",
"'host'",
"]",
".",
"$",
"port",
".",
"$",
"parts",
"[",
"'path'",
"]",
".",
"$",
"query",
";",
"}"
] | Returns the Current URL.
@return string The current URL.
@see http://code.google.com/p/oauth2-php
@author Originally written by Naitik Shah <[email protected]>.
@author Update to draft v10 by Edison Wong <[email protected]> | [
"Returns",
"the",
"Current",
"URL",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaConnect/Client.php#L111-L136 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaConnect/Client.php | Client.getAccessToken | protected function getAccessToken()
{
$token = self::$persistance->getVariable('token');
if(!$this->isAccessTokenExpired($token))
{
return $token->access_token;
}
else if ($token !== null && $token->refresh_token !== null)
{
$token = $this->getTokenFromRefreshToken($token->refresh_token);
return $token->access_token;
}
if(isset($_REQUEST['code']))
{
$code = $_REQUEST['code'];
if($code)
{
$redirectURI = self::$persistance->getVariable('redirect_uri') ? : $this->getCurrentURI();
$token = $this->getTokenFromCode($code, $redirectURI);
self::$persistance->deleteVariable('redirect_uri');
self::$persistance->deleteVariable('code');
return $token->access_token;
}
}
} | php | protected function getAccessToken()
{
$token = self::$persistance->getVariable('token');
if(!$this->isAccessTokenExpired($token))
{
return $token->access_token;
}
else if ($token !== null && $token->refresh_token !== null)
{
$token = $this->getTokenFromRefreshToken($token->refresh_token);
return $token->access_token;
}
if(isset($_REQUEST['code']))
{
$code = $_REQUEST['code'];
if($code)
{
$redirectURI = self::$persistance->getVariable('redirect_uri') ? : $this->getCurrentURI();
$token = $this->getTokenFromCode($code, $redirectURI);
self::$persistance->deleteVariable('redirect_uri');
self::$persistance->deleteVariable('code');
return $token->access_token;
}
}
} | [
"protected",
"function",
"getAccessToken",
"(",
")",
"{",
"$",
"token",
"=",
"self",
"::",
"$",
"persistance",
"->",
"getVariable",
"(",
"'token'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isAccessTokenExpired",
"(",
"$",
"token",
")",
")",
"{",
"return",
"$",
"token",
"->",
"access_token",
";",
"}",
"else",
"if",
"(",
"$",
"token",
"!==",
"null",
"&&",
"$",
"token",
"->",
"refresh_token",
"!==",
"null",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"getTokenFromRefreshToken",
"(",
"$",
"token",
"->",
"refresh_token",
")",
";",
"return",
"$",
"token",
"->",
"access_token",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'code'",
"]",
")",
")",
"{",
"$",
"code",
"=",
"$",
"_REQUEST",
"[",
"'code'",
"]",
";",
"if",
"(",
"$",
"code",
")",
"{",
"$",
"redirectURI",
"=",
"self",
"::",
"$",
"persistance",
"->",
"getVariable",
"(",
"'redirect_uri'",
")",
"?",
":",
"$",
"this",
"->",
"getCurrentURI",
"(",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"getTokenFromCode",
"(",
"$",
"code",
",",
"$",
"redirectURI",
")",
";",
"self",
"::",
"$",
"persistance",
"->",
"deleteVariable",
"(",
"'redirect_uri'",
")",
";",
"self",
"::",
"$",
"persistance",
"->",
"deleteVariable",
"(",
"'code'",
")",
";",
"return",
"$",
"token",
"->",
"access_token",
";",
"}",
"}",
"}"
] | Tries to get an access token.
If one is found in the session, it returns it.
If a code is found in the request, it tries to exchange it for an access
token on the OAuth2 Token Endpoint
Else it returns false
@return string An OAuth2 access token, or false if none is found | [
"Tries",
"to",
"get",
"an",
"access",
"token",
".",
"If",
"one",
"is",
"found",
"in",
"the",
"session",
"it",
"returns",
"it",
".",
"If",
"a",
"code",
"is",
"found",
"in",
"the",
"request",
"it",
"tries",
"to",
"exchange",
"it",
"for",
"an",
"access",
"token",
"on",
"the",
"OAuth2",
"Token",
"Endpoint",
"Else",
"it",
"returns",
"false"
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaConnect/Client.php#L193-L221 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaConnect/Client.php | Client.executeOAuth2 | protected function executeOAuth2($method, $ressource, array $params = array())
{
$this->headers['authorization'] = sprintf('Authorization: Bearer %s', $this->getAccessToken());
// We don't need auth since we are using an access token
$this->enableAuth = false;
try
{
$result = $this->execute($method, $ressource, $params);
$this->enableAuth = true;
return $result;
}
catch(Exception $e)
{
$this->enableAuth = true;
throw $e;
}
} | php | protected function executeOAuth2($method, $ressource, array $params = array())
{
$this->headers['authorization'] = sprintf('Authorization: Bearer %s', $this->getAccessToken());
// We don't need auth since we are using an access token
$this->enableAuth = false;
try
{
$result = $this->execute($method, $ressource, $params);
$this->enableAuth = true;
return $result;
}
catch(Exception $e)
{
$this->enableAuth = true;
throw $e;
}
} | [
"protected",
"function",
"executeOAuth2",
"(",
"$",
"method",
",",
"$",
"ressource",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"'authorization'",
"]",
"=",
"sprintf",
"(",
"'Authorization: Bearer %s'",
",",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
")",
";",
"// We don't need auth since we are using an access token",
"$",
"this",
"->",
"enableAuth",
"=",
"false",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"execute",
"(",
"$",
"method",
",",
"$",
"ressource",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"enableAuth",
"=",
"true",
";",
"return",
"$",
"result",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"enableAuth",
"=",
"true",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] | Executes an request on the API with an OAuth2 access token.
It works just like its parent execute() method.
@see \Maniaplanet\WebServices\HTTPClient::execute() | [
"Executes",
"an",
"request",
"on",
"the",
"API",
"with",
"an",
"OAuth2",
"access",
"token",
".",
"It",
"works",
"just",
"like",
"its",
"parent",
"execute",
"()",
"method",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaConnect/Client.php#L304-L320 |
digitalkaoz/versioneye-php | src/Output/Projects.php | Projects.all | public function all(OutputInterface $output, array $response)
{
$this->printTable($output,
['Key', 'Name', 'Type', 'Public', 'Dependencies', 'Outdated', 'Updated At', 'Bad Licenses', 'Unknown Licenses'],
['ids', 'name', 'project_type', 'public', 'dep_number', 'out_number', 'updated_at', 'licenses_red', 'licenses_unknown'],
$response,
function ($key, $value) use ($output) {
if ('public' === $key) {
return $value === 1 ? 'Yes' : 'No';
}
if (!in_array($key, ['out_number', 'licenses_red', 'licenses_unknown'], true)) {
return $value;
}
return $this->printBoolean($output, $value > 0 ? $value : 'No', $value, !$value, false);
}
);
} | php | public function all(OutputInterface $output, array $response)
{
$this->printTable($output,
['Key', 'Name', 'Type', 'Public', 'Dependencies', 'Outdated', 'Updated At', 'Bad Licenses', 'Unknown Licenses'],
['ids', 'name', 'project_type', 'public', 'dep_number', 'out_number', 'updated_at', 'licenses_red', 'licenses_unknown'],
$response,
function ($key, $value) use ($output) {
if ('public' === $key) {
return $value === 1 ? 'Yes' : 'No';
}
if (!in_array($key, ['out_number', 'licenses_red', 'licenses_unknown'], true)) {
return $value;
}
return $this->printBoolean($output, $value > 0 ? $value : 'No', $value, !$value, false);
}
);
} | [
"public",
"function",
"all",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"printTable",
"(",
"$",
"output",
",",
"[",
"'Key'",
",",
"'Name'",
",",
"'Type'",
",",
"'Public'",
",",
"'Dependencies'",
",",
"'Outdated'",
",",
"'Updated At'",
",",
"'Bad Licenses'",
",",
"'Unknown Licenses'",
"]",
",",
"[",
"'ids'",
",",
"'name'",
",",
"'project_type'",
",",
"'public'",
",",
"'dep_number'",
",",
"'out_number'",
",",
"'updated_at'",
",",
"'licenses_red'",
",",
"'licenses_unknown'",
"]",
",",
"$",
"response",
",",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"use",
"(",
"$",
"output",
")",
"{",
"if",
"(",
"'public'",
"===",
"$",
"key",
")",
"{",
"return",
"$",
"value",
"===",
"1",
"?",
"'Yes'",
":",
"'No'",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"[",
"'out_number'",
",",
"'licenses_red'",
",",
"'licenses_unknown'",
"]",
",",
"true",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"printBoolean",
"(",
"$",
"output",
",",
"$",
"value",
">",
"0",
"?",
"$",
"value",
":",
"'No'",
",",
"$",
"value",
",",
"!",
"$",
"value",
",",
"false",
")",
";",
"}",
")",
";",
"}"
] | output for projects API.
@param OutputInterface $output
@param array $response | [
"output",
"for",
"projects",
"API",
"."
] | train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/Projects.php#L20-L38 |
digitalkaoz/versioneye-php | src/Output/Projects.php | Projects.licenses | public function licenses(OutputInterface $output, array $response)
{
$table = $this->createTable($output);
$table->setHeaders(['license', 'name']);
foreach ($response['licenses'] as $license => $projects) {
foreach ($projects as $project) {
$name = $license === 'unknown' ? '<error>' . $project['name'] . '</error>' : $project['name'];
$license = $license === 'unknown' ? '<error>unknown</error>' : $license;
$table->addRow([$license, $name]);
}
}
$table->render($output);
} | php | public function licenses(OutputInterface $output, array $response)
{
$table = $this->createTable($output);
$table->setHeaders(['license', 'name']);
foreach ($response['licenses'] as $license => $projects) {
foreach ($projects as $project) {
$name = $license === 'unknown' ? '<error>' . $project['name'] . '</error>' : $project['name'];
$license = $license === 'unknown' ? '<error>unknown</error>' : $license;
$table->addRow([$license, $name]);
}
}
$table->render($output);
} | [
"public",
"function",
"licenses",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"response",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"createTable",
"(",
"$",
"output",
")",
";",
"$",
"table",
"->",
"setHeaders",
"(",
"[",
"'license'",
",",
"'name'",
"]",
")",
";",
"foreach",
"(",
"$",
"response",
"[",
"'licenses'",
"]",
"as",
"$",
"license",
"=>",
"$",
"projects",
")",
"{",
"foreach",
"(",
"$",
"projects",
"as",
"$",
"project",
")",
"{",
"$",
"name",
"=",
"$",
"license",
"===",
"'unknown'",
"?",
"'<error>'",
".",
"$",
"project",
"[",
"'name'",
"]",
".",
"'</error>'",
":",
"$",
"project",
"[",
"'name'",
"]",
";",
"$",
"license",
"=",
"$",
"license",
"===",
"'unknown'",
"?",
"'<error>unknown</error>'",
":",
"$",
"license",
";",
"$",
"table",
"->",
"addRow",
"(",
"[",
"$",
"license",
",",
"$",
"name",
"]",
")",
";",
"}",
"}",
"$",
"table",
"->",
"render",
"(",
"$",
"output",
")",
";",
"}"
] | output for licenses API.
@param OutputInterface $output
@param array $response | [
"output",
"for",
"licenses",
"API",
"."
] | train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/Projects.php#L46-L61 |
digitalkaoz/versioneye-php | src/Output/Projects.php | Projects.output | private function output(OutputInterface $output, array $response)
{
$this->printList($output,
['Name', 'Key', 'Type', 'Public', 'Outdated', 'Updated At', 'Bad Licenses', 'Unknown Licenses'],
['name', 'id', 'project_type', 'public', 'out_number', 'updated_at', 'licenses_red', 'licenses_unknown'],
$response,
function ($key, $value) use ($output) {
if (in_array($key, ['Outdated', 'Bad Licenses', 'Unknown Licenses'], true)) {
return $this->printBoolean($output, $value === 0 ? 'No' : $value, $value, !$value, false);
}
return $value;
}
);
$this->printTable($output,
['Name', 'Stable', 'Outdated', 'Current', 'Requested', 'Licenses', 'Vulnerabilities'],
['name', 'stable', 'outdated', 'version_current', 'version_requested', 'licenses', 'security_vulnerabilities'],
$response['dependencies'],
function ($key, $value) use ($output) {
if ('licenses' === $key) {
return implode(', ', array_column($value, 'name'));
}
if ('stable' === $key) {
return $this->printBoolean($output, 'Yes', 'No', $value, false);
}
if ('outdated' === $key) {
return $this->printBoolean($output, 'No', 'Yes', !$value, false);
}
if ('security_vulnerabilities' === $key) {
if (is_array($value)) {
return $this->printBoolean($output, 'No', implode(', ', array_column($value, 'cve')), count($value) === 0, false);
}
return $this->printBoolean($output, 'No', 'Yes', true, false);
}
return $value;
}
);
} | php | private function output(OutputInterface $output, array $response)
{
$this->printList($output,
['Name', 'Key', 'Type', 'Public', 'Outdated', 'Updated At', 'Bad Licenses', 'Unknown Licenses'],
['name', 'id', 'project_type', 'public', 'out_number', 'updated_at', 'licenses_red', 'licenses_unknown'],
$response,
function ($key, $value) use ($output) {
if (in_array($key, ['Outdated', 'Bad Licenses', 'Unknown Licenses'], true)) {
return $this->printBoolean($output, $value === 0 ? 'No' : $value, $value, !$value, false);
}
return $value;
}
);
$this->printTable($output,
['Name', 'Stable', 'Outdated', 'Current', 'Requested', 'Licenses', 'Vulnerabilities'],
['name', 'stable', 'outdated', 'version_current', 'version_requested', 'licenses', 'security_vulnerabilities'],
$response['dependencies'],
function ($key, $value) use ($output) {
if ('licenses' === $key) {
return implode(', ', array_column($value, 'name'));
}
if ('stable' === $key) {
return $this->printBoolean($output, 'Yes', 'No', $value, false);
}
if ('outdated' === $key) {
return $this->printBoolean($output, 'No', 'Yes', !$value, false);
}
if ('security_vulnerabilities' === $key) {
if (is_array($value)) {
return $this->printBoolean($output, 'No', implode(', ', array_column($value, 'cve')), count($value) === 0, false);
}
return $this->printBoolean($output, 'No', 'Yes', true, false);
}
return $value;
}
);
} | [
"private",
"function",
"output",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"printList",
"(",
"$",
"output",
",",
"[",
"'Name'",
",",
"'Key'",
",",
"'Type'",
",",
"'Public'",
",",
"'Outdated'",
",",
"'Updated At'",
",",
"'Bad Licenses'",
",",
"'Unknown Licenses'",
"]",
",",
"[",
"'name'",
",",
"'id'",
",",
"'project_type'",
",",
"'public'",
",",
"'out_number'",
",",
"'updated_at'",
",",
"'licenses_red'",
",",
"'licenses_unknown'",
"]",
",",
"$",
"response",
",",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"use",
"(",
"$",
"output",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"[",
"'Outdated'",
",",
"'Bad Licenses'",
",",
"'Unknown Licenses'",
"]",
",",
"true",
")",
")",
"{",
"return",
"$",
"this",
"->",
"printBoolean",
"(",
"$",
"output",
",",
"$",
"value",
"===",
"0",
"?",
"'No'",
":",
"$",
"value",
",",
"$",
"value",
",",
"!",
"$",
"value",
",",
"false",
")",
";",
"}",
"return",
"$",
"value",
";",
"}",
")",
";",
"$",
"this",
"->",
"printTable",
"(",
"$",
"output",
",",
"[",
"'Name'",
",",
"'Stable'",
",",
"'Outdated'",
",",
"'Current'",
",",
"'Requested'",
",",
"'Licenses'",
",",
"'Vulnerabilities'",
"]",
",",
"[",
"'name'",
",",
"'stable'",
",",
"'outdated'",
",",
"'version_current'",
",",
"'version_requested'",
",",
"'licenses'",
",",
"'security_vulnerabilities'",
"]",
",",
"$",
"response",
"[",
"'dependencies'",
"]",
",",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"use",
"(",
"$",
"output",
")",
"{",
"if",
"(",
"'licenses'",
"===",
"$",
"key",
")",
"{",
"return",
"implode",
"(",
"', '",
",",
"array_column",
"(",
"$",
"value",
",",
"'name'",
")",
")",
";",
"}",
"if",
"(",
"'stable'",
"===",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"printBoolean",
"(",
"$",
"output",
",",
"'Yes'",
",",
"'No'",
",",
"$",
"value",
",",
"false",
")",
";",
"}",
"if",
"(",
"'outdated'",
"===",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"printBoolean",
"(",
"$",
"output",
",",
"'No'",
",",
"'Yes'",
",",
"!",
"$",
"value",
",",
"false",
")",
";",
"}",
"if",
"(",
"'security_vulnerabilities'",
"===",
"$",
"key",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"printBoolean",
"(",
"$",
"output",
",",
"'No'",
",",
"implode",
"(",
"', '",
",",
"array_column",
"(",
"$",
"value",
",",
"'cve'",
")",
")",
",",
"count",
"(",
"$",
"value",
")",
"===",
"0",
",",
"false",
")",
";",
"}",
"return",
"$",
"this",
"->",
"printBoolean",
"(",
"$",
"output",
",",
"'No'",
",",
"'Yes'",
",",
"true",
",",
"false",
")",
";",
"}",
"return",
"$",
"value",
";",
"}",
")",
";",
"}"
] | default output for create/show/update.
@param OutputInterface $output
@param array $response | [
"default",
"output",
"for",
"create",
"/",
"show",
"/",
"update",
"."
] | train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/Projects.php#L113-L154 |
lelivrescolaire/SQSBundle | Model/SQS.php | SQS.createQueue | public function createQueue(QueueInterface $queue)
{
$response = $this->getClient()->createQueue(array(
"QueueName" => $queue->getName()
));
$queue->setUrl(trim($response->get('QueueUrl')));
return $queue;
} | php | public function createQueue(QueueInterface $queue)
{
$response = $this->getClient()->createQueue(array(
"QueueName" => $queue->getName()
));
$queue->setUrl(trim($response->get('QueueUrl')));
return $queue;
} | [
"public",
"function",
"createQueue",
"(",
"QueueInterface",
"$",
"queue",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"createQueue",
"(",
"array",
"(",
"\"QueueName\"",
"=>",
"$",
"queue",
"->",
"getName",
"(",
")",
")",
")",
";",
"$",
"queue",
"->",
"setUrl",
"(",
"trim",
"(",
"$",
"response",
"->",
"get",
"(",
"'QueueUrl'",
")",
")",
")",
";",
"return",
"$",
"queue",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lelivrescolaire/SQSBundle/blob/bba3fa6d63d0ae1bddbc7b2fe3c2e737f49d6559/Model/SQS.php#L83-L92 |
lelivrescolaire/SQSBundle | Model/SQS.php | SQS.listQueues | public function listQueues($prefix = null)
{
$response = $this->getClient()->listQueues(array(
'QueueNamePrefix' => ($prefix ?: '')
));
$service = $this;
$queues = array_map(function ($queueUrl) use ($service) {
$queueName = $service->getQueueFactory()->getNameFromUrl(trim($queueUrl));
return $service->getQueue($queueName);
}, $response->get('QueueUrls'));
return $queues;
} | php | public function listQueues($prefix = null)
{
$response = $this->getClient()->listQueues(array(
'QueueNamePrefix' => ($prefix ?: '')
));
$service = $this;
$queues = array_map(function ($queueUrl) use ($service) {
$queueName = $service->getQueueFactory()->getNameFromUrl(trim($queueUrl));
return $service->getQueue($queueName);
}, $response->get('QueueUrls'));
return $queues;
} | [
"public",
"function",
"listQueues",
"(",
"$",
"prefix",
"=",
"null",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"listQueues",
"(",
"array",
"(",
"'QueueNamePrefix'",
"=>",
"(",
"$",
"prefix",
"?",
":",
"''",
")",
")",
")",
";",
"$",
"service",
"=",
"$",
"this",
";",
"$",
"queues",
"=",
"array_map",
"(",
"function",
"(",
"$",
"queueUrl",
")",
"use",
"(",
"$",
"service",
")",
"{",
"$",
"queueName",
"=",
"$",
"service",
"->",
"getQueueFactory",
"(",
")",
"->",
"getNameFromUrl",
"(",
"trim",
"(",
"$",
"queueUrl",
")",
")",
";",
"return",
"$",
"service",
"->",
"getQueue",
"(",
"$",
"queueName",
")",
";",
"}",
",",
"$",
"response",
"->",
"get",
"(",
"'QueueUrls'",
")",
")",
";",
"return",
"$",
"queues",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lelivrescolaire/SQSBundle/blob/bba3fa6d63d0ae1bddbc7b2fe3c2e737f49d6559/Model/SQS.php#L109-L123 |
sebastiaanluca/laravel-unbreakable-migrations | src/TransactionalMigration.php | TransactionalMigration.executeInTransaction | protected function executeInTransaction(string $method) : void
{
try {
$this->database->beginTransaction();
$this->{$method}();
$this->database->commit();
} catch (Exception $exception) {
$this->database->rollBack();
$this->handleException($exception);
}
} | php | protected function executeInTransaction(string $method) : void
{
try {
$this->database->beginTransaction();
$this->{$method}();
$this->database->commit();
} catch (Exception $exception) {
$this->database->rollBack();
$this->handleException($exception);
}
} | [
"protected",
"function",
"executeInTransaction",
"(",
"string",
"$",
"method",
")",
":",
"void",
"{",
"try",
"{",
"$",
"this",
"->",
"database",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
")",
";",
"$",
"this",
"->",
"database",
"->",
"commit",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"database",
"->",
"rollBack",
"(",
")",
";",
"$",
"this",
"->",
"handleException",
"(",
"$",
"exception",
")",
";",
"}",
"}"
] | Execute the migration command inside a transaction layer.
@param string $method
@return void | [
"Execute",
"the",
"migration",
"command",
"inside",
"a",
"transaction",
"layer",
"."
] | train | https://github.com/sebastiaanluca/laravel-unbreakable-migrations/blob/3c831b204770b80c97351c3b881dcbf924236a13/src/TransactionalMigration.php#L38-L51 |
datasift/php_webdriver | src/php/DataSift/WebDriver/WebDriverContainer.php | WebDriverContainer.getElement | public function getElement($using, $value)
{
// try to get the requested element from the open session
try {
$results = $this->curl(
'POST',
'/element',
array(
'using' => $using,
'value' => $value
)
);
}
catch (E5xx_NoSuchElementWebDriverError $e) {
// the element does not exist
throw new E5xx_NoSuchElementWebDriverError(
500,
sprintf(
'Element not found with %s, %s',
$using,
$value
) . "\n\n" . $e->getMessage(),
$e->getResults()
);
}
// if we get here, then we can return the element back to the
// caller :)
return $this->newWebDriverElement($results['value']);
} | php | public function getElement($using, $value)
{
// try to get the requested element from the open session
try {
$results = $this->curl(
'POST',
'/element',
array(
'using' => $using,
'value' => $value
)
);
}
catch (E5xx_NoSuchElementWebDriverError $e) {
// the element does not exist
throw new E5xx_NoSuchElementWebDriverError(
500,
sprintf(
'Element not found with %s, %s',
$using,
$value
) . "\n\n" . $e->getMessage(),
$e->getResults()
);
}
// if we get here, then we can return the element back to the
// caller :)
return $this->newWebDriverElement($results['value']);
} | [
"public",
"function",
"getElement",
"(",
"$",
"using",
",",
"$",
"value",
")",
"{",
"// try to get the requested element from the open session",
"try",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"curl",
"(",
"'POST'",
",",
"'/element'",
",",
"array",
"(",
"'using'",
"=>",
"$",
"using",
",",
"'value'",
"=>",
"$",
"value",
")",
")",
";",
"}",
"catch",
"(",
"E5xx_NoSuchElementWebDriverError",
"$",
"e",
")",
"{",
"// the element does not exist",
"throw",
"new",
"E5xx_NoSuchElementWebDriverError",
"(",
"500",
",",
"sprintf",
"(",
"'Element not found with %s, %s'",
",",
"$",
"using",
",",
"$",
"value",
")",
".",
"\"\\n\\n\"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getResults",
"(",
")",
")",
";",
"}",
"// if we get here, then we can return the element back to the",
"// caller :)",
"return",
"$",
"this",
"->",
"newWebDriverElement",
"(",
"$",
"results",
"[",
"'value'",
"]",
")",
";",
"}"
] | retrieve an element from the currently loaded page
@param string $using the search strategy
@param string $value the term to search for
@return WebDriverElement the element that has been searched for | [
"retrieve",
"an",
"element",
"from",
"the",
"currently",
"loaded",
"page"
] | train | https://github.com/datasift/php_webdriver/blob/efca991198616b53c8f40b59ad05306e2b10e7f0/src/php/DataSift/WebDriver/WebDriverContainer.php#L51-L80 |
datasift/php_webdriver | src/php/DataSift/WebDriver/WebDriverContainer.php | WebDriverContainer.getElements | public function getElements($using, $value)
{
try {
$results = $this->curl(
'POST',
'/elements',
array(
'using' => $using,
'value' => $value
)
);
}
catch (E5xx_NoSuchElementWebDriverError $e) {
// the element does not exist
throw new E5xx_NoSuchElementWebDriverError(
sprintf(
'Element not found with %s, %s',
$using,
$value
) . "\n\n" . $e->getMessage(),
$e->getResults()
);
}
// if we get here, then we can return the set of elements back
// to the caller :)
// if (!(is_array($results['value'])))
// {
// var_dump($results);
// }
return array_filter(array_map(
array($this, 'newWebDriverElement'), $results['value'])
);
} | php | public function getElements($using, $value)
{
try {
$results = $this->curl(
'POST',
'/elements',
array(
'using' => $using,
'value' => $value
)
);
}
catch (E5xx_NoSuchElementWebDriverError $e) {
// the element does not exist
throw new E5xx_NoSuchElementWebDriverError(
sprintf(
'Element not found with %s, %s',
$using,
$value
) . "\n\n" . $e->getMessage(),
$e->getResults()
);
}
// if we get here, then we can return the set of elements back
// to the caller :)
// if (!(is_array($results['value'])))
// {
// var_dump($results);
// }
return array_filter(array_map(
array($this, 'newWebDriverElement'), $results['value'])
);
} | [
"public",
"function",
"getElements",
"(",
"$",
"using",
",",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"curl",
"(",
"'POST'",
",",
"'/elements'",
",",
"array",
"(",
"'using'",
"=>",
"$",
"using",
",",
"'value'",
"=>",
"$",
"value",
")",
")",
";",
"}",
"catch",
"(",
"E5xx_NoSuchElementWebDriverError",
"$",
"e",
")",
"{",
"// the element does not exist",
"throw",
"new",
"E5xx_NoSuchElementWebDriverError",
"(",
"sprintf",
"(",
"'Element not found with %s, %s'",
",",
"$",
"using",
",",
"$",
"value",
")",
".",
"\"\\n\\n\"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getResults",
"(",
")",
")",
";",
"}",
"// if we get here, then we can return the set of elements back",
"// to the caller :)",
"// if (!(is_array($results['value'])))",
"// {",
"// var_dump($results);",
"// }",
"return",
"array_filter",
"(",
"array_map",
"(",
"array",
"(",
"$",
"this",
",",
"'newWebDriverElement'",
")",
",",
"$",
"results",
"[",
"'value'",
"]",
")",
")",
";",
"}"
] | Find all occurances of an element on the current page
@param string $using the search strategy
@param string $value the term to search for
@return array(WebDriverElement) | [
"Find",
"all",
"occurances",
"of",
"an",
"element",
"on",
"the",
"current",
"page"
] | train | https://github.com/datasift/php_webdriver/blob/efca991198616b53c8f40b59ad05306e2b10e7f0/src/php/DataSift/WebDriver/WebDriverContainer.php#L90-L125 |
datasift/php_webdriver | src/php/DataSift/WebDriver/WebDriverContainer.php | WebDriverContainer.newWebDriverElement | protected function newWebDriverElement($value)
{
// is the returned element in the format we expect?
if (!array_key_exists('ELEMENT', (array) $value)) {
// no, it is not
return null;
}
return new WebDriverElement(
$this->getElementPath($value['ELEMENT']), // url
$value['ELEMENT'] // id
);
} | php | protected function newWebDriverElement($value)
{
// is the returned element in the format we expect?
if (!array_key_exists('ELEMENT', (array) $value)) {
// no, it is not
return null;
}
return new WebDriverElement(
$this->getElementPath($value['ELEMENT']), // url
$value['ELEMENT'] // id
);
} | [
"protected",
"function",
"newWebDriverElement",
"(",
"$",
"value",
")",
"{",
"// is the returned element in the format we expect?",
"if",
"(",
"!",
"array_key_exists",
"(",
"'ELEMENT'",
",",
"(",
"array",
")",
"$",
"value",
")",
")",
"{",
"// no, it is not",
"return",
"null",
";",
"}",
"return",
"new",
"WebDriverElement",
"(",
"$",
"this",
"->",
"getElementPath",
"(",
"$",
"value",
"[",
"'ELEMENT'",
"]",
")",
",",
"// url",
"$",
"value",
"[",
"'ELEMENT'",
"]",
"// id",
")",
";",
"}"
] | helper method to wrap an element inside the WebDriverElement
object
@param array $value the raw element data returned from webdriver
@return WebDriverElement the WebDriverElement object for the raw
element | [
"helper",
"method",
"to",
"wrap",
"an",
"element",
"inside",
"the",
"WebDriverElement",
"object"
] | train | https://github.com/datasift/php_webdriver/blob/efca991198616b53c8f40b59ad05306e2b10e7f0/src/php/DataSift/WebDriver/WebDriverContainer.php#L136-L148 |
xinix-technology/norm | src/Norm/Collection.php | Collection.schema | public function schema($key = null, $value = null)
{
$numArgs = func_num_args();
if (0 === $numArgs) {
return $this->schema;
} elseif (1 === $numArgs) {
if (is_array($key)) {
$this->schema = new NObject($key);
} elseif ($this->schema->offsetExists($key)) {
return $this->schema[$key];
}
} else {
$this->schema[$key] = $value;
}
} | php | public function schema($key = null, $value = null)
{
$numArgs = func_num_args();
if (0 === $numArgs) {
return $this->schema;
} elseif (1 === $numArgs) {
if (is_array($key)) {
$this->schema = new NObject($key);
} elseif ($this->schema->offsetExists($key)) {
return $this->schema[$key];
}
} else {
$this->schema[$key] = $value;
}
} | [
"public",
"function",
"schema",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"numArgs",
"=",
"func_num_args",
"(",
")",
";",
"if",
"(",
"0",
"===",
"$",
"numArgs",
")",
"{",
"return",
"$",
"this",
"->",
"schema",
";",
"}",
"elseif",
"(",
"1",
"===",
"$",
"numArgs",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"schema",
"=",
"new",
"NObject",
"(",
"$",
"key",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"schema",
"->",
"offsetExists",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"schema",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"schema",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Getter and setter of collection schema. If there is no argument specified, the method will set and override schema. If argument specified, method will act as getter to specific field schema.
@param string $schema
@return mixed | [
"Getter",
"and",
"setter",
"of",
"collection",
"schema",
".",
"If",
"there",
"is",
"no",
"argument",
"specified",
"the",
"method",
"will",
"set",
"and",
"override",
"schema",
".",
"If",
"argument",
"specified",
"method",
"will",
"act",
"as",
"getter",
"to",
"specific",
"field",
"schema",
"."
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L172-L186 |
xinix-technology/norm | src/Norm/Collection.php | Collection.prepare | public function prepare($key, $value, $schema = null)
{
if (is_null($schema)) {
$schema = $this->schema($key);
if (is_null($schema)) {
return $value;
// throw new \Exception('Cannot prepare data to set. Schema not found for key ['.$key.'].');
}
}
return $schema->prepare($value);
} | php | public function prepare($key, $value, $schema = null)
{
if (is_null($schema)) {
$schema = $this->schema($key);
if (is_null($schema)) {
return $value;
// throw new \Exception('Cannot prepare data to set. Schema not found for key ['.$key.'].');
}
}
return $schema->prepare($value);
} | [
"public",
"function",
"prepare",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"schema",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"schema",
")",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"schema",
"(",
"$",
"key",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"schema",
")",
")",
"{",
"return",
"$",
"value",
";",
"// throw new \\Exception('Cannot prepare data to set. Schema not found for key ['.$key.'].');",
"}",
"}",
"return",
"$",
"schema",
"->",
"prepare",
"(",
"$",
"value",
")",
";",
"}"
] | Prepare data value for specific field name
@param string $key Field name
@param mixed $value Original data value
@param Norm\Schema\Field $schema If specified will override default schema
@return mixed Prepared data value | [
"Prepare",
"data",
"value",
"for",
"specific",
"field",
"name"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L197-L207 |
xinix-technology/norm | src/Norm/Collection.php | Collection.attach | public function attach($document)
{
if (isset($this->connection)) {
$document = $this->connection->unmarshall($document);
}
// wrap document as NObject instance to make sure it can be override by hooks
$document = new NObject($document);
$this->applyHook('attaching', $document);
if (isset($this->options['model'])) {
$Model = $this->options['model'];
$model = new $Model($document->toArray(), array(
'collection' => $this,
));
} else {
$model = new Model($document->toArray(), array(
'collection' => $this,
));
}
$this->applyHook('attached', $model);
return $model;
} | php | public function attach($document)
{
if (isset($this->connection)) {
$document = $this->connection->unmarshall($document);
}
// wrap document as NObject instance to make sure it can be override by hooks
$document = new NObject($document);
$this->applyHook('attaching', $document);
if (isset($this->options['model'])) {
$Model = $this->options['model'];
$model = new $Model($document->toArray(), array(
'collection' => $this,
));
} else {
$model = new Model($document->toArray(), array(
'collection' => $this,
));
}
$this->applyHook('attached', $model);
return $model;
} | [
"public",
"function",
"attach",
"(",
"$",
"document",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"connection",
")",
")",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"connection",
"->",
"unmarshall",
"(",
"$",
"document",
")",
";",
"}",
"// wrap document as NObject instance to make sure it can be override by hooks",
"$",
"document",
"=",
"new",
"NObject",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"applyHook",
"(",
"'attaching'",
",",
"$",
"document",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'model'",
"]",
")",
")",
"{",
"$",
"Model",
"=",
"$",
"this",
"->",
"options",
"[",
"'model'",
"]",
";",
"$",
"model",
"=",
"new",
"$",
"Model",
"(",
"$",
"document",
"->",
"toArray",
"(",
")",
",",
"array",
"(",
"'collection'",
"=>",
"$",
"this",
",",
")",
")",
";",
"}",
"else",
"{",
"$",
"model",
"=",
"new",
"Model",
"(",
"$",
"document",
"->",
"toArray",
"(",
")",
",",
"array",
"(",
"'collection'",
"=>",
"$",
"this",
",",
")",
")",
";",
"}",
"$",
"this",
"->",
"applyHook",
"(",
"'attached'",
",",
"$",
"model",
")",
";",
"return",
"$",
"model",
";",
"}"
] | Attach document to Norm system as model.
@param mixed document Raw document data
@return Norm\Model Attached model | [
"Attach",
"document",
"to",
"Norm",
"system",
"as",
"model",
"."
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L216-L241 |
xinix-technology/norm | src/Norm/Collection.php | Collection.find | public function find($criteria = array())
{
if (!is_array($criteria)) {
$criteria = array(
'$id' => $criteria,
);
}
// wrap criteria as NObject instance to make sure it can be override by hooks
$criteria = new NObject($criteria);
$this->applyHook('searching', $criteria);
$cursor = $this->connection->query($this, $criteria->toArray());
$this->applyHook('searched', $cursor);
return $cursor;
} | php | public function find($criteria = array())
{
if (!is_array($criteria)) {
$criteria = array(
'$id' => $criteria,
);
}
// wrap criteria as NObject instance to make sure it can be override by hooks
$criteria = new NObject($criteria);
$this->applyHook('searching', $criteria);
$cursor = $this->connection->query($this, $criteria->toArray());
$this->applyHook('searched', $cursor);
return $cursor;
} | [
"public",
"function",
"find",
"(",
"$",
"criteria",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"criteria",
")",
")",
"{",
"$",
"criteria",
"=",
"array",
"(",
"'$id'",
"=>",
"$",
"criteria",
",",
")",
";",
"}",
"// wrap criteria as NObject instance to make sure it can be override by hooks",
"$",
"criteria",
"=",
"new",
"NObject",
"(",
"$",
"criteria",
")",
";",
"$",
"this",
"->",
"applyHook",
"(",
"'searching'",
",",
"$",
"criteria",
")",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"$",
"this",
",",
"$",
"criteria",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"this",
"->",
"applyHook",
"(",
"'searched'",
",",
"$",
"cursor",
")",
";",
"return",
"$",
"cursor",
";",
"}"
] | Find data with specified criteria
@param array $criteria
@return Norm\Cursor | [
"Find",
"data",
"with",
"specified",
"criteria"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L250-L266 |
xinix-technology/norm | src/Norm/Collection.php | Collection.findOne | public function findOne($criteria = array())
{
$model = $this->fetchCache($criteria);
if (is_null($model)) {
$cursor = $this->find($criteria);
$model = $cursor->getNext();
$this->rememberCache($criteria, $model);
}
return $model;
} | php | public function findOne($criteria = array())
{
$model = $this->fetchCache($criteria);
if (is_null($model)) {
$cursor = $this->find($criteria);
$model = $cursor->getNext();
$this->rememberCache($criteria, $model);
}
return $model;
} | [
"public",
"function",
"findOne",
"(",
"$",
"criteria",
"=",
"array",
"(",
")",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"fetchCache",
"(",
"$",
"criteria",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"model",
")",
")",
"{",
"$",
"cursor",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"criteria",
")",
";",
"$",
"model",
"=",
"$",
"cursor",
"->",
"getNext",
"(",
")",
";",
"$",
"this",
"->",
"rememberCache",
"(",
"$",
"criteria",
",",
"$",
"model",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | Find one document from collection
@param array|mixed $criteria Criteria to search
@return Norm\Model | [
"Find",
"one",
"document",
"from",
"collection"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L275-L286 |
xinix-technology/norm | src/Norm/Collection.php | Collection.newInstance | public function newInstance($cloned = array())
{
if ($cloned instanceof Model) {
$cloned = $cloned->toArray(Model::FETCH_PUBLISHED);
}
if (isset($this->options['model'])) {
$Model = $this->options['model'];
return new $Model($cloned, array('collection' => $this));
} else {
return new Model($cloned, array('collection' => $this));
}
} | php | public function newInstance($cloned = array())
{
if ($cloned instanceof Model) {
$cloned = $cloned->toArray(Model::FETCH_PUBLISHED);
}
if (isset($this->options['model'])) {
$Model = $this->options['model'];
return new $Model($cloned, array('collection' => $this));
} else {
return new Model($cloned, array('collection' => $this));
}
} | [
"public",
"function",
"newInstance",
"(",
"$",
"cloned",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"cloned",
"instanceof",
"Model",
")",
"{",
"$",
"cloned",
"=",
"$",
"cloned",
"->",
"toArray",
"(",
"Model",
"::",
"FETCH_PUBLISHED",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'model'",
"]",
")",
")",
"{",
"$",
"Model",
"=",
"$",
"this",
"->",
"options",
"[",
"'model'",
"]",
";",
"return",
"new",
"$",
"Model",
"(",
"$",
"cloned",
",",
"array",
"(",
"'collection'",
"=>",
"$",
"this",
")",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Model",
"(",
"$",
"cloned",
",",
"array",
"(",
"'collection'",
"=>",
"$",
"this",
")",
")",
";",
"}",
"}"
] | Create new instance of model
@param array|\Norm\Model $cloned Model to clone
@return \Norm\Model | [
"Create",
"new",
"instance",
"of",
"model"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L295-L307 |
xinix-technology/norm | src/Norm/Collection.php | Collection.filter | public function filter(Model $model, $key = null)
{
if (is_null($this->filter)) {
$this->filter = Filter::fromSchema($this->schema());
}
$this->applyHook('filtering', $model, $key);
$result = $this->filter->run($model, $key);
$this->applyHook('filtered', $model, $key);
return $result;
} | php | public function filter(Model $model, $key = null)
{
if (is_null($this->filter)) {
$this->filter = Filter::fromSchema($this->schema());
}
$this->applyHook('filtering', $model, $key);
$result = $this->filter->run($model, $key);
$this->applyHook('filtered', $model, $key);
return $result;
} | [
"public",
"function",
"filter",
"(",
"Model",
"$",
"model",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"filter",
")",
")",
"{",
"$",
"this",
"->",
"filter",
"=",
"Filter",
"::",
"fromSchema",
"(",
"$",
"this",
"->",
"schema",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"applyHook",
"(",
"'filtering'",
",",
"$",
"model",
",",
"$",
"key",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"filter",
"->",
"run",
"(",
"$",
"model",
",",
"$",
"key",
")",
";",
"$",
"this",
"->",
"applyHook",
"(",
"'filtered'",
",",
"$",
"model",
",",
"$",
"key",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Filter model data with functions to cleanse, prepare and validate data. When key argument specified, filter will run partially for specified key only.
@param \Norm\Model $model
@param string $key Key field of model
@return bool True if success and false if fail | [
"Filter",
"model",
"data",
"with",
"functions",
"to",
"cleanse",
"prepare",
"and",
"validate",
"data",
".",
"When",
"key",
"argument",
"specified",
"filter",
"will",
"run",
"partially",
"for",
"specified",
"key",
"only",
"."
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L318-L329 |
xinix-technology/norm | src/Norm/Collection.php | Collection.save | public function save(Model $model, $options = array())
{
$options = array_merge(array(
'filter' => true,
'observer' => true,
), $options);
if ($options['filter']) {
$this->filter($model);
}
if ($options['observer']) {
$this->applyHook('saving', $model, $options);
}
$modified = $this->connection->persist($this, $model->dump());
$model->setId($modified['$id']);
if ($options['observer']) {
$this->applyHook('saved', $model, $options);
}
$model->sync($modified);
$this->resetCache();
} | php | public function save(Model $model, $options = array())
{
$options = array_merge(array(
'filter' => true,
'observer' => true,
), $options);
if ($options['filter']) {
$this->filter($model);
}
if ($options['observer']) {
$this->applyHook('saving', $model, $options);
}
$modified = $this->connection->persist($this, $model->dump());
$model->setId($modified['$id']);
if ($options['observer']) {
$this->applyHook('saved', $model, $options);
}
$model->sync($modified);
$this->resetCache();
} | [
"public",
"function",
"save",
"(",
"Model",
"$",
"model",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"array",
"(",
"'filter'",
"=>",
"true",
",",
"'observer'",
"=>",
"true",
",",
")",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'filter'",
"]",
")",
"{",
"$",
"this",
"->",
"filter",
"(",
"$",
"model",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'observer'",
"]",
")",
"{",
"$",
"this",
"->",
"applyHook",
"(",
"'saving'",
",",
"$",
"model",
",",
"$",
"options",
")",
";",
"}",
"$",
"modified",
"=",
"$",
"this",
"->",
"connection",
"->",
"persist",
"(",
"$",
"this",
",",
"$",
"model",
"->",
"dump",
"(",
")",
")",
";",
"$",
"model",
"->",
"setId",
"(",
"$",
"modified",
"[",
"'$id'",
"]",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'observer'",
"]",
")",
"{",
"$",
"this",
"->",
"applyHook",
"(",
"'saved'",
",",
"$",
"model",
",",
"$",
"options",
")",
";",
"}",
"$",
"model",
"->",
"sync",
"(",
"$",
"modified",
")",
";",
"$",
"this",
"->",
"resetCache",
"(",
")",
";",
"}"
] | Save model to persistent state
@param \Norm\Model $model
@param array $options
@return void | [
"Save",
"model",
"to",
"persistent",
"state"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L339-L363 |
xinix-technology/norm | src/Norm/Collection.php | Collection.remove | public function remove(Model $model = null)
{
if (func_num_args() === 0) {
$this->connection->remove($this);
} else {
// avoid remove empty model
if (is_null($model)) {
throw new \Exception('[Norm/Collection] Cannot remove null model');
}
$this->applyHook('removing', $model);
$result = $this->connection->remove($this, $model);
if ($result) {
$model->reset();
}
$this->applyHook('removed', $model);
}
} | php | public function remove(Model $model = null)
{
if (func_num_args() === 0) {
$this->connection->remove($this);
} else {
// avoid remove empty model
if (is_null($model)) {
throw new \Exception('[Norm/Collection] Cannot remove null model');
}
$this->applyHook('removing', $model);
$result = $this->connection->remove($this, $model);
if ($result) {
$model->reset();
}
$this->applyHook('removed', $model);
}
} | [
"public",
"function",
"remove",
"(",
"Model",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"remove",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"// avoid remove empty model",
"if",
"(",
"is_null",
"(",
"$",
"model",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'[Norm/Collection] Cannot remove null model'",
")",
";",
"}",
"$",
"this",
"->",
"applyHook",
"(",
"'removing'",
",",
"$",
"model",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"connection",
"->",
"remove",
"(",
"$",
"this",
",",
"$",
"model",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"model",
"->",
"reset",
"(",
")",
";",
"}",
"$",
"this",
"->",
"applyHook",
"(",
"'removed'",
",",
"$",
"model",
")",
";",
"}",
"}"
] | Remove single model
@param \Norm\Model $model
@return void | [
"Remove",
"single",
"model"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L372-L391 |
xinix-technology/norm | src/Norm/Collection.php | Collection.observe | protected function observe($observer)
{
if (method_exists($observer, 'saving')) {
$this->hook('saving', array($observer, 'saving'));
}
if (method_exists($observer, 'saved')) {
$this->hook('saved', array($observer, 'saved'));
}
if (method_exists($observer, 'filtering')) {
$this->hook('filtering', array($observer, 'filtering'));
}
if (method_exists($observer, 'filtered')) {
$this->hook('filtered', array($observer, 'filtered'));
}
if (method_exists($observer, 'removing')) {
$this->hook('removing', array($observer, 'removing'));
}
if (method_exists($observer, 'removed')) {
$this->hook('removed', array($observer, 'removed'));
}
if (method_exists($observer, 'searching')) {
$this->hook('searching', array($observer, 'searching'));
}
if (method_exists($observer, 'searched')) {
$this->hook('searched', array($observer, 'searched'));
}
if (method_exists($observer, 'attaching')) {
$this->hook('attaching', array($observer, 'attaching'));
}
if (method_exists($observer, 'attached')) {
$this->hook('attached', array($observer, 'attached'));
}
if (method_exists($observer, 'initialized')) {
$this->hook('initialized', array($observer, 'initialized'));
}
} | php | protected function observe($observer)
{
if (method_exists($observer, 'saving')) {
$this->hook('saving', array($observer, 'saving'));
}
if (method_exists($observer, 'saved')) {
$this->hook('saved', array($observer, 'saved'));
}
if (method_exists($observer, 'filtering')) {
$this->hook('filtering', array($observer, 'filtering'));
}
if (method_exists($observer, 'filtered')) {
$this->hook('filtered', array($observer, 'filtered'));
}
if (method_exists($observer, 'removing')) {
$this->hook('removing', array($observer, 'removing'));
}
if (method_exists($observer, 'removed')) {
$this->hook('removed', array($observer, 'removed'));
}
if (method_exists($observer, 'searching')) {
$this->hook('searching', array($observer, 'searching'));
}
if (method_exists($observer, 'searched')) {
$this->hook('searched', array($observer, 'searched'));
}
if (method_exists($observer, 'attaching')) {
$this->hook('attaching', array($observer, 'attaching'));
}
if (method_exists($observer, 'attached')) {
$this->hook('attached', array($observer, 'attached'));
}
if (method_exists($observer, 'initialized')) {
$this->hook('initialized', array($observer, 'initialized'));
}
} | [
"protected",
"function",
"observe",
"(",
"$",
"observer",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'saving'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'saving'",
",",
"array",
"(",
"$",
"observer",
",",
"'saving'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'saved'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'saved'",
",",
"array",
"(",
"$",
"observer",
",",
"'saved'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'filtering'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'filtering'",
",",
"array",
"(",
"$",
"observer",
",",
"'filtering'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'filtered'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'filtered'",
",",
"array",
"(",
"$",
"observer",
",",
"'filtered'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'removing'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'removing'",
",",
"array",
"(",
"$",
"observer",
",",
"'removing'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'removed'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'removed'",
",",
"array",
"(",
"$",
"observer",
",",
"'removed'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'searching'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'searching'",
",",
"array",
"(",
"$",
"observer",
",",
"'searching'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'searched'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'searched'",
",",
"array",
"(",
"$",
"observer",
",",
"'searched'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'attaching'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'attaching'",
",",
"array",
"(",
"$",
"observer",
",",
"'attaching'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'attached'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'attached'",
",",
"array",
"(",
"$",
"observer",
",",
"'attached'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"observer",
",",
"'initialized'",
")",
")",
"{",
"$",
"this",
"->",
"hook",
"(",
"'initialized'",
",",
"array",
"(",
"$",
"observer",
",",
"'initialized'",
")",
")",
";",
"}",
"}"
] | Override this to add new functionality of observer to the collection, otherwise you are not necessarilly to know about this.
@param NObject $observer
@return void | [
"Override",
"this",
"to",
"add",
"new",
"functionality",
"of",
"observer",
"to",
"the",
"collection",
"otherwise",
"you",
"are",
"not",
"necessarilly",
"to",
"know",
"about",
"this",
".",
"@param",
"NObject",
"$observer"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L399-L444 |
xinix-technology/norm | src/Norm/Collection.php | Collection.rememberCache | protected function rememberCache($criteria, $model)
{
$ser = serialize($criteria);
$this->cache[$ser] = $model;
} | php | protected function rememberCache($criteria, $model)
{
$ser = serialize($criteria);
$this->cache[$ser] = $model;
} | [
"protected",
"function",
"rememberCache",
"(",
"$",
"criteria",
",",
"$",
"model",
")",
"{",
"$",
"ser",
"=",
"serialize",
"(",
"$",
"criteria",
")",
";",
"$",
"this",
"->",
"cache",
"[",
"$",
"ser",
"]",
"=",
"$",
"model",
";",
"}"
] | Put item in cache bags.
@method rememberCache
@param mixed $criteria
@param \Norm\Model $model [description]
@return void | [
"Put",
"item",
"in",
"cache",
"bags",
"."
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L468-L473 |
xinix-technology/norm | src/Norm/Collection.php | Collection.fetchCache | protected function fetchCache($criteria)
{
$ser = serialize($criteria);
if (isset($this->cache[$ser])) {
return $this->cache[$ser];
}
} | php | protected function fetchCache($criteria)
{
$ser = serialize($criteria);
if (isset($this->cache[$ser])) {
return $this->cache[$ser];
}
} | [
"protected",
"function",
"fetchCache",
"(",
"$",
"criteria",
")",
"{",
"$",
"ser",
"=",
"serialize",
"(",
"$",
"criteria",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"ser",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"[",
"$",
"ser",
"]",
";",
"}",
"}"
] | Get item from cache.
@method fetchCache
@param NObject $criteria
@return void|\Norm\Model | [
"Get",
"item",
"from",
"cache",
"."
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Collection.php#L484-L491 |
silvercommerce/catalogue-frontend | src/control/ModelAsController.php | ModelAsController.controller_for_object | public static function controller_for_object($object, $action = null)
{
$controller = $object->getControllerName();
if ($action && class_exists($controller . '_' . ucfirst($action))) {
$controller = $controller . '_' . ucfirst($action);
}
return Injector::inst()->create($controller, $object);
} | php | public static function controller_for_object($object, $action = null)
{
$controller = $object->getControllerName();
if ($action && class_exists($controller . '_' . ucfirst($action))) {
$controller = $controller . '_' . ucfirst($action);
}
return Injector::inst()->create($controller, $object);
} | [
"public",
"static",
"function",
"controller_for_object",
"(",
"$",
"object",
",",
"$",
"action",
"=",
"null",
")",
"{",
"$",
"controller",
"=",
"$",
"object",
"->",
"getControllerName",
"(",
")",
";",
"if",
"(",
"$",
"action",
"&&",
"class_exists",
"(",
"$",
"controller",
".",
"'_'",
".",
"ucfirst",
"(",
"$",
"action",
")",
")",
")",
"{",
"$",
"controller",
"=",
"$",
"controller",
".",
"'_'",
".",
"ucfirst",
"(",
"$",
"action",
")",
";",
"}",
"return",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"$",
"controller",
",",
"$",
"object",
")",
";",
"}"
] | Get the appropriate {@link CatalogueProductController} or
{@link CatalogueProductController} for handling the relevent
object.
@param $object A {@link DataObject} with the getControllerName() method
@param string $action
@return CatalogueController | [
"Get",
"the",
"appropriate",
"{",
"@link",
"CatalogueProductController",
"}",
"or",
"{",
"@link",
"CatalogueProductController",
"}",
"for",
"handling",
"the",
"relevent",
"object",
"."
] | train | https://github.com/silvercommerce/catalogue-frontend/blob/671f1e32bf6bc6eb193c6608ae904cd055540cc4/src/control/ModelAsController.php#L28-L37 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionExtra | public function actionExtra()
{
$user = $this->findModel(Yii::$app->user->id);
return $user->extra->toArray();
} | php | public function actionExtra()
{
$user = $this->findModel(Yii::$app->user->id);
return $user->extra->toArray();
} | [
"public",
"function",
"actionExtra",
"(",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"findModel",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
")",
";",
"return",
"$",
"user",
"->",
"extra",
"->",
"toArray",
"(",
")",
";",
"}"
] | 读取用户扩展数据
@return array
@throws NotFoundHttpException | [
"读取用户扩展数据"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L63-L67 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionProfile | public function actionProfile()
{
if (($model = UserProfile::findOne(['user_id' => Yii::$app->user->identity->getId()])) !== null) {
if (!Yii::$app->request->isGet) {
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($model->save() === false && !$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
}
}
return $model;
} else {
throw new NotFoundHttpException ('User not found.');
}
} | php | public function actionProfile()
{
if (($model = UserProfile::findOne(['user_id' => Yii::$app->user->identity->getId()])) !== null) {
if (!Yii::$app->request->isGet) {
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($model->save() === false && !$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
}
}
return $model;
} else {
throw new NotFoundHttpException ('User not found.');
}
} | [
"public",
"function",
"actionProfile",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"model",
"=",
"UserProfile",
"::",
"findOne",
"(",
"[",
"'user_id'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"identity",
"->",
"getId",
"(",
")",
"]",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"isGet",
")",
"{",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"getBodyParams",
"(",
")",
",",
"''",
")",
";",
"if",
"(",
"$",
"model",
"->",
"save",
"(",
")",
"===",
"false",
"&&",
"!",
"$",
"model",
"->",
"hasErrors",
"(",
")",
")",
"{",
"throw",
"new",
"ServerErrorHttpException",
"(",
"'Failed to update the object for unknown reason.'",
")",
";",
"}",
"}",
"return",
"$",
"model",
";",
"}",
"else",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'User not found.'",
")",
";",
"}",
"}"
] | 获取个人扩展资料
@return UserProfile
@throws NotFoundHttpException
@throws ServerErrorHttpException
@throws \yii\base\InvalidConfigException | [
"获取个人扩展资料"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L76-L89 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionSocial | public function actionSocial()
{
$user = $this->findModel(Yii::$app->user->id);
return $user->getSocialAccounts();
} | php | public function actionSocial()
{
$user = $this->findModel(Yii::$app->user->id);
return $user->getSocialAccounts();
} | [
"public",
"function",
"actionSocial",
"(",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"findModel",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
")",
";",
"return",
"$",
"user",
"->",
"getSocialAccounts",
"(",
")",
";",
"}"
] | 获取我绑定的社交媒体账户
@return \yuncms\user\models\UserSocialAccount[]
@throws NotFoundHttpException | [
"获取我绑定的社交媒体账户"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L96-L100 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionMe | public function actionMe()
{
$user = $this->findModel(Yii::$app->user->id);
return [
'id' => $user->id,
'username' => $user->username,
'nickname' => $user->nickname,
'email' => $user->email,
'mobile' => $user->mobile,
'mobile_confirmed_at' => $user->mobile_confirmed_at,
'faceUrl' => $user->faceUrl,
'identified' => $user->identified,
'transfer_balance' => $user->transfer_balance,
'balance' => $user->balance
];
} | php | public function actionMe()
{
$user = $this->findModel(Yii::$app->user->id);
return [
'id' => $user->id,
'username' => $user->username,
'nickname' => $user->nickname,
'email' => $user->email,
'mobile' => $user->mobile,
'mobile_confirmed_at' => $user->mobile_confirmed_at,
'faceUrl' => $user->faceUrl,
'identified' => $user->identified,
'transfer_balance' => $user->transfer_balance,
'balance' => $user->balance
];
} | [
"public",
"function",
"actionMe",
"(",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"findModel",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
")",
";",
"return",
"[",
"'id'",
"=>",
"$",
"user",
"->",
"id",
",",
"'username'",
"=>",
"$",
"user",
"->",
"username",
",",
"'nickname'",
"=>",
"$",
"user",
"->",
"nickname",
",",
"'email'",
"=>",
"$",
"user",
"->",
"email",
",",
"'mobile'",
"=>",
"$",
"user",
"->",
"mobile",
",",
"'mobile_confirmed_at'",
"=>",
"$",
"user",
"->",
"mobile_confirmed_at",
",",
"'faceUrl'",
"=>",
"$",
"user",
"->",
"faceUrl",
",",
"'identified'",
"=>",
"$",
"user",
"->",
"identified",
",",
"'transfer_balance'",
"=>",
"$",
"user",
"->",
"transfer_balance",
",",
"'balance'",
"=>",
"$",
"user",
"->",
"balance",
"]",
";",
"}"
] | 获取个人基本资料
@return array
@throws NotFoundHttpException | [
"获取个人基本资料"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L107-L122 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionPassword | public function actionPassword()
{
$model = new UserSettingsForm();
$model->load(Yii::$app->request->post(), '');
if ($model->save()) {
Yii::$app->getResponse()->setStatusCode(200);
return $model;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} | php | public function actionPassword()
{
$model = new UserSettingsForm();
$model->load(Yii::$app->request->post(), '');
if ($model->save()) {
Yii::$app->getResponse()->setStatusCode(200);
return $model;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} | [
"public",
"function",
"actionPassword",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"UserSettingsForm",
"(",
")",
";",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
",",
"''",
")",
";",
"if",
"(",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"setStatusCode",
"(",
"200",
")",
";",
"return",
"$",
"model",
";",
"}",
"elseif",
"(",
"!",
"$",
"model",
"->",
"hasErrors",
"(",
")",
")",
"{",
"throw",
"new",
"ServerErrorHttpException",
"(",
"'Failed to create the object for unknown reason.'",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | 修改密码
@return UserSettingsForm
@throws ServerErrorHttpException | [
"修改密码"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L212-L223 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionRecovery | public function actionRecovery()
{
$model = new UserRecoveryForm();
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($model->resetPassword()) {
Yii::$app->getResponse()->setStatusCode(200);
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} | php | public function actionRecovery()
{
$model = new UserRecoveryForm();
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($model->resetPassword()) {
Yii::$app->getResponse()->setStatusCode(200);
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} | [
"public",
"function",
"actionRecovery",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"UserRecoveryForm",
"(",
")",
";",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"getBodyParams",
"(",
")",
",",
"''",
")",
";",
"if",
"(",
"$",
"model",
"->",
"resetPassword",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"setStatusCode",
"(",
"200",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"model",
"->",
"hasErrors",
"(",
")",
")",
"{",
"throw",
"new",
"ServerErrorHttpException",
"(",
"'Failed to create the object for unknown reason.'",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | 重置密码
@return UserRecoveryForm
@throws ServerErrorHttpException
@throws \yii\base\Exception
@throws \yii\base\InvalidConfigException | [
"重置密码"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L232-L242 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionAvatar | public function actionAvatar()
{
$model = new AvatarForm();
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if (($model->save()) !== false) {
Yii::$app->getResponse()->setStatusCode(200);
return $model;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} | php | public function actionAvatar()
{
$model = new AvatarForm();
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if (($model->save()) !== false) {
Yii::$app->getResponse()->setStatusCode(200);
return $model;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} | [
"public",
"function",
"actionAvatar",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"AvatarForm",
"(",
")",
";",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"getBodyParams",
"(",
")",
",",
"''",
")",
";",
"if",
"(",
"(",
"$",
"model",
"->",
"save",
"(",
")",
")",
"!==",
"false",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"setStatusCode",
"(",
"200",
")",
";",
"return",
"$",
"model",
";",
"}",
"elseif",
"(",
"!",
"$",
"model",
"->",
"hasErrors",
"(",
")",
")",
"{",
"throw",
"new",
"ServerErrorHttpException",
"(",
"'Failed to create the object for unknown reason.'",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | 上传头像
@return AvatarForm|bool
@throws ServerErrorHttpException
@throws \yii\base\InvalidConfigException | [
"上传头像"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L250-L261 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionBindMobile | public function actionBindMobile()
{
$model = new UserBindMobileForm();
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if (($user = $model->bind()) != false) {
Yii::$app->getResponse()->setStatusCode(200);
return $user;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} | php | public function actionBindMobile()
{
$model = new UserBindMobileForm();
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if (($user = $model->bind()) != false) {
Yii::$app->getResponse()->setStatusCode(200);
return $user;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} | [
"public",
"function",
"actionBindMobile",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"UserBindMobileForm",
"(",
")",
";",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"getBodyParams",
"(",
")",
",",
"''",
")",
";",
"if",
"(",
"(",
"$",
"user",
"=",
"$",
"model",
"->",
"bind",
"(",
")",
")",
"!=",
"false",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"setStatusCode",
"(",
"200",
")",
";",
"return",
"$",
"user",
";",
"}",
"elseif",
"(",
"!",
"$",
"model",
"->",
"hasErrors",
"(",
")",
")",
"{",
"throw",
"new",
"ServerErrorHttpException",
"(",
"'Failed to create the object for unknown reason.'",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | 绑定手机号
@return bool|User|UserBindMobileForm
@throws ServerErrorHttpException
@throws \yii\base\InvalidConfigException | [
"绑定手机号"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L269-L280 |
yuncms/framework | src/rest/controllers/PersonController.php | PersonController.actionIdentification | public function actionIdentification()
{
if (!class_exists('yuncms\identification\rest\models\Identification')) {
throw new InvalidConfigException('No identification module installed.');
} else {
if (Yii::$app->request->isPost) {
$model = \yuncms\identification\rest\models\Identification::findByUserId(Yii::$app->user->getId());
$model->scenario = \yuncms\identification\rest\models\Identification::SCENARIO_UPDATE;
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if (($model->save()) != false) {
$response = Yii::$app->getResponse();
$response->setStatusCode(201);
return $model;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} else if (Yii::$app->request->isGet) {
return \yuncms\identification\rest\models\Identification::findByUserId(Yii::$app->user->getId());
}
throw new MethodNotAllowedHttpException();
}
} | php | public function actionIdentification()
{
if (!class_exists('yuncms\identification\rest\models\Identification')) {
throw new InvalidConfigException('No identification module installed.');
} else {
if (Yii::$app->request->isPost) {
$model = \yuncms\identification\rest\models\Identification::findByUserId(Yii::$app->user->getId());
$model->scenario = \yuncms\identification\rest\models\Identification::SCENARIO_UPDATE;
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if (($model->save()) != false) {
$response = Yii::$app->getResponse();
$response->setStatusCode(201);
return $model;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
} else if (Yii::$app->request->isGet) {
return \yuncms\identification\rest\models\Identification::findByUserId(Yii::$app->user->getId());
}
throw new MethodNotAllowedHttpException();
}
} | [
"public",
"function",
"actionIdentification",
"(",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'yuncms\\identification\\rest\\models\\Identification'",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'No identification module installed.'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"isPost",
")",
"{",
"$",
"model",
"=",
"\\",
"yuncms",
"\\",
"identification",
"\\",
"rest",
"\\",
"models",
"\\",
"Identification",
"::",
"findByUserId",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"getId",
"(",
")",
")",
";",
"$",
"model",
"->",
"scenario",
"=",
"\\",
"yuncms",
"\\",
"identification",
"\\",
"rest",
"\\",
"models",
"\\",
"Identification",
"::",
"SCENARIO_UPDATE",
";",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"getBodyParams",
"(",
")",
",",
"''",
")",
";",
"if",
"(",
"(",
"$",
"model",
"->",
"save",
"(",
")",
")",
"!=",
"false",
")",
"{",
"$",
"response",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
";",
"$",
"response",
"->",
"setStatusCode",
"(",
"201",
")",
";",
"return",
"$",
"model",
";",
"}",
"elseif",
"(",
"!",
"$",
"model",
"->",
"hasErrors",
"(",
")",
")",
"{",
"throw",
"new",
"ServerErrorHttpException",
"(",
"'Failed to create the object for unknown reason.'",
")",
";",
"}",
"return",
"$",
"model",
";",
"}",
"else",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"isGet",
")",
"{",
"return",
"\\",
"yuncms",
"\\",
"identification",
"\\",
"rest",
"\\",
"models",
"\\",
"Identification",
"::",
"findByUserId",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"getId",
"(",
")",
")",
";",
"}",
"throw",
"new",
"MethodNotAllowedHttpException",
"(",
")",
";",
"}",
"}"
] | 实名认证
@return \yuncms\identification\rest\models\Identification
@throws MethodNotAllowedHttpException
@throws ServerErrorHttpException
@throws \yii\base\InvalidConfigException | [
"实名认证"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/controllers/PersonController.php#L289-L311 |
yuncms/framework | src/sms/gateways/AliyunGateway.php | AliyunGateway.init | public function init()
{
parent::init();
if (empty ($this->accessId)) {
throw new InvalidConfigException ('The "accessId" property must be set.');
}
if (empty ($this->accessKey)) {
throw new InvalidConfigException ('The "accessKey" property must be set.');
}
if (empty ($this->signName)) {
throw new InvalidConfigException ('The "signName" property must be set.');
}
} | php | public function init()
{
parent::init();
if (empty ($this->accessId)) {
throw new InvalidConfigException ('The "accessId" property must be set.');
}
if (empty ($this->accessKey)) {
throw new InvalidConfigException ('The "accessKey" property must be set.');
}
if (empty ($this->signName)) {
throw new InvalidConfigException ('The "signName" property must be set.');
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"accessId",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'The \"accessId\" property must be set.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"accessKey",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'The \"accessKey\" property must be set.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"signName",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'The \"signName\" property must be set.'",
")",
";",
"}",
"}"
] | 初始化短信
@throws InvalidConfigException | [
"初始化短信"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sms/gateways/AliyunGateway.php#L53-L65 |
yuncms/framework | src/sms/gateways/AliyunGateway.php | AliyunGateway.generateSign | protected function generateSign($params)
{
ksort($params);
$stringToSign = 'GET&%2F&' . urlencode(http_build_query($params, null, '&', PHP_QUERY_RFC3986));
return base64_encode(hash_hmac('sha1', $stringToSign, $this->accessKey . '&', true));
} | php | protected function generateSign($params)
{
ksort($params);
$stringToSign = 'GET&%2F&' . urlencode(http_build_query($params, null, '&', PHP_QUERY_RFC3986));
return base64_encode(hash_hmac('sha1', $stringToSign, $this->accessKey . '&', true));
} | [
"protected",
"function",
"generateSign",
"(",
"$",
"params",
")",
"{",
"ksort",
"(",
"$",
"params",
")",
";",
"$",
"stringToSign",
"=",
"'GET&%2F&'",
".",
"urlencode",
"(",
"http_build_query",
"(",
"$",
"params",
",",
"null",
",",
"'&'",
",",
"PHP_QUERY_RFC3986",
")",
")",
";",
"return",
"base64_encode",
"(",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"stringToSign",
",",
"$",
"this",
"->",
"accessKey",
".",
"'&'",
",",
"true",
")",
")",
";",
"}"
] | Generate Sign.
@param array $params
@return string | [
"Generate",
"Sign",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sms/gateways/AliyunGateway.php#L115-L120 |
Josantonius/WP_Menu | src/class-wp-menu.php | WP_Menu.add | public static function add( $type, $data = [], $function = 0, $styles = 0, $scripts = 0 ) {
if ( ! is_admin() || ! self::required_params_exist( $type, $data ) ) {
return false;
}
$data = self::set_params( $data, $function, $styles, $scripts );
$slug = $data['slug'];
self::$data[ $type ][ $slug ] = $data;
add_action(
'admin_menu', function() use ( $type, $slug ) {
self::set( $type, $slug );
}
);
return true;
} | php | public static function add( $type, $data = [], $function = 0, $styles = 0, $scripts = 0 ) {
if ( ! is_admin() || ! self::required_params_exist( $type, $data ) ) {
return false;
}
$data = self::set_params( $data, $function, $styles, $scripts );
$slug = $data['slug'];
self::$data[ $type ][ $slug ] = $data;
add_action(
'admin_menu', function() use ( $type, $slug ) {
self::set( $type, $slug );
}
);
return true;
} | [
"public",
"static",
"function",
"add",
"(",
"$",
"type",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"function",
"=",
"0",
",",
"$",
"styles",
"=",
"0",
",",
"$",
"scripts",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"is_admin",
"(",
")",
"||",
"!",
"self",
"::",
"required_params_exist",
"(",
"$",
"type",
",",
"$",
"data",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"data",
"=",
"self",
"::",
"set_params",
"(",
"$",
"data",
",",
"$",
"function",
",",
"$",
"styles",
",",
"$",
"scripts",
")",
";",
"$",
"slug",
"=",
"$",
"data",
"[",
"'slug'",
"]",
";",
"self",
"::",
"$",
"data",
"[",
"$",
"type",
"]",
"[",
"$",
"slug",
"]",
"=",
"$",
"data",
";",
"add_action",
"(",
"'admin_menu'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"type",
",",
"$",
"slug",
")",
"{",
"self",
"::",
"set",
"(",
"$",
"type",
",",
"$",
"slug",
")",
";",
"}",
")",
";",
"return",
"true",
";",
"}"
] | Add menu or submenu.
@param string $type → menu | submenu.
@param array $data → settings.
@param mixed $function → method to be called to output page content.
@param mixed $styles → method to be called to load page styles.
@param mixed $scripts → method to be called to load page scripts.
@see https://github.com/Josantonius/WP_Menu#addtype-data-function-styles-scripts
@return boolean | [
"Add",
"menu",
"or",
"submenu",
"."
] | train | https://github.com/Josantonius/WP_Menu/blob/90df3355007083cc156353dde94ee73d3fea0ce5/src/class-wp-menu.php#L40-L59 |
Josantonius/WP_Menu | src/class-wp-menu.php | WP_Menu.set_params | private static function set_params( $data, $function, $styles, $scripts ) {
$params = [ 'title', 'capability', 'icon_url', 'position' ];
foreach ( $params as $param ) {
if ( isset( $data[ $param ] ) ) {
continue;
}
switch ( $param ) {
case 'title':
$data[ $param ] = $data['name'];
break;
case 'capability':
$data[ $param ] = 'manage_options';
break;
case 'icon_url':
$data[ $param ] = '';
break;
case 'position':
$data[ $param ] = null;
break;
}
}
$data['styles'] = $styles;
$data['scripts'] = $scripts;
$data['function'] = self::validate_method( $function ) ? $function : '';
return $data;
} | php | private static function set_params( $data, $function, $styles, $scripts ) {
$params = [ 'title', 'capability', 'icon_url', 'position' ];
foreach ( $params as $param ) {
if ( isset( $data[ $param ] ) ) {
continue;
}
switch ( $param ) {
case 'title':
$data[ $param ] = $data['name'];
break;
case 'capability':
$data[ $param ] = 'manage_options';
break;
case 'icon_url':
$data[ $param ] = '';
break;
case 'position':
$data[ $param ] = null;
break;
}
}
$data['styles'] = $styles;
$data['scripts'] = $scripts;
$data['function'] = self::validate_method( $function ) ? $function : '';
return $data;
} | [
"private",
"static",
"function",
"set_params",
"(",
"$",
"data",
",",
"$",
"function",
",",
"$",
"styles",
",",
"$",
"scripts",
")",
"{",
"$",
"params",
"=",
"[",
"'title'",
",",
"'capability'",
",",
"'icon_url'",
",",
"'position'",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"param",
"]",
")",
")",
"{",
"continue",
";",
"}",
"switch",
"(",
"$",
"param",
")",
"{",
"case",
"'title'",
":",
"$",
"data",
"[",
"$",
"param",
"]",
"=",
"$",
"data",
"[",
"'name'",
"]",
";",
"break",
";",
"case",
"'capability'",
":",
"$",
"data",
"[",
"$",
"param",
"]",
"=",
"'manage_options'",
";",
"break",
";",
"case",
"'icon_url'",
":",
"$",
"data",
"[",
"$",
"param",
"]",
"=",
"''",
";",
"break",
";",
"case",
"'position'",
":",
"$",
"data",
"[",
"$",
"param",
"]",
"=",
"null",
";",
"break",
";",
"}",
"}",
"$",
"data",
"[",
"'styles'",
"]",
"=",
"$",
"styles",
";",
"$",
"data",
"[",
"'scripts'",
"]",
"=",
"$",
"scripts",
";",
"$",
"data",
"[",
"'function'",
"]",
"=",
"self",
"::",
"validate_method",
"(",
"$",
"function",
")",
"?",
"$",
"function",
":",
"''",
";",
"return",
"$",
"data",
";",
"}"
] | Set menu/submenu parameters.
@since 1.0.4
@param array $data → settings.
@param mixed $function → method to be called to output page content.
@param mixed $styles → method to be called to load page styles.
@param mixed $scripts → method to be called to load page scripts.
@return array parameters | [
"Set",
"menu",
"/",
"submenu",
"parameters",
"."
] | train | https://github.com/Josantonius/WP_Menu/blob/90df3355007083cc156353dde94ee73d3fea0ce5/src/class-wp-menu.php#L73-L109 |
Josantonius/WP_Menu | src/class-wp-menu.php | WP_Menu.required_params_exist | private static function required_params_exist( $type, $data ) {
$required = [ 'name', 'slug' ];
if ( 'submenu' === $type ) {
array_push( $required, 'parent' );
}
foreach ( $required as $field ) {
if ( ! isset( $data[ $field ] ) || empty( $data[ $field ] ) ) {
return false;
}
}
return true;
} | php | private static function required_params_exist( $type, $data ) {
$required = [ 'name', 'slug' ];
if ( 'submenu' === $type ) {
array_push( $required, 'parent' );
}
foreach ( $required as $field ) {
if ( ! isset( $data[ $field ] ) || empty( $data[ $field ] ) ) {
return false;
}
}
return true;
} | [
"private",
"static",
"function",
"required_params_exist",
"(",
"$",
"type",
",",
"$",
"data",
")",
"{",
"$",
"required",
"=",
"[",
"'name'",
",",
"'slug'",
"]",
";",
"if",
"(",
"'submenu'",
"===",
"$",
"type",
")",
"{",
"array_push",
"(",
"$",
"required",
",",
"'parent'",
")",
";",
"}",
"foreach",
"(",
"$",
"required",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
"||",
"empty",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validate if the required parameters exist.
@since 1.0.4
@param string $type → menu | submenu.
@param array $data → settings.
@return boolean | [
"Validate",
"if",
"the",
"required",
"parameters",
"exist",
"."
] | train | https://github.com/Josantonius/WP_Menu/blob/90df3355007083cc156353dde94ee73d3fea0ce5/src/class-wp-menu.php#L121-L136 |
Josantonius/WP_Menu | src/class-wp-menu.php | WP_Menu.set | private static function set( $type, $slug ) {
global $pagenow;
$data = self::$data[ $type ][ $slug ];
do_action( 'wp_menu_pre_add_' . $type . '_page' );
if ( 'menu' === $type ) {
$page = add_menu_page(
$data['title'],
$data['name'],
$data['capability'],
$data['slug'],
$data['function'],
$data['icon_url'],
$data['position']
);
} elseif ( 'submenu' === $type ) {
$page = add_submenu_page(
$data['parent'],
$data['title'],
$data['name'],
$data['capability'],
$data['slug'],
$data['function']
);
}
do_action( 'wp_menu_after_add_' . $type . '_page', 'load-' . $page );
if ( ! $pagenow || 'admin.php' === $pagenow ) {
self::set_action( $page, $data['styles'] );
self::set_action( $page, $data['scripts'] );
}
} | php | private static function set( $type, $slug ) {
global $pagenow;
$data = self::$data[ $type ][ $slug ];
do_action( 'wp_menu_pre_add_' . $type . '_page' );
if ( 'menu' === $type ) {
$page = add_menu_page(
$data['title'],
$data['name'],
$data['capability'],
$data['slug'],
$data['function'],
$data['icon_url'],
$data['position']
);
} elseif ( 'submenu' === $type ) {
$page = add_submenu_page(
$data['parent'],
$data['title'],
$data['name'],
$data['capability'],
$data['slug'],
$data['function']
);
}
do_action( 'wp_menu_after_add_' . $type . '_page', 'load-' . $page );
if ( ! $pagenow || 'admin.php' === $pagenow ) {
self::set_action( $page, $data['styles'] );
self::set_action( $page, $data['scripts'] );
}
} | [
"private",
"static",
"function",
"set",
"(",
"$",
"type",
",",
"$",
"slug",
")",
"{",
"global",
"$",
"pagenow",
";",
"$",
"data",
"=",
"self",
"::",
"$",
"data",
"[",
"$",
"type",
"]",
"[",
"$",
"slug",
"]",
";",
"do_action",
"(",
"'wp_menu_pre_add_'",
".",
"$",
"type",
".",
"'_page'",
")",
";",
"if",
"(",
"'menu'",
"===",
"$",
"type",
")",
"{",
"$",
"page",
"=",
"add_menu_page",
"(",
"$",
"data",
"[",
"'title'",
"]",
",",
"$",
"data",
"[",
"'name'",
"]",
",",
"$",
"data",
"[",
"'capability'",
"]",
",",
"$",
"data",
"[",
"'slug'",
"]",
",",
"$",
"data",
"[",
"'function'",
"]",
",",
"$",
"data",
"[",
"'icon_url'",
"]",
",",
"$",
"data",
"[",
"'position'",
"]",
")",
";",
"}",
"elseif",
"(",
"'submenu'",
"===",
"$",
"type",
")",
"{",
"$",
"page",
"=",
"add_submenu_page",
"(",
"$",
"data",
"[",
"'parent'",
"]",
",",
"$",
"data",
"[",
"'title'",
"]",
",",
"$",
"data",
"[",
"'name'",
"]",
",",
"$",
"data",
"[",
"'capability'",
"]",
",",
"$",
"data",
"[",
"'slug'",
"]",
",",
"$",
"data",
"[",
"'function'",
"]",
")",
";",
"}",
"do_action",
"(",
"'wp_menu_after_add_'",
".",
"$",
"type",
".",
"'_page'",
",",
"'load-'",
".",
"$",
"page",
")",
";",
"if",
"(",
"!",
"$",
"pagenow",
"||",
"'admin.php'",
"===",
"$",
"pagenow",
")",
"{",
"self",
"::",
"set_action",
"(",
"$",
"page",
",",
"$",
"data",
"[",
"'styles'",
"]",
")",
";",
"self",
"::",
"set_action",
"(",
"$",
"page",
",",
"$",
"data",
"[",
"'scripts'",
"]",
")",
";",
"}",
"}"
] | Set menu and submenu admin.
@since 1.0.1
@param string $type → menu|submenu.
@param string $slug → menu|submenu slug. | [
"Set",
"menu",
"and",
"submenu",
"admin",
"."
] | train | https://github.com/Josantonius/WP_Menu/blob/90df3355007083cc156353dde94ee73d3fea0ce5/src/class-wp-menu.php#L146-L184 |
Josantonius/WP_Menu | src/class-wp-menu.php | WP_Menu.validate_method | private static function validate_method( $method ) {
if ( $method && isset( $method[0] ) && isset( $method[1] ) ) {
if ( method_exists( $method[0], $method[1] ) ) {
return true;
}
}
return false;
} | php | private static function validate_method( $method ) {
if ( $method && isset( $method[0] ) && isset( $method[1] ) ) {
if ( method_exists( $method[0], $method[1] ) ) {
return true;
}
}
return false;
} | [
"private",
"static",
"function",
"validate_method",
"(",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"method",
"&&",
"isset",
"(",
"$",
"method",
"[",
"0",
"]",
")",
"&&",
"isset",
"(",
"$",
"method",
"[",
"1",
"]",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"method",
"[",
"0",
"]",
",",
"$",
"method",
"[",
"1",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if method exists.
@since 1.0.2
@param array $method → [class|object, method].
@return boolean | [
"Check",
"if",
"method",
"exists",
"."
] | train | https://github.com/Josantonius/WP_Menu/blob/90df3355007083cc156353dde94ee73d3fea0ce5/src/class-wp-menu.php#L195-L204 |
cohesion/cohesion-core | src/Structure/DTO.php | DTO.getVarsWithoutCircularReferences | private function getVarsWithoutCircularReferences($showNulls, &$previousDTOs = []) {
$previousDTOs[spl_object_hash($this)] = true;
$classProperties = $this->reflection->getProperties(\ReflectionProperty::IS_PROTECTED);
$vars = array();
foreach ($classProperties as $property) {
if (!isset($this->{$property->name})) {
$var = null;
// if it's another DTO
} else if ($this->{$property->name} instanceof DTO) {
// If this will cause a circular reference issue just ignore it
if (!isset($previousDTOs[spl_object_hash($this->{$property->name})])) {
// Get it's vars
$var = $this->{$property->name}->getVarsWithoutCircularReferences($showNulls, $previousDTOs);
}
// If it's an array of DTOs
} else if (is_array($this->{$property->name})
&& count($this->{$property->name}) > 0
&& $this->{$property->name}[0] instanceof DTO) {
$var = array();
// Get the vars for each
foreach ($this->{$property->name} as $i => $v) {
if (!isset($previousDTOs[spl_object_hash($v)])) {
$var[$i] = $v->getVarsWithoutCircularReferences($showNulls, $previousDTOs);
}
}
// If it's some other kind of object
} else if (is_object($this->{$property->name}) && method_exists($this->{$property->name}, '__toString')) {
$var = (string)$this->{$property->name};
// Otherwise
} else {
// Just use the value
$var = $this->{$property->name};
}
if ($showNulls || ($var !== null && (!is_array($var) || count($var) > 0))) {
$vars[$this->camelToUnderscore($property->name)] = $var;
}
}
return $vars;
} | php | private function getVarsWithoutCircularReferences($showNulls, &$previousDTOs = []) {
$previousDTOs[spl_object_hash($this)] = true;
$classProperties = $this->reflection->getProperties(\ReflectionProperty::IS_PROTECTED);
$vars = array();
foreach ($classProperties as $property) {
if (!isset($this->{$property->name})) {
$var = null;
// if it's another DTO
} else if ($this->{$property->name} instanceof DTO) {
// If this will cause a circular reference issue just ignore it
if (!isset($previousDTOs[spl_object_hash($this->{$property->name})])) {
// Get it's vars
$var = $this->{$property->name}->getVarsWithoutCircularReferences($showNulls, $previousDTOs);
}
// If it's an array of DTOs
} else if (is_array($this->{$property->name})
&& count($this->{$property->name}) > 0
&& $this->{$property->name}[0] instanceof DTO) {
$var = array();
// Get the vars for each
foreach ($this->{$property->name} as $i => $v) {
if (!isset($previousDTOs[spl_object_hash($v)])) {
$var[$i] = $v->getVarsWithoutCircularReferences($showNulls, $previousDTOs);
}
}
// If it's some other kind of object
} else if (is_object($this->{$property->name}) && method_exists($this->{$property->name}, '__toString')) {
$var = (string)$this->{$property->name};
// Otherwise
} else {
// Just use the value
$var = $this->{$property->name};
}
if ($showNulls || ($var !== null && (!is_array($var) || count($var) > 0))) {
$vars[$this->camelToUnderscore($property->name)] = $var;
}
}
return $vars;
} | [
"private",
"function",
"getVarsWithoutCircularReferences",
"(",
"$",
"showNulls",
",",
"&",
"$",
"previousDTOs",
"=",
"[",
"]",
")",
"{",
"$",
"previousDTOs",
"[",
"spl_object_hash",
"(",
"$",
"this",
")",
"]",
"=",
"true",
";",
"$",
"classProperties",
"=",
"$",
"this",
"->",
"reflection",
"->",
"getProperties",
"(",
"\\",
"ReflectionProperty",
"::",
"IS_PROTECTED",
")",
";",
"$",
"vars",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"classProperties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
")",
")",
"{",
"$",
"var",
"=",
"null",
";",
"// if it's another DTO",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
"instanceof",
"DTO",
")",
"{",
"// If this will cause a circular reference issue just ignore it",
"if",
"(",
"!",
"isset",
"(",
"$",
"previousDTOs",
"[",
"spl_object_hash",
"(",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
")",
"]",
")",
")",
"{",
"// Get it's vars",
"$",
"var",
"=",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
"->",
"getVarsWithoutCircularReferences",
"(",
"$",
"showNulls",
",",
"$",
"previousDTOs",
")",
";",
"}",
"// If it's an array of DTOs",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
"[",
"0",
"]",
"instanceof",
"DTO",
")",
"{",
"$",
"var",
"=",
"array",
"(",
")",
";",
"// Get the vars for each",
"foreach",
"(",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
"as",
"$",
"i",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"previousDTOs",
"[",
"spl_object_hash",
"(",
"$",
"v",
")",
"]",
")",
")",
"{",
"$",
"var",
"[",
"$",
"i",
"]",
"=",
"$",
"v",
"->",
"getVarsWithoutCircularReferences",
"(",
"$",
"showNulls",
",",
"$",
"previousDTOs",
")",
";",
"}",
"}",
"// If it's some other kind of object",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
")",
"&&",
"method_exists",
"(",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
",",
"'__toString'",
")",
")",
"{",
"$",
"var",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
";",
"// Otherwise",
"}",
"else",
"{",
"// Just use the value",
"$",
"var",
"=",
"$",
"this",
"->",
"{",
"$",
"property",
"->",
"name",
"}",
";",
"}",
"if",
"(",
"$",
"showNulls",
"||",
"(",
"$",
"var",
"!==",
"null",
"&&",
"(",
"!",
"is_array",
"(",
"$",
"var",
")",
"||",
"count",
"(",
"$",
"var",
")",
">",
"0",
")",
")",
")",
"{",
"$",
"vars",
"[",
"$",
"this",
"->",
"camelToUnderscore",
"(",
"$",
"property",
"->",
"name",
")",
"]",
"=",
"$",
"var",
";",
"}",
"}",
"return",
"$",
"vars",
";",
"}"
] | Export protected class parameters as an associative array.
This function will make sure that even if the object has a circular
reference it won't crash the system by calling the `getVars` function.
If there is a circular reference the later one will be left out of the
output | [
"Export",
"protected",
"class",
"parameters",
"as",
"an",
"associative",
"array",
"."
] | train | https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Structure/DTO.php#L120-L158 |
aedart/laravel-helpers | src/Traits/Redis/RedisTrait.php | RedisTrait.getRedis | public function getRedis(): ?Connection
{
if (!$this->hasRedis()) {
$this->setRedis($this->getDefaultRedis());
}
return $this->redis;
} | php | public function getRedis(): ?Connection
{
if (!$this->hasRedis()) {
$this->setRedis($this->getDefaultRedis());
}
return $this->redis;
} | [
"public",
"function",
"getRedis",
"(",
")",
":",
"?",
"Connection",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRedis",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setRedis",
"(",
"$",
"this",
"->",
"getDefaultRedis",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redis",
";",
"}"
] | Get redis
If no redis has been set, this method will
set and return a default redis, if any such
value is available
@see getDefaultRedis()
@return Connection|null redis or null if none redis has been set | [
"Get",
"redis"
] | train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Redis/RedisTrait.php#L53-L59 |
aedart/laravel-helpers | src/Traits/Redis/RedisTrait.php | RedisTrait.getDefaultRedis | public function getDefaultRedis(): ?Connection
{
// From Laravel 5.4, the redis facade now returns the
// Redis Manager, which is why we must use it to obtain
// the default Redis connection. Thus, the
// "Illuminate\Contracts\Redis\Database" interface is no
// longer used.
$factory = Redis::getFacadeRoot();
if (isset($factory)) {
return $factory->connection();
}
return $factory;
} | php | public function getDefaultRedis(): ?Connection
{
// From Laravel 5.4, the redis facade now returns the
// Redis Manager, which is why we must use it to obtain
// the default Redis connection. Thus, the
// "Illuminate\Contracts\Redis\Database" interface is no
// longer used.
$factory = Redis::getFacadeRoot();
if (isset($factory)) {
return $factory->connection();
}
return $factory;
} | [
"public",
"function",
"getDefaultRedis",
"(",
")",
":",
"?",
"Connection",
"{",
"// From Laravel 5.4, the redis facade now returns the",
"// Redis Manager, which is why we must use it to obtain",
"// the default Redis connection. Thus, the",
"// \"Illuminate\\Contracts\\Redis\\Database\" interface is no",
"// longer used.",
"$",
"factory",
"=",
"Redis",
"::",
"getFacadeRoot",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"factory",
")",
")",
"{",
"return",
"$",
"factory",
"->",
"connection",
"(",
")",
";",
"}",
"return",
"$",
"factory",
";",
"}"
] | Get a default redis value, if any is available
@return Connection|null A default redis value or Null if no default value is available | [
"Get",
"a",
"default",
"redis",
"value",
"if",
"any",
"is",
"available"
] | train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Redis/RedisTrait.php#L76-L88 |
digitalkaoz/versioneye-php | src/Api/Projects.php | Projects.mergeGa | public function mergeGa($group, $artifact, $child)
{
return $this->request(sprintf('projects/%s/%s/merge_ga/%s', $group, $artifact, $child));
} | php | public function mergeGa($group, $artifact, $child)
{
return $this->request(sprintf('projects/%s/%s/merge_ga/%s', $group, $artifact, $child));
} | [
"public",
"function",
"mergeGa",
"(",
"$",
"group",
",",
"$",
"artifact",
",",
"$",
"child",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"sprintf",
"(",
"'projects/%s/%s/merge_ga/%s'",
",",
"$",
"group",
",",
"$",
"artifact",
",",
"$",
"child",
")",
")",
";",
"}"
] | merge two projects together (only for maven projects).
@param string $group
@param string $artifact
@param string $child
@return array | [
"merge",
"two",
"projects",
"together",
"(",
"only",
"for",
"maven",
"projects",
")",
"."
] | train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/Projects.php#L123-L126 |
steeffeen/FancyManiaLinks | FML/UniqueID.php | UniqueID.check | public static function check(Identifiable $element)
{
$elementId = $element->getId();
if (!$elementId) {
$element->setId(new static());
return $element->getId();
}
$dangerousCharacters = array(' ', '|', PHP_EOL);
$danger = false;
foreach ($dangerousCharacters as $dangerousCharacter) {
if (stripos($elementId, $dangerousCharacter) !== false) {
$danger = true;
break;
}
}
if ($danger) {
trigger_error("Don't use special characters in IDs, they might cause problems! Stripping them for you...");
$elementId = str_ireplace($dangerousCharacters, '', $elementId);
$element->setId($elementId);
}
return $element->getId();
} | php | public static function check(Identifiable $element)
{
$elementId = $element->getId();
if (!$elementId) {
$element->setId(new static());
return $element->getId();
}
$dangerousCharacters = array(' ', '|', PHP_EOL);
$danger = false;
foreach ($dangerousCharacters as $dangerousCharacter) {
if (stripos($elementId, $dangerousCharacter) !== false) {
$danger = true;
break;
}
}
if ($danger) {
trigger_error("Don't use special characters in IDs, they might cause problems! Stripping them for you...");
$elementId = str_ireplace($dangerousCharacters, '', $elementId);
$element->setId($elementId);
}
return $element->getId();
} | [
"public",
"static",
"function",
"check",
"(",
"Identifiable",
"$",
"element",
")",
"{",
"$",
"elementId",
"=",
"$",
"element",
"->",
"getId",
"(",
")",
";",
"if",
"(",
"!",
"$",
"elementId",
")",
"{",
"$",
"element",
"->",
"setId",
"(",
"new",
"static",
"(",
")",
")",
";",
"return",
"$",
"element",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"dangerousCharacters",
"=",
"array",
"(",
"' '",
",",
"'|'",
",",
"PHP_EOL",
")",
";",
"$",
"danger",
"=",
"false",
";",
"foreach",
"(",
"$",
"dangerousCharacters",
"as",
"$",
"dangerousCharacter",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"elementId",
",",
"$",
"dangerousCharacter",
")",
"!==",
"false",
")",
"{",
"$",
"danger",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"danger",
")",
"{",
"trigger_error",
"(",
"\"Don't use special characters in IDs, they might cause problems! Stripping them for you...\"",
")",
";",
"$",
"elementId",
"=",
"str_ireplace",
"(",
"$",
"dangerousCharacters",
",",
"''",
",",
"$",
"elementId",
")",
";",
"$",
"element",
"->",
"setId",
"(",
"$",
"elementId",
")",
";",
"}",
"return",
"$",
"element",
"->",
"getId",
"(",
")",
";",
"}"
] | Check and return the Id of an Identifable Element
@param Identifiable $element Identifable element
@return string | [
"Check",
"and",
"return",
"the",
"Id",
"of",
"an",
"Identifable",
"Element"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/UniqueID.php#L48-L73 |
tomphp/patch-builder | src/TomPHP/PatchBuilder/Buffer/LineBuffer.php | LineBuffer.getLines | public function getLines(LineRangeInterface $range)
{
$this->assertRangeIsInsideBuffer($range);
return array_slice(
$this->contents,
$range->getStart()->getNumber(),
$range->getLength()
);
} | php | public function getLines(LineRangeInterface $range)
{
$this->assertRangeIsInsideBuffer($range);
return array_slice(
$this->contents,
$range->getStart()->getNumber(),
$range->getLength()
);
} | [
"public",
"function",
"getLines",
"(",
"LineRangeInterface",
"$",
"range",
")",
"{",
"$",
"this",
"->",
"assertRangeIsInsideBuffer",
"(",
"$",
"range",
")",
";",
"return",
"array_slice",
"(",
"$",
"this",
"->",
"contents",
",",
"$",
"range",
"->",
"getStart",
"(",
")",
"->",
"getNumber",
"(",
")",
",",
"$",
"range",
"->",
"getLength",
"(",
")",
")",
";",
"}"
] | @param LineRangeInterface $range
@return string[] | [
"@param",
"LineRangeInterface",
"$range"
] | train | https://github.com/tomphp/patch-builder/blob/4419eaad23016c7db1deffc6cce3f539096c11ce/src/TomPHP/PatchBuilder/Buffer/LineBuffer.php#L44-L53 |
yoanm/symfony-jsonrpc-http-server-doc | src/Creator/HttpServerDocCreator.php | HttpServerDocCreator.create | public function create($host = null) : HttpServerDoc
{
$serverDoc = new HttpServerDoc();
if (null !== $this->jsonRpcEndpoint) {
$serverDoc->setEndpoint($this->jsonRpcEndpoint);
}
if (null !== $host) {
$serverDoc->setHost($host);
}
$this->appendMethodsDoc($serverDoc);
$event = new ServerDocCreatedEvent($serverDoc);
$this->dispatcher->dispatch($event::EVENT_NAME, $event);
return $serverDoc;
} | php | public function create($host = null) : HttpServerDoc
{
$serverDoc = new HttpServerDoc();
if (null !== $this->jsonRpcEndpoint) {
$serverDoc->setEndpoint($this->jsonRpcEndpoint);
}
if (null !== $host) {
$serverDoc->setHost($host);
}
$this->appendMethodsDoc($serverDoc);
$event = new ServerDocCreatedEvent($serverDoc);
$this->dispatcher->dispatch($event::EVENT_NAME, $event);
return $serverDoc;
} | [
"public",
"function",
"create",
"(",
"$",
"host",
"=",
"null",
")",
":",
"HttpServerDoc",
"{",
"$",
"serverDoc",
"=",
"new",
"HttpServerDoc",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"jsonRpcEndpoint",
")",
"{",
"$",
"serverDoc",
"->",
"setEndpoint",
"(",
"$",
"this",
"->",
"jsonRpcEndpoint",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"host",
")",
"{",
"$",
"serverDoc",
"->",
"setHost",
"(",
"$",
"host",
")",
";",
"}",
"$",
"this",
"->",
"appendMethodsDoc",
"(",
"$",
"serverDoc",
")",
";",
"$",
"event",
"=",
"new",
"ServerDocCreatedEvent",
"(",
"$",
"serverDoc",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"$",
"event",
"::",
"EVENT_NAME",
",",
"$",
"event",
")",
";",
"return",
"$",
"serverDoc",
";",
"}"
] | @param string|null $host
@return HttpServerDoc | [
"@param",
"string|null",
"$host"
] | train | https://github.com/yoanm/symfony-jsonrpc-http-server-doc/blob/7a59862f74fef29d0e2ad017188977419503ad94/src/Creator/HttpServerDocCreator.php#L39-L55 |
yoanm/symfony-jsonrpc-http-server-doc | src/Creator/HttpServerDocCreator.php | HttpServerDocCreator.addJsonRpcMethod | public function addJsonRpcMethod(string $methodName, JsonRpcMethodInterface $method) : void
{
$this->methodList[$methodName] = $method;
} | php | public function addJsonRpcMethod(string $methodName, JsonRpcMethodInterface $method) : void
{
$this->methodList[$methodName] = $method;
} | [
"public",
"function",
"addJsonRpcMethod",
"(",
"string",
"$",
"methodName",
",",
"JsonRpcMethodInterface",
"$",
"method",
")",
":",
"void",
"{",
"$",
"this",
"->",
"methodList",
"[",
"$",
"methodName",
"]",
"=",
"$",
"method",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/yoanm/symfony-jsonrpc-http-server-doc/blob/7a59862f74fef29d0e2ad017188977419503ad94/src/Creator/HttpServerDocCreator.php#L60-L63 |
simple-php-mvc/simple-php-mvc | src/MVC/Server/HttpRequest.php | HttpRequest.is | public function is($characteristic)
{
switch ( strtolower($characteristic) ) {
case "ajax":
return (
isset($this->_env['HTTP_X_REQUESTED_WITH']) &&
$this->_env['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest"
);
case "delete":
return ( $this->method == "DELETE" );
case "flash":
return (
$this->_env['HTTP_USER_AGENT'] == "Shockwave Flash"
);
case "get":
return ( $this->method == "GET" );
case "head":
return ( $this->method == "HEAD" );
case "mobile":
$mobile_user_agents = array(
"Android", "AvantGo", "Blackberry", "DoCoMo", "iPod",
"iPhone", "J2ME", "NetFront", "Nokia", "MIDP", "Opera Mini",
"PalmOS", "PalmSource", "Plucker", "portalmmm",
"ReqwirelessWeb", "SonyEricsson", "Symbian", "UP\.Browser",
"Windows CE", "Xiino"
);
$pattern = "/" . implode("|", $mobile_user_agents) . "/i";
return (boolean) preg_match(
$pattern, $this->_env['HTTP_USER_AGENT']
);
case "options":
return ( $this->method == "OPTIONS" );
case "post":
return ( $this->method == "POST" );
case "put":
return ( $this->method == "PUT" );
case "ssl":
return $this->_env['HTTPS'];
default:
return false;
}
} | php | public function is($characteristic)
{
switch ( strtolower($characteristic) ) {
case "ajax":
return (
isset($this->_env['HTTP_X_REQUESTED_WITH']) &&
$this->_env['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest"
);
case "delete":
return ( $this->method == "DELETE" );
case "flash":
return (
$this->_env['HTTP_USER_AGENT'] == "Shockwave Flash"
);
case "get":
return ( $this->method == "GET" );
case "head":
return ( $this->method == "HEAD" );
case "mobile":
$mobile_user_agents = array(
"Android", "AvantGo", "Blackberry", "DoCoMo", "iPod",
"iPhone", "J2ME", "NetFront", "Nokia", "MIDP", "Opera Mini",
"PalmOS", "PalmSource", "Plucker", "portalmmm",
"ReqwirelessWeb", "SonyEricsson", "Symbian", "UP\.Browser",
"Windows CE", "Xiino"
);
$pattern = "/" . implode("|", $mobile_user_agents) . "/i";
return (boolean) preg_match(
$pattern, $this->_env['HTTP_USER_AGENT']
);
case "options":
return ( $this->method == "OPTIONS" );
case "post":
return ( $this->method == "POST" );
case "put":
return ( $this->method == "PUT" );
case "ssl":
return $this->_env['HTTPS'];
default:
return false;
}
} | [
"public",
"function",
"is",
"(",
"$",
"characteristic",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"characteristic",
")",
")",
"{",
"case",
"\"ajax\"",
":",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"_env",
"[",
"'HTTP_X_REQUESTED_WITH'",
"]",
")",
"&&",
"$",
"this",
"->",
"_env",
"[",
"'HTTP_X_REQUESTED_WITH'",
"]",
"==",
"\"XMLHttpRequest\"",
")",
";",
"case",
"\"delete\"",
":",
"return",
"(",
"$",
"this",
"->",
"method",
"==",
"\"DELETE\"",
")",
";",
"case",
"\"flash\"",
":",
"return",
"(",
"$",
"this",
"->",
"_env",
"[",
"'HTTP_USER_AGENT'",
"]",
"==",
"\"Shockwave Flash\"",
")",
";",
"case",
"\"get\"",
":",
"return",
"(",
"$",
"this",
"->",
"method",
"==",
"\"GET\"",
")",
";",
"case",
"\"head\"",
":",
"return",
"(",
"$",
"this",
"->",
"method",
"==",
"\"HEAD\"",
")",
";",
"case",
"\"mobile\"",
":",
"$",
"mobile_user_agents",
"=",
"array",
"(",
"\"Android\"",
",",
"\"AvantGo\"",
",",
"\"Blackberry\"",
",",
"\"DoCoMo\"",
",",
"\"iPod\"",
",",
"\"iPhone\"",
",",
"\"J2ME\"",
",",
"\"NetFront\"",
",",
"\"Nokia\"",
",",
"\"MIDP\"",
",",
"\"Opera Mini\"",
",",
"\"PalmOS\"",
",",
"\"PalmSource\"",
",",
"\"Plucker\"",
",",
"\"portalmmm\"",
",",
"\"ReqwirelessWeb\"",
",",
"\"SonyEricsson\"",
",",
"\"Symbian\"",
",",
"\"UP\\.Browser\"",
",",
"\"Windows CE\"",
",",
"\"Xiino\"",
")",
";",
"$",
"pattern",
"=",
"\"/\"",
".",
"implode",
"(",
"\"|\"",
",",
"$",
"mobile_user_agents",
")",
".",
"\"/i\"",
";",
"return",
"(",
"boolean",
")",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"_env",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
";",
"case",
"\"options\"",
":",
"return",
"(",
"$",
"this",
"->",
"method",
"==",
"\"OPTIONS\"",
")",
";",
"case",
"\"post\"",
":",
"return",
"(",
"$",
"this",
"->",
"method",
"==",
"\"POST\"",
")",
";",
"case",
"\"put\"",
":",
"return",
"(",
"$",
"this",
"->",
"method",
"==",
"\"PUT\"",
")",
";",
"case",
"\"ssl\"",
":",
"return",
"$",
"this",
"->",
"_env",
"[",
"'HTTPS'",
"]",
";",
"default",
":",
"return",
"false",
";",
"}",
"}"
] | Checks for request characteristics.
The full list of request characteristics is as follows:
* "ajax" - XHR
* "delete" - DELETE REQUEST_METHOD
* "flash" - "Shockwave Flash" HTTP_USER_AGENT
* "get" - GET REQUEST_METHOD
* "head" - HEAD REQUEST_METHOD
* "mobile" - any one of the following HTTP_USER_AGENTS:
1. "Android"
1. "AvantGo"
1. "Blackberry"
1. "DoCoMo"
1. "iPod"
1. "iPhone"
1. "J2ME"
1. "NetFront"
1. "Nokia"
1. "MIDP"
1. "Opera Mini"
1. "PalmOS"
1. "PalmSource"
1. "Plucker"
1. "portalmmm"
1. "ReqwirelessWeb"
1. "SonyEricsson"
1. "Symbian"
1. "UP.Browser"
1. "Windows CE"
1. "Xiino"
* "options" - OPTIONS REQUEST_METHOD
* "post" - POST REQUEST_METHOD
* "put" - PUT REQUEST_METHOD
* "ssl" - HTTPS
@access public
@param string $characteristic The characteristic.
@return bool | [
"Checks",
"for",
"request",
"characteristics",
"."
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Server/HttpRequest.php#L277-L318 |
simple-php-mvc/simple-php-mvc | src/MVC/Server/HttpRequest.php | HttpRequest.parseUrl | protected function parseUrl($url = "")
{
$parsed = ($url) ? parse_url($url) : parse_url($this->_env['REQUEST_URI']);
if (preg_match('/[a-zA-Z0-9_]+\.php/i', $parsed['path'], $matches)) {
$parsed['path'] = preg_replace("/$matches[0]/", '/', $parsed['path']);
}
return $parsed;
} | php | protected function parseUrl($url = "")
{
$parsed = ($url) ? parse_url($url) : parse_url($this->_env['REQUEST_URI']);
if (preg_match('/[a-zA-Z0-9_]+\.php/i', $parsed['path'], $matches)) {
$parsed['path'] = preg_replace("/$matches[0]/", '/', $parsed['path']);
}
return $parsed;
} | [
"protected",
"function",
"parseUrl",
"(",
"$",
"url",
"=",
"\"\"",
")",
"{",
"$",
"parsed",
"=",
"(",
"$",
"url",
")",
"?",
"parse_url",
"(",
"$",
"url",
")",
":",
"parse_url",
"(",
"$",
"this",
"->",
"_env",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/[a-zA-Z0-9_]+\\.php/i'",
",",
"$",
"parsed",
"[",
"'path'",
"]",
",",
"$",
"matches",
")",
")",
"{",
"$",
"parsed",
"[",
"'path'",
"]",
"=",
"preg_replace",
"(",
"\"/$matches[0]/\"",
",",
"'/'",
",",
"$",
"parsed",
"[",
"'path'",
"]",
")",
";",
"}",
"return",
"$",
"parsed",
";",
"}"
] | Get parsed url
@param string $url Url to parse
@return array Parsed Url | [
"Get",
"parsed",
"url"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Server/HttpRequest.php#L396-L405 |
steeffeen/FancyManiaLinks | FML/Script/Features/ControlScript.php | ControlScript.setControl | public function setControl(Control $control)
{
$control->checkId();
$control->addScriptFeature($this);
$this->control = $control;
$this->updateScriptEvents();
return $this;
} | php | public function setControl(Control $control)
{
$control->checkId();
$control->addScriptFeature($this);
$this->control = $control;
$this->updateScriptEvents();
return $this;
} | [
"public",
"function",
"setControl",
"(",
"Control",
"$",
"control",
")",
"{",
"$",
"control",
"->",
"checkId",
"(",
")",
";",
"$",
"control",
"->",
"addScriptFeature",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"control",
"=",
"$",
"control",
";",
"$",
"this",
"->",
"updateScriptEvents",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the Control
@api
@param Control $control Control
@return static | [
"Set",
"the",
"Control"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ControlScript.php#L75-L82 |
steeffeen/FancyManiaLinks | FML/Script/Features/ControlScript.php | ControlScript.updateScriptEvents | protected function updateScriptEvents()
{
if (!$this->control || !ScriptLabel::isEventLabel($this->labelName)) {
return $this;
}
if ($this->control instanceof Scriptable) {
$this->control->setScriptEvents(true);
}
return $this;
} | php | protected function updateScriptEvents()
{
if (!$this->control || !ScriptLabel::isEventLabel($this->labelName)) {
return $this;
}
if ($this->control instanceof Scriptable) {
$this->control->setScriptEvents(true);
}
return $this;
} | [
"protected",
"function",
"updateScriptEvents",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"control",
"||",
"!",
"ScriptLabel",
"::",
"isEventLabel",
"(",
"$",
"this",
"->",
"labelName",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"control",
"instanceof",
"Scriptable",
")",
"{",
"$",
"this",
"->",
"control",
"->",
"setScriptEvents",
"(",
"true",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Enable Script Events on the Control if needed
@return static | [
"Enable",
"Script",
"Events",
"on",
"the",
"Control",
"if",
"needed"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ControlScript.php#L152-L161 |
steeffeen/FancyManiaLinks | FML/Script/Features/ControlScript.php | ControlScript.buildScriptText | protected function buildScriptText()
{
$controlId = Builder::escapeText($this->control->getId());
$scriptText = '';
$closeBlock = false;
if (ScriptLabel::isEventLabel($this->labelName)) {
$scriptText .= "
if (Event.ControlId == {$controlId}) {
declare Control <=> Event.Control;";
$closeBlock = true;
} else {
$scriptText .= "
declare Control <=> Page.GetFirstChild({$controlId});";
}
$class = $this->control->getManiaScriptClass();
$name = preg_replace('/^CMl/', '', $class, 1);
$scriptText .= "
declare {$name} <=> (Control as {$class});
";
$scriptText .= $this->scriptText . "
";
if ($closeBlock) {
$scriptText .= "}";
}
return $scriptText;
} | php | protected function buildScriptText()
{
$controlId = Builder::escapeText($this->control->getId());
$scriptText = '';
$closeBlock = false;
if (ScriptLabel::isEventLabel($this->labelName)) {
$scriptText .= "
if (Event.ControlId == {$controlId}) {
declare Control <=> Event.Control;";
$closeBlock = true;
} else {
$scriptText .= "
declare Control <=> Page.GetFirstChild({$controlId});";
}
$class = $this->control->getManiaScriptClass();
$name = preg_replace('/^CMl/', '', $class, 1);
$scriptText .= "
declare {$name} <=> (Control as {$class});
";
$scriptText .= $this->scriptText . "
";
if ($closeBlock) {
$scriptText .= "}";
}
return $scriptText;
} | [
"protected",
"function",
"buildScriptText",
"(",
")",
"{",
"$",
"controlId",
"=",
"Builder",
"::",
"escapeText",
"(",
"$",
"this",
"->",
"control",
"->",
"getId",
"(",
")",
")",
";",
"$",
"scriptText",
"=",
"''",
";",
"$",
"closeBlock",
"=",
"false",
";",
"if",
"(",
"ScriptLabel",
"::",
"isEventLabel",
"(",
"$",
"this",
"->",
"labelName",
")",
")",
"{",
"$",
"scriptText",
".=",
"\"\nif (Event.ControlId == {$controlId}) {\ndeclare Control <=> Event.Control;\"",
";",
"$",
"closeBlock",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"scriptText",
".=",
"\"\ndeclare Control <=> Page.GetFirstChild({$controlId});\"",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"control",
"->",
"getManiaScriptClass",
"(",
")",
";",
"$",
"name",
"=",
"preg_replace",
"(",
"'/^CMl/'",
",",
"''",
",",
"$",
"class",
",",
"1",
")",
";",
"$",
"scriptText",
".=",
"\"\ndeclare {$name} <=> (Control as {$class});\n\"",
";",
"$",
"scriptText",
".=",
"$",
"this",
"->",
"scriptText",
".",
"\"\n\"",
";",
"if",
"(",
"$",
"closeBlock",
")",
"{",
"$",
"scriptText",
".=",
"\"}\"",
";",
"}",
"return",
"$",
"scriptText",
";",
"}"
] | Build the script text for the Control
@return string | [
"Build",
"the",
"script",
"text",
"for",
"the",
"Control"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ControlScript.php#L178-L203 |
yuncms/framework | src/services/Path.php | Path.getVendorPath | public function getVendorPath(): string
{
if ($this->_vendorPath !== null) {
return $this->_vendorPath;
}
$vendorPath = Yii::getAlias('@vendor');
if ($vendorPath === false) {
throw new Exception('There was a problem getting the vendor path.');
}
return $this->_vendorPath = FileHelper::normalizePath($vendorPath);
} | php | public function getVendorPath(): string
{
if ($this->_vendorPath !== null) {
return $this->_vendorPath;
}
$vendorPath = Yii::getAlias('@vendor');
if ($vendorPath === false) {
throw new Exception('There was a problem getting the vendor path.');
}
return $this->_vendorPath = FileHelper::normalizePath($vendorPath);
} | [
"public",
"function",
"getVendorPath",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"_vendorPath",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_vendorPath",
";",
"}",
"$",
"vendorPath",
"=",
"Yii",
"::",
"getAlias",
"(",
"'@vendor'",
")",
";",
"if",
"(",
"$",
"vendorPath",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'There was a problem getting the vendor path.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_vendorPath",
"=",
"FileHelper",
"::",
"normalizePath",
"(",
"$",
"vendorPath",
")",
";",
"}"
] | Returns the path to the `vendor/` directory.
@return string
@throws Exception | [
"Returns",
"the",
"path",
"to",
"the",
"vendor",
"/",
"directory",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/services/Path.php#L39-L52 |
yuncms/framework | src/services/Path.php | Path.getRuntimePath | public function getRuntimePath(): string
{
if ($this->_runtimePath !== null) {
return $this->_runtimePath;
}
$runtimePath = Yii::getAlias('@runtime');
if ($runtimePath === false) {
throw new Exception('There was a problem getting the vendor path.');
}
return $this->_runtimePath = FileHelper::normalizePath($runtimePath);
} | php | public function getRuntimePath(): string
{
if ($this->_runtimePath !== null) {
return $this->_runtimePath;
}
$runtimePath = Yii::getAlias('@runtime');
if ($runtimePath === false) {
throw new Exception('There was a problem getting the vendor path.');
}
return $this->_runtimePath = FileHelper::normalizePath($runtimePath);
} | [
"public",
"function",
"getRuntimePath",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"_runtimePath",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_runtimePath",
";",
"}",
"$",
"runtimePath",
"=",
"Yii",
"::",
"getAlias",
"(",
"'@runtime'",
")",
";",
"if",
"(",
"$",
"runtimePath",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'There was a problem getting the vendor path.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_runtimePath",
"=",
"FileHelper",
"::",
"normalizePath",
"(",
"$",
"runtimePath",
")",
";",
"}"
] | Returns the path to the `@runtime/` directory.
@return string
@throws Exception | [
"Returns",
"the",
"path",
"to",
"the",
"@runtime",
"/",
"directory",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/services/Path.php#L60-L71 |
yuncms/framework | src/services/Path.php | Path.getTempPath | public function getTempPath(): string
{
$path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'temp';
FileHelper::createDirectory($path);
return $path;
} | php | public function getTempPath(): string
{
$path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'temp';
FileHelper::createDirectory($path);
return $path;
} | [
"public",
"function",
"getTempPath",
"(",
")",
":",
"string",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getRuntimePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'temp'",
";",
"FileHelper",
"::",
"createDirectory",
"(",
"$",
"path",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Returns the path to the `@runtime/temp/` directory.
@return string
@throws Exception | [
"Returns",
"the",
"path",
"to",
"the",
"@runtime",
"/",
"temp",
"/",
"directory",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/services/Path.php#L79-L84 |
yuncms/framework | src/services/Path.php | Path.getLogPath | public function getLogPath(): string
{
$path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'logs';
FileHelper::createDirectory($path);
return $path;
} | php | public function getLogPath(): string
{
$path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'logs';
FileHelper::createDirectory($path);
return $path;
} | [
"public",
"function",
"getLogPath",
"(",
")",
":",
"string",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getRuntimePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'logs'",
";",
"FileHelper",
"::",
"createDirectory",
"(",
"$",
"path",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Returns the path to the `@runtime/logs/` directory.
@return string
@throws Exception | [
"Returns",
"the",
"path",
"to",
"the",
"@runtime",
"/",
"logs",
"/",
"directory",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/services/Path.php#L92-L97 |
yuncms/framework | src/services/Path.php | Path.getSessionPath | public function getSessionPath(): string
{
$path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'sessions';
FileHelper::createDirectory($path);
return $path;
} | php | public function getSessionPath(): string
{
$path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'sessions';
FileHelper::createDirectory($path);
return $path;
} | [
"public",
"function",
"getSessionPath",
"(",
")",
":",
"string",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getRuntimePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'sessions'",
";",
"FileHelper",
"::",
"createDirectory",
"(",
"$",
"path",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Returns the path to the `@runtime/sessions/` directory.
@return string
@throws Exception | [
"Returns",
"the",
"path",
"to",
"the",
"@runtime",
"/",
"sessions",
"/",
"directory",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/services/Path.php#L105-L110 |
yuncms/framework | src/services/Path.php | Path.getCachePath | public function getCachePath(): string
{
$path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'cache';
FileHelper::createDirectory($path);
return $path;
} | php | public function getCachePath(): string
{
$path = $this->getRuntimePath() . DIRECTORY_SEPARATOR . 'cache';
FileHelper::createDirectory($path);
return $path;
} | [
"public",
"function",
"getCachePath",
"(",
")",
":",
"string",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getRuntimePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'cache'",
";",
"FileHelper",
"::",
"createDirectory",
"(",
"$",
"path",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Returns the path to the file cache directory.
This will be located at `@runtime/cache/` by default, but that can be overridden with the 'cachePath'.
@return string
@throws Exception | [
"Returns",
"the",
"path",
"to",
"the",
"file",
"cache",
"directory",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/services/Path.php#L120-L125 |
aedart/laravel-helpers | src/Traits/Translation/LangTrait.php | LangTrait.getLang | public function getLang(): ?Translator
{
if (!$this->hasLang()) {
$this->setLang($this->getDefaultLang());
}
return $this->lang;
} | php | public function getLang(): ?Translator
{
if (!$this->hasLang()) {
$this->setLang($this->getDefaultLang());
}
return $this->lang;
} | [
"public",
"function",
"getLang",
"(",
")",
":",
"?",
"Translator",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLang",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setLang",
"(",
"$",
"this",
"->",
"getDefaultLang",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"lang",
";",
"}"
] | Get lang
If no lang has been set, this method will
set and return a default lang, if any such
value is available
@see getDefaultLang()
@return Translator|null lang or null if none lang has been set | [
"Get",
"lang"
] | train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Translation/LangTrait.php#L53-L59 |
webforge-labs/psc-cms | lib/Psc/Code/Generate/GFunction.php | GFunction.php | public function php($baseIndent = 0) {
$php = NULL;
$cr = "\n";
$php .= $this->phpSignature($baseIndent);
$php .= $this->phpBody($baseIndent);
return $php;
} | php | public function php($baseIndent = 0) {
$php = NULL;
$cr = "\n";
$php .= $this->phpSignature($baseIndent);
$php .= $this->phpBody($baseIndent);
return $php;
} | [
"public",
"function",
"php",
"(",
"$",
"baseIndent",
"=",
"0",
")",
"{",
"$",
"php",
"=",
"NULL",
";",
"$",
"cr",
"=",
"\"\\n\"",
";",
"$",
"php",
".=",
"$",
"this",
"->",
"phpSignature",
"(",
"$",
"baseIndent",
")",
";",
"$",
"php",
".=",
"$",
"this",
"->",
"phpBody",
"(",
"$",
"baseIndent",
")",
";",
"return",
"$",
"php",
";",
"}"
] | Gibt den PHPCode für die Funktion zurück
nach der } ist kein LF | [
"Gibt",
"den",
"PHPCode",
"für",
"die",
"Funktion",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Code/Generate/GFunction.php#L87-L95 |
webforge-labs/psc-cms | lib/Psc/Code/Generate/GFunction.php | GFunction.setBodyCode | public function setBodyCode(Array $lines) {
$this->sourceCode = implode("\n",$lines); // indent egal, wird eh nicht geparsed, da wir ja schon bodyCode fertig haben
$this->body = array(); // cache reset
$this->bodyCode = $lines;
return $this;
} | php | public function setBodyCode(Array $lines) {
$this->sourceCode = implode("\n",$lines); // indent egal, wird eh nicht geparsed, da wir ja schon bodyCode fertig haben
$this->body = array(); // cache reset
$this->bodyCode = $lines;
return $this;
} | [
"public",
"function",
"setBodyCode",
"(",
"Array",
"$",
"lines",
")",
"{",
"$",
"this",
"->",
"sourceCode",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"// indent egal, wird eh nicht geparsed, da wir ja schon bodyCode fertig haben",
"$",
"this",
"->",
"body",
"=",
"array",
"(",
")",
";",
"// cache reset",
"$",
"this",
"->",
"bodyCode",
"=",
"$",
"lines",
";",
"return",
"$",
"this",
";",
"}"
] | Setzt den Body Code als Array (jede Zeile ein Eintrag im Array)
anders als setBody ist dies hier schneller, da bei setBody immer der Body-Code erneut geparsed werden muss (wegen indentation)
es ist aber zu gewährleisten, dass wirklich jede Zeile ein Eintag im Array ist | [
"Setzt",
"den",
"Body",
"Code",
"als",
"Array",
"(",
"jede",
"Zeile",
"ein",
"Eintrag",
"im",
"Array",
")"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Code/Generate/GFunction.php#L244-L249 |
webforge-labs/psc-cms | lib/Psc/Code/Generate/GFunction.php | GFunction.appendBodyLines | public function appendBodyLines(Array $codeLines) {
$this->bodyCode = array_merge($this->getBodyCode(), $codeLines);
return $this;
} | php | public function appendBodyLines(Array $codeLines) {
$this->bodyCode = array_merge($this->getBodyCode(), $codeLines);
return $this;
} | [
"public",
"function",
"appendBodyLines",
"(",
"Array",
"$",
"codeLines",
")",
"{",
"$",
"this",
"->",
"bodyCode",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getBodyCode",
"(",
")",
",",
"$",
"codeLines",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Fügt dem Code der Funktion neue Zeilen am Ende hinzu
@param array $codeLines | [
"Fügt",
"dem",
"Code",
"der",
"Funktion",
"neue",
"Zeilen",
"am",
"Ende",
"hinzu"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Code/Generate/GFunction.php#L306-L309 |
PortaText/php-sdk | src/PortaText/Command/Api/NumberVerify.php | NumberVerify.getEndpoint | protected function getEndpoint($method)
{
$number = $this->getArgument("number");
if (is_null($number)) {
throw new \InvalidArgumentException("Number cant be null");
}
$this->delArgument("number");
$endpoint = "number_verify/$number";
$code = $this->getArgument("code");
$this->delArgument("code");
if (!is_null($code)) {
$endpoint .= "?code=$code";
}
return $endpoint;
} | php | protected function getEndpoint($method)
{
$number = $this->getArgument("number");
if (is_null($number)) {
throw new \InvalidArgumentException("Number cant be null");
}
$this->delArgument("number");
$endpoint = "number_verify/$number";
$code = $this->getArgument("code");
$this->delArgument("code");
if (!is_null($code)) {
$endpoint .= "?code=$code";
}
return $endpoint;
} | [
"protected",
"function",
"getEndpoint",
"(",
"$",
"method",
")",
"{",
"$",
"number",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"number\"",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"number",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Number cant be null\"",
")",
";",
"}",
"$",
"this",
"->",
"delArgument",
"(",
"\"number\"",
")",
";",
"$",
"endpoint",
"=",
"\"number_verify/$number\"",
";",
"$",
"code",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"code\"",
")",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"code\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"code",
")",
")",
"{",
"$",
"endpoint",
".=",
"\"?code=$code\"",
";",
"}",
"return",
"$",
"endpoint",
";",
"}"
] | Returns a string with the endpoint for the given command.
@param string $method Method for this command.
@return string | [
"Returns",
"a",
"string",
"with",
"the",
"endpoint",
"for",
"the",
"given",
"command",
"."
] | train | https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/NumberVerify.php#L76-L91 |
digitalkaoz/versioneye-php | src/Client.php | Client.api | public function api($name)
{
$this->initializeClient($this->url, $this->client);
$class = 'Rs\\VersionEye\\Api\\' . ucfirst($name);
if (class_exists($class)) {
return new $class($this->client);
} else {
throw new \InvalidArgumentException('unknown api "' . $name . '" requested');
}
} | php | public function api($name)
{
$this->initializeClient($this->url, $this->client);
$class = 'Rs\\VersionEye\\Api\\' . ucfirst($name);
if (class_exists($class)) {
return new $class($this->client);
} else {
throw new \InvalidArgumentException('unknown api "' . $name . '" requested');
}
} | [
"public",
"function",
"api",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"initializeClient",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"client",
")",
";",
"$",
"class",
"=",
"'Rs\\\\VersionEye\\\\Api\\\\'",
".",
"ucfirst",
"(",
"$",
"name",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"client",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'unknown api \"'",
".",
"$",
"name",
".",
"'\" requested'",
")",
";",
"}",
"}"
] | returns an api.
@param string $name
@throws \InvalidArgumentException
@return Api | [
"returns",
"an",
"api",
"."
] | train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Client.php#L46-L57 |
digitalkaoz/versioneye-php | src/Client.php | Client.initializeClient | private function initializeClient($url, HttpClient $client = null)
{
if ($client) {
return $this->client = $client;
}
return $this->client = $this->createDefaultHttpClient($url);
} | php | private function initializeClient($url, HttpClient $client = null)
{
if ($client) {
return $this->client = $client;
}
return $this->client = $this->createDefaultHttpClient($url);
} | [
"private",
"function",
"initializeClient",
"(",
"$",
"url",
",",
"HttpClient",
"$",
"client",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"client",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"=",
"$",
"client",
";",
"}",
"return",
"$",
"this",
"->",
"client",
"=",
"$",
"this",
"->",
"createDefaultHttpClient",
"(",
"$",
"url",
")",
";",
"}"
] | initializes the http client.
@param string $url
@param HttpClient $client
@return HttpClient | [
"initializes",
"the",
"http",
"client",
"."
] | train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Client.php#L77-L84 |
periaptio/empress-generator | src/Generators/ModelGenerator.php | ModelGenerator.getTemplateData | public function getTemplateData($schema, $data = [])
{
$importTraits = $traits = [];
if (isset($schema['deleted_at']) && $schema['deleted_at']['type'] === 'date') {
$importTraits[] = $variables['SOFT_DELETE_IMPORT'];
$traits[] = $variables['SOFT_DELETE_TRAIT'];
}
if ($this->command->type === 'model' && $this->command->option('auth')) {
$importTraits = array_merge($importTraits, $variables['AUTH_IMPORT']);
$traits = array_merge($traits, $variables['AUTH_TRAIT']);
} else {
$data['AUTH_IMPLEMENTS'] = '';
}
$data['IMPORT_TRAIT'] = !empty($importTraits) ? implode(PHP_EOL, $importTraits)."\n" : '';
$data['USE_TRAIT'] = !empty($traits) ? "use ".implode(", ", $traits).";\n" : '';
// generate fillable
$fillableStr = [];
foreach ($this->fillableColumns as $column) {
$fillableStr[] = "'".$column['field']."'";
}
$data['FIELDS'] = implode(",\n\t\t", $fillableStr);
$validations = $this->getValidationRules($data['TABLE_NAME']);
$data['RULES'] = implode(",\n\t\t", $validations);
$data['CAST'] = implode(",\n\t\t", $this->getCasts());
$functions = $this->relationshipGenerator->getFunctionsFromTable($data['TABLE_NAME']);
$relationships = implode("\n", $functions);
$data['RELATIONSHIPS'] = $relationships;
return $data;
} | php | public function getTemplateData($schema, $data = [])
{
$importTraits = $traits = [];
if (isset($schema['deleted_at']) && $schema['deleted_at']['type'] === 'date') {
$importTraits[] = $variables['SOFT_DELETE_IMPORT'];
$traits[] = $variables['SOFT_DELETE_TRAIT'];
}
if ($this->command->type === 'model' && $this->command->option('auth')) {
$importTraits = array_merge($importTraits, $variables['AUTH_IMPORT']);
$traits = array_merge($traits, $variables['AUTH_TRAIT']);
} else {
$data['AUTH_IMPLEMENTS'] = '';
}
$data['IMPORT_TRAIT'] = !empty($importTraits) ? implode(PHP_EOL, $importTraits)."\n" : '';
$data['USE_TRAIT'] = !empty($traits) ? "use ".implode(", ", $traits).";\n" : '';
// generate fillable
$fillableStr = [];
foreach ($this->fillableColumns as $column) {
$fillableStr[] = "'".$column['field']."'";
}
$data['FIELDS'] = implode(",\n\t\t", $fillableStr);
$validations = $this->getValidationRules($data['TABLE_NAME']);
$data['RULES'] = implode(",\n\t\t", $validations);
$data['CAST'] = implode(",\n\t\t", $this->getCasts());
$functions = $this->relationshipGenerator->getFunctionsFromTable($data['TABLE_NAME']);
$relationships = implode("\n", $functions);
$data['RELATIONSHIPS'] = $relationships;
return $data;
} | [
"public",
"function",
"getTemplateData",
"(",
"$",
"schema",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"importTraits",
"=",
"$",
"traits",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"schema",
"[",
"'deleted_at'",
"]",
")",
"&&",
"$",
"schema",
"[",
"'deleted_at'",
"]",
"[",
"'type'",
"]",
"===",
"'date'",
")",
"{",
"$",
"importTraits",
"[",
"]",
"=",
"$",
"variables",
"[",
"'SOFT_DELETE_IMPORT'",
"]",
";",
"$",
"traits",
"[",
"]",
"=",
"$",
"variables",
"[",
"'SOFT_DELETE_TRAIT'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"command",
"->",
"type",
"===",
"'model'",
"&&",
"$",
"this",
"->",
"command",
"->",
"option",
"(",
"'auth'",
")",
")",
"{",
"$",
"importTraits",
"=",
"array_merge",
"(",
"$",
"importTraits",
",",
"$",
"variables",
"[",
"'AUTH_IMPORT'",
"]",
")",
";",
"$",
"traits",
"=",
"array_merge",
"(",
"$",
"traits",
",",
"$",
"variables",
"[",
"'AUTH_TRAIT'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'AUTH_IMPLEMENTS'",
"]",
"=",
"''",
";",
"}",
"$",
"data",
"[",
"'IMPORT_TRAIT'",
"]",
"=",
"!",
"empty",
"(",
"$",
"importTraits",
")",
"?",
"implode",
"(",
"PHP_EOL",
",",
"$",
"importTraits",
")",
".",
"\"\\n\"",
":",
"''",
";",
"$",
"data",
"[",
"'USE_TRAIT'",
"]",
"=",
"!",
"empty",
"(",
"$",
"traits",
")",
"?",
"\"use \"",
".",
"implode",
"(",
"\", \"",
",",
"$",
"traits",
")",
".",
"\";\\n\"",
":",
"''",
";",
"// generate fillable",
"$",
"fillableStr",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fillableColumns",
"as",
"$",
"column",
")",
"{",
"$",
"fillableStr",
"[",
"]",
"=",
"\"'\"",
".",
"$",
"column",
"[",
"'field'",
"]",
".",
"\"'\"",
";",
"}",
"$",
"data",
"[",
"'FIELDS'",
"]",
"=",
"implode",
"(",
"\",\\n\\t\\t\"",
",",
"$",
"fillableStr",
")",
";",
"$",
"validations",
"=",
"$",
"this",
"->",
"getValidationRules",
"(",
"$",
"data",
"[",
"'TABLE_NAME'",
"]",
")",
";",
"$",
"data",
"[",
"'RULES'",
"]",
"=",
"implode",
"(",
"\",\\n\\t\\t\"",
",",
"$",
"validations",
")",
";",
"$",
"data",
"[",
"'CAST'",
"]",
"=",
"implode",
"(",
"\",\\n\\t\\t\"",
",",
"$",
"this",
"->",
"getCasts",
"(",
")",
")",
";",
"$",
"functions",
"=",
"$",
"this",
"->",
"relationshipGenerator",
"->",
"getFunctionsFromTable",
"(",
"$",
"data",
"[",
"'TABLE_NAME'",
"]",
")",
";",
"$",
"relationships",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"functions",
")",
";",
"$",
"data",
"[",
"'RELATIONSHIPS'",
"]",
"=",
"$",
"relationships",
";",
"return",
"$",
"data",
";",
"}"
] | Fetch the template data
@return array | [
"Fetch",
"the",
"template",
"data"
] | train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Generators/ModelGenerator.php#L91-L126 |
yuncms/framework | src/widgets/ActiveField.php | ActiveField.fileInput | public function fileInput($options = [])
{
$options = ArrayHelper::merge([
'class' => 'filestyle',
'data' => [
'buttonText' => Yii::t('yuncms', 'Choose file'),
]
], $options);
BootstrapFileStyleAsset::register(Yii::$app->view);
return parent::fileInput($options);
} | php | public function fileInput($options = [])
{
$options = ArrayHelper::merge([
'class' => 'filestyle',
'data' => [
'buttonText' => Yii::t('yuncms', 'Choose file'),
]
], $options);
BootstrapFileStyleAsset::register(Yii::$app->view);
return parent::fileInput($options);
} | [
"public",
"function",
"fileInput",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"ArrayHelper",
"::",
"merge",
"(",
"[",
"'class'",
"=>",
"'filestyle'",
",",
"'data'",
"=>",
"[",
"'buttonText'",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Choose file'",
")",
",",
"]",
"]",
",",
"$",
"options",
")",
";",
"BootstrapFileStyleAsset",
"::",
"register",
"(",
"Yii",
"::",
"$",
"app",
"->",
"view",
")",
";",
"return",
"parent",
"::",
"fileInput",
"(",
"$",
"options",
")",
";",
"}"
] | 显示文件上传窗口
@param array $options
@return \yii\bootstrap\ActiveField | [
"显示文件上传窗口"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/widgets/ActiveField.php#L27-L37 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.