repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
swoft-cloud/swoft-framework
src/Event/EventManager.php
EventManager.hasListenerQueue
public function hasListenerQueue($event): bool { if ($event instanceof EventInterface) { $event = $event->getName(); } return isset($this->listeners[$event]); }
php
public function hasListenerQueue($event): bool { if ($event instanceof EventInterface) { $event = $event->getName(); } return isset($this->listeners[$event]); }
[ "public", "function", "hasListenerQueue", "(", "$", "event", ")", ":", "bool", "{", "if", "(", "$", "event", "instanceof", "EventInterface", ")", "{", "$", "event", "=", "$", "event", "->", "getName", "(", ")", ";", "}", "return", "isset", "(", "$", ...
是否存在 对事件的 监听队列 @param EventInterface|string $event @return boolean
[ "是否存在", "对事件的", "监听队列" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/EventManager.php#L350-L357
swoft-cloud/swoft-framework
src/Event/EventManager.php
EventManager.hasListener
public function hasListener($listener, $event = null): bool { if ($event) { if ($event instanceof EventInterface) { $event = $event->getName(); } if (isset($this->listeners[$event])) { return $this->listeners[$event]->has($listener); } } else { foreach ($this->listeners as $queue) { if ($queue->has($listener)) { return true; } } } return false; }
php
public function hasListener($listener, $event = null): bool { if ($event) { if ($event instanceof EventInterface) { $event = $event->getName(); } if (isset($this->listeners[$event])) { return $this->listeners[$event]->has($listener); } } else { foreach ($this->listeners as $queue) { if ($queue->has($listener)) { return true; } } } return false; }
[ "public", "function", "hasListener", "(", "$", "listener", ",", "$", "event", "=", "null", ")", ":", "bool", "{", "if", "(", "$", "event", ")", "{", "if", "(", "$", "event", "instanceof", "EventInterface", ")", "{", "$", "event", "=", "$", "event", ...
是否存在(对事件的)监听器 @param $listener @param EventInterface|string $event @return bool
[ "是否存在", "(", "对事件的", ")", "监听器" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/EventManager.php#L375-L394
swoft-cloud/swoft-framework
src/Event/EventManager.php
EventManager.getListenerPriority
public function getListenerPriority($listener, $event) { if ($event instanceof EventInterface) { $event = $event->getName(); } if (isset($this->listeners[$event])) { return $this->listeners[$event]->getPriority($listener); } return null; }
php
public function getListenerPriority($listener, $event) { if ($event instanceof EventInterface) { $event = $event->getName(); } if (isset($this->listeners[$event])) { return $this->listeners[$event]->getPriority($listener); } return null; }
[ "public", "function", "getListenerPriority", "(", "$", "listener", ",", "$", "event", ")", "{", "if", "(", "$", "event", "instanceof", "EventInterface", ")", "{", "$", "event", "=", "$", "event", "->", "getName", "(", ")", ";", "}", "if", "(", "isset",...
获取事件的一个监听器的优先级别 @param $listener @param string|EventInterface $event @return int|null
[ "获取事件的一个监听器的优先级别" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/EventManager.php#L402-L413
swoft-cloud/swoft-framework
src/Event/EventManager.php
EventManager.getListenerQueue
public function getListenerQueue($event) { if ($event instanceof EventInterface) { $event = $event->getName(); } if (isset($this->listeners[$event])) { return $this->listeners[$event]; } return null; }
php
public function getListenerQueue($event) { if ($event instanceof EventInterface) { $event = $event->getName(); } if (isset($this->listeners[$event])) { return $this->listeners[$event]; } return null; }
[ "public", "function", "getListenerQueue", "(", "$", "event", ")", "{", "if", "(", "$", "event", "instanceof", "EventInterface", ")", "{", "$", "event", "=", "$", "event", "->", "getName", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->"...
获取事件的所有监听器 @param string|EventInterface $event @return ListenerQueue|null
[ "获取事件的所有监听器" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/EventManager.php#L420-L431
swoft-cloud/swoft-framework
src/Event/EventManager.php
EventManager.getListeners
public function getListeners($event): array { if ($event instanceof EventInterface) { $event = $event->getName(); } if (isset($this->listeners[$event])) { return $this->listeners[$event]->getAll(); } return []; }
php
public function getListeners($event): array { if ($event instanceof EventInterface) { $event = $event->getName(); } if (isset($this->listeners[$event])) { return $this->listeners[$event]->getAll(); } return []; }
[ "public", "function", "getListeners", "(", "$", "event", ")", ":", "array", "{", "if", "(", "$", "event", "instanceof", "EventInterface", ")", "{", "$", "event", "=", "$", "event", "->", "getName", "(", ")", ";", "}", "if", "(", "isset", "(", "$", ...
获取事件的所有监听器 @param string|EventInterface $event @return array
[ "获取事件的所有监听器" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/EventManager.php#L438-L449
swoft-cloud/swoft-framework
src/Event/EventManager.php
EventManager.removeListener
public function removeListener($listener, $event = null): bool { if ($event) { if ($event instanceof EventInterface) { $event = $event->getName(); } // 存在对这个事件的监听队列 if (isset($this->listeners[$event])) { $this->listeners[$event]->remove($listener); } } else { foreach ($this->listeners as $queue) { /** @var $queue ListenerQueue */ $queue->remove($listener); } } return true; }
php
public function removeListener($listener, $event = null): bool { if ($event) { if ($event instanceof EventInterface) { $event = $event->getName(); } // 存在对这个事件的监听队列 if (isset($this->listeners[$event])) { $this->listeners[$event]->remove($listener); } } else { foreach ($this->listeners as $queue) { /** @var $queue ListenerQueue */ $queue->remove($listener); } } return true; }
[ "public", "function", "removeListener", "(", "$", "listener", ",", "$", "event", "=", "null", ")", ":", "bool", "{", "if", "(", "$", "event", ")", "{", "if", "(", "$", "event", "instanceof", "EventInterface", ")", "{", "$", "event", "=", "$", "event"...
移除对某个事件的监听 @param $listener @param null|string|EventInterface $event 为空时,移除监听者队列中所有名为 $listener 的监听者 否则, 则移除对事件 $event 的监听者 @return bool
[ "移除对某个事件的监听" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/EventManager.php#L473-L492
swoft-cloud/swoft-framework
src/Event/EventManager.php
EventManager.addEvent
public function addEvent($event, array $params = []): self { $event = $this->wrapperEvent($event, null, $params); /** @var $event Event */ if (($event instanceof EventInterface) && !isset($this->events[$event->getName()])) { $this->events[$event->getName()] = $event; } return $this; }
php
public function addEvent($event, array $params = []): self { $event = $this->wrapperEvent($event, null, $params); /** @var $event Event */ if (($event instanceof EventInterface) && !isset($this->events[$event->getName()])) { $this->events[$event->getName()] = $event; } return $this; }
[ "public", "function", "addEvent", "(", "$", "event", ",", "array", "$", "params", "=", "[", "]", ")", ":", "self", "{", "$", "event", "=", "$", "this", "->", "wrapperEvent", "(", "$", "event", ",", "null", ",", "$", "params", ")", ";", "/** @var $e...
添加一个不存在的事件 @param EventInterface|string $event | event name @param array $params @return $this @throws \InvalidArgumentException
[ "添加一个不存在的事件" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/EventManager.php#L534-L544
swoft-cloud/swoft-framework
src/Event/EventManager.php
EventManager.setEvent
public function setEvent($event, array $params = []): self { $event = $this->wrapperEvent($event, null, $params); if ($event instanceof EventInterface) { $this->events[$event->getName()] = $event; } return $this; }
php
public function setEvent($event, array $params = []): self { $event = $this->wrapperEvent($event, null, $params); if ($event instanceof EventInterface) { $this->events[$event->getName()] = $event; } return $this; }
[ "public", "function", "setEvent", "(", "$", "event", ",", "array", "$", "params", "=", "[", "]", ")", ":", "self", "{", "$", "event", "=", "$", "this", "->", "wrapperEvent", "(", "$", "event", ",", "null", ",", "$", "params", ")", ";", "if", "(",...
设定一个事件处理 @param string|EventInterface $event @param array $params @return $this @throws \InvalidArgumentException
[ "设定一个事件处理" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/EventManager.php#L553-L562
swoft-cloud/swoft-framework
src/Bean/Collector/DefinitionCollector.php
DefinitionCollector.collect
public static function collect(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null) { if ($objectAnnotation instanceof Definition) { $name = $objectAnnotation->getName(); self::$definitions[$className] = empty($name) ? $className : $name; } }
php
public static function collect(string $className, $objectAnnotation = null, string $propertyName = "", string $methodName = "", $propertyValue = null) { if ($objectAnnotation instanceof Definition) { $name = $objectAnnotation->getName(); self::$definitions[$className] = empty($name) ? $className : $name; } }
[ "public", "static", "function", "collect", "(", "string", "$", "className", ",", "$", "objectAnnotation", "=", "null", ",", "string", "$", "propertyName", "=", "\"\"", ",", "string", "$", "methodName", "=", "\"\"", ",", "$", "propertyValue", "=", "null", "...
collect @param string $className @param Definition $objectAnnotation @param string $propertyName @param string $methodName @param null $propertyValue @return void
[ "collect" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/Collector/DefinitionCollector.php#L29-L36
swoft-cloud/swoft-framework
src/Bean/BeanFactory.php
BeanFactory.init
public static function init() { $properties = self::getProperties(); self::$container = new Container(); self::$container->setProperties($properties); self::$container->autoloadServerAnnotation(); $definition = self::getServerDefinition(); self::$container->addDefinitions($definition); self::$container->initBeans(); }
php
public static function init() { $properties = self::getProperties(); self::$container = new Container(); self::$container->setProperties($properties); self::$container->autoloadServerAnnotation(); $definition = self::getServerDefinition(); self::$container->addDefinitions($definition); self::$container->initBeans(); }
[ "public", "static", "function", "init", "(", ")", "{", "$", "properties", "=", "self", "::", "getProperties", "(", ")", ";", "self", "::", "$", "container", "=", "new", "Container", "(", ")", ";", "self", "::", "$", "container", "->", "setProperties", ...
Init beans @throws \InvalidArgumentException @throws \ReflectionException
[ "Init", "beans" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/BeanFactory.php#L28-L39
swoft-cloud/swoft-framework
src/Bean/BeanFactory.php
BeanFactory.reload
public static function reload(array $definitions = []) { $properties = self::getProperties(); $workerDefinitions = self::getWorkerDefinition(); $definitions = ArrayHelper::merge($workerDefinitions, $definitions); self::$container->setProperties($properties); self::$container->addDefinitions($definitions); self::$container->autoloadWorkerAnnotation(); $componentDefinitions = self::getComponentDefinitions(); self::$container->addDefinitions($componentDefinitions); /* @var Aop $aop Init reload AOP */ $aop = App::getBean(Aop::class); $aop->init(); self::$container->initBeans(); }
php
public static function reload(array $definitions = []) { $properties = self::getProperties(); $workerDefinitions = self::getWorkerDefinition(); $definitions = ArrayHelper::merge($workerDefinitions, $definitions); self::$container->setProperties($properties); self::$container->addDefinitions($definitions); self::$container->autoloadWorkerAnnotation(); $componentDefinitions = self::getComponentDefinitions(); self::$container->addDefinitions($componentDefinitions); /* @var Aop $aop Init reload AOP */ $aop = App::getBean(Aop::class); $aop->init(); self::$container->initBeans(); }
[ "public", "static", "function", "reload", "(", "array", "$", "definitions", "=", "[", "]", ")", "{", "$", "properties", "=", "self", "::", "getProperties", "(", ")", ";", "$", "workerDefinitions", "=", "self", "::", "getWorkerDefinition", "(", ")", ";", ...
Reload bean definitions @param array $definitions append definitions to config loader @throws \ReflectionException
[ "Reload", "bean", "definitions" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/BeanFactory.php#L47-L65
swoft-cloud/swoft-framework
src/Bean/BeanFactory.php
BeanFactory.getCoreBean
private static function getCoreBean(string $type): array { $collector = BootBeanCollector::getCollector(); if (!isset($collector[$type])) { return []; } $coreBeans = []; /** @var array $bootBeans */ $bootBeans = $collector[$type]; foreach ($bootBeans as $beanName) { /* @var \Swoft\Core\BootBeanInterface $bootBean */ $bootBean = App::getBean($beanName); $beans = $bootBean->beans(); $coreBeans = ArrayHelper::merge($coreBeans, $beans); } return $coreBeans; }
php
private static function getCoreBean(string $type): array { $collector = BootBeanCollector::getCollector(); if (!isset($collector[$type])) { return []; } $coreBeans = []; /** @var array $bootBeans */ $bootBeans = $collector[$type]; foreach ($bootBeans as $beanName) { /* @var \Swoft\Core\BootBeanInterface $bootBean */ $bootBean = App::getBean($beanName); $beans = $bootBean->beans(); $coreBeans = ArrayHelper::merge($coreBeans, $beans); } return $coreBeans; }
[ "private", "static", "function", "getCoreBean", "(", "string", "$", "type", ")", ":", "array", "{", "$", "collector", "=", "BootBeanCollector", "::", "getCollector", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "collector", "[", "$", "type", "]", ...
@param string $type @return array
[ "@param", "string", "$type" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Bean/BeanFactory.php#L150-L168
swoft-cloud/swoft-framework
src/Core/Coroutine.php
Coroutine.create
public static function create(callable $cb) { $tid = self::tid(); return SwCoroutine::create(function () use ($cb, $tid) { $id = SwCoroutine::getuid(); self::$idMap[$id] = $tid; PhpHelper::call($cb); }); }
php
public static function create(callable $cb) { $tid = self::tid(); return SwCoroutine::create(function () use ($cb, $tid) { $id = SwCoroutine::getuid(); self::$idMap[$id] = $tid; PhpHelper::call($cb); }); }
[ "public", "static", "function", "create", "(", "callable", "$", "cb", ")", "{", "$", "tid", "=", "self", "::", "tid", "(", ")", ";", "return", "SwCoroutine", "::", "create", "(", "function", "(", ")", "use", "(", "$", "cb", ",", "$", "tid", ")", ...
Create a coroutine @param callable $cb @return bool
[ "Create", "a", "coroutine" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/Coroutine.php#L66-L75
swoft-cloud/swoft-framework
src/Event/ListenerQueue.php
ListenerQueue.add
public function add($listener, $priority): self { // transfer to object. like string/array if (!\is_object($listener)) { $listener = new LazyListener($listener); } if (!$this->has($listener)) { // Compute the internal priority as an array. 计算内部优先级为一个数组。 // @see http://php.net/manual/zh/splpriorityqueue.compare.php#93999 $priorityData = [(int)$priority, $this->counter--]; $this->store->attach($listener, $priorityData); $this->queue->insert($listener, $priorityData); } return $this; }
php
public function add($listener, $priority): self { // transfer to object. like string/array if (!\is_object($listener)) { $listener = new LazyListener($listener); } if (!$this->has($listener)) { // Compute the internal priority as an array. 计算内部优先级为一个数组。 // @see http://php.net/manual/zh/splpriorityqueue.compare.php#93999 $priorityData = [(int)$priority, $this->counter--]; $this->store->attach($listener, $priorityData); $this->queue->insert($listener, $priorityData); } return $this; }
[ "public", "function", "add", "(", "$", "listener", ",", "$", "priority", ")", ":", "self", "{", "// transfer to object. like string/array", "if", "(", "!", "\\", "is_object", "(", "$", "listener", ")", ")", "{", "$", "listener", "=", "new", "LazyListener", ...
添加一个监听器, 增加了添加 callback(string|array) @param \Closure|callable|\stdClass|mixed $listener 监听器 @param integer $priority 优先级 @return $this
[ "添加一个监听器", "增加了添加", "callback", "(", "string|array", ")" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/ListenerQueue.php#L43-L60
swoft-cloud/swoft-framework
src/Event/ListenerQueue.php
ListenerQueue.remove
public function remove($listener): self { if ($this->has($listener)) { $this->store->detach($listener); $this->store->rewind(); $queue = new \SplPriorityQueue(); foreach ($this->store as $otherListener) { // 优先级信息 @see self::add(). It like `[priority, counter value]` $priority = $this->store->getInfo(); $queue->insert($otherListener, $priority); } $this->queue = $queue; } return $this; }
php
public function remove($listener): self { if ($this->has($listener)) { $this->store->detach($listener); $this->store->rewind(); $queue = new \SplPriorityQueue(); foreach ($this->store as $otherListener) { // 优先级信息 @see self::add(). It like `[priority, counter value]` $priority = $this->store->getInfo(); $queue->insert($otherListener, $priority); } $this->queue = $queue; } return $this; }
[ "public", "function", "remove", "(", "$", "listener", ")", ":", "self", "{", "if", "(", "$", "this", "->", "has", "(", "$", "listener", ")", ")", "{", "$", "this", "->", "store", "->", "detach", "(", "$", "listener", ")", ";", "$", "this", "->", ...
删除一个监听器 @param $listener @return $this
[ "删除一个监听器" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/ListenerQueue.php#L67-L85
swoft-cloud/swoft-framework
src/Event/ListenerQueue.php
ListenerQueue.getPriority
public function getPriority($listener, $default = null) { if ($this->store->contains($listener)) { // @see self::add(). attach as: `[priority, counter value]` return $this->store[$listener][0]; } return $default; }
php
public function getPriority($listener, $default = null) { if ($this->store->contains($listener)) { // @see self::add(). attach as: `[priority, counter value]` return $this->store[$listener][0]; } return $default; }
[ "public", "function", "getPriority", "(", "$", "listener", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "this", "->", "store", "->", "contains", "(", "$", "listener", ")", ")", "{", "// @see self::add(). attach as: `[priority, counter value]`", ...
Get the priority of the given listener. 得到指定监听器的优先级 @param mixed $listener The listener. @param mixed $default The default value to return if the listener doesn't exist. @return mixed The listener priority if it exists, null otherwise.
[ "Get", "the", "priority", "of", "the", "given", "listener", ".", "得到指定监听器的优先级" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Event/ListenerQueue.php#L93-L101
swoft-cloud/swoft-framework
src/Core/Config.php
Config.offsetSet
public function offsetSet($offset, $value) { if (\is_string($offset) || \is_int($offset)) { $this->properties[$offset] = $value; } }
php
public function offsetSet($offset, $value) { if (\is_string($offset) || \is_int($offset)) { $this->properties[$offset] = $value; } }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", "{", "if", "(", "\\", "is_string", "(", "$", "offset", ")", "||", "\\", "is_int", "(", "$", "offset", ")", ")", "{", "$", "this", "->", "properties", "[", "$", "offset",...
Offset to set @param mixed $offset The offset to assign the value to. @param mixed $value The value to set. @return void
[ "Offset", "to", "set" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/Config.php#L116-L121
swoft-cloud/swoft-framework
src/Core/Config.php
Config.load
public function load( string $dir, array $excludeFiles = [], string $strategy = DirHelper::SCAN_BFS, string $structure = self::STRUCTURE_MERGE ): self { $mapping = []; if (StringHelper::contains($dir, ['@'])) { $dir = App::getAlias($dir); } if (!is_dir($dir)) { throw new \InvalidArgumentException('Invalid dir parameter'); } $dir = DirHelper::formatPath($dir); $files = DirHelper::glob($dir, '*.php', $strategy); foreach ($files as $file) { if (! is_readable($file) || ArrayHelper::isIn($file, $excludeFiles)) { continue; } $loadedConfig = require $file; if (!\is_array($loadedConfig)) { throw new \InvalidArgumentException('Syntax error find in config file: ' . $file); } $fileName = DirHelper::basename([$file]); $key = current(explode('.', current($fileName))); switch ($structure) { case self::STRUCTURE_SEPARATE: $configMap = [$key => $loadedConfig]; break; case self::STRUCTURE_MERGE: default: $configMap = $loadedConfig; break; } $mapping = ArrayHelper::merge($mapping, $configMap); } $this->properties = $mapping; return $this; }
php
public function load( string $dir, array $excludeFiles = [], string $strategy = DirHelper::SCAN_BFS, string $structure = self::STRUCTURE_MERGE ): self { $mapping = []; if (StringHelper::contains($dir, ['@'])) { $dir = App::getAlias($dir); } if (!is_dir($dir)) { throw new \InvalidArgumentException('Invalid dir parameter'); } $dir = DirHelper::formatPath($dir); $files = DirHelper::glob($dir, '*.php', $strategy); foreach ($files as $file) { if (! is_readable($file) || ArrayHelper::isIn($file, $excludeFiles)) { continue; } $loadedConfig = require $file; if (!\is_array($loadedConfig)) { throw new \InvalidArgumentException('Syntax error find in config file: ' . $file); } $fileName = DirHelper::basename([$file]); $key = current(explode('.', current($fileName))); switch ($structure) { case self::STRUCTURE_SEPARATE: $configMap = [$key => $loadedConfig]; break; case self::STRUCTURE_MERGE: default: $configMap = $loadedConfig; break; } $mapping = ArrayHelper::merge($mapping, $configMap); } $this->properties = $mapping; return $this; }
[ "public", "function", "load", "(", "string", "$", "dir", ",", "array", "$", "excludeFiles", "=", "[", "]", ",", "string", "$", "strategy", "=", "DirHelper", "::", "SCAN_BFS", ",", "string", "$", "structure", "=", "self", "::", "STRUCTURE_MERGE", ")", ":"...
Load all files to container from $dir according by strategy @param string $dir the directory path that you want to scan @param array $excludeFiles method will skip it if the file full path match in $exculdeFiles @param string $strategy Scan strategy, DirHelper::SCAN_CURRENT_DIR Only Scan the current directory; DirHelper::SCAN_BFS Breadth First Search; DirHelper::SCAN_DFS Depth First Search @param string $structure self::STRUCTURE_MERGE merge all files result to an array, e.g. [ content1, content2 ]; self::STRUCTURE_SEPARATE merge all files result to an assoc array, use the file name as key, e.g. [ fileName1 => content1, fileName2 => content2 ] @return \Swoft\Core\Config @throws \InvalidArgumentException
[ "Load", "all", "files", "to", "container", "from", "$dir", "according", "by", "strategy" ]
train
https://github.com/swoft-cloud/swoft-framework/blob/454e2f378373cbc93b07449dc305326deaab2ec2/src/Core/Config.php#L215-L254
Brain-WP/BrainMonkey
src/Expectation/Expectation.php
Expectation.andAlsoExpectIt
public function andAlsoExpectIt() { $method = $this->target->mockMethodName(); /** @noinspection PhpMethodParametersCountMismatchInspection */ $this->expectation = $this->expectation->getMock()->shouldReceive($method); return $this; }
php
public function andAlsoExpectIt() { $method = $this->target->mockMethodName(); /** @noinspection PhpMethodParametersCountMismatchInspection */ $this->expectation = $this->expectation->getMock()->shouldReceive($method); return $this; }
[ "public", "function", "andAlsoExpectIt", "(", ")", "{", "$", "method", "=", "$", "this", "->", "target", "->", "mockMethodName", "(", ")", ";", "/** @noinspection PhpMethodParametersCountMismatchInspection */", "$", "this", "->", "expectation", "=", "$", "this", "...
Mockery expectation allow chaining different expectations with by chaining `getMock()` method. Since `getMock()` is disabled for Brain Monkey expectation this methods provides a way to chain expectations. @return static
[ "Mockery", "expectation", "allow", "chaining", "different", "expectations", "with", "by", "chaining", "getMock", "()", "method", ".", "Since", "getMock", "()", "is", "disabled", "for", "Brain", "Monkey", "expectation", "this", "methods", "provides", "a", "way", ...
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/Expectation.php#L171-L178
Brain-WP/BrainMonkey
src/Expectation/Expectation.php
Expectation.withNoArgs
public function withNoArgs() { if ( ! in_array($this->target->type(), self::NO_ARGS_EXPECTATION_TYPES, true)) { throw Exception\ExpectationArgsRequired::forExpectationType($this->target); } $this->expectation = $this->expectation->withNoArgs(); return $this; }
php
public function withNoArgs() { if ( ! in_array($this->target->type(), self::NO_ARGS_EXPECTATION_TYPES, true)) { throw Exception\ExpectationArgsRequired::forExpectationType($this->target); } $this->expectation = $this->expectation->withNoArgs(); return $this; }
[ "public", "function", "withNoArgs", "(", ")", "{", "if", "(", "!", "in_array", "(", "$", "this", "->", "target", "->", "type", "(", ")", ",", "self", "::", "NO_ARGS_EXPECTATION_TYPES", ",", "true", ")", ")", "{", "throw", "Exception", "\\", "ExpectationA...
WordPress action and filters addition and filters applying requires at least one argument, and setting an expectation of no arguments for those triggers an error in Brain Monkey. @return static @throws \Brain\Monkey\Expectation\Exception\ExpectationArgsRequired
[ "WordPress", "action", "and", "filters", "addition", "and", "filters", "applying", "requires", "at", "least", "one", "argument", "and", "setting", "an", "expectation", "of", "no", "arguments", "for", "those", "triggers", "an", "error", "in", "Brain", "Monkey", ...
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/Expectation.php#L187-L196
Brain-WP/BrainMonkey
src/Expectation/Expectation.php
Expectation.whenHappen
public function whenHappen(callable $callback) { if (in_array($this->target->type(), self::RETURNING_EXPECTATION_TYPES, true)) { throw Exception\NotAllowedMethod::forWhenHappen($this->target); } $this->expectation->andReturnUsing($callback); return $this; }
php
public function whenHappen(callable $callback) { if (in_array($this->target->type(), self::RETURNING_EXPECTATION_TYPES, true)) { throw Exception\NotAllowedMethod::forWhenHappen($this->target); } $this->expectation->andReturnUsing($callback); return $this; }
[ "public", "function", "whenHappen", "(", "callable", "$", "callback", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "target", "->", "type", "(", ")", ",", "self", "::", "RETURNING_EXPECTATION_TYPES", ",", "true", ")", ")", "{", "throw", "Excep...
Brain Monkey doesn't allow return expectation for actions (added/done) nor for added filters. However, it is desirable to do something when the expected callback is used, this is the reason to be of this method. ``` Actions::expectDone('some_action')->once()->whenHappen(function($some_arg) { echo "{$some_arg} was passed to " . current_filter(); }); ``` Snippet above will not change the return of `do_action('some_action', $some_arg)` like a normal return expectation would do, but allows to catch expected events with a callback. For expectation types that allows return expectation (functions, applied filters) this method becomes just an alias for Mockery `andReturnUsing()`. @param callable $callback @return static @throws \Brain\Monkey\Expectation\Exception\NotAllowedMethod
[ "Brain", "Monkey", "doesn", "t", "allow", "return", "expectation", "for", "actions", "(", "added", "/", "done", ")", "nor", "for", "added", "filters", ".", "However", "it", "is", "desirable", "to", "do", "something", "when", "the", "expected", "callback", ...
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/Expectation.php#L221-L230
Brain-WP/BrainMonkey
src/Name/CallbackStringForm.php
CallbackStringForm.assertMethodCallable
private function assertMethodCallable($class_name, $method, $callable) { if ( class_exists($class_name) && ! (method_exists($class_name, $method) || is_callable([$class_name, $method])) ) { throw Exception\InvalidCallable::forCallable($callable); } }
php
private function assertMethodCallable($class_name, $method, $callable) { if ( class_exists($class_name) && ! (method_exists($class_name, $method) || is_callable([$class_name, $method])) ) { throw Exception\InvalidCallable::forCallable($callable); } }
[ "private", "function", "assertMethodCallable", "(", "$", "class_name", ",", "$", "method", ",", "$", "callable", ")", "{", "if", "(", "class_exists", "(", "$", "class_name", ")", "&&", "!", "(", "method_exists", "(", "$", "class_name", ",", "$", "method", ...
Ensure method existence only if class is available. @param string $class_name @param string $method @param string|array $callable @throws \Brain\Monkey\Name\Exception\InvalidCallable @throws \Brain\Monkey\Name\Exception\NotInvokableObjectAsCallback
[ "Ensure", "method", "existence", "only", "if", "class", "is", "available", "." ]
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Name/CallbackStringForm.php#L179-L187
Brain-WP/BrainMonkey
src/Name/ClosureStringForm.php
ClosureStringForm.buildName
private function buildName(\Closure $closure) { $reflection = new \ReflectionFunction($closure); // Quite hackish, but it seems there's no better way to get if a closure is static $bind = @\Closure::bind($closure, new \stdClass); $static = $bind === null || (new \ReflectionFunction($bind))->getClosureThis() === null; $arguments = array_map('strval', array_map( [ClosureParamStringForm::class, 'fromReflectionParameter'], $reflection->getParameters() )); $name = $static ? 'static function (' : 'function ('; return $name.implode($arguments, ', ').')'; }
php
private function buildName(\Closure $closure) { $reflection = new \ReflectionFunction($closure); // Quite hackish, but it seems there's no better way to get if a closure is static $bind = @\Closure::bind($closure, new \stdClass); $static = $bind === null || (new \ReflectionFunction($bind))->getClosureThis() === null; $arguments = array_map('strval', array_map( [ClosureParamStringForm::class, 'fromReflectionParameter'], $reflection->getParameters() )); $name = $static ? 'static function (' : 'function ('; return $name.implode($arguments, ', ').')'; }
[ "private", "function", "buildName", "(", "\\", "Closure", "$", "closure", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionFunction", "(", "$", "closure", ")", ";", "// Quite hackish, but it seems there's no better way to get if a closure is static", "$", "bind...
Checks the name of a function and throw an exception if is not valid. When name is valid returns an array of the name itself and its namespace parts. @param \Closure $closure @return string
[ "Checks", "the", "name", "of", "a", "function", "and", "throw", "an", "exception", "if", "is", "not", "valid", ".", "When", "name", "is", "valid", "returns", "an", "array", "of", "the", "name", "itself", "and", "its", "namespace", "parts", "." ]
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Name/ClosureStringForm.php#L109-L127
Brain-WP/BrainMonkey
src/Name/FunctionName.php
FunctionName.parseName
private function parseName($function_name) { $chunks = is_string($function_name) ? explode('\\', ltrim($function_name, '\\')) : null; $valid = $chunks ? preg_filter(self::VALID_NAME_PATTERN, '$0', $chunks) : null; if ( ! $valid || $valid !== $chunks) { $name = is_string($function_name) ? "'{$function_name}'" : 'Variable of type '.gettype($function_name); throw Exception\InvalidName::forFunction($name); } return [array_pop($chunks), implode('\\', $chunks)]; }
php
private function parseName($function_name) { $chunks = is_string($function_name) ? explode('\\', ltrim($function_name, '\\')) : null; $valid = $chunks ? preg_filter(self::VALID_NAME_PATTERN, '$0', $chunks) : null; if ( ! $valid || $valid !== $chunks) { $name = is_string($function_name) ? "'{$function_name}'" : 'Variable of type '.gettype($function_name); throw Exception\InvalidName::forFunction($name); } return [array_pop($chunks), implode('\\', $chunks)]; }
[ "private", "function", "parseName", "(", "$", "function_name", ")", "{", "$", "chunks", "=", "is_string", "(", "$", "function_name", ")", "?", "explode", "(", "'\\\\'", ",", "ltrim", "(", "$", "function_name", ",", "'\\\\'", ")", ")", ":", "null", ";", ...
Checks the name of a function and throw an exception if is not valid. When name is valid returns an array of the name itself and its namespace parts. @param string $function_name @return \string[] @throws \Brain\Monkey\Name\Exception\InvalidName
[ "Checks", "the", "name", "of", "a", "function", "and", "throw", "an", "exception", "if", "is", "not", "valid", ".", "When", "name", "is", "valid", "returns", "an", "array", "of", "the", "name", "itself", "and", "its", "namespace", "parts", "." ]
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Name/FunctionName.php#L83-L97
Brain-WP/BrainMonkey
src/Expectation/FunctionStub.php
FunctionStub.alias
public function alias(callable $callback) { $fqn = $this->function_name->fullyQualifiedName(); \Patchwork\redefine($fqn, $callback); $this->assertRedefined($fqn); }
php
public function alias(callable $callback) { $fqn = $this->function_name->fullyQualifiedName(); \Patchwork\redefine($fqn, $callback); $this->assertRedefined($fqn); }
[ "public", "function", "alias", "(", "callable", "$", "callback", ")", "{", "$", "fqn", "=", "$", "this", "->", "function_name", "->", "fullyQualifiedName", "(", ")", ";", "\\", "Patchwork", "\\", "redefine", "(", "$", "fqn", ",", "$", "callback", ")", ...
Redefine target function replacing it on the fly with a given callable. @param callable $callback
[ "Redefine", "target", "function", "replacing", "it", "on", "the", "fly", "with", "a", "given", "callable", "." ]
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/FunctionStub.php#L68-L73
Brain-WP/BrainMonkey
src/Expectation/FunctionStub.php
FunctionStub.redefineUsingExpectation
public function redefineUsingExpectation(Expectation $expectation) { $fqn = $this->function_name->fullyQualifiedName(); $this->alias(function (...$args) use ($expectation, $fqn) { $mock = $expectation->mockeryExpectation()->getMock(); $target = new ExpectationTarget(ExpectationTarget::TYPE_FUNCTION, $fqn); return $mock->{$target->mockMethodName()}(...$args); }); }
php
public function redefineUsingExpectation(Expectation $expectation) { $fqn = $this->function_name->fullyQualifiedName(); $this->alias(function (...$args) use ($expectation, $fqn) { $mock = $expectation->mockeryExpectation()->getMock(); $target = new ExpectationTarget(ExpectationTarget::TYPE_FUNCTION, $fqn); return $mock->{$target->mockMethodName()}(...$args); }); }
[ "public", "function", "redefineUsingExpectation", "(", "Expectation", "$", "expectation", ")", "{", "$", "fqn", "=", "$", "this", "->", "function_name", "->", "fullyQualifiedName", "(", ")", ";", "$", "this", "->", "alias", "(", "function", "(", "...", "$", ...
Redefine target function replacing it with a function that execute Brain Monkey expectation target method on the mock associated with given Brain Monkey expectation. @param \Brain\Monkey\Expectation\Expectation $expectation @return void
[ "Redefine", "target", "function", "replacing", "it", "with", "a", "function", "that", "execute", "Brain", "Monkey", "expectation", "target", "method", "on", "the", "mock", "associated", "with", "given", "Brain", "Monkey", "expectation", "." ]
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/FunctionStub.php#L82-L93
Brain-WP/BrainMonkey
src/Expectation/FunctionStub.php
FunctionStub.justReturn
public function justReturn($return = null) { $fqn = ltrim($this->function_name->fullyQualifiedName(), '\\'); \Patchwork\redefine($fqn, function () use ($return) { return $return; }); $this->assertRedefined($fqn); }
php
public function justReturn($return = null) { $fqn = ltrim($this->function_name->fullyQualifiedName(), '\\'); \Patchwork\redefine($fqn, function () use ($return) { return $return; }); $this->assertRedefined($fqn); }
[ "public", "function", "justReturn", "(", "$", "return", "=", "null", ")", "{", "$", "fqn", "=", "ltrim", "(", "$", "this", "->", "function_name", "->", "fullyQualifiedName", "(", ")", ",", "'\\\\'", ")", ";", "\\", "Patchwork", "\\", "redefine", "(", "...
Redefine target function making it return an arbitrary value. @param mixed $return
[ "Redefine", "target", "function", "making", "it", "return", "an", "arbitrary", "value", "." ]
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/FunctionStub.php#L100-L109
Brain-WP/BrainMonkey
src/Expectation/FunctionStub.php
FunctionStub.justEcho
public function justEcho($value = null) { is_null($value) and $value = ''; $fqn = ltrim($this->function_name->fullyQualifiedName(), '\\'); $this->assertPrintable($value, 'provided to justEcho'); \Patchwork\redefine($fqn, function () use ($value) { echo $value; }); $this->assertRedefined($fqn); }
php
public function justEcho($value = null) { is_null($value) and $value = ''; $fqn = ltrim($this->function_name->fullyQualifiedName(), '\\'); $this->assertPrintable($value, 'provided to justEcho'); \Patchwork\redefine($fqn, function () use ($value) { echo $value; }); $this->assertRedefined($fqn); }
[ "public", "function", "justEcho", "(", "$", "value", "=", "null", ")", "{", "is_null", "(", "$", "value", ")", "and", "$", "value", "=", "''", ";", "$", "fqn", "=", "ltrim", "(", "$", "this", "->", "function_name", "->", "fullyQualifiedName", "(", ")...
Redefine target function making it echo an arbitrary value. @param mixed $value @throws \Brain\Monkey\Expectation\Exception\InvalidArgumentForStub
[ "Redefine", "target", "function", "making", "it", "echo", "an", "arbitrary", "value", "." ]
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/FunctionStub.php#L117-L129
Brain-WP/BrainMonkey
src/Expectation/FunctionStub.php
FunctionStub.returnArg
public function returnArg($arg_num = 1) { $arg_num = $this->assertValidArgNum($arg_num); $fqn = $this->function_name->fullyQualifiedName(); \Patchwork\redefine($fqn, function (...$args) use ($fqn, $arg_num) { if ( ! array_key_exists($arg_num - 1, $args)) { $count = count($args); throw new Exception\InvalidArgumentForStub( "{$fqn} was called with {$count} params, can't return argument \"{$arg_num}\"." ); } return $args[$arg_num - 1]; }); $this->assertRedefined($fqn); }
php
public function returnArg($arg_num = 1) { $arg_num = $this->assertValidArgNum($arg_num); $fqn = $this->function_name->fullyQualifiedName(); \Patchwork\redefine($fqn, function (...$args) use ($fqn, $arg_num) { if ( ! array_key_exists($arg_num - 1, $args)) { $count = count($args); throw new Exception\InvalidArgumentForStub( "{$fqn} was called with {$count} params, can't return argument \"{$arg_num}\"." ); } return $args[$arg_num - 1]; }); $this->assertRedefined($fqn); }
[ "public", "function", "returnArg", "(", "$", "arg_num", "=", "1", ")", "{", "$", "arg_num", "=", "$", "this", "->", "assertValidArgNum", "(", "$", "arg_num", ")", ";", "$", "fqn", "=", "$", "this", "->", "function_name", "->", "fullyQualifiedName", "(", ...
Redefine target function making it return one of the received arguments, the first by default. Redefined function will throw an exception if the function does not receive desired argument. @param int $arg_num The position (1-based) of the argument to return
[ "Redefine", "target", "function", "making", "it", "return", "one", "of", "the", "received", "arguments", "the", "first", "by", "default", ".", "Redefined", "function", "will", "throw", "an", "exception", "if", "the", "function", "does", "not", "receive", "desi...
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/FunctionStub.php#L138-L155
Brain-WP/BrainMonkey
src/Expectation/FunctionStub.php
FunctionStub.echoArg
public function echoArg($arg_num = 1) { $arg_num = $this->assertValidArgNum($arg_num); $fqn = $this->function_name->fullyQualifiedName(); \Patchwork\redefine($fqn, function (...$args) use ($fqn, $arg_num) { if ( ! array_key_exists($arg_num - 1, $args)) { $count = count($args); throw new \RuntimeException( "{$fqn} was called with {$count} params, can't return argument \"{$arg_num}\"." ); } $arg = $args[$arg_num - 1]; $this->assertPrintable($arg, "passed as argument {$arg_num} to {$fqn}"); echo (string) $arg; }); $this->assertRedefined($fqn); }
php
public function echoArg($arg_num = 1) { $arg_num = $this->assertValidArgNum($arg_num); $fqn = $this->function_name->fullyQualifiedName(); \Patchwork\redefine($fqn, function (...$args) use ($fqn, $arg_num) { if ( ! array_key_exists($arg_num - 1, $args)) { $count = count($args); throw new \RuntimeException( "{$fqn} was called with {$count} params, can't return argument \"{$arg_num}\"." ); } $arg = $args[$arg_num - 1]; $this->assertPrintable($arg, "passed as argument {$arg_num} to {$fqn}"); echo (string) $arg; }); $this->assertRedefined($fqn); }
[ "public", "function", "echoArg", "(", "$", "arg_num", "=", "1", ")", "{", "$", "arg_num", "=", "$", "this", "->", "assertValidArgNum", "(", "$", "arg_num", ")", ";", "$", "fqn", "=", "$", "this", "->", "function_name", "->", "fullyQualifiedName", "(", ...
Redefine target function making it echo one of the received arguments, the first by default. Redefined function will throw an exception if the function does not receive desired argument. @param int $arg_num The position (1-based) of the argument to echo @throws \Brain\Monkey\Expectation\Exception\InvalidArgumentForStub
[ "Redefine", "target", "function", "making", "it", "echo", "one", "of", "the", "received", "arguments", "the", "first", "by", "default", ".", "Redefined", "function", "will", "throw", "an", "exception", "if", "the", "function", "does", "not", "receive", "desire...
train
https://github.com/Brain-WP/BrainMonkey/blob/9d25c5802a2f796000d2d0cc318b1c13fd2752f2/src/Expectation/FunctionStub.php#L164-L187
igaster/laravel-theme
src/Themes.php
Themes.exists
public function exists($themeName) { foreach ($this->themes as $theme) { if ($theme->name == $themeName) { return true; } } return false; }
php
public function exists($themeName) { foreach ($this->themes as $theme) { if ($theme->name == $themeName) { return true; } } return false; }
[ "public", "function", "exists", "(", "$", "themeName", ")", "{", "foreach", "(", "$", "this", "->", "themes", "as", "$", "theme", ")", "{", "if", "(", "$", "theme", "->", "name", "==", "$", "themeName", ")", "{", "return", "true", ";", "}", "}", ...
Check if @themeName is registered @return bool
[ "Check", "if", "@themeName", "is", "registered" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L46-L55
igaster/laravel-theme
src/Themes.php
Themes.set
public function set($themeName) { if ($this->exists($themeName)) { $theme = $this->find($themeName); } else { $theme = new Theme($themeName); } $this->activeTheme = $theme; // Get theme view paths $paths = $theme->getViewPaths(); // fall-back to default paths (set in views.php config file) foreach ($this->laravelViewsPath as $path) { if (!in_array($path, $paths)) { $paths[] = $path; } } config(['view.paths' => $paths]); $themeViewFinder = app('view.finder'); $themeViewFinder->setPaths($paths); Event::dispatch('igaster.laravel-theme.change', $theme); return $theme; }
php
public function set($themeName) { if ($this->exists($themeName)) { $theme = $this->find($themeName); } else { $theme = new Theme($themeName); } $this->activeTheme = $theme; // Get theme view paths $paths = $theme->getViewPaths(); // fall-back to default paths (set in views.php config file) foreach ($this->laravelViewsPath as $path) { if (!in_array($path, $paths)) { $paths[] = $path; } } config(['view.paths' => $paths]); $themeViewFinder = app('view.finder'); $themeViewFinder->setPaths($paths); Event::dispatch('igaster.laravel-theme.change', $theme); return $theme; }
[ "public", "function", "set", "(", "$", "themeName", ")", "{", "if", "(", "$", "this", "->", "exists", "(", "$", "themeName", ")", ")", "{", "$", "theme", "=", "$", "this", "->", "find", "(", "$", "themeName", ")", ";", "}", "else", "{", "$", "t...
Enable $themeName & set view paths @return Theme
[ "Enable", "$themeName", "&", "set", "view", "paths" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L62-L88
igaster/laravel-theme
src/Themes.php
Themes.find
public function find($themeName) { // Search for registered themes foreach ($this->themes as $theme) { if ($theme->name == $themeName) { return $theme; } } throw new Exceptions\themeNotFound($themeName); }
php
public function find($themeName) { // Search for registered themes foreach ($this->themes as $theme) { if ($theme->name == $themeName) { return $theme; } } throw new Exceptions\themeNotFound($themeName); }
[ "public", "function", "find", "(", "$", "themeName", ")", "{", "// Search for registered themes\r", "foreach", "(", "$", "this", "->", "themes", "as", "$", "theme", ")", "{", "if", "(", "$", "theme", "->", "name", "==", "$", "themeName", ")", "{", "retur...
Find a theme by it's name @return Theme
[ "Find", "a", "theme", "by", "it", "s", "name" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L115-L126
igaster/laravel-theme
src/Themes.php
Themes.add
public function add(Theme $theme) { if ($this->exists($theme->name)) { throw new Exceptions\themeAlreadyExists($theme); } $this->themes[] = $theme; return $theme; }
php
public function add(Theme $theme) { if ($this->exists($theme->name)) { throw new Exceptions\themeAlreadyExists($theme); } $this->themes[] = $theme; return $theme; }
[ "public", "function", "add", "(", "Theme", "$", "theme", ")", "{", "if", "(", "$", "this", "->", "exists", "(", "$", "theme", "->", "name", ")", ")", "{", "throw", "new", "Exceptions", "\\", "themeAlreadyExists", "(", "$", "theme", ")", ";", "}", "...
Register a new theme @return Theme
[ "Register", "a", "new", "theme" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L133-L140
igaster/laravel-theme
src/Themes.php
Themes.rebuildCache
public function rebuildCache() { $themes = $this->scanJsonFiles(); // file_put_contents($this->cachePath, json_encode($themes, JSON_PRETTY_PRINT)); $stub = file_get_contents(__DIR__ . '/stubs/cache.stub'); $contents = str_replace('[CACHE]', var_export($themes, true), $stub); file_put_contents($this->cachePath, $contents); }
php
public function rebuildCache() { $themes = $this->scanJsonFiles(); // file_put_contents($this->cachePath, json_encode($themes, JSON_PRETTY_PRINT)); $stub = file_get_contents(__DIR__ . '/stubs/cache.stub'); $contents = str_replace('[CACHE]', var_export($themes, true), $stub); file_put_contents($this->cachePath, $contents); }
[ "public", "function", "rebuildCache", "(", ")", "{", "$", "themes", "=", "$", "this", "->", "scanJsonFiles", "(", ")", ";", "// file_put_contents($this->cachePath, json_encode($themes, JSON_PRETTY_PRINT));\r", "$", "stub", "=", "file_get_contents", "(", "__DIR__", ".", ...
Rebuilds the cache file
[ "Rebuilds", "the", "cache", "file" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L154-L162
igaster/laravel-theme
src/Themes.php
Themes.loadCache
public function loadCache() { if (!file_exists($this->cachePath)) { $this->rebuildCache(); } // $data = json_decode(file_get_contents($this->cachePath), true); $data = include $this->cachePath; if ($data === null) { throw new \Exception("Invalid theme cache json file [{$this->cachePath}]"); } return $data; }
php
public function loadCache() { if (!file_exists($this->cachePath)) { $this->rebuildCache(); } // $data = json_decode(file_get_contents($this->cachePath), true); $data = include $this->cachePath; if ($data === null) { throw new \Exception("Invalid theme cache json file [{$this->cachePath}]"); } return $data; }
[ "public", "function", "loadCache", "(", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "cachePath", ")", ")", "{", "$", "this", "->", "rebuildCache", "(", ")", ";", "}", "// $data = json_decode(file_get_contents($this->cachePath), true);\r", "$...
Loads themes from the cache
[ "Loads", "themes", "from", "the", "cache" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L165-L179
igaster/laravel-theme
src/Themes.php
Themes.scanJsonFiles
public function scanJsonFiles() { $themes = []; foreach (glob($this->themes_path('*'), GLOB_ONLYDIR) as $themeFolder) { $themeFolder = realpath($themeFolder); if (file_exists($jsonFilename = $themeFolder . '/' . 'theme.json')) { $folders = explode(DIRECTORY_SEPARATOR, $themeFolder); $themeName = end($folders); // default theme settings $defaults = [ 'name' => $themeName, 'asset-path' => $themeName, 'extends' => null, ]; // If theme.json is not an empty file parse json values $json = file_get_contents($jsonFilename); if ($json !== "") { $data = json_decode($json, true); if ($data === null) { throw new \Exception("Invalid theme.json file at [$themeFolder]"); } } else { $data = []; } // We already know views-path since we have scaned folders. // we will overide this setting if exists $data['views-path'] = $themeName; $themes[] = array_merge($defaults, $data); } } return $themes; }
php
public function scanJsonFiles() { $themes = []; foreach (glob($this->themes_path('*'), GLOB_ONLYDIR) as $themeFolder) { $themeFolder = realpath($themeFolder); if (file_exists($jsonFilename = $themeFolder . '/' . 'theme.json')) { $folders = explode(DIRECTORY_SEPARATOR, $themeFolder); $themeName = end($folders); // default theme settings $defaults = [ 'name' => $themeName, 'asset-path' => $themeName, 'extends' => null, ]; // If theme.json is not an empty file parse json values $json = file_get_contents($jsonFilename); if ($json !== "") { $data = json_decode($json, true); if ($data === null) { throw new \Exception("Invalid theme.json file at [$themeFolder]"); } } else { $data = []; } // We already know views-path since we have scaned folders. // we will overide this setting if exists $data['views-path'] = $themeName; $themes[] = array_merge($defaults, $data); } } return $themes; }
[ "public", "function", "scanJsonFiles", "(", ")", "{", "$", "themes", "=", "[", "]", ";", "foreach", "(", "glob", "(", "$", "this", "->", "themes_path", "(", "'*'", ")", ",", "GLOB_ONLYDIR", ")", "as", "$", "themeFolder", ")", "{", "$", "themeFolder", ...
Scans theme folders for theme.json files and returns an array of themes
[ "Scans", "theme", "folders", "for", "theme", ".", "json", "files", "and", "returns", "an", "array", "of", "themes" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L182-L218
igaster/laravel-theme
src/Themes.php
Themes.scanThemes
public function scanThemes() { $parentThemes = []; $themesConfig = config('themes.themes', []); foreach ($this->loadThemesJson() as $data) { // Are theme settings overriden in config/themes.php? if (array_key_exists($data['name'], $themesConfig)) { $data = array_merge($data, $themesConfig[$data['name']]); } // Create theme $theme = new Theme( $data['name'], $data['asset-path'], $data['views-path'] ); // Has a parent theme? Store parent name to resolve later. if ($data['extends']) { $parentThemes[$theme->name] = $data['extends']; } // Load the rest of the values as theme Settings $theme->loadSettings($data); } // Add themes from config/themes.php foreach ($themesConfig as $themeName => $themeConfig) { // Is it an element with no values? if (is_string($themeConfig)) { $themeName = $themeConfig; $themeConfig = []; } // Create new or Update existing? if (!$this->exists($themeName)) { $theme = new Theme($themeName); } else { $theme = $this->find($themeName); } // Load Values from config/themes.php if (isset($themeConfig['asset-path'])) { $theme->assetPath = $themeConfig['asset-path']; } if (isset($themeConfig['views-path'])) { $theme->viewsPath = $themeConfig['views-path']; } if (isset($themeConfig['extends'])) { $parentThemes[$themeName] = $themeConfig['extends']; } $theme->loadSettings(array_merge($theme->settings, $themeConfig)); } // All themes are loaded. Now we can assign the parents to the child-themes foreach ($parentThemes as $childName => $parentName) { $child = $this->find($childName); if ($this->exists($parentName)) { $parent = $this->find($parentName); } else { $parent = new Theme($parentName); } $child->setParent($parent); } }
php
public function scanThemes() { $parentThemes = []; $themesConfig = config('themes.themes', []); foreach ($this->loadThemesJson() as $data) { // Are theme settings overriden in config/themes.php? if (array_key_exists($data['name'], $themesConfig)) { $data = array_merge($data, $themesConfig[$data['name']]); } // Create theme $theme = new Theme( $data['name'], $data['asset-path'], $data['views-path'] ); // Has a parent theme? Store parent name to resolve later. if ($data['extends']) { $parentThemes[$theme->name] = $data['extends']; } // Load the rest of the values as theme Settings $theme->loadSettings($data); } // Add themes from config/themes.php foreach ($themesConfig as $themeName => $themeConfig) { // Is it an element with no values? if (is_string($themeConfig)) { $themeName = $themeConfig; $themeConfig = []; } // Create new or Update existing? if (!$this->exists($themeName)) { $theme = new Theme($themeName); } else { $theme = $this->find($themeName); } // Load Values from config/themes.php if (isset($themeConfig['asset-path'])) { $theme->assetPath = $themeConfig['asset-path']; } if (isset($themeConfig['views-path'])) { $theme->viewsPath = $themeConfig['views-path']; } if (isset($themeConfig['extends'])) { $parentThemes[$themeName] = $themeConfig['extends']; } $theme->loadSettings(array_merge($theme->settings, $themeConfig)); } // All themes are loaded. Now we can assign the parents to the child-themes foreach ($parentThemes as $childName => $parentName) { $child = $this->find($childName); if ($this->exists($parentName)) { $parent = $this->find($parentName); } else { $parent = new Theme($parentName); } $child->setParent($parent); } }
[ "public", "function", "scanThemes", "(", ")", "{", "$", "parentThemes", "=", "[", "]", ";", "$", "themesConfig", "=", "config", "(", "'themes.themes'", ",", "[", "]", ")", ";", "foreach", "(", "$", "this", "->", "loadThemesJson", "(", ")", "as", "$", ...
Scan all folders inside the themes path & config/themes.php If a "theme.json" file is found then load it and setup theme
[ "Scan", "all", "folders", "inside", "the", "themes", "path", "&", "config", "/", "themes", ".", "php", "If", "a", "theme", ".", "json", "file", "is", "found", "then", "load", "it", "and", "setup", "theme" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L233-L305
igaster/laravel-theme
src/Themes.php
Themes.url
public function url($filename) { // If no Theme set, return /$filename if (!$this->current()) { return "/" . ltrim($filename, '/'); } return $this->current()->url($filename); }
php
public function url($filename) { // If no Theme set, return /$filename if (!$this->current()) { return "/" . ltrim($filename, '/'); } return $this->current()->url($filename); }
[ "public", "function", "url", "(", "$", "filename", ")", "{", "// If no Theme set, return /$filename\r", "if", "(", "!", "$", "this", "->", "current", "(", ")", ")", "{", "return", "\"/\"", ".", "ltrim", "(", "$", "filename", ",", "'/'", ")", ";", "}", ...
Return url of current theme
[ "Return", "url", "of", "current", "theme" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L312-L320
igaster/laravel-theme
src/Themes.php
Themes.img
public function img($src, $alt = '', $class = '', $attributes = []) { return sprintf('<img src="%s" alt="%s" class="%s" %s>', $this->url($src), $alt, $class, $this->HtmlAttributes($attributes) ); }
php
public function img($src, $alt = '', $class = '', $attributes = []) { return sprintf('<img src="%s" alt="%s" class="%s" %s>', $this->url($src), $alt, $class, $this->HtmlAttributes($attributes) ); }
[ "public", "function", "img", "(", "$", "src", ",", "$", "alt", "=", "''", ",", "$", "class", "=", "''", ",", "$", "attributes", "=", "[", "]", ")", "{", "return", "sprintf", "(", "'<img src=\"%s\" alt=\"%s\" class=\"%s\" %s>'", ",", "$", "this", "->", ...
Return img tag @param string $src @param string $alt @param string $Class @param array $attributes @return string
[ "Return", "img", "tag" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L369-L377
igaster/laravel-theme
src/Themes.php
Themes.HtmlAttributes
private function HtmlAttributes($attributes) { $formatted = join(' ', array_map(function ($key) use ($attributes) { if (is_bool($attributes[$key])) { return $attributes[$key] ? $key : ''; } return $key . '="' . $attributes[$key] . '"'; }, array_keys($attributes))); return $formatted; }
php
private function HtmlAttributes($attributes) { $formatted = join(' ', array_map(function ($key) use ($attributes) { if (is_bool($attributes[$key])) { return $attributes[$key] ? $key : ''; } return $key . '="' . $attributes[$key] . '"'; }, array_keys($attributes))); return $formatted; }
[ "private", "function", "HtmlAttributes", "(", "$", "attributes", ")", "{", "$", "formatted", "=", "join", "(", "' '", ",", "array_map", "(", "function", "(", "$", "key", ")", "use", "(", "$", "attributes", ")", "{", "if", "(", "is_bool", "(", "$", "a...
Return attributes in html format @param array $attributes @return string
[ "Return", "attributes", "in", "html", "format" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Themes.php#L385-L394
igaster/laravel-theme
src/themeViewFinder.php
themeViewFinder.findNamespacedView
protected function findNamespacedView($name) { // Extract the $view and the $namespace parts list($namespace, $view) = $this->parseNamespaceSegments($name); $paths = $this->addThemeNamespacePaths($namespace); // Find and return the view return $this->findInPaths($view, $paths); }
php
protected function findNamespacedView($name) { // Extract the $view and the $namespace parts list($namespace, $view) = $this->parseNamespaceSegments($name); $paths = $this->addThemeNamespacePaths($namespace); // Find and return the view return $this->findInPaths($view, $paths); }
[ "protected", "function", "findNamespacedView", "(", "$", "name", ")", "{", "// Extract the $view and the $namespace parts\r", "list", "(", "$", "namespace", ",", "$", "view", ")", "=", "$", "this", "->", "parseNamespaceSegments", "(", "$", "name", ")", ";", "$",...
/* Override findNamespacedView() to add "Theme/vendor/..." paths @param string $name @return string
[ "/", "*", "Override", "findNamespacedView", "()", "to", "add", "Theme", "/", "vendor", "/", "...", "paths" ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/themeViewFinder.php#L22-L31
igaster/laravel-theme
src/themeViewFinder.php
themeViewFinder.replaceNamespace
public function replaceNamespace($namespace, $hints) { $this->hints[$namespace] = (array) $hints; // Overide Error Pages if ($namespace == 'errors' || $namespace == 'mails') { $searchPaths = array_diff($this->paths, Theme::getLaravelViewPaths()); $addPaths = array_map(function ($path) use ($namespace) { return "$path/$namespace"; }, $searchPaths); $this->prependNamespace($namespace, $addPaths); } }
php
public function replaceNamespace($namespace, $hints) { $this->hints[$namespace] = (array) $hints; // Overide Error Pages if ($namespace == 'errors' || $namespace == 'mails') { $searchPaths = array_diff($this->paths, Theme::getLaravelViewPaths()); $addPaths = array_map(function ($path) use ($namespace) { return "$path/$namespace"; }, $searchPaths); $this->prependNamespace($namespace, $addPaths); } }
[ "public", "function", "replaceNamespace", "(", "$", "namespace", ",", "$", "hints", ")", "{", "$", "this", "->", "hints", "[", "$", "namespace", "]", "=", "(", "array", ")", "$", "hints", ";", "// Overide Error Pages\r", "if", "(", "$", "namespace", "=="...
Override replaceNamespace() to add path for custom error pages "Theme/errors/..." @param string $namespace @param string|array $hints @return void
[ "Override", "replaceNamespace", "()", "to", "add", "path", "for", "custom", "error", "pages", "Theme", "/", "errors", "/", "..." ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/themeViewFinder.php#L95-L110
igaster/laravel-theme
src/Middleware/setTheme.php
setTheme.handle
public function handle($request, Closure $next, $themeName) { Theme::set($themeName); return $next($request); }
php
public function handle($request, Closure $next, $themeName) { Theme::set($themeName); return $next($request); }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ",", "$", "themeName", ")", "{", "Theme", "::", "set", "(", "$", "themeName", ")", ";", "return", "$", "next", "(", "$", "request", ")", ";", "}" ]
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @param string $themeName @return mixed
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/igaster/laravel-theme/blob/0b8be5dba752bbd9e8f1de31efb4a300aa19790e/src/Middleware/setTheme.php#L16-L20
ADmad/cakephp-social-auth
src/Http/Client.php
Client.request
public function request( $url, array $parameters = [], $method = SocialConnectClient::GET, array $headers = [], array $options = [] ) { switch ($method) { case SocialConnectClient::GET: $response = $this->_client->get( $url, $parameters, ['headers' => $headers] ); break; case SocialConnectClient::POST: $response = $this->_client->post( $url, $parameters, ['headers' => $headers] ); break; case SocialConnectClient::PUT: $response = $this->_client->put( $url, $parameters, ['headers' => $headers] ); break; case SocialConnectClient::DELETE: $response = $this->_client->delete( $url, $parameters, ['headers' => $headers] ); break; default: throw new InvalidArgumentException("Method {$method} is not supported"); } return new Response( $response->getStatusCode(), (string)$response->getBody(), $response->getHeaders() ); }
php
public function request( $url, array $parameters = [], $method = SocialConnectClient::GET, array $headers = [], array $options = [] ) { switch ($method) { case SocialConnectClient::GET: $response = $this->_client->get( $url, $parameters, ['headers' => $headers] ); break; case SocialConnectClient::POST: $response = $this->_client->post( $url, $parameters, ['headers' => $headers] ); break; case SocialConnectClient::PUT: $response = $this->_client->put( $url, $parameters, ['headers' => $headers] ); break; case SocialConnectClient::DELETE: $response = $this->_client->delete( $url, $parameters, ['headers' => $headers] ); break; default: throw new InvalidArgumentException("Method {$method} is not supported"); } return new Response( $response->getStatusCode(), (string)$response->getBody(), $response->getHeaders() ); }
[ "public", "function", "request", "(", "$", "url", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "method", "=", "SocialConnectClient", "::", "GET", ",", "array", "$", "headers", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ...
Request specify url. @param string $url Request URL. @param array $parameters Request parameters. @param string $method Request method. @param array $headers Request headers. @param array $options Unused. @return \SocialConnect\Common\Http\Response
[ "Request", "specify", "url", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Http/Client.php#L46-L91
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._handleLoginAction
protected function _handleLoginAction(ServerRequest $request, Response $response) { $request->allowMethod($this->getConfig('requestMethod')); $providerName = $request->getParam('provider'); $provider = $this->_getService($request)->getProvider($providerName); $authUrl = $provider->makeAuthUrl(); $this->_setRedirectUrl($request); return $response->withLocation($authUrl); }
php
protected function _handleLoginAction(ServerRequest $request, Response $response) { $request->allowMethod($this->getConfig('requestMethod')); $providerName = $request->getParam('provider'); $provider = $this->_getService($request)->getProvider($providerName); $authUrl = $provider->makeAuthUrl(); $this->_setRedirectUrl($request); return $response->withLocation($authUrl); }
[ "protected", "function", "_handleLoginAction", "(", "ServerRequest", "$", "request", ",", "Response", "$", "response", ")", "{", "$", "request", "->", "allowMethod", "(", "$", "this", "->", "getConfig", "(", "'requestMethod'", ")", ")", ";", "$", "providerName...
Handle login action, initiate authentication process. @param \Cake\Http\ServerRequest $request The request. @param \Cake\Http\Response $response The response. @return \Cake\Http\Response A response.
[ "Handle", "login", "action", "initiate", "authentication", "process", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L166-L177
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._handleCallbackAction
protected function _handleCallbackAction(ServerRequest $request, Response $response) { $this->_setupModelInstances(); $config = $this->getConfig(); $providerName = $request->getParam('provider'); $profile = $this->_getProfile($providerName, $request); if (!$profile) { return $response->withLocation( Router::url($config['loginUrl'], true) . '?error=' . $this->_error ); } $user = $this->_getUser($profile); if (!$user) { return $response->withLocation( Router::url($config['loginUrl'], true) . '?error=' . $this->_error ); } $user->unsetProperty($config['fields']['password']); if (!$config['userEntity']) { $user = $user->toArray(); } $event = $this->dispatchEvent(self::EVENT_AFTER_IDENTIFY, ['user' => $user]); $result = $event->getResult(); if ($result !== null) { $user = $event->getResult(); } $request->getSession()->write($config['sessionKey'], $user); return $response->withLocation( Router::url($this->_getRedirectUrl($request), true) ); }
php
protected function _handleCallbackAction(ServerRequest $request, Response $response) { $this->_setupModelInstances(); $config = $this->getConfig(); $providerName = $request->getParam('provider'); $profile = $this->_getProfile($providerName, $request); if (!$profile) { return $response->withLocation( Router::url($config['loginUrl'], true) . '?error=' . $this->_error ); } $user = $this->_getUser($profile); if (!$user) { return $response->withLocation( Router::url($config['loginUrl'], true) . '?error=' . $this->_error ); } $user->unsetProperty($config['fields']['password']); if (!$config['userEntity']) { $user = $user->toArray(); } $event = $this->dispatchEvent(self::EVENT_AFTER_IDENTIFY, ['user' => $user]); $result = $event->getResult(); if ($result !== null) { $user = $event->getResult(); } $request->getSession()->write($config['sessionKey'], $user); return $response->withLocation( Router::url($this->_getRedirectUrl($request), true) ); }
[ "protected", "function", "_handleCallbackAction", "(", "ServerRequest", "$", "request", ",", "Response", "$", "response", ")", "{", "$", "this", "->", "_setupModelInstances", "(", ")", ";", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", ...
Handle callback action. @param \Cake\Http\ServerRequest $request The request. @param \Cake\Http\Response $response The response. @return \Cake\Http\Response A response.
[ "Handle", "callback", "action", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L187-L225
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._setupModelInstances
protected function _setupModelInstances() { $this->_profileModel = $this->loadModel($this->getConfig('profileModel')); $this->_profileModel->belongsTo($this->getConfig('userModel')); $this->_userModel = $this->loadModel($this->getConfig('userModel')); }
php
protected function _setupModelInstances() { $this->_profileModel = $this->loadModel($this->getConfig('profileModel')); $this->_profileModel->belongsTo($this->getConfig('userModel')); $this->_userModel = $this->loadModel($this->getConfig('userModel')); }
[ "protected", "function", "_setupModelInstances", "(", ")", "{", "$", "this", "->", "_profileModel", "=", "$", "this", "->", "loadModel", "(", "$", "this", "->", "getConfig", "(", "'profileModel'", ")", ")", ";", "$", "this", "->", "_profileModel", "->", "b...
Setup model instances. @return void
[ "Setup", "model", "instances", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L232-L238
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._getProfile
protected function _getProfile($providerName, ServerRequest $request) { try { $provider = $this->_getService($request)->getProvider($providerName); $accessToken = $provider->getAccessTokenByRequestParameters($request->getQueryParams()); $identity = $provider->getIdentity($accessToken); } catch (SocialConnectException $e) { $this->_error = 'provider_failure'; if ($this->getConfig('logErrors')) { Log::error($this->_getLogMessage($request, $e)); } return null; } $profile = $this->_profileModel->find() ->where([ $this->_profileModel->aliasField('provider') => $providerName, $this->_profileModel->aliasField('identifier') => $identity->id, ]) ->first(); $profile = $this->_patchProfile( $providerName, $identity, $accessToken, $profile ?: null ); if ($profile->isDirty()) { $this->_saveProfile($profile); } return $profile; }
php
protected function _getProfile($providerName, ServerRequest $request) { try { $provider = $this->_getService($request)->getProvider($providerName); $accessToken = $provider->getAccessTokenByRequestParameters($request->getQueryParams()); $identity = $provider->getIdentity($accessToken); } catch (SocialConnectException $e) { $this->_error = 'provider_failure'; if ($this->getConfig('logErrors')) { Log::error($this->_getLogMessage($request, $e)); } return null; } $profile = $this->_profileModel->find() ->where([ $this->_profileModel->aliasField('provider') => $providerName, $this->_profileModel->aliasField('identifier') => $identity->id, ]) ->first(); $profile = $this->_patchProfile( $providerName, $identity, $accessToken, $profile ?: null ); if ($profile->isDirty()) { $this->_saveProfile($profile); } return $profile; }
[ "protected", "function", "_getProfile", "(", "$", "providerName", ",", "ServerRequest", "$", "request", ")", "{", "try", "{", "$", "provider", "=", "$", "this", "->", "_getService", "(", "$", "request", ")", "->", "getProvider", "(", "$", "providerName", "...
Get social profile record. @param string $providerName Provider name. @param \Cake\Http\ServerRequest $request Request instance. @return \Cake\Datasource\EntityInterface|null
[ "Get", "social", "profile", "record", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L248-L282
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._getUser
protected function _getUser($profile) { $user = null; if ($profile->get('user_id')) { $userPkField = $this->_userModel->aliasField((string)$this->_userModel->getPrimaryKey()); $user = $this->_userModel->find() ->where([ $userPkField => $profile->get('user_id'), ]) ->find($this->getConfig('finder')) ->first(); } if (!$user) { if ($profile->get('user_id')) { $this->_error = 'finder_failure'; return null; } $user = $this->_getUserEntity($profile); $profile->set('user_id', $user->id); } if ($profile->isDirty()) { $this->_saveProfile($profile); } $user->set('social_profile', $profile); $user->unsetProperty($this->getConfig('fields.password')); return $user; }
php
protected function _getUser($profile) { $user = null; if ($profile->get('user_id')) { $userPkField = $this->_userModel->aliasField((string)$this->_userModel->getPrimaryKey()); $user = $this->_userModel->find() ->where([ $userPkField => $profile->get('user_id'), ]) ->find($this->getConfig('finder')) ->first(); } if (!$user) { if ($profile->get('user_id')) { $this->_error = 'finder_failure'; return null; } $user = $this->_getUserEntity($profile); $profile->set('user_id', $user->id); } if ($profile->isDirty()) { $this->_saveProfile($profile); } $user->set('social_profile', $profile); $user->unsetProperty($this->getConfig('fields.password')); return $user; }
[ "protected", "function", "_getUser", "(", "$", "profile", ")", "{", "$", "user", "=", "null", ";", "if", "(", "$", "profile", "->", "get", "(", "'user_id'", ")", ")", "{", "$", "userPkField", "=", "$", "this", "->", "_userModel", "->", "aliasField", ...
Get user record. @param \Cake\Datasource\EntityInterface $profile Social profile entity @return array|\Cake\Datasource\EntityInterface|null User array or entity on success, null on failure.
[ "Get", "user", "record", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L292-L326
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._patchProfile
protected function _patchProfile( $providerName, SocialConnectUser $identity, AccessTokenInterface $accessToken, EntityInterface $profile = null ) { if ($profile === null) { $profile = $this->_profileModel->newEntity([ 'provider' => $providerName, ]); } $data = [ 'access_token' => $accessToken, ]; foreach (get_object_vars($identity) as $key => $value) { switch ($key) { case 'id': $data['identifier'] = $value; break; case 'lastname': $data['last_name'] = $value; break; case 'firstname': $data['first_name'] = $value; break; case 'birthday': $data['birth_date'] = $value; break; case 'emailVerified': $data['email_verified'] = $value; break; case 'fullname': $data['full_name'] = $value; break; case 'sex': $data['gender'] = $value; break; case 'pictureURL': $data['picture_url'] = $value; break; default: $data[$key] = $value; break; } } return $this->_profileModel->patchEntity($profile, $data); }
php
protected function _patchProfile( $providerName, SocialConnectUser $identity, AccessTokenInterface $accessToken, EntityInterface $profile = null ) { if ($profile === null) { $profile = $this->_profileModel->newEntity([ 'provider' => $providerName, ]); } $data = [ 'access_token' => $accessToken, ]; foreach (get_object_vars($identity) as $key => $value) { switch ($key) { case 'id': $data['identifier'] = $value; break; case 'lastname': $data['last_name'] = $value; break; case 'firstname': $data['first_name'] = $value; break; case 'birthday': $data['birth_date'] = $value; break; case 'emailVerified': $data['email_verified'] = $value; break; case 'fullname': $data['full_name'] = $value; break; case 'sex': $data['gender'] = $value; break; case 'pictureURL': $data['picture_url'] = $value; break; default: $data[$key] = $value; break; } } return $this->_profileModel->patchEntity($profile, $data); }
[ "protected", "function", "_patchProfile", "(", "$", "providerName", ",", "SocialConnectUser", "$", "identity", ",", "AccessTokenInterface", "$", "accessToken", ",", "EntityInterface", "$", "profile", "=", "null", ")", "{", "if", "(", "$", "profile", "===", "null...
Get social profile entity. @param string $providerName Provider name. @param \SocialConnect\Common\Entity\User $identity Social connect entity. @param \SocialConnect\Provider\AccessTokenInterface $accessToken Access token @param \Cake\Datasource\EntityInterface $profile Social profile entity @return \Cake\Datasource\EntityInterface
[ "Get", "social", "profile", "entity", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L338-L387
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._getUserEntity
protected function _getUserEntity(EntityInterface $profile) { $callbackMethod = $this->getConfig('getUserCallback'); $user = call_user_func([$this->_userModel, $callbackMethod], $profile); if (!($user instanceof EntityInterface)) { throw new RuntimeException('"getUserCallback" method must return a user entity.'); } return $user; }
php
protected function _getUserEntity(EntityInterface $profile) { $callbackMethod = $this->getConfig('getUserCallback'); $user = call_user_func([$this->_userModel, $callbackMethod], $profile); if (!($user instanceof EntityInterface)) { throw new RuntimeException('"getUserCallback" method must return a user entity.'); } return $user; }
[ "protected", "function", "_getUserEntity", "(", "EntityInterface", "$", "profile", ")", "{", "$", "callbackMethod", "=", "$", "this", "->", "getConfig", "(", "'getUserCallback'", ")", ";", "$", "user", "=", "call_user_func", "(", "[", "$", "this", "->", "_us...
Get new user entity. The method specified in "getUserCallback" will be called on the User model with profile entity. The method should return a persisted user entity. @param \Cake\Datasource\EntityInterface $profile Social profile entity. @return \Cake\Datasource\EntityInterface User entity.
[ "Get", "new", "user", "entity", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L399-L410
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._getService
protected function _getService(ServerRequest $request) { if ($this->_service !== null) { return $this->_service; } $serviceConfig = $this->getConfig('serviceConfig'); if (empty($serviceConfig)) { Configure::load('social_auth'); $serviceConfig = Configure::consume('SocialAuth'); } $serviceConfig['redirectUri'] = Router::url([ 'plugin' => 'ADmad/SocialAuth', 'controller' => 'Auth', 'action' => 'callback', ], true); $request->getSession()->start(); $httpClient = $this->getConfig('httpClient'); if (is_string($httpClient)) { $httpClient = new $httpClient(); } $this->_service = new Service( $httpClient, new Session(), $serviceConfig ); return $this->_service; }
php
protected function _getService(ServerRequest $request) { if ($this->_service !== null) { return $this->_service; } $serviceConfig = $this->getConfig('serviceConfig'); if (empty($serviceConfig)) { Configure::load('social_auth'); $serviceConfig = Configure::consume('SocialAuth'); } $serviceConfig['redirectUri'] = Router::url([ 'plugin' => 'ADmad/SocialAuth', 'controller' => 'Auth', 'action' => 'callback', ], true); $request->getSession()->start(); $httpClient = $this->getConfig('httpClient'); if (is_string($httpClient)) { $httpClient = new $httpClient(); } $this->_service = new Service( $httpClient, new Session(), $serviceConfig ); return $this->_service; }
[ "protected", "function", "_getService", "(", "ServerRequest", "$", "request", ")", "{", "if", "(", "$", "this", "->", "_service", "!==", "null", ")", "{", "return", "$", "this", "->", "_service", ";", "}", "$", "serviceConfig", "=", "$", "this", "->", ...
Get social connect service instance. @param \Cake\Http\ServerRequest $request Request instance. @return \SocialConnect\Auth\Service
[ "Get", "social", "connect", "service", "instance", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L435-L467
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._setRedirectUrl
protected function _setRedirectUrl(ServerRequest $request) { $request->getSession()->delete('SocialAuth.redirectUrl'); $redirectUrl = $request->getQuery(static::QUERY_STRING_REDIRECT); if (empty($redirectUrl) || substr($redirectUrl, 0, 1) !== '/' || substr($redirectUrl, 0, 2) === '//' ) { return; } $request->getSession()->write('SocialAuth.redirectUrl', $redirectUrl); }
php
protected function _setRedirectUrl(ServerRequest $request) { $request->getSession()->delete('SocialAuth.redirectUrl'); $redirectUrl = $request->getQuery(static::QUERY_STRING_REDIRECT); if (empty($redirectUrl) || substr($redirectUrl, 0, 1) !== '/' || substr($redirectUrl, 0, 2) === '//' ) { return; } $request->getSession()->write('SocialAuth.redirectUrl', $redirectUrl); }
[ "protected", "function", "_setRedirectUrl", "(", "ServerRequest", "$", "request", ")", "{", "$", "request", "->", "getSession", "(", ")", "->", "delete", "(", "'SocialAuth.redirectUrl'", ")", ";", "$", "redirectUrl", "=", "$", "request", "->", "getQuery", "(",...
Save URL to redirect to after authentication to session. @param \Cake\Http\ServerRequest $request Request instance. @return void
[ "Save", "URL", "to", "redirect", "to", "after", "authentication", "to", "session", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L476-L489
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._getRedirectUrl
protected function _getRedirectUrl(ServerRequest $request) { $redirectUrl = $request->getSession()->read('SocialAuth.redirectUrl'); if ($redirectUrl) { $request->getSession()->delete('SocialAuth.redirectUrl'); return $redirectUrl; } return $this->getConfig('loginRedirect'); }
php
protected function _getRedirectUrl(ServerRequest $request) { $redirectUrl = $request->getSession()->read('SocialAuth.redirectUrl'); if ($redirectUrl) { $request->getSession()->delete('SocialAuth.redirectUrl'); return $redirectUrl; } return $this->getConfig('loginRedirect'); }
[ "protected", "function", "_getRedirectUrl", "(", "ServerRequest", "$", "request", ")", "{", "$", "redirectUrl", "=", "$", "request", "->", "getSession", "(", ")", "->", "read", "(", "'SocialAuth.redirectUrl'", ")", ";", "if", "(", "$", "redirectUrl", ")", "{...
Get URL to redirect to after authentication. @param \Cake\Http\ServerRequest $request Request instance. @return string|array
[ "Get", "URL", "to", "redirect", "to", "after", "authentication", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L498-L508
ADmad/cakephp-social-auth
src/Middleware/SocialAuthMiddleware.php
SocialAuthMiddleware._getLogMessage
protected function _getLogMessage($request, $exception) { $message = sprintf( '[%s] %s', get_class($exception), $exception->getMessage() ); $message .= "\nRequest URL: " . $request->getRequestTarget(); $referer = $request->getHeaderLine('Referer'); if ($referer) { $message .= "\nReferer URL: " . $referer; } if ($exception instanceof InvalidResponse && $exception->getResponse()) { $message .= "\nProvider Response: " . $exception->getResponse()->getBody(); } $message .= "\nStack Trace:\n" . $exception->getTraceAsString() . "\n\n"; return $message; }
php
protected function _getLogMessage($request, $exception) { $message = sprintf( '[%s] %s', get_class($exception), $exception->getMessage() ); $message .= "\nRequest URL: " . $request->getRequestTarget(); $referer = $request->getHeaderLine('Referer'); if ($referer) { $message .= "\nReferer URL: " . $referer; } if ($exception instanceof InvalidResponse && $exception->getResponse()) { $message .= "\nProvider Response: " . $exception->getResponse()->getBody(); } $message .= "\nStack Trace:\n" . $exception->getTraceAsString() . "\n\n"; return $message; }
[ "protected", "function", "_getLogMessage", "(", "$", "request", ",", "$", "exception", ")", "{", "$", "message", "=", "sprintf", "(", "'[%s] %s'", ",", "get_class", "(", "$", "exception", ")", ",", "$", "exception", "->", "getMessage", "(", ")", ")", ";"...
Generate the error log message. @param \Psr\Http\Message\ServerRequestInterface $request The current request. @param \Exception $exception The exception to log a message for. @return string Error message
[ "Generate", "the", "error", "log", "message", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Middleware/SocialAuthMiddleware.php#L518-L540
ADmad/cakephp-social-auth
src/Database/Type/SerializeType.php
SerializeType.toDatabase
public function toDatabase($value, Driver $driver) { if ($value === null || is_string($value)) { return $value; } return serialize($value); }
php
public function toDatabase($value, Driver $driver) { if ($value === null || is_string($value)) { return $value; } return serialize($value); }
[ "public", "function", "toDatabase", "(", "$", "value", ",", "Driver", "$", "driver", ")", "{", "if", "(", "$", "value", "===", "null", "||", "is_string", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "return", "serialize", "(", ...
Convert a value data into a serialized string. @param mixed $value The value to convert. @param \Cake\Database\Driver $driver The driver instance to convert with. @return string|null
[ "Convert", "a", "value", "data", "into", "a", "serialized", "string", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Database/Type/SerializeType.php#L26-L33
ADmad/cakephp-social-auth
src/Database/Type/SerializeType.php
SerializeType.toStatement
public function toStatement($value, Driver $driver) { if ($value === null) { return PDO::PARAM_NULL; } return PDO::PARAM_LOB; }
php
public function toStatement($value, Driver $driver) { if ($value === null) { return PDO::PARAM_NULL; } return PDO::PARAM_LOB; }
[ "public", "function", "toStatement", "(", "$", "value", ",", "Driver", "$", "driver", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "PDO", "::", "PARAM_NULL", ";", "}", "return", "PDO", "::", "PARAM_LOB", ";", "}" ]
Get the correct PDO binding type for string data. @param mixed $value The value being bound. @param \Cake\Database\Driver $driver The driver. @return int
[ "Get", "the", "correct", "PDO", "binding", "type", "for", "string", "data", "." ]
train
https://github.com/ADmad/cakephp-social-auth/blob/5816ee3b616ae649f1ef7affa6d1181126e95c6d/src/Database/Type/SerializeType.php#L60-L67
zestframework/Zest_Framework
src/Validation/Validation.php
Validation.jsonCompile
public function jsonCompile($data, $policie) { $passed = call_user_func_array([new JsonRules(), $policie], [$data]); if ($passed !== true) { Handler::set($this->messages[$policie], 'json'); } }
php
public function jsonCompile($data, $policie) { $passed = call_user_func_array([new JsonRules(), $policie], [$data]); if ($passed !== true) { Handler::set($this->messages[$policie], 'json'); } }
[ "public", "function", "jsonCompile", "(", "$", "data", ",", "$", "policie", ")", "{", "$", "passed", "=", "call_user_func_array", "(", "[", "new", "JsonRules", "(", ")", ",", "$", "policie", "]", ",", "[", "$", "data", "]", ")", ";", "if", "(", "$"...
Compile Json. @param $data (array) ['policies'] => policies ['value'] => Value to be checked ['field'] => field name @return string
[ "Compile", "Json", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Validation/Validation.php#L53-L59
zestframework/Zest_Framework
src/Validation/Validation.php
Validation.databaseCompile
public function databaseCompile($data, $table) { $rule = 'unique'; $passed = call_user_func_array([new databaseRules(), $rule], [$data['field'], $data['value'], $table]); if ($passed !== true) { Handler::set( str_replace(':field', $data['field'], $this->messages[$rule]), $data['field']); } }
php
public function databaseCompile($data, $table) { $rule = 'unique'; $passed = call_user_func_array([new databaseRules(), $rule], [$data['field'], $data['value'], $table]); if ($passed !== true) { Handler::set( str_replace(':field', $data['field'], $this->messages[$rule]), $data['field']); } }
[ "public", "function", "databaseCompile", "(", "$", "data", ",", "$", "table", ")", "{", "$", "rule", "=", "'unique'", ";", "$", "passed", "=", "call_user_func_array", "(", "[", "new", "databaseRules", "(", ")", ",", "$", "rule", "]", ",", "[", "$", "...
Compile Database Unique. @param $data (array) ['policies'] => policies ['value'] => Value to be checked ['field'] => field name @return string
[ "Compile", "Database", "Unique", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Validation/Validation.php#L71-L79
zestframework/Zest_Framework
src/Validation/Validation.php
Validation.inputCompile
public function inputCompile(array $data) { foreach ($data['policies'] as $rule => $policy) { $passed = call_user_func_array([new InputRules(), $rule], [$data['value']]); if ($passed !== true) { Handler::set( str_replace(':field', $data['field'], $this->messages[$rule]), $data['field']); } } }
php
public function inputCompile(array $data) { foreach ($data['policies'] as $rule => $policy) { $passed = call_user_func_array([new InputRules(), $rule], [$data['value']]); if ($passed !== true) { Handler::set( str_replace(':field', $data['field'], $this->messages[$rule]), $data['field']); } } }
[ "public", "function", "inputCompile", "(", "array", "$", "data", ")", "{", "foreach", "(", "$", "data", "[", "'policies'", "]", "as", "$", "rule", "=>", "$", "policy", ")", "{", "$", "passed", "=", "call_user_func_array", "(", "[", "new", "InputRules", ...
Compile input. @param $data (array) ['policies'] => policies ['value'] => Value to be checked ['field'] => field name @return string
[ "Compile", "input", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Validation/Validation.php#L91-L100
zestframework/Zest_Framework
src/Validation/Validation.php
Validation.make
public function make($data, $policies, $type) { if ($type === 'input') { foreach ($data as $field => $value) { if (array_key_exists($field, $policies)) { $this->inputCompile( ['field' => $field, 'value' => $value, 'policies' => $policies[$field]] ); } } } elseif ($type === 'json') { $this->jsonCompile($data, $policies); } elseif ($type === 'database') { $this->databaseCompile($data, $policies); } }
php
public function make($data, $policies, $type) { if ($type === 'input') { foreach ($data as $field => $value) { if (array_key_exists($field, $policies)) { $this->inputCompile( ['field' => $field, 'value' => $value, 'policies' => $policies[$field]] ); } } } elseif ($type === 'json') { $this->jsonCompile($data, $policies); } elseif ($type === 'database') { $this->databaseCompile($data, $policies); } }
[ "public", "function", "make", "(", "$", "data", ",", "$", "policies", ",", "$", "type", ")", "{", "if", "(", "$", "type", "===", "'input'", ")", "{", "foreach", "(", "$", "data", "as", "$", "field", "=>", "$", "value", ")", "{", "if", "(", "arr...
Compile input. @param $data (array) ['policies'] => policies ['value'] => Value to be checked ['field'] => field name @return string
[ "Compile", "input", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Validation/Validation.php#L112-L127
zestframework/Zest_Framework
src/http/Clients/CURL.php
CURL.setMethod
public function setMethod($method) { parent::setMethod($method); if ($method !== 'GET') { switch ($method) { case 'POST': $this->setOption(CURLOPT_POST, true); break; default: $this->setOption(CURLOPT_CUSTOMREQUEST, $this->method); break; } } return $this; }
php
public function setMethod($method) { parent::setMethod($method); if ($method !== 'GET') { switch ($method) { case 'POST': $this->setOption(CURLOPT_POST, true); break; default: $this->setOption(CURLOPT_CUSTOMREQUEST, $this->method); break; } } return $this; }
[ "public", "function", "setMethod", "(", "$", "method", ")", "{", "parent", "::", "setMethod", "(", "$", "method", ")", ";", "if", "(", "$", "method", "!==", "'GET'", ")", "{", "switch", "(", "$", "method", ")", "{", "case", "'POST'", ":", "$", "thi...
Set the method. @param (string) $method @since 3.0.0 @return object
[ "Set", "the", "method", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Clients/CURL.php#L57-L72
zestframework/Zest_Framework
src/http/Clients/CURL.php
CURL.open
public function open() { $url = $this->url; $headers = []; // Set query data if there is any if (count($this->fields) > 0) { if ($this->method == 'GET') { $url = $this->options[CURLOPT_URL].'?'.$this->getQuery(); $this->setOption(CURLOPT_URL, $url); } else { if (isset($this->requestHeaders['Content-Type']) && ($this->requestHeaders['Content-Type'] != 'multipart/form-data')) { $this->setOption(CURLOPT_POSTFIELDS, $this->getQuery()); $this->setRequestHeader('Content-Length', $this->getQueryLength()); } else { $this->setOption(CURLOPT_POSTFIELDS, $this->fields); } $this->setOption(CURLOPT_POSTFIELDS, $this->fields); $this->setOption(CURLOPT_URL, $url); } } if ($this->hasRequestHeaders()) { foreach ($this->requestHeaders as $header => $value) { $headers[] = $header.': '.$value; } $this->setOption(CURLOPT_HTTPHEADER, $headers); } $this->response = curl_exec($this->resource); if ($this->response === false) { $this->throwError('Error: '.curl_errno($this->resource).' => '.curl_error($this->resource).'.'); } return $this; }
php
public function open() { $url = $this->url; $headers = []; // Set query data if there is any if (count($this->fields) > 0) { if ($this->method == 'GET') { $url = $this->options[CURLOPT_URL].'?'.$this->getQuery(); $this->setOption(CURLOPT_URL, $url); } else { if (isset($this->requestHeaders['Content-Type']) && ($this->requestHeaders['Content-Type'] != 'multipart/form-data')) { $this->setOption(CURLOPT_POSTFIELDS, $this->getQuery()); $this->setRequestHeader('Content-Length', $this->getQueryLength()); } else { $this->setOption(CURLOPT_POSTFIELDS, $this->fields); } $this->setOption(CURLOPT_POSTFIELDS, $this->fields); $this->setOption(CURLOPT_URL, $url); } } if ($this->hasRequestHeaders()) { foreach ($this->requestHeaders as $header => $value) { $headers[] = $header.': '.$value; } $this->setOption(CURLOPT_HTTPHEADER, $headers); } $this->response = curl_exec($this->resource); if ($this->response === false) { $this->throwError('Error: '.curl_errno($this->resource).' => '.curl_error($this->resource).'.'); } return $this; }
[ "public", "function", "open", "(", ")", "{", "$", "url", "=", "$", "this", "->", "url", ";", "$", "headers", "=", "[", "]", ";", "// Set query data if there is any", "if", "(", "count", "(", "$", "this", "->", "fields", ")", ">", "0", ")", "{", "if...
Create and open cURL resource. @since 3.0.0 @return object
[ "Create", "and", "open", "cURL", "resource", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Clients/CURL.php#L93-L129
zestframework/Zest_Framework
src/http/Clients/CURL.php
CURL.setOption
public function setOption($option, $value) { $this->options[$option] = $value; curl_setopt($this->resource, $option, $value); return $this; }
php
public function setOption($option, $value) { $this->options[$option] = $value; curl_setopt($this->resource, $option, $value); return $this; }
[ "public", "function", "setOption", "(", "$", "option", ",", "$", "value", ")", "{", "$", "this", "->", "options", "[", "$", "option", "]", "=", "$", "value", ";", "curl_setopt", "(", "$", "this", "->", "resource", ",", "$", "option", ",", "$", "val...
Set curl session option. @param (mixed) $option (mixed) $value @since 3.0.0 @return object
[ "Set", "curl", "session", "option", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Clients/CURL.php#L141-L147
zestframework/Zest_Framework
src/http/Clients/CURL.php
CURL.setOptios
public function setOptios($options) { foreach ($options as $option => $value) { $this->setOption($option, $value); } curl_setopt_array($this->resource, $options); return $this; }
php
public function setOptios($options) { foreach ($options as $option => $value) { $this->setOption($option, $value); } curl_setopt_array($this->resource, $options); return $this; }
[ "public", "function", "setOptios", "(", "$", "options", ")", "{", "foreach", "(", "$", "options", "as", "$", "option", "=>", "$", "value", ")", "{", "$", "this", "->", "setOption", "(", "$", "option", ",", "$", "value", ")", ";", "}", "curl_setopt_ar...
Set curl session options. @param (array) $options @since 3.0.0 @return object
[ "Set", "curl", "session", "options", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Clients/CURL.php#L158-L166
zestframework/Zest_Framework
src/http/Clients/CURL.php
CURL.getInfo
public function getInfo($option = null) { return ($option !== null) ? curl_getinfo($this->resource, $option) : curl_getinfo($this->resource); }
php
public function getInfo($option = null) { return ($option !== null) ? curl_getinfo($this->resource, $option) : curl_getinfo($this->resource); }
[ "public", "function", "getInfo", "(", "$", "option", "=", "null", ")", "{", "return", "(", "$", "option", "!==", "null", ")", "?", "curl_getinfo", "(", "$", "this", "->", "resource", ",", "$", "option", ")", ":", "curl_getinfo", "(", "$", "this", "->...
Get curl last session info. @param (mixes) $option @since 3.0.0 @return mixes
[ "Get", "curl", "last", "session", "info", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Clients/CURL.php#L247-L250
zestframework/Zest_Framework
src/http/Clients/CURL.php
CURL.send
public function send() { $this->open(); if ($this->response === false) { throw new \Exception('Error: '.curl_errno($this->resource).' => '.curl_error($this->resource).'.'); } // If the CURLOPT_RETURNTRANSFER option is set to true, get the response body and parse the headers. if (isset($this->options[CURLOPT_RETURNTRANSFER]) && ($this->options[CURLOPT_RETURNTRANSFER] == true)) { $headerSize = $this->getInfo(CURLINFO_HEADER_SIZE); if ($this->options[CURLOPT_HEADER]) { $this->responseHeader = substr($this->response, 0, $headerSize); $this->body = substr($this->response, $headerSize); $this->parseResponseHeaders(); } else { $this->body = $this->response; } } if (array_key_exists('Content-Encoding', $this->responseHeaders)) { $this->decodeBody(); } }
php
public function send() { $this->open(); if ($this->response === false) { throw new \Exception('Error: '.curl_errno($this->resource).' => '.curl_error($this->resource).'.'); } // If the CURLOPT_RETURNTRANSFER option is set to true, get the response body and parse the headers. if (isset($this->options[CURLOPT_RETURNTRANSFER]) && ($this->options[CURLOPT_RETURNTRANSFER] == true)) { $headerSize = $this->getInfo(CURLINFO_HEADER_SIZE); if ($this->options[CURLOPT_HEADER]) { $this->responseHeader = substr($this->response, 0, $headerSize); $this->body = substr($this->response, $headerSize); $this->parseResponseHeaders(); } else { $this->body = $this->response; } } if (array_key_exists('Content-Encoding', $this->responseHeaders)) { $this->decodeBody(); } }
[ "public", "function", "send", "(", ")", "{", "$", "this", "->", "open", "(", ")", ";", "if", "(", "$", "this", "->", "response", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Error: '", ".", "curl_errno", "(", "$", "this", "->...
Method to send the request and get the response. @since 3.0.0 @return void
[ "Method", "to", "send", "the", "request", "and", "get", "the", "response", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Clients/CURL.php#L259-L281
zestframework/Zest_Framework
src/http/Clients/CURL.php
CURL.parseResponseHeaders
protected function parseResponseHeaders() { if ($this->responseHeader !== null) { $headers = explode("\n", $this->responseHeader); foreach ($headers as $header) { if (strpos($header, 'HTTP') !== false) { $this->version = substr($header, 0, strpos($header, ' ')); $this->version = substr($this->version, (strpos($this->version, '/') + 1)); preg_match('/\d\d\d/', trim($header), $match); $this->code = $match[0]; $this->message = trim(str_replace('HTTP/'.$this->version.' '.$this->code.' ', '', $header)); } elseif (strpos($header, ':') !== false) { $name = substr($header, 0, strpos($header, ':')); $value = substr($header, strpos($header, ':') + 1); $this->responseHeaders[trim($name)] = trim($value); } } } }
php
protected function parseResponseHeaders() { if ($this->responseHeader !== null) { $headers = explode("\n", $this->responseHeader); foreach ($headers as $header) { if (strpos($header, 'HTTP') !== false) { $this->version = substr($header, 0, strpos($header, ' ')); $this->version = substr($this->version, (strpos($this->version, '/') + 1)); preg_match('/\d\d\d/', trim($header), $match); $this->code = $match[0]; $this->message = trim(str_replace('HTTP/'.$this->version.' '.$this->code.' ', '', $header)); } elseif (strpos($header, ':') !== false) { $name = substr($header, 0, strpos($header, ':')); $value = substr($header, strpos($header, ':') + 1); $this->responseHeaders[trim($name)] = trim($value); } } } }
[ "protected", "function", "parseResponseHeaders", "(", ")", "{", "if", "(", "$", "this", "->", "responseHeader", "!==", "null", ")", "{", "$", "headers", "=", "explode", "(", "\"\\n\"", ",", "$", "this", "->", "responseHeader", ")", ";", "foreach", "(", "...
Parse headers. @since 3.0.0 @return void
[ "Parse", "headers", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Clients/CURL.php#L316-L334
zestframework/Zest_Framework
src/Image/Avatar/AGd.php
AGd.genImage
public function genImage() { $this->image = imagecreatetruecolor($this->getPxRatio() * 5, $this->getPxRatio() * 5); $bg = $this->getBgColor(); if (!empty($bg)) { $background = imagecolorallocate($this->image, $bg[0], $bg[1], $bg[2]); imagefill($this->image, 0, 0, $background); } else { $transparent = imagecolorallocatealpha($this->image, 255, 255, 255, 127); imagefill($this->image, 0, 0, $transparent); imagesavealpha($this->image, true); } $color = $this->getColor(); $color = imagecolorallocate($this->image, $color[0], $color[1], $color[2]); $font = __DIR__.DIRECTORY_SEPARATOR.'\fonts\arial.ttf'; imagettftext($this->image, $this->getPxRatio() * 3, 0, round(($this->getPxRatio() * 5) / 5.5), round(($this->getPxRatio() * 5) / 1.3), $color, $font, $this->getCharacter()); return $this->image; }
php
public function genImage() { $this->image = imagecreatetruecolor($this->getPxRatio() * 5, $this->getPxRatio() * 5); $bg = $this->getBgColor(); if (!empty($bg)) { $background = imagecolorallocate($this->image, $bg[0], $bg[1], $bg[2]); imagefill($this->image, 0, 0, $background); } else { $transparent = imagecolorallocatealpha($this->image, 255, 255, 255, 127); imagefill($this->image, 0, 0, $transparent); imagesavealpha($this->image, true); } $color = $this->getColor(); $color = imagecolorallocate($this->image, $color[0], $color[1], $color[2]); $font = __DIR__.DIRECTORY_SEPARATOR.'\fonts\arial.ttf'; imagettftext($this->image, $this->getPxRatio() * 3, 0, round(($this->getPxRatio() * 5) / 5.5), round(($this->getPxRatio() * 5) / 1.3), $color, $font, $this->getCharacter()); return $this->image; }
[ "public", "function", "genImage", "(", ")", "{", "$", "this", "->", "image", "=", "imagecreatetruecolor", "(", "$", "this", "->", "getPxRatio", "(", ")", "*", "5", ",", "$", "this", "->", "getPxRatio", "(", ")", "*", "5", ")", ";", "$", "bg", "=", ...
Generate the iamge. @since 3.0.0 @return resource
[ "Generate", "the", "iamge", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Image/Avatar/AGd.php#L37-L56
zestframework/Zest_Framework
src/Image/Avatar/AGd.php
AGd.getImgBinary
public function getImgBinary($string, $size = '', $color = '', $bg = '') { ob_start(); imagepng($this->getImgResource($string, $size, $color, $bg)); return ob_get_clean(); }
php
public function getImgBinary($string, $size = '', $color = '', $bg = '') { ob_start(); imagepng($this->getImgResource($string, $size, $color, $bg)); return ob_get_clean(); }
[ "public", "function", "getImgBinary", "(", "$", "string", ",", "$", "size", "=", "''", ",", "$", "color", "=", "''", ",", "$", "bg", "=", "''", ")", "{", "ob_start", "(", ")", ";", "imagepng", "(", "$", "this", "->", "getImgResource", "(", "$", "...
Get Image binary data. @param $string string. $size side of image. $color foreground color of image. $bg background color of image. @since 3.0.0 @return binary
[ "Get", "Image", "binary", "data", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Image/Avatar/AGd.php#L70-L76
zestframework/Zest_Framework
src/Image/Avatar/AGd.php
AGd.getImgResource
public function getImgResource($string, $size = '', $color = '', $bg = '') { return $this->setHashString($string)->setSize($size)->setColor($color)->setBgColor($bg)->genImage(); }
php
public function getImgResource($string, $size = '', $color = '', $bg = '') { return $this->setHashString($string)->setSize($size)->setColor($color)->setBgColor($bg)->genImage(); }
[ "public", "function", "getImgResource", "(", "$", "string", ",", "$", "size", "=", "''", ",", "$", "color", "=", "''", ",", "$", "bg", "=", "''", ")", "{", "return", "$", "this", "->", "setHashString", "(", "$", "string", ")", "->", "setSize", "(",...
Get Image resource data. @param $string string. $size side of image. $color foreground color of image. $bg background color of image. @since 3.0.0 @return resource
[ "Get", "Image", "resource", "data", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Image/Avatar/AGd.php#L90-L93
zestframework/Zest_Framework
src/http/Headers.php
Headers.update
public function update($key, $value) { if (!empty($this->get($this->normalizeKey($key)))) { $this->headers[$this->normalizeKey($key)] = $value; } }
php
public function update($key, $value) { if (!empty($this->get($this->normalizeKey($key)))) { $this->headers[$this->normalizeKey($key)] = $value; } }
[ "public", "function", "update", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "get", "(", "$", "this", "->", "normalizeKey", "(", "$", "key", ")", ")", ")", ")", "{", "$", "this", "->", "headers"...
Update existing header. @param (string) $key The header key @param (string) $value The new header value @since 3.0.0 @return void
[ "Update", "existing", "header", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Headers.php#L92-L97
zestframework/Zest_Framework
src/http/Headers.php
Headers.has
public function has($key) { return (isset($this->headers[$this->normalizeKey($key)])) ? true : false; }
php
public function has($key) { return (isset($this->headers[$this->normalizeKey($key)])) ? true : false; }
[ "public", "function", "has", "(", "$", "key", ")", "{", "return", "(", "isset", "(", "$", "this", "->", "headers", "[", "$", "this", "->", "normalizeKey", "(", "$", "key", ")", "]", ")", ")", "?", "true", ":", "false", ";", "}" ]
Get the header by key. @param (string) $key The header key @since 3.0.0 @return bool
[ "Get", "the", "header", "by", "key", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Headers.php#L134-L137
zestframework/Zest_Framework
src/http/Headers.php
Headers.send
public function send($code = null, array $headers = null, $compress = false) { if ($code !== null) { $this->withStatus($code); } if ($headers !== null) { $this->setHeaders($headers); } $body = $this->body; $this->headers['Content-Length'] = strlen($body); if ($compress === true) { $encoding = ''; if (preg_match('/ *gzip *,?/', $this->headers['accept-encoding'])) { $encoding = 'gzip'; } elseif (preg_match('/ *deflate *,?/', $this->headers['accept-encoding'])) { $encoding = 'deflate'; } (isset($encoding)) ? $this->headers['Content-Encoding'] = $encoding : null; $body = static::encodeBody($body, $encoding); } $this->sendHeaders(); echo $body; }
php
public function send($code = null, array $headers = null, $compress = false) { if ($code !== null) { $this->withStatus($code); } if ($headers !== null) { $this->setHeaders($headers); } $body = $this->body; $this->headers['Content-Length'] = strlen($body); if ($compress === true) { $encoding = ''; if (preg_match('/ *gzip *,?/', $this->headers['accept-encoding'])) { $encoding = 'gzip'; } elseif (preg_match('/ *deflate *,?/', $this->headers['accept-encoding'])) { $encoding = 'deflate'; } (isset($encoding)) ? $this->headers['Content-Encoding'] = $encoding : null; $body = static::encodeBody($body, $encoding); } $this->sendHeaders(); echo $body; }
[ "public", "function", "send", "(", "$", "code", "=", "null", ",", "array", "$", "headers", "=", "null", ",", "$", "compress", "=", "false", ")", "{", "if", "(", "$", "code", "!==", "null", ")", "{", "$", "this", "->", "withStatus", "(", "$", "cod...
Send response. @param (int) $code Status code. @param (array) $headers Headers. @param (bool) $compress Content compression. @since 3.0.0 @return void
[ "Send", "response", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Headers.php#L178-L202
zestframework/Zest_Framework
src/http/Headers.php
Headers.sendHeaders
public function sendHeaders() { if (headers_sent()) { throw new \Exception('The headers have already been sent.'); } header("HTTP/{$this->version} {$this->code} {$this->reasonPhrase}"); foreach ($this->headers as $name => $value) { if (is_array($value)) { foreach ($value as $key => $val) { header($key.': '.$val); } } else { header($name.': '.$value); } } }
php
public function sendHeaders() { if (headers_sent()) { throw new \Exception('The headers have already been sent.'); } header("HTTP/{$this->version} {$this->code} {$this->reasonPhrase}"); foreach ($this->headers as $name => $value) { if (is_array($value)) { foreach ($value as $key => $val) { header($key.': '.$val); } } else { header($name.': '.$value); } } }
[ "public", "function", "sendHeaders", "(", ")", "{", "if", "(", "headers_sent", "(", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'The headers have already been sent.'", ")", ";", "}", "header", "(", "\"HTTP/{$this->version} {$this->code} {$this->reasonPhras...
Send headers. @since 3.0.0 @return void
[ "Send", "headers", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/http/Headers.php#L211-L227
zestframework/Zest_Framework
src/Common/Logger/Logger.php
Logger.log
public function log($level, $message, array $context = []) { if (is_string($level)) { if (!array_key_exists($level, $this->levels)) { throw new \Exception("Log level {$level} is not valid. Please use syslog levels instead", 500); } else { $level = $this->levels[$level]; } } if (array_key_exists('exception', $context)) { if ($context['exception'] instanceof \Exception) { $exc = $context['exception']; $message .= " Exception: {$exc->getMessage()}"; unset($context['exception']); } else { unset($context['exception']); } } $level = $this->s_levels[$level]; return $this->interpolate($message, $context, $level); }
php
public function log($level, $message, array $context = []) { if (is_string($level)) { if (!array_key_exists($level, $this->levels)) { throw new \Exception("Log level {$level} is not valid. Please use syslog levels instead", 500); } else { $level = $this->levels[$level]; } } if (array_key_exists('exception', $context)) { if ($context['exception'] instanceof \Exception) { $exc = $context['exception']; $message .= " Exception: {$exc->getMessage()}"; unset($context['exception']); } else { unset($context['exception']); } } $level = $this->s_levels[$level]; return $this->interpolate($message, $context, $level); }
[ "public", "function", "log", "(", "$", "level", ",", "$", "message", ",", "array", "$", "context", "=", "[", "]", ")", "{", "if", "(", "is_string", "(", "$", "level", ")", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "level", ",", "$",...
Log. @param (string) $level Error level (string or PHP syslog priority) @param (string) $message Error message @param (array) $context Contextual array @since 2.0.3 @return void
[ "Log", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Common/Logger/Logger.php#L88-L109
zestframework/Zest_Framework
src/Common/Logger/Logger.php
Logger.writer
public function writer($level, $message) { (!empty($this->file)) ? $fileName = $this->file : $fileName = '.logs'; $fileHandling = new FileHandling(); $text = 'Date/time: '.date('Y-m-d h:i:s A')." , Level: $level , message: ".$message."\n"; $file = route()->storage->log.$fileName; $fileHandling->open($file, 'readWriteAppend')->write($text); $fileHandling->close(); }
php
public function writer($level, $message) { (!empty($this->file)) ? $fileName = $this->file : $fileName = '.logs'; $fileHandling = new FileHandling(); $text = 'Date/time: '.date('Y-m-d h:i:s A')." , Level: $level , message: ".$message."\n"; $file = route()->storage->log.$fileName; $fileHandling->open($file, 'readWriteAppend')->write($text); $fileHandling->close(); }
[ "public", "function", "writer", "(", "$", "level", ",", "$", "message", ")", "{", "(", "!", "empty", "(", "$", "this", "->", "file", ")", ")", "?", "$", "fileName", "=", "$", "this", "->", "file", ":", "$", "fileName", "=", "'.logs'", ";", "$", ...
Write the log message in files. @param (string) $string Error level (string or PHP syslog priority) @param (string) $message Error message @since 2.0.3 @return void
[ "Write", "the", "log", "message", "in", "files", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Common/Logger/Logger.php#L121-L129
zestframework/Zest_Framework
src/Common/Logger/Logger.php
Logger.logException
public function logException($level, $message, array $context = [], $exception = null) { $this->log($level, $message, array_merge($context, ['exception'=>$exception])); }
php
public function logException($level, $message, array $context = [], $exception = null) { $this->log($level, $message, array_merge($context, ['exception'=>$exception])); }
[ "public", "function", "logException", "(", "$", "level", ",", "$", "message", ",", "array", "$", "context", "=", "[", "]", ",", "$", "exception", "=", "null", ")", "{", "$", "this", "->", "log", "(", "$", "level", ",", "$", "message", ",", "array_m...
Log an Exception. @param (string) $level Error level (string or PHP syslog priority) @oaram (string) $message Error message @param (array) $context Contextual array @param (Expection) $exception Exception @since 2.0.3 @return void
[ "Log", "an", "Exception", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Common/Logger/Logger.php#L188-L191
zestframework/Zest_Framework
src/Common/Logger/Logger.php
Logger.interpolate
public function interpolate($string, array $params, $level) { foreach ($params as $placeholder => $value) { $params['{'.(string) $placeholder.'}'] = (string) $value; unset($params[$placeholder]); } $message = strtr($string, $params); $this->writer($level, $message); $this->store([ 'message' => $message, 'level' => $level, ]); }
php
public function interpolate($string, array $params, $level) { foreach ($params as $placeholder => $value) { $params['{'.(string) $placeholder.'}'] = (string) $value; unset($params[$placeholder]); } $message = strtr($string, $params); $this->writer($level, $message); $this->store([ 'message' => $message, 'level' => $level, ]); }
[ "public", "function", "interpolate", "(", "$", "string", ",", "array", "$", "params", ",", "$", "level", ")", "{", "foreach", "(", "$", "params", "as", "$", "placeholder", "=>", "$", "value", ")", "{", "$", "params", "[", "'{'", ".", "(", "string", ...
Interpolate string with parameters. @param (string) $string String with parameters @param (array) $params Parameter arrays @param (string) $level Level of log @since 2.0.3 @return void
[ "Interpolate", "string", "with", "parameters", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Common/Logger/Logger.php#L204-L216
zestframework/Zest_Framework
src/View/View.php
View.setFile
protected static function setFile($file) { if (self::$isCom === false) { $incFile = route()->views.'/'.$file.'.php'; if (file_exists($incFile)) { self::$file = $incFile; } } else { $incFile = route()->com.$file.'.php'; if (file_exists($incFile)) { self::$file = $incFile; } } }
php
protected static function setFile($file) { if (self::$isCom === false) { $incFile = route()->views.'/'.$file.'.php'; if (file_exists($incFile)) { self::$file = $incFile; } } else { $incFile = route()->com.$file.'.php'; if (file_exists($incFile)) { self::$file = $incFile; } } }
[ "protected", "static", "function", "setFile", "(", "$", "file", ")", "{", "if", "(", "self", "::", "$", "isCom", "===", "false", ")", "{", "$", "incFile", "=", "route", "(", ")", "->", "views", ".", "'/'", ".", "$", "file", ".", "'.php'", ";", "i...
Set file. @param $file file with path. @since 1.0.0 @return void
[ "Set", "file", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/View/View.php#L52-L65
zestframework/Zest_Framework
src/View/View.php
View.renderTemplate
public static function renderTemplate($file, $args = []) { if (!empty($file)) { self::setFile($file); extract($args, EXTR_SKIP); if (file_exists(self::$file)) { ob_start(); require_once self::$file; } else { throw new \Exception("Sorry, view file {$file} not exists", 404); } } else { throw new \Exception('Sorry, file much be provided', 404); } }
php
public static function renderTemplate($file, $args = []) { if (!empty($file)) { self::setFile($file); extract($args, EXTR_SKIP); if (file_exists(self::$file)) { ob_start(); require_once self::$file; } else { throw new \Exception("Sorry, view file {$file} not exists", 404); } } else { throw new \Exception('Sorry, file much be provided', 404); } }
[ "public", "static", "function", "renderTemplate", "(", "$", "file", ",", "$", "args", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "file", ")", ")", "{", "self", "::", "setFile", "(", "$", "file", ")", ";", "extract", "(", "$", "...
Render a view template. @param (string) $file Name of files. @param (array) $args Attributes. @since 1.0.0 @return void
[ "Render", "a", "view", "template", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/View/View.php#L77-L91
zestframework/Zest_Framework
src/View/View.php
View.view
public static function view($file, array $args = [], bool $minify = false, array $headers = [], $code = 200) { $headers['Content-Type'] = 'text/html'; if ($minify === true) { $minify = new Minify(); self::renderTemplate($file, $args); $config = [ 'code' => $code, 'body' => $minify->htmlMinify(ob_get_clean(), 'code'), 'headers' => [ $headers, ], ]; $response = new Response($config); $response->send(); } else { self::renderTemplate($file, $args); $config = [ 'code' => $code, 'body' => ob_get_clean(), 'headers' => [ $headers, ], ]; $response = new Response($config); $response->send(); } }
php
public static function view($file, array $args = [], bool $minify = false, array $headers = [], $code = 200) { $headers['Content-Type'] = 'text/html'; if ($minify === true) { $minify = new Minify(); self::renderTemplate($file, $args); $config = [ 'code' => $code, 'body' => $minify->htmlMinify(ob_get_clean(), 'code'), 'headers' => [ $headers, ], ]; $response = new Response($config); $response->send(); } else { self::renderTemplate($file, $args); $config = [ 'code' => $code, 'body' => ob_get_clean(), 'headers' => [ $headers, ], ]; $response = new Response($config); $response->send(); } }
[ "public", "static", "function", "view", "(", "$", "file", ",", "array", "$", "args", "=", "[", "]", ",", "bool", "$", "minify", "=", "false", ",", "array", "$", "headers", "=", "[", "]", ",", "$", "code", "=", "200", ")", "{", "$", "headers", "...
Rander the view. @param (string) $file Name of files @param (array) $args Attributes. @param (bool) $minify Is code should be minify @param (array) $headers Custom headers. @since 1.0.0 @return mixed
[ "Rander", "the", "view", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/View/View.php#L105-L132
zestframework/Zest_Framework
src/Cache/Adapter/SessionCache.php
SessionCache.getItemTtl
public function getItemTtl($key) { if (isset($_SESSION['__CACHE__'][$key])) { $data = json_decode($_SESSION['__CACHE__'][$key], true); if ($data['ttl'] === 0 || (time() - $data['start'] <= $data['ttl'])) { $ttl = $data['ttl']; } else { $this->deleteItem($key); } } return (isset($ttl)) ? $ttl : false; }
php
public function getItemTtl($key) { if (isset($_SESSION['__CACHE__'][$key])) { $data = json_decode($_SESSION['__CACHE__'][$key], true); if ($data['ttl'] === 0 || (time() - $data['start'] <= $data['ttl'])) { $ttl = $data['ttl']; } else { $this->deleteItem($key); } } return (isset($ttl)) ? $ttl : false; }
[ "public", "function", "getItemTtl", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", "[", "'__CACHE__'", "]", "[", "$", "key", "]", ")", ")", "{", "$", "data", "=", "json_decode", "(", "$", "_SESSION", "[", "'__CACHE__'", "]", "...
Get the time-to-live for an item in cache. @param (string) $key @since 3.0.0 @return mixed
[ "Get", "the", "time", "-", "to", "-", "live", "for", "an", "item", "in", "cache", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Cache/Adapter/SessionCache.php#L46-L58
zestframework/Zest_Framework
src/Cache/Adapter/SessionCache.php
SessionCache.saveItem
public function saveItem($key, $value, $ttl = null) { $_SESSION['__CACHE__'][$key] = json_encode([ 'start' => time(), 'ttl' => ($ttl !== null) ? (int) $ttl : $this->ttl, 'value' => $value, ]); return $this; }
php
public function saveItem($key, $value, $ttl = null) { $_SESSION['__CACHE__'][$key] = json_encode([ 'start' => time(), 'ttl' => ($ttl !== null) ? (int) $ttl : $this->ttl, 'value' => $value, ]); return $this; }
[ "public", "function", "saveItem", "(", "$", "key", ",", "$", "value", ",", "$", "ttl", "=", "null", ")", "{", "$", "_SESSION", "[", "'__CACHE__'", "]", "[", "$", "key", "]", "=", "json_encode", "(", "[", "'start'", "=>", "time", "(", ")", ",", "'...
Save an item to cache. @param (string) $key @param (mixed) $value @param (int) $ttl @since 3.0.0 @return object
[ "Save", "an", "item", "to", "cache", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Cache/Adapter/SessionCache.php#L71-L80
zestframework/Zest_Framework
src/Cache/Adapter/SessionCache.php
SessionCache.getItem
public function getItem($key) { if (isset($_SESSION['__CACHE__'][$key])) { $data = json_decode($_SESSION['__CACHE__'][$key], true); if ($data['ttl'] === 0 || (time() - $data['start'] <= $data['ttl'])) { $value = $data['value']; } else { $this->deleteItem($key); } } return (isset($value)) ? $value : false; }
php
public function getItem($key) { if (isset($_SESSION['__CACHE__'][$key])) { $data = json_decode($_SESSION['__CACHE__'][$key], true); if ($data['ttl'] === 0 || (time() - $data['start'] <= $data['ttl'])) { $value = $data['value']; } else { $this->deleteItem($key); } } return (isset($value)) ? $value : false; }
[ "public", "function", "getItem", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", "[", "'__CACHE__'", "]", "[", "$", "key", "]", ")", ")", "{", "$", "data", "=", "json_decode", "(", "$", "_SESSION", "[", "'__CACHE__'", "]", "[",...
Get value form the cache. @param (string) $key @since 3.0.0 @return mixed
[ "Get", "value", "form", "the", "cache", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Cache/Adapter/SessionCache.php#L91-L103
zestframework/Zest_Framework
src/Benchmark/Benchmark.php
Benchmark.elapsedTime
public function elapsedTime(int $round = null) { $time = $this->end - $this->start; if (!is_null($round)) { $time = round($time, $round); } return (float) $time; }
php
public function elapsedTime(int $round = null) { $time = $this->end - $this->start; if (!is_null($round)) { $time = round($time, $round); } return (float) $time; }
[ "public", "function", "elapsedTime", "(", "int", "$", "round", "=", "null", ")", "{", "$", "time", "=", "$", "this", "->", "end", "-", "$", "this", "->", "start", ";", "if", "(", "!", "is_null", "(", "$", "round", ")", ")", "{", "$", "time", "=...
Get the elapsed time. @param (int) $round round. @since 2.0.0 @return void
[ "Get", "the", "elapsed", "time", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Benchmark/Benchmark.php#L74-L82
zestframework/Zest_Framework
src/Component/Components.php
Components.delete
public function delete($name) { if (file_exists(route()->com.$name)) { (new Files())->deleteDir(route()->com.$name); } }
php
public function delete($name) { if (file_exists(route()->com.$name)) { (new Files())->deleteDir(route()->com.$name); } }
[ "public", "function", "delete", "(", "$", "name", ")", "{", "if", "(", "file_exists", "(", "route", "(", ")", "->", "com", ".", "$", "name", ")", ")", "{", "(", "new", "Files", "(", ")", ")", "->", "deleteDir", "(", "route", "(", ")", "->", "co...
Delete component by name. @param (string) $name Name of component. @since 3.0.0 @return void
[ "Delete", "component", "by", "name", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Component/Components.php#L48-L53
zestframework/Zest_Framework
src/Component/Components.php
Components.install
public function install($archive, $name) { $exploadName = explode('.', $name); $name = $exploadName[0]; $storageData = route()->storage_data; $file = $storageData.$archive; $files = new Files(); $files->mkdir($storageData.'tmp/'); $files->mkdir($storageData.'tmp/'.$name); (new Zip())->extract($file, $storageData.'tmp/'.$name.'/', true); if (file_exists($storageData.'tmp/'.$name.'/component.json')) { $file = new FileHandling(); $c = $file->open($storageData.'/tmp/'.$name.'/component.json', 'readOnly')->read(); $file->close(); $config = json_decode($c, true); if ($this->isSupported($config['requires']['version'], $config['requires']['comparator']) === true) { if (!file_exists(route()->com.$name)) { $files->moveDir($storageData.'tmp/', route()->com, $name); return true; } } } return false; }
php
public function install($archive, $name) { $exploadName = explode('.', $name); $name = $exploadName[0]; $storageData = route()->storage_data; $file = $storageData.$archive; $files = new Files(); $files->mkdir($storageData.'tmp/'); $files->mkdir($storageData.'tmp/'.$name); (new Zip())->extract($file, $storageData.'tmp/'.$name.'/', true); if (file_exists($storageData.'tmp/'.$name.'/component.json')) { $file = new FileHandling(); $c = $file->open($storageData.'/tmp/'.$name.'/component.json', 'readOnly')->read(); $file->close(); $config = json_decode($c, true); if ($this->isSupported($config['requires']['version'], $config['requires']['comparator']) === true) { if (!file_exists(route()->com.$name)) { $files->moveDir($storageData.'tmp/', route()->com, $name); return true; } } } return false; }
[ "public", "function", "install", "(", "$", "archive", ",", "$", "name", ")", "{", "$", "exploadName", "=", "explode", "(", "'.'", ",", "$", "name", ")", ";", "$", "name", "=", "$", "exploadName", "[", "0", "]", ";", "$", "storageData", "=", "route"...
Install the component. @param (string) $archive Valid component zip archive in Data folder. @param (string) $name Name of component. @since 3.0.0 @return bool
[ "Install", "the", "component", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Component/Components.php#L65-L90
zestframework/Zest_Framework
src/Component/Components.php
Components.enableOrDisable
public function enableOrDisable($name, $status) { $file = route()->com.$name.'/component.json'; if (file_exists($file)) { $fileHandling = new FileHandling(); $c = $fileHandling->open($file, 'readOnly')->read(); $config = json_decode($c, true); $config['status'] = $status; $config = json_encode($config, JSON_PRETTY_PRINT); $fileHandling->open($file, 'writeOnly')->write($config); $fileHandling->close(); return true; } return false; }
php
public function enableOrDisable($name, $status) { $file = route()->com.$name.'/component.json'; if (file_exists($file)) { $fileHandling = new FileHandling(); $c = $fileHandling->open($file, 'readOnly')->read(); $config = json_decode($c, true); $config['status'] = $status; $config = json_encode($config, JSON_PRETTY_PRINT); $fileHandling->open($file, 'writeOnly')->write($config); $fileHandling->close(); return true; } return false; }
[ "public", "function", "enableOrDisable", "(", "$", "name", ",", "$", "status", ")", "{", "$", "file", "=", "route", "(", ")", "->", "com", ".", "$", "name", ".", "'/component.json'", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "...
Activate or Disable component. @param (string) $name Name of component. @param (bool) $status Valid status. @since 3.0.0 @return bool
[ "Activate", "or", "Disable", "component", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Component/Components.php#L102-L118
zestframework/Zest_Framework
src/Component/Components.php
Components.getConponentConfigByName
public function getConponentConfigByName($name) { $file = route()->com.$name.'/component.json'; if (file_exists($file)) { $fileHandling = new FileHandling(); $c = $fileHandling->open($file, 'readOnly')->read(); return json_decode($c, true); } return false; }
php
public function getConponentConfigByName($name) { $file = route()->com.$name.'/component.json'; if (file_exists($file)) { $fileHandling = new FileHandling(); $c = $fileHandling->open($file, 'readOnly')->read(); return json_decode($c, true); } return false; }
[ "public", "function", "getConponentConfigByName", "(", "$", "name", ")", "{", "$", "file", "=", "route", "(", ")", "->", "com", ".", "$", "name", ".", "'/component.json'", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "$", "fileHandli...
Get the component json file configuration. @param (string) $name Name of component. @since 3.0.0 @return bool
[ "Get", "the", "component", "json", "file", "configuration", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Component/Components.php#L157-L168
zestframework/Zest_Framework
src/Component/Components.php
Components.isSupported
public function isSupported($zVersion, $comparator) { if (version_compare($zVersion, Version::VERSION, $comparator) === true) { return true; } return false; }
php
public function isSupported($zVersion, $comparator) { if (version_compare($zVersion, Version::VERSION, $comparator) === true) { return true; } return false; }
[ "public", "function", "isSupported", "(", "$", "zVersion", ",", "$", "comparator", ")", "{", "if", "(", "version_compare", "(", "$", "zVersion", ",", "Version", "::", "VERSION", ",", "$", "comparator", ")", "===", "true", ")", "{", "return", "true", ";",...
Determine whether the component is supported with current version of Zest. @param (string) $zVersion Zest version number from component config file. @param (string) $comparator Operator that used to compare version. @since 3.0.0 @return bool
[ "Determine", "whether", "the", "component", "is", "supported", "with", "current", "version", "of", "Zest", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Component/Components.php#L180-L187
zestframework/Zest_Framework
src/Component/Components.php
Components.moveToTrash
public function moveToTrash($name) { if (file_exists(route()->com.$name)) { (new Files())->moveDir(route()->com, route()->storage_data.'com', $name); } }
php
public function moveToTrash($name) { if (file_exists(route()->com.$name)) { (new Files())->moveDir(route()->com, route()->storage_data.'com', $name); } }
[ "public", "function", "moveToTrash", "(", "$", "name", ")", "{", "if", "(", "file_exists", "(", "route", "(", ")", "->", "com", ".", "$", "name", ")", ")", "{", "(", "new", "Files", "(", ")", ")", "->", "moveDir", "(", "route", "(", ")", "->", ...
Move to trash component by name. @param (string) $name Name of component. @since 3.0.0 @return void
[ "Move", "to", "trash", "component", "by", "name", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Component/Components.php#L198-L203
zestframework/Zest_Framework
src/Component/Components.php
Components.restoreFromTrash
public function restoreFromTrash($name) { if (file_exists(route()->storage_data.'com/'.$name)) { (new Files())->moveDir(route()->storage_data.'com', route()->com, $name); } }
php
public function restoreFromTrash($name) { if (file_exists(route()->storage_data.'com/'.$name)) { (new Files())->moveDir(route()->storage_data.'com', route()->com, $name); } }
[ "public", "function", "restoreFromTrash", "(", "$", "name", ")", "{", "if", "(", "file_exists", "(", "route", "(", ")", "->", "storage_data", ".", "'com/'", ".", "$", "name", ")", ")", "{", "(", "new", "Files", "(", ")", ")", "->", "moveDir", "(", ...
Restore from trash component by name. @param (string) $name Name of component. @since 3.0.0 @return void
[ "Restore", "from", "trash", "component", "by", "name", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Component/Components.php#L214-L219
zestframework/Zest_Framework
src/Common/Container/DIS.php
DIS.handler
public function handler() { $dependencies = $this->dependencies; foreach ($this->getDependencies() as $depenci => $value) { $this->register($depenci, function () use ($value) { return $value; }); } }
php
public function handler() { $dependencies = $this->dependencies; foreach ($this->getDependencies() as $depenci => $value) { $this->register($depenci, function () use ($value) { return $value; }); } }
[ "public", "function", "handler", "(", ")", "{", "$", "dependencies", "=", "$", "this", "->", "dependencies", ";", "foreach", "(", "$", "this", "->", "getDependencies", "(", ")", "as", "$", "depenci", "=>", "$", "value", ")", "{", "$", "this", "->", "...
Register the dependencies. @since 2.0.3 @return void
[ "Register", "the", "dependencies", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Common/Container/DIS.php#L63-L71
zestframework/Zest_Framework
src/Common/Container/DIS.php
DIS.mergeDependencies
public function mergeDependencies($dependency = []) { $this->dependencies = array_merge((array) $dependency, (array) $this->getDependencies()); $this->dependencies = Conversion::arrayObject($this->dependencies); }
php
public function mergeDependencies($dependency = []) { $this->dependencies = array_merge((array) $dependency, (array) $this->getDependencies()); $this->dependencies = Conversion::arrayObject($this->dependencies); }
[ "public", "function", "mergeDependencies", "(", "$", "dependency", "=", "[", "]", ")", "{", "$", "this", "->", "dependencies", "=", "array_merge", "(", "(", "array", ")", "$", "dependency", ",", "(", "array", ")", "$", "this", "->", "getDependencies", "(...
Merge to container. @param (array) $dependency valid dependency @since 2.0.3 @return void
[ "Merge", "to", "container", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Common/Container/DIS.php#L135-L139
zestframework/Zest_Framework
src/Auth/Update.php
Update.update
public function update($params, $id) { if (is_array($params)) { foreach (array_keys($params) as $key => $value) { $paramsRules = [$value => ['required' => true]]; } $paramsValidate = new Validation($params, $paramsRules); if ($paramsValidate->fail()) { Error::set($paramsValidate->error()->get()); } } if ($this->fail() !== true) { $fields = [ 'db_name' => __config()->auth->db_name, 'table' => __config()->auth->db_table, 'columns' => $params, 'wheres' => ['id = '.$id], ]; $db = new DB(); $db->db()->update($fields); $db->db()->close(); Success::set(__printl('auth:success:update')); } }
php
public function update($params, $id) { if (is_array($params)) { foreach (array_keys($params) as $key => $value) { $paramsRules = [$value => ['required' => true]]; } $paramsValidate = new Validation($params, $paramsRules); if ($paramsValidate->fail()) { Error::set($paramsValidate->error()->get()); } } if ($this->fail() !== true) { $fields = [ 'db_name' => __config()->auth->db_name, 'table' => __config()->auth->db_table, 'columns' => $params, 'wheres' => ['id = '.$id], ]; $db = new DB(); $db->db()->update($fields); $db->db()->close(); Success::set(__printl('auth:success:update')); } }
[ "public", "function", "update", "(", "$", "params", ",", "$", "id", ")", "{", "if", "(", "is_array", "(", "$", "params", ")", ")", "{", "foreach", "(", "array_keys", "(", "$", "params", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", ...
Update the users. @param (array) $params fields like [name => thisname] @param (int) $id id of user @since 2.0.3 @return void
[ "Update", "the", "users", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Auth/Update.php#L37-L60
zestframework/Zest_Framework
src/Auth/Update.php
Update.updatePassword
public function updatePassword($password, $repeat, $id) { if ($password !== $repeat) { Error::set(__printl('auth:error:password:confirm'), 'password'); } elseif (__config()->auth->sticky_password === true) { if (!(new PasswordManipulation())->isValid($password)) { Error::set(__printl('auth:error:password:sticky'), 'password'); } } if ($this->fail() !== true) { $password_hash = Hash::make($password); $params = ['password' => $password_hash]; $fields = [ 'db_name' => __config()->auth->db_name, 'table' => __config()->auth->db_table, 'columns' => $params, 'wheres' => ['id = '.$id], ]; $db = new DB(); $db->db()->update($fields); $db->db()->close(); Success::set(__printl('auth:success:update_password')); } }
php
public function updatePassword($password, $repeat, $id) { if ($password !== $repeat) { Error::set(__printl('auth:error:password:confirm'), 'password'); } elseif (__config()->auth->sticky_password === true) { if (!(new PasswordManipulation())->isValid($password)) { Error::set(__printl('auth:error:password:sticky'), 'password'); } } if ($this->fail() !== true) { $password_hash = Hash::make($password); $params = ['password' => $password_hash]; $fields = [ 'db_name' => __config()->auth->db_name, 'table' => __config()->auth->db_table, 'columns' => $params, 'wheres' => ['id = '.$id], ]; $db = new DB(); $db->db()->update($fields); $db->db()->close(); Success::set(__printl('auth:success:update_password')); } }
[ "public", "function", "updatePassword", "(", "$", "password", ",", "$", "repeat", ",", "$", "id", ")", "{", "if", "(", "$", "password", "!==", "$", "repeat", ")", "{", "Error", "::", "set", "(", "__printl", "(", "'auth:error:password:confirm'", ")", ",",...
Check is username is exists or not. @param (mixed) $password password of user @param (mixed) $repeat confirm password @param (int) $id id of user @since 2.0.3 @return void
[ "Check", "is", "username", "is", "exists", "or", "not", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Auth/Update.php#L73-L96
zestframework/Zest_Framework
src/Common/OperatingSystem.php
OperatingSystem.phpOs
public function phpOs() { $os = PHP_OS; switch ($os) { case 'WINNT': case 'WINNT32': case 'WINNT64': case 'Windows': $c_os = 'Windows'; break; case 'DragonFly': case 'FreeBSD': case 'NetBSD': case 'OpenBSD': $c_os = 'BSD'; break; case 'Linux': $c_os = 'Linux'; break; case 'SunOS': $c_os = 'Solaris'; break; default: $c_os = 'Unknown'; break; } return $c_os; }
php
public function phpOs() { $os = PHP_OS; switch ($os) { case 'WINNT': case 'WINNT32': case 'WINNT64': case 'Windows': $c_os = 'Windows'; break; case 'DragonFly': case 'FreeBSD': case 'NetBSD': case 'OpenBSD': $c_os = 'BSD'; break; case 'Linux': $c_os = 'Linux'; break; case 'SunOS': $c_os = 'Solaris'; break; default: $c_os = 'Unknown'; break; } return $c_os; }
[ "public", "function", "phpOs", "(", ")", "{", "$", "os", "=", "PHP_OS", ";", "switch", "(", "$", "os", ")", "{", "case", "'WINNT'", ":", "case", "'WINNT32'", ":", "case", "'WINNT64'", ":", "case", "'Windows'", ":", "$", "c_os", "=", "'Windows'", ";",...
Get the operating system name. @since 2.0.3 @return string
[ "Get", "the", "operating", "system", "name", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Common/OperatingSystem.php#L44-L72
zestframework/Zest_Framework
src/Common/Container/Dependency.php
Dependency.resolve
public function resolve($concrete, $params) { if ($concrete instanceof \Closure) { return $concrete($this, $params); } $reflector = new \ReflectionClass($concrete); // check if class is instantiable if (!$reflector->isInstantiable()) { throw new \Exception("Class {$concrete} is not instantiable", 500); } // get class constructor $constructor = $reflector->getConstructor(); if (is_null($constructor)) { // get new instance from class return $reflector->newInstance(); } // get constructor params $parameters = $constructor->getParameters(); $dependencies = $this->getResolveDependencies($parameters, $params); // get new instance with dependencies resolved return $reflector->newInstanceArgs($dependencies); }
php
public function resolve($concrete, $params) { if ($concrete instanceof \Closure) { return $concrete($this, $params); } $reflector = new \ReflectionClass($concrete); // check if class is instantiable if (!$reflector->isInstantiable()) { throw new \Exception("Class {$concrete} is not instantiable", 500); } // get class constructor $constructor = $reflector->getConstructor(); if (is_null($constructor)) { // get new instance from class return $reflector->newInstance(); } // get constructor params $parameters = $constructor->getParameters(); $dependencies = $this->getResolveDependencies($parameters, $params); // get new instance with dependencies resolved return $reflector->newInstanceArgs($dependencies); }
[ "public", "function", "resolve", "(", "$", "concrete", ",", "$", "params", ")", "{", "if", "(", "$", "concrete", "instanceof", "\\", "Closure", ")", "{", "return", "$", "concrete", "(", "$", "this", ",", "$", "params", ")", ";", "}", "$", "reflector"...
Resolve single. @param $concrete the class. @param $params constructur args. @since 3.0.0 @return mixed
[ "Resolve", "single", "." ]
train
https://github.com/zestframework/Zest_Framework/blob/481ce7fbbd4a8eabb80a2d5a8c8d58b4639418cd/src/Common/Container/Dependency.php#L50-L71