id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
11,800 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.setRightMenu | public function setRightMenu($container)
{
if (null === $container) {
throw Exception\InvalidArgumentException(
'Container must be a string alias or an instance of '
. 'Zend\Navigation\AbstractContainer'
);
}
$this->parseContainer($container);
$this->rightMenu = $container;
return $this;
} | php | public function setRightMenu($container)
{
if (null === $container) {
throw Exception\InvalidArgumentException(
'Container must be a string alias or an instance of '
. 'Zend\Navigation\AbstractContainer'
);
}
$this->parseContainer($container);
$this->rightMenu = $container;
return $this;
} | [
"public",
"function",
"setRightMenu",
"(",
"$",
"container",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"container",
")",
"{",
"throw",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'Container must be a string alias or an instance of '",
".",
"'Zend\\Navigation\\AbstractContainer'",
")",
";",
"}",
"$",
"this",
"->",
"parseContainer",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"rightMenu",
"=",
"$",
"container",
";",
"return",
"$",
"this",
";",
"}"
] | Set right menu
@param boolean|string|AbstractContainer $container Container to render or
false for no menu
@return Navbar | [
"Set",
"right",
"menu"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L136-L147 |
11,801 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.renderNavigation | protected function renderNavigation(AbstractContainer $container, array $options)
{
// Start html
$html = $this->renderNavbarContainerHeader($options)
. $this->renderNavbarMenu($container, $options);
// Add form if applicable
if ($options['useForm']) {
$html .= $this->renderNavbarForm($options);
}
// Add right aligned menu
if ($options['rightMenu']) {
$html .= $this->renderNavbarRightMenu($options);
}
// Finish html
$html .= $this->renderNavbarContainerFooter();
return $html;
} | php | protected function renderNavigation(AbstractContainer $container, array $options)
{
// Start html
$html = $this->renderNavbarContainerHeader($options)
. $this->renderNavbarMenu($container, $options);
// Add form if applicable
if ($options['useForm']) {
$html .= $this->renderNavbarForm($options);
}
// Add right aligned menu
if ($options['rightMenu']) {
$html .= $this->renderNavbarRightMenu($options);
}
// Finish html
$html .= $this->renderNavbarContainerFooter();
return $html;
} | [
"protected",
"function",
"renderNavigation",
"(",
"AbstractContainer",
"$",
"container",
",",
"array",
"$",
"options",
")",
"{",
"// Start html",
"$",
"html",
"=",
"$",
"this",
"->",
"renderNavbarContainerHeader",
"(",
"$",
"options",
")",
".",
"$",
"this",
"->",
"renderNavbarMenu",
"(",
"$",
"container",
",",
"$",
"options",
")",
";",
"// Add form if applicable",
"if",
"(",
"$",
"options",
"[",
"'useForm'",
"]",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"renderNavbarForm",
"(",
"$",
"options",
")",
";",
"}",
"// Add right aligned menu",
"if",
"(",
"$",
"options",
"[",
"'rightMenu'",
"]",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"renderNavbarRightMenu",
"(",
"$",
"options",
")",
";",
"}",
"// Finish html",
"$",
"html",
".=",
"$",
"this",
"->",
"renderNavbarContainerFooter",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] | Render navbar container
@param AbstractContainer $container Container to create menu from.
@param array $options Options for controlling rendering
@throws Exception\InvalidArgumentException | [
"Render",
"navbar",
"container"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L174-L193 |
11,802 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.renderNavbarMenu | protected function renderNavbarMenu(AbstractContainer $container, array $options)
{
// Create iterator
$iterator = new \RecursiveIteratorIterator($container, \RecursiveIteratorIterator::SELF_FIRST);
$iterator->setMaxDepth(self::MAX_RENDER_DEPTH);
// Add pages
$html = '';
$prevDepth = -1;
foreach ($iterator as $page) {
if (!$this->accept($page)) {
continue;
}
// Create navbar page
$depth = $iterator->getDepth();
$html .= $this->renderNavbarMenuPage($page, $options, $depth, $prevDepth);
// Store depth for next iteration
$prevDepth = $depth;
}
// Check if any html was created
if ($html) {
// Close open ul/li tags
for ($i = $prevDepth + 1; $i > 0; $i--) {
$html .= '</li></ul>';
}
}
return $html;
} | php | protected function renderNavbarMenu(AbstractContainer $container, array $options)
{
// Create iterator
$iterator = new \RecursiveIteratorIterator($container, \RecursiveIteratorIterator::SELF_FIRST);
$iterator->setMaxDepth(self::MAX_RENDER_DEPTH);
// Add pages
$html = '';
$prevDepth = -1;
foreach ($iterator as $page) {
if (!$this->accept($page)) {
continue;
}
// Create navbar page
$depth = $iterator->getDepth();
$html .= $this->renderNavbarMenuPage($page, $options, $depth, $prevDepth);
// Store depth for next iteration
$prevDepth = $depth;
}
// Check if any html was created
if ($html) {
// Close open ul/li tags
for ($i = $prevDepth + 1; $i > 0; $i--) {
$html .= '</li></ul>';
}
}
return $html;
} | [
"protected",
"function",
"renderNavbarMenu",
"(",
"AbstractContainer",
"$",
"container",
",",
"array",
"$",
"options",
")",
"{",
"// Create iterator",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"$",
"container",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"$",
"iterator",
"->",
"setMaxDepth",
"(",
"self",
"::",
"MAX_RENDER_DEPTH",
")",
";",
"// Add pages",
"$",
"html",
"=",
"''",
";",
"$",
"prevDepth",
"=",
"-",
"1",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"page",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"accept",
"(",
"$",
"page",
")",
")",
"{",
"continue",
";",
"}",
"// Create navbar page",
"$",
"depth",
"=",
"$",
"iterator",
"->",
"getDepth",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"renderNavbarMenuPage",
"(",
"$",
"page",
",",
"$",
"options",
",",
"$",
"depth",
",",
"$",
"prevDepth",
")",
";",
"// Store depth for next iteration",
"$",
"prevDepth",
"=",
"$",
"depth",
";",
"}",
"// Check if any html was created",
"if",
"(",
"$",
"html",
")",
"{",
"// Close open ul/li tags",
"for",
"(",
"$",
"i",
"=",
"$",
"prevDepth",
"+",
"1",
";",
"$",
"i",
">",
"0",
";",
"$",
"i",
"--",
")",
"{",
"$",
"html",
".=",
"'</li></ul>'",
";",
"}",
"}",
"return",
"$",
"html",
";",
"}"
] | Render navbar menu
@param AbstractContainer $container Container to render
@param array $options Options for controlling rendering
@return string | [
"Render",
"navbar",
"menu"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L272-L302 |
11,803 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.renderNavbarMenuPage | protected function renderNavbarMenuPage(AbstractPage $page, array $options, $depth, $prevDepth)
{
// Check for depth
$html = '';
if ($depth > $prevDepth) {
// Start new ul tag
$ulClass = $this->createNavbarMenuClass($page, $options['ulClass'], $depth);
$html .= '<ul' . $ulClass . '>';
} elseif ($depth < $prevDepth) {
// Close open li/ul tags until we're at current depth
for ($i = $prevDepth; $i > $depth; $i--) {
$html .= '</li></ul>';
}
// Close previous li tag
$html .= '</li>';
} elseif ($depth == $prevDepth) {
// Close previous li tag
$html .= '</li>';
}
// Check for divider
if ($page->get('divider')) {
$html .= '<li class="divider"></li>';
}
// Check if page is empty
if ($this->isPageEmpty($page)) {
return $html;
}
// Add menu item
$liClass = $this->createNavbarMenuItemClass($page, $options['addClassToLi'], $depth);
$html .= '<li' . $liClass . '>' . $this->htmlify(
$page,
$options['addClassToLi'],
$options['iconPosition'],
$depth >= self::MAX_RENDER_DEPTH
);
return $html;
} | php | protected function renderNavbarMenuPage(AbstractPage $page, array $options, $depth, $prevDepth)
{
// Check for depth
$html = '';
if ($depth > $prevDepth) {
// Start new ul tag
$ulClass = $this->createNavbarMenuClass($page, $options['ulClass'], $depth);
$html .= '<ul' . $ulClass . '>';
} elseif ($depth < $prevDepth) {
// Close open li/ul tags until we're at current depth
for ($i = $prevDepth; $i > $depth; $i--) {
$html .= '</li></ul>';
}
// Close previous li tag
$html .= '</li>';
} elseif ($depth == $prevDepth) {
// Close previous li tag
$html .= '</li>';
}
// Check for divider
if ($page->get('divider')) {
$html .= '<li class="divider"></li>';
}
// Check if page is empty
if ($this->isPageEmpty($page)) {
return $html;
}
// Add menu item
$liClass = $this->createNavbarMenuItemClass($page, $options['addClassToLi'], $depth);
$html .= '<li' . $liClass . '>' . $this->htmlify(
$page,
$options['addClassToLi'],
$options['iconPosition'],
$depth >= self::MAX_RENDER_DEPTH
);
return $html;
} | [
"protected",
"function",
"renderNavbarMenuPage",
"(",
"AbstractPage",
"$",
"page",
",",
"array",
"$",
"options",
",",
"$",
"depth",
",",
"$",
"prevDepth",
")",
"{",
"// Check for depth",
"$",
"html",
"=",
"''",
";",
"if",
"(",
"$",
"depth",
">",
"$",
"prevDepth",
")",
"{",
"// Start new ul tag",
"$",
"ulClass",
"=",
"$",
"this",
"->",
"createNavbarMenuClass",
"(",
"$",
"page",
",",
"$",
"options",
"[",
"'ulClass'",
"]",
",",
"$",
"depth",
")",
";",
"$",
"html",
".=",
"'<ul'",
".",
"$",
"ulClass",
".",
"'>'",
";",
"}",
"elseif",
"(",
"$",
"depth",
"<",
"$",
"prevDepth",
")",
"{",
"// Close open li/ul tags until we're at current depth",
"for",
"(",
"$",
"i",
"=",
"$",
"prevDepth",
";",
"$",
"i",
">",
"$",
"depth",
";",
"$",
"i",
"--",
")",
"{",
"$",
"html",
".=",
"'</li></ul>'",
";",
"}",
"// Close previous li tag",
"$",
"html",
".=",
"'</li>'",
";",
"}",
"elseif",
"(",
"$",
"depth",
"==",
"$",
"prevDepth",
")",
"{",
"// Close previous li tag",
"$",
"html",
".=",
"'</li>'",
";",
"}",
"// Check for divider",
"if",
"(",
"$",
"page",
"->",
"get",
"(",
"'divider'",
")",
")",
"{",
"$",
"html",
".=",
"'<li class=\"divider\"></li>'",
";",
"}",
"// Check if page is empty",
"if",
"(",
"$",
"this",
"->",
"isPageEmpty",
"(",
"$",
"page",
")",
")",
"{",
"return",
"$",
"html",
";",
"}",
"// Add menu item",
"$",
"liClass",
"=",
"$",
"this",
"->",
"createNavbarMenuItemClass",
"(",
"$",
"page",
",",
"$",
"options",
"[",
"'addClassToLi'",
"]",
",",
"$",
"depth",
")",
";",
"$",
"html",
".=",
"'<li'",
".",
"$",
"liClass",
".",
"'>'",
".",
"$",
"this",
"->",
"htmlify",
"(",
"$",
"page",
",",
"$",
"options",
"[",
"'addClassToLi'",
"]",
",",
"$",
"options",
"[",
"'iconPosition'",
"]",
",",
"$",
"depth",
">=",
"self",
"::",
"MAX_RENDER_DEPTH",
")",
";",
"return",
"$",
"html",
";",
"}"
] | Render navbar menu page
@param AbstractPage $page Page to render
@param array $options Options for controlling rendering
@param integer $depth Current iteration depth
@param integer $prevDepth Previous iteration depth
@return string | [
"Render",
"navbar",
"menu",
"page"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L313-L354 |
11,804 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.isPageEmpty | protected function isPageEmpty(AbstractPage $page)
{
if ($page->get('route')) {
return false;
}
if (!$page->hasPages(true)) {
return true;
}
$isGranted = $this->getView()->plugin('isGranted');
foreach ($page->getPages() as $childPage) {
if (!$childPage->isVisible()) {
continue;
}
if ($isGranted($childPage->get('permission'))) {
return false;
}
}
return true;
} | php | protected function isPageEmpty(AbstractPage $page)
{
if ($page->get('route')) {
return false;
}
if (!$page->hasPages(true)) {
return true;
}
$isGranted = $this->getView()->plugin('isGranted');
foreach ($page->getPages() as $childPage) {
if (!$childPage->isVisible()) {
continue;
}
if ($isGranted($childPage->get('permission'))) {
return false;
}
}
return true;
} | [
"protected",
"function",
"isPageEmpty",
"(",
"AbstractPage",
"$",
"page",
")",
"{",
"if",
"(",
"$",
"page",
"->",
"get",
"(",
"'route'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"page",
"->",
"hasPages",
"(",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"isGranted",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"plugin",
"(",
"'isGranted'",
")",
";",
"foreach",
"(",
"$",
"page",
"->",
"getPages",
"(",
")",
"as",
"$",
"childPage",
")",
"{",
"if",
"(",
"!",
"$",
"childPage",
"->",
"isVisible",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"isGranted",
"(",
"$",
"childPage",
"->",
"get",
"(",
"'permission'",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Is the page empty?
@param AbstractPage $page Page to check
@return boolean | [
"Is",
"the",
"page",
"empty?"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L362-L384 |
11,805 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.renderNavbarRightMenu | protected function renderNavbarRightMenu(array $options)
{
// Get container to use
$container = $options['rightMenu'];
$this->parseContainer($container);
if (null === $container) {
$container = new Navigation;
}
// Set option
$options['ulClass'] .= ' navbar-right';
return $this->renderNavbarMenu($container, $options);
} | php | protected function renderNavbarRightMenu(array $options)
{
// Get container to use
$container = $options['rightMenu'];
$this->parseContainer($container);
if (null === $container) {
$container = new Navigation;
}
// Set option
$options['ulClass'] .= ' navbar-right';
return $this->renderNavbarMenu($container, $options);
} | [
"protected",
"function",
"renderNavbarRightMenu",
"(",
"array",
"$",
"options",
")",
"{",
"// Get container to use",
"$",
"container",
"=",
"$",
"options",
"[",
"'rightMenu'",
"]",
";",
"$",
"this",
"->",
"parseContainer",
"(",
"$",
"container",
")",
";",
"if",
"(",
"null",
"===",
"$",
"container",
")",
"{",
"$",
"container",
"=",
"new",
"Navigation",
";",
"}",
"// Set option",
"$",
"options",
"[",
"'ulClass'",
"]",
".=",
"' navbar-right'",
";",
"return",
"$",
"this",
"->",
"renderNavbarMenu",
"(",
"$",
"container",
",",
"$",
"options",
")",
";",
"}"
] | Render navbar right aligned menu
@param array $options Options for controlling rendering
@return string | [
"Render",
"navbar",
"right",
"aligned",
"menu"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L392-L405 |
11,806 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.createNavbarContainerClass | protected function createNavbarContainerClass(array $options)
{
// Create navbar container class
$containerClass = 'navbar';
if ($options['inverse']) {
$containerClass .= ' navbar-inverse';
}
if ($options['fixed']) {
$containerClass .= ' navbar-fixed-';
switch ($options['fixed']) {
case 'top':
case 'bottom':
$containerClass .= $options['fixed'];
break;
default:
throw new Exception\InvalidArgumentException(
'Only top and bottom are acceptable navbarFixed options'
);
}
}
return $containerClass;
} | php | protected function createNavbarContainerClass(array $options)
{
// Create navbar container class
$containerClass = 'navbar';
if ($options['inverse']) {
$containerClass .= ' navbar-inverse';
}
if ($options['fixed']) {
$containerClass .= ' navbar-fixed-';
switch ($options['fixed']) {
case 'top':
case 'bottom':
$containerClass .= $options['fixed'];
break;
default:
throw new Exception\InvalidArgumentException(
'Only top and bottom are acceptable navbarFixed options'
);
}
}
return $containerClass;
} | [
"protected",
"function",
"createNavbarContainerClass",
"(",
"array",
"$",
"options",
")",
"{",
"// Create navbar container class",
"$",
"containerClass",
"=",
"'navbar'",
";",
"if",
"(",
"$",
"options",
"[",
"'inverse'",
"]",
")",
"{",
"$",
"containerClass",
".=",
"' navbar-inverse'",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'fixed'",
"]",
")",
"{",
"$",
"containerClass",
".=",
"' navbar-fixed-'",
";",
"switch",
"(",
"$",
"options",
"[",
"'fixed'",
"]",
")",
"{",
"case",
"'top'",
":",
"case",
"'bottom'",
":",
"$",
"containerClass",
".=",
"$",
"options",
"[",
"'fixed'",
"]",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'Only top and bottom are acceptable navbarFixed options'",
")",
";",
"}",
"}",
"return",
"$",
"containerClass",
";",
"}"
] | Create navbar container class
@param array $options Options for controlling rendering
@return array
@throws Exception\InvalidArgumentException | [
"Create",
"navbar",
"container",
"class"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L433-L454 |
11,807 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.createNavbarMenuClass | protected function createNavbarMenuClass(AbstractPage $page, $ulClass, $depth)
{
if ($depth === 0 && $ulClass) {
return ' class="' . $this->escapeHtmlAttribute($ulClass) . '"';
} elseif ($page->getParent() && $depth <= self::MAX_RENDER_DEPTH) {
return ' class="dropdown-menu"';
}
return '';
} | php | protected function createNavbarMenuClass(AbstractPage $page, $ulClass, $depth)
{
if ($depth === 0 && $ulClass) {
return ' class="' . $this->escapeHtmlAttribute($ulClass) . '"';
} elseif ($page->getParent() && $depth <= self::MAX_RENDER_DEPTH) {
return ' class="dropdown-menu"';
}
return '';
} | [
"protected",
"function",
"createNavbarMenuClass",
"(",
"AbstractPage",
"$",
"page",
",",
"$",
"ulClass",
",",
"$",
"depth",
")",
"{",
"if",
"(",
"$",
"depth",
"===",
"0",
"&&",
"$",
"ulClass",
")",
"{",
"return",
"' class=\"'",
".",
"$",
"this",
"->",
"escapeHtmlAttribute",
"(",
"$",
"ulClass",
")",
".",
"'\"'",
";",
"}",
"elseif",
"(",
"$",
"page",
"->",
"getParent",
"(",
")",
"&&",
"$",
"depth",
"<=",
"self",
"::",
"MAX_RENDER_DEPTH",
")",
"{",
"return",
"' class=\"dropdown-menu\"'",
";",
"}",
"return",
"''",
";",
"}"
] | Create navbar menu class
@param AbstractPage $page Page being rendered
@param string $ulClass The ul class to set,
$param integer $depth Current iteration depth
@return string | [
"Create",
"navbar",
"menu",
"class"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L464-L473 |
11,808 | internalsystemerror/ise-module-bootstrap | src/View/Helper/Navigation/Navbar.php | Navbar.createNavbarMenuItemClass | protected function createNavbarMenuItemClass(AbstractPage $page, $addClassToLi, $depth)
{
// Render li tag and page
$liClasses = [];
// Is page active
if ($page->isActive()) {
$liClasses[] = 'active';
}
// Does page have children
if ($page->hasPages() && $depth < self::MAX_RENDER_DEPTH) {
$liClasses[] = 'dropdown';
}
// Add page class
if ($addClassToLi && $page->getClass()) {
$liClasses[] = $page->getClass();
}
// Create li
if ($liClasses) {
return ' class="' . implode(' ', $liClasses) . '"';
}
return '';
} | php | protected function createNavbarMenuItemClass(AbstractPage $page, $addClassToLi, $depth)
{
// Render li tag and page
$liClasses = [];
// Is page active
if ($page->isActive()) {
$liClasses[] = 'active';
}
// Does page have children
if ($page->hasPages() && $depth < self::MAX_RENDER_DEPTH) {
$liClasses[] = 'dropdown';
}
// Add page class
if ($addClassToLi && $page->getClass()) {
$liClasses[] = $page->getClass();
}
// Create li
if ($liClasses) {
return ' class="' . implode(' ', $liClasses) . '"';
}
return '';
} | [
"protected",
"function",
"createNavbarMenuItemClass",
"(",
"AbstractPage",
"$",
"page",
",",
"$",
"addClassToLi",
",",
"$",
"depth",
")",
"{",
"// Render li tag and page",
"$",
"liClasses",
"=",
"[",
"]",
";",
"// Is page active",
"if",
"(",
"$",
"page",
"->",
"isActive",
"(",
")",
")",
"{",
"$",
"liClasses",
"[",
"]",
"=",
"'active'",
";",
"}",
"// Does page have children",
"if",
"(",
"$",
"page",
"->",
"hasPages",
"(",
")",
"&&",
"$",
"depth",
"<",
"self",
"::",
"MAX_RENDER_DEPTH",
")",
"{",
"$",
"liClasses",
"[",
"]",
"=",
"'dropdown'",
";",
"}",
"// Add page class",
"if",
"(",
"$",
"addClassToLi",
"&&",
"$",
"page",
"->",
"getClass",
"(",
")",
")",
"{",
"$",
"liClasses",
"[",
"]",
"=",
"$",
"page",
"->",
"getClass",
"(",
")",
";",
"}",
"// Create li",
"if",
"(",
"$",
"liClasses",
")",
"{",
"return",
"' class=\"'",
".",
"implode",
"(",
"' '",
",",
"$",
"liClasses",
")",
".",
"'\"'",
";",
"}",
"return",
"''",
";",
"}"
] | Create navbar menu item class
@param AbstractPage $page Page being rendered
@param boolean $addClassToLi Whether to add the page class to the
li, or leave it for the a
$param integer $depth Current iteration depth
@return string | [
"Create",
"navbar",
"menu",
"item",
"class"
] | 289afa531a12e6159568b592b95964374442e850 | https://github.com/internalsystemerror/ise-module-bootstrap/blob/289afa531a12e6159568b592b95964374442e850/src/View/Helper/Navigation/Navbar.php#L484-L510 |
11,809 | Arcavias/ext-zend | lib/custom/src/MW/Common/Criteria/Lucene.php | MW_Common_Criteria_Lucene.getConditionString | public function getConditionString( array $types, array $translations = array(), array $plugins = array() )
{
if( $this->_conditions !== null ) {
return $string = $this->_conditions->toString( $types, $translations, $plugins );
}
return new Zend_Search_Lucene_Search_Query_Insignificant();
} | php | public function getConditionString( array $types, array $translations = array(), array $plugins = array() )
{
if( $this->_conditions !== null ) {
return $string = $this->_conditions->toString( $types, $translations, $plugins );
}
return new Zend_Search_Lucene_Search_Query_Insignificant();
} | [
"public",
"function",
"getConditionString",
"(",
"array",
"$",
"types",
",",
"array",
"$",
"translations",
"=",
"array",
"(",
")",
",",
"array",
"$",
"plugins",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_conditions",
"!==",
"null",
")",
"{",
"return",
"$",
"string",
"=",
"$",
"this",
"->",
"_conditions",
"->",
"toString",
"(",
"$",
"types",
",",
"$",
"translations",
",",
"$",
"plugins",
")",
";",
"}",
"return",
"new",
"Zend_Search_Lucene_Search_Query_Insignificant",
"(",
")",
";",
"}"
] | Returns the expression string.
@param array $types Associative list of item names and their types
@param array $translations Associative list of item names that should be translated
@param array $plugins Associative list of item names and plugins implementing MW_Common_Criteria_Plugin_Interface
@return string Expression string for searching | [
"Returns",
"the",
"expression",
"string",
"."
] | 1d2adc81ae0091a70f1053e0f095d55e656a3c96 | https://github.com/Arcavias/ext-zend/blob/1d2adc81ae0091a70f1053e0f095d55e656a3c96/lib/custom/src/MW/Common/Criteria/Lucene.php#L106-L113 |
11,810 | Arcavias/ext-zend | lib/custom/src/MW/Common/Criteria/Lucene.php | MW_Common_Criteria_Lucene.getSortationString | public function getSortationString( array $types, array $translations = array() )
{
$sortation = '';
foreach( $this->_sortations as $sortitem )
{
if( ( $string = $sortitem->toString( $types, $translations ) ) !== '' ) {
$sortation .= $string;
}
}
return $sortation;
} | php | public function getSortationString( array $types, array $translations = array() )
{
$sortation = '';
foreach( $this->_sortations as $sortitem )
{
if( ( $string = $sortitem->toString( $types, $translations ) ) !== '' ) {
$sortation .= $string;
}
}
return $sortation;
} | [
"public",
"function",
"getSortationString",
"(",
"array",
"$",
"types",
",",
"array",
"$",
"translations",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sortation",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"_sortations",
"as",
"$",
"sortitem",
")",
"{",
"if",
"(",
"(",
"$",
"string",
"=",
"$",
"sortitem",
"->",
"toString",
"(",
"$",
"types",
",",
"$",
"translations",
")",
")",
"!==",
"''",
")",
"{",
"$",
"sortation",
".=",
"$",
"string",
";",
"}",
"}",
"return",
"$",
"sortation",
";",
"}"
] | Returns the string for sorting the result
@param array $names List of item names
@param array $translations Associative list of item names that should be translated
@return string Order string for sorting the items | [
"Returns",
"the",
"string",
"for",
"sorting",
"the",
"result"
] | 1d2adc81ae0091a70f1053e0f095d55e656a3c96 | https://github.com/Arcavias/ext-zend/blob/1d2adc81ae0091a70f1053e0f095d55e656a3c96/lib/custom/src/MW/Common/Criteria/Lucene.php#L151-L163 |
11,811 | vworldat/composer-construction-kit-installer | src/ConstructionKitBuildingBlocksDetector.php | ConstructionKitBuildingBlocksDetector.checkSettings | protected function checkSettings()
{
$io = $this->event->getIO();
if ($this->disabled) {
$io->write('<info>[C33sConstructionKitBundle] C33sConstructionKit is disabled</info>');
return false;
}
if (!is_dir($this->appDir)) {
$currentDir = getcwd();
$io->write("<warning>[C33sConstructionKitBundle] The symfony-app-dir {$this->appDir} specified in composer.json was not found in {$currentDir}. Cannot generate building blocks file.</warning>");
return false;
}
return true;
} | php | protected function checkSettings()
{
$io = $this->event->getIO();
if ($this->disabled) {
$io->write('<info>[C33sConstructionKitBundle] C33sConstructionKit is disabled</info>');
return false;
}
if (!is_dir($this->appDir)) {
$currentDir = getcwd();
$io->write("<warning>[C33sConstructionKitBundle] The symfony-app-dir {$this->appDir} specified in composer.json was not found in {$currentDir}. Cannot generate building blocks file.</warning>");
return false;
}
return true;
} | [
"protected",
"function",
"checkSettings",
"(",
")",
"{",
"$",
"io",
"=",
"$",
"this",
"->",
"event",
"->",
"getIO",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"disabled",
")",
"{",
"$",
"io",
"->",
"write",
"(",
"'<info>[C33sConstructionKitBundle] C33sConstructionKit is disabled</info>'",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"appDir",
")",
")",
"{",
"$",
"currentDir",
"=",
"getcwd",
"(",
")",
";",
"$",
"io",
"->",
"write",
"(",
"\"<warning>[C33sConstructionKitBundle] The symfony-app-dir {$this->appDir} specified in composer.json was not found in {$currentDir}. Cannot generate building blocks file.</warning>\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check various settings before performing any updates.
@return bool | [
"Check",
"various",
"settings",
"before",
"performing",
"any",
"updates",
"."
] | 1ccf82bb86d5a7e5c95fff5f50c83f21f10b89ca | https://github.com/vworldat/composer-construction-kit-installer/blob/1ccf82bb86d5a7e5c95fff5f50c83f21f10b89ca/src/ConstructionKitBuildingBlocksDetector.php#L68-L86 |
11,812 | vworldat/composer-construction-kit-installer | src/ConstructionKitBuildingBlocksDetector.php | ConstructionKitBuildingBlocksDetector.listChanges | protected function listChanges($existingConfig, array $blocks)
{
$existingBlocks = array();
if (isset($existingConfig['c33s_construction_kit']['composer_building_blocks']) && is_array($existingConfig['c33s_construction_kit']['composer_building_blocks'])) {
foreach ($existingConfig['c33s_construction_kit']['composer_building_blocks'] as $packageBlocks) {
if (is_array($packageBlocks)) {
$existingBlocks = array_merge($existingBlocks, $packageBlocks);
}
}
}
$added = array_diff($blocks, $existingBlocks);
$removed = array_diff($existingBlocks, $blocks);
if (count($added)) {
$this->event->getIO()->write('<info>[C33sConstructionKitBundle] Found new building blocks:</info>');
$added = array_map(function ($block) {
return ' - '.$block;
}, $added);
$this->event->getIO()->write($added);
}
if (count($removed)) {
$this->event->getIO()->write('<info>[C33sConstructionKitBundle] The following building blocks have been removed:</info>');
$removed = array_map(function ($block) {
return ' - '.$block;
}, $removed);
$this->event->getIO()->write($removed);
}
} | php | protected function listChanges($existingConfig, array $blocks)
{
$existingBlocks = array();
if (isset($existingConfig['c33s_construction_kit']['composer_building_blocks']) && is_array($existingConfig['c33s_construction_kit']['composer_building_blocks'])) {
foreach ($existingConfig['c33s_construction_kit']['composer_building_blocks'] as $packageBlocks) {
if (is_array($packageBlocks)) {
$existingBlocks = array_merge($existingBlocks, $packageBlocks);
}
}
}
$added = array_diff($blocks, $existingBlocks);
$removed = array_diff($existingBlocks, $blocks);
if (count($added)) {
$this->event->getIO()->write('<info>[C33sConstructionKitBundle] Found new building blocks:</info>');
$added = array_map(function ($block) {
return ' - '.$block;
}, $added);
$this->event->getIO()->write($added);
}
if (count($removed)) {
$this->event->getIO()->write('<info>[C33sConstructionKitBundle] The following building blocks have been removed:</info>');
$removed = array_map(function ($block) {
return ' - '.$block;
}, $removed);
$this->event->getIO()->write($removed);
}
} | [
"protected",
"function",
"listChanges",
"(",
"$",
"existingConfig",
",",
"array",
"$",
"blocks",
")",
"{",
"$",
"existingBlocks",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"existingConfig",
"[",
"'c33s_construction_kit'",
"]",
"[",
"'composer_building_blocks'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"existingConfig",
"[",
"'c33s_construction_kit'",
"]",
"[",
"'composer_building_blocks'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"existingConfig",
"[",
"'c33s_construction_kit'",
"]",
"[",
"'composer_building_blocks'",
"]",
"as",
"$",
"packageBlocks",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"packageBlocks",
")",
")",
"{",
"$",
"existingBlocks",
"=",
"array_merge",
"(",
"$",
"existingBlocks",
",",
"$",
"packageBlocks",
")",
";",
"}",
"}",
"}",
"$",
"added",
"=",
"array_diff",
"(",
"$",
"blocks",
",",
"$",
"existingBlocks",
")",
";",
"$",
"removed",
"=",
"array_diff",
"(",
"$",
"existingBlocks",
",",
"$",
"blocks",
")",
";",
"if",
"(",
"count",
"(",
"$",
"added",
")",
")",
"{",
"$",
"this",
"->",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"'<info>[C33sConstructionKitBundle] Found new building blocks:</info>'",
")",
";",
"$",
"added",
"=",
"array_map",
"(",
"function",
"(",
"$",
"block",
")",
"{",
"return",
"' - '",
".",
"$",
"block",
";",
"}",
",",
"$",
"added",
")",
";",
"$",
"this",
"->",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"$",
"added",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"removed",
")",
")",
"{",
"$",
"this",
"->",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"'<info>[C33sConstructionKitBundle] The following building blocks have been removed:</info>'",
")",
";",
"$",
"removed",
"=",
"array_map",
"(",
"function",
"(",
"$",
"block",
")",
"{",
"return",
"' - '",
".",
"$",
"block",
";",
"}",
",",
"$",
"removed",
")",
";",
"$",
"this",
"->",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"$",
"removed",
")",
";",
"}",
"}"
] | Display information regarding changed building blocks.
@param mixed $existingConfig
@param mixed $blocks | [
"Display",
"information",
"regarding",
"changed",
"building",
"blocks",
"."
] | 1ccf82bb86d5a7e5c95fff5f50c83f21f10b89ca | https://github.com/vworldat/composer-construction-kit-installer/blob/1ccf82bb86d5a7e5c95fff5f50c83f21f10b89ca/src/ConstructionKitBuildingBlocksDetector.php#L134-L163 |
11,813 | vworldat/composer-construction-kit-installer | src/ConstructionKitBuildingBlocksDetector.php | ConstructionKitBuildingBlocksDetector.getPackagesData | protected function getPackagesData()
{
$composer = $this->event->getComposer();
$locker = $composer->getLocker();
if (isset($locker)) {
$lockData = $locker->getLockData();
$allPackages = isset($lockData['packages']) ? $lockData['packages'] : array();
}
$packages = array();
// Only add those packages that we can reasonably
// assume are components into our packages list
foreach ($allPackages as $package) {
if (isset($package['extra']['c33s-building-blocks']) && is_array($package['extra']['c33s-building-blocks'])) {
$packages[] = $package;
}
}
// Add the root package to the packages list.
$root = $composer->getPackage();
if ($root) {
$dumper = new ArrayDumper();
$package = $dumper->dump($root);
if (isset($package['extra']['c33s-building-blocks']) && is_array($package['extra']['c33s-building-blocks'])) {
$packages[] = $package;
}
}
return $packages;
} | php | protected function getPackagesData()
{
$composer = $this->event->getComposer();
$locker = $composer->getLocker();
if (isset($locker)) {
$lockData = $locker->getLockData();
$allPackages = isset($lockData['packages']) ? $lockData['packages'] : array();
}
$packages = array();
// Only add those packages that we can reasonably
// assume are components into our packages list
foreach ($allPackages as $package) {
if (isset($package['extra']['c33s-building-blocks']) && is_array($package['extra']['c33s-building-blocks'])) {
$packages[] = $package;
}
}
// Add the root package to the packages list.
$root = $composer->getPackage();
if ($root) {
$dumper = new ArrayDumper();
$package = $dumper->dump($root);
if (isset($package['extra']['c33s-building-blocks']) && is_array($package['extra']['c33s-building-blocks'])) {
$packages[] = $package;
}
}
return $packages;
} | [
"protected",
"function",
"getPackagesData",
"(",
")",
"{",
"$",
"composer",
"=",
"$",
"this",
"->",
"event",
"->",
"getComposer",
"(",
")",
";",
"$",
"locker",
"=",
"$",
"composer",
"->",
"getLocker",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"locker",
")",
")",
"{",
"$",
"lockData",
"=",
"$",
"locker",
"->",
"getLockData",
"(",
")",
";",
"$",
"allPackages",
"=",
"isset",
"(",
"$",
"lockData",
"[",
"'packages'",
"]",
")",
"?",
"$",
"lockData",
"[",
"'packages'",
"]",
":",
"array",
"(",
")",
";",
"}",
"$",
"packages",
"=",
"array",
"(",
")",
";",
"// Only add those packages that we can reasonably",
"// assume are components into our packages list",
"foreach",
"(",
"$",
"allPackages",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"package",
"[",
"'extra'",
"]",
"[",
"'c33s-building-blocks'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"package",
"[",
"'extra'",
"]",
"[",
"'c33s-building-blocks'",
"]",
")",
")",
"{",
"$",
"packages",
"[",
"]",
"=",
"$",
"package",
";",
"}",
"}",
"// Add the root package to the packages list.",
"$",
"root",
"=",
"$",
"composer",
"->",
"getPackage",
"(",
")",
";",
"if",
"(",
"$",
"root",
")",
"{",
"$",
"dumper",
"=",
"new",
"ArrayDumper",
"(",
")",
";",
"$",
"package",
"=",
"$",
"dumper",
"->",
"dump",
"(",
"$",
"root",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"package",
"[",
"'extra'",
"]",
"[",
"'c33s-building-blocks'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"package",
"[",
"'extra'",
"]",
"[",
"'c33s-building-blocks'",
"]",
")",
")",
"{",
"$",
"packages",
"[",
"]",
"=",
"$",
"package",
";",
"}",
"}",
"return",
"$",
"packages",
";",
"}"
] | Get active non-dev packages from composer's locker that include an c33s-building-blocks extra array.
@return array | [
"Get",
"active",
"non",
"-",
"dev",
"packages",
"from",
"composer",
"s",
"locker",
"that",
"include",
"an",
"c33s",
"-",
"building",
"-",
"blocks",
"extra",
"array",
"."
] | 1ccf82bb86d5a7e5c95fff5f50c83f21f10b89ca | https://github.com/vworldat/composer-construction-kit-installer/blob/1ccf82bb86d5a7e5c95fff5f50c83f21f10b89ca/src/ConstructionKitBuildingBlocksDetector.php#L170-L200 |
11,814 | vworldat/composer-construction-kit-installer | src/ConstructionKitBuildingBlocksDetector.php | ConstructionKitBuildingBlocksDetector.storeConfig | protected function storeConfig(array $blocksByPackage)
{
$content = "# This file is auto-generated by c33s/composer-construction-kit-installer\n# upon each composer dump-autoload event\n";
$content .= Yaml::dump(array(
'c33s_construction_kit' => array(
'composer_building_blocks' => $blocksByPackage,
),
), 4);
$fs = new Filesystem();
$fs->dumpFile($this->getFilename(), $content);
} | php | protected function storeConfig(array $blocksByPackage)
{
$content = "# This file is auto-generated by c33s/composer-construction-kit-installer\n# upon each composer dump-autoload event\n";
$content .= Yaml::dump(array(
'c33s_construction_kit' => array(
'composer_building_blocks' => $blocksByPackage,
),
), 4);
$fs = new Filesystem();
$fs->dumpFile($this->getFilename(), $content);
} | [
"protected",
"function",
"storeConfig",
"(",
"array",
"$",
"blocksByPackage",
")",
"{",
"$",
"content",
"=",
"\"# This file is auto-generated by c33s/composer-construction-kit-installer\\n# upon each composer dump-autoload event\\n\"",
";",
"$",
"content",
".=",
"Yaml",
"::",
"dump",
"(",
"array",
"(",
"'c33s_construction_kit'",
"=>",
"array",
"(",
"'composer_building_blocks'",
"=>",
"$",
"blocksByPackage",
",",
")",
",",
")",
",",
"4",
")",
";",
"$",
"fs",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"fs",
"->",
"dumpFile",
"(",
"$",
"this",
"->",
"getFilename",
"(",
")",
",",
"$",
"content",
")",
";",
"}"
] | Save new blocks config to file.
@param array $blocks | [
"Save",
"new",
"blocks",
"config",
"to",
"file",
"."
] | 1ccf82bb86d5a7e5c95fff5f50c83f21f10b89ca | https://github.com/vworldat/composer-construction-kit-installer/blob/1ccf82bb86d5a7e5c95fff5f50c83f21f10b89ca/src/ConstructionKitBuildingBlocksDetector.php#L217-L228 |
11,815 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.isCached | public function isCached($type, $hash, $version)
{
// If the base file isn't cached we do not need to check the file names
if (!isset($this->cachedFiles[$hash])) {
return false;
}
$searchedFile = $this->buildFilePath($type, $hash, $version);
foreach ($this->cachedFiles as $baseFileHash => $cachedFile) {
if ($cachedFile['file'] === $searchedFile) {
return true;
}
}
return false;
} | php | public function isCached($type, $hash, $version)
{
// If the base file isn't cached we do not need to check the file names
if (!isset($this->cachedFiles[$hash])) {
return false;
}
$searchedFile = $this->buildFilePath($type, $hash, $version);
foreach ($this->cachedFiles as $baseFileHash => $cachedFile) {
if ($cachedFile['file'] === $searchedFile) {
return true;
}
}
return false;
} | [
"public",
"function",
"isCached",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
"{",
"// If the base file isn't cached we do not need to check the file names",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"searchedFile",
"=",
"$",
"this",
"->",
"buildFilePath",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"cachedFiles",
"as",
"$",
"baseFileHash",
"=>",
"$",
"cachedFile",
")",
"{",
"if",
"(",
"$",
"cachedFile",
"[",
"'file'",
"]",
"===",
"$",
"searchedFile",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if the given file is cached, otherwise return false.
@access public
@param string $type
@param string $hash
@param string $version
@return boolean | [
"Returns",
"true",
"if",
"the",
"given",
"file",
"is",
"cached",
"otherwise",
"return",
"false",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L199-L214 |
11,816 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.getAssetContent | public function getAssetContent($type, $hash, $version)
{
if (!$this->isCached($type, $hash, $version)) {
return '';
}
$targetFile = $this->buildFilePath($type, $hash, $version);
return $this->fileBackend->loadFromFile($targetFile);
} | php | public function getAssetContent($type, $hash, $version)
{
if (!$this->isCached($type, $hash, $version)) {
return '';
}
$targetFile = $this->buildFilePath($type, $hash, $version);
return $this->fileBackend->loadFromFile($targetFile);
} | [
"public",
"function",
"getAssetContent",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCached",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"targetFile",
"=",
"$",
"this",
"->",
"buildFilePath",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
";",
"return",
"$",
"this",
"->",
"fileBackend",
"->",
"loadFromFile",
"(",
"$",
"targetFile",
")",
";",
"}"
] | Returns the content of the given type and file.
@access public
@param string $type
@param string $hash
@param string $version
@return string | [
"Returns",
"the",
"content",
"of",
"the",
"given",
"type",
"and",
"file",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L225-L233 |
11,817 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.getCachedAssetTimestamp | public function getCachedAssetTimestamp($type, $hash, $version)
{
if (!$this->isCached($type, $hash, $version)) {
return 0;
}
return $this->cachedFiles[$hash]['timestamp'];
} | php | public function getCachedAssetTimestamp($type, $hash, $version)
{
if (!$this->isCached($type, $hash, $version)) {
return 0;
}
return $this->cachedFiles[$hash]['timestamp'];
} | [
"public",
"function",
"getCachedAssetTimestamp",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCached",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
"[",
"'timestamp'",
"]",
";",
"}"
] | Returns the timestamp of the cached asset
@param string $type
@param string $hash
@param string $version
@return integer | [
"Returns",
"the",
"timestamp",
"of",
"the",
"cached",
"asset"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L243-L250 |
11,818 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.displayAssetType | public function displayAssetType($type)
{
$files = $this->assetManager->getAssetFiles($type);
// If there are no files for the given type return here.
if ($files === false) {
return;
}
if ($this->combineAssets) {
$this->displayCombinedAssets($type, $files);
} else {
foreach ($files as $file) {
$cachedFile = $this->generateCachedFile($type, $file->getFileName());
if ($cachedFile !== false) {
echo $this->generateHtmlCode($type, $cachedFile['file']);
}
}
}
} | php | public function displayAssetType($type)
{
$files = $this->assetManager->getAssetFiles($type);
// If there are no files for the given type return here.
if ($files === false) {
return;
}
if ($this->combineAssets) {
$this->displayCombinedAssets($type, $files);
} else {
foreach ($files as $file) {
$cachedFile = $this->generateCachedFile($type, $file->getFileName());
if ($cachedFile !== false) {
echo $this->generateHtmlCode($type, $cachedFile['file']);
}
}
}
} | [
"public",
"function",
"displayAssetType",
"(",
"$",
"type",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"assetManager",
"->",
"getAssetFiles",
"(",
"$",
"type",
")",
";",
"// If there are no files for the given type return here.",
"if",
"(",
"$",
"files",
"===",
"false",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"combineAssets",
")",
"{",
"$",
"this",
"->",
"displayCombinedAssets",
"(",
"$",
"type",
",",
"$",
"files",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"cachedFile",
"=",
"$",
"this",
"->",
"generateCachedFile",
"(",
"$",
"type",
",",
"$",
"file",
"->",
"getFileName",
"(",
")",
")",
";",
"if",
"(",
"$",
"cachedFile",
"!==",
"false",
")",
"{",
"echo",
"$",
"this",
"->",
"generateHtmlCode",
"(",
"$",
"type",
",",
"$",
"cachedFile",
"[",
"'file'",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Make the cache for an asset type and display the html
code to include the asset type.
@access public
@param string $type
@return string | [
"Make",
"the",
"cache",
"for",
"an",
"asset",
"type",
"and",
"display",
"the",
"html",
"code",
"to",
"include",
"the",
"asset",
"type",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L260-L280 |
11,819 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.displayCombinedAssets | protected function displayCombinedAssets($type, $files)
{
$isValid = $this->validateTypeCache($type, $files);
// If the cache isn't valid, we build the cache
$result = $isValid;
if (!$isValid) {
$result = $this->buildTypeCache($type, $files);
}
// If the cache is valid, load the file
if ($result) {
$hash = $this->getTypeHash($type);
$cachedFile = $this->cachedFiles[$hash]['file'];
echo $this->generateHtmlCode($type, $cachedFile);
}
} | php | protected function displayCombinedAssets($type, $files)
{
$isValid = $this->validateTypeCache($type, $files);
// If the cache isn't valid, we build the cache
$result = $isValid;
if (!$isValid) {
$result = $this->buildTypeCache($type, $files);
}
// If the cache is valid, load the file
if ($result) {
$hash = $this->getTypeHash($type);
$cachedFile = $this->cachedFiles[$hash]['file'];
echo $this->generateHtmlCode($type, $cachedFile);
}
} | [
"protected",
"function",
"displayCombinedAssets",
"(",
"$",
"type",
",",
"$",
"files",
")",
"{",
"$",
"isValid",
"=",
"$",
"this",
"->",
"validateTypeCache",
"(",
"$",
"type",
",",
"$",
"files",
")",
";",
"// If the cache isn't valid, we build the cache",
"$",
"result",
"=",
"$",
"isValid",
";",
"if",
"(",
"!",
"$",
"isValid",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"buildTypeCache",
"(",
"$",
"type",
",",
"$",
"files",
")",
";",
"}",
"// If the cache is valid, load the file",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"hash",
"=",
"$",
"this",
"->",
"getTypeHash",
"(",
"$",
"type",
")",
";",
"$",
"cachedFile",
"=",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
"[",
"'file'",
"]",
";",
"echo",
"$",
"this",
"->",
"generateHtmlCode",
"(",
"$",
"type",
",",
"$",
"cachedFile",
")",
";",
"}",
"}"
] | Displays the combined assets for the given asset type
@param string $type
@param array $files | [
"Displays",
"the",
"combined",
"assets",
"for",
"the",
"given",
"asset",
"type"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L288-L305 |
11,820 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.getAssetUrl | public function getAssetUrl($type, $assetName)
{
$file = $this->assetManager->getAssetFile($type, $assetName);
if ($file === false) {
return;
}
$cachedFile = $this->generateCachedFile($type, $file->getFileName());
return $this->getUrlToTheAssetLoader($cachedFile['file']);
} | php | public function getAssetUrl($type, $assetName)
{
$file = $this->assetManager->getAssetFile($type, $assetName);
if ($file === false) {
return;
}
$cachedFile = $this->generateCachedFile($type, $file->getFileName());
return $this->getUrlToTheAssetLoader($cachedFile['file']);
} | [
"public",
"function",
"getAssetUrl",
"(",
"$",
"type",
",",
"$",
"assetName",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"assetManager",
"->",
"getAssetFile",
"(",
"$",
"type",
",",
"$",
"assetName",
")",
";",
"if",
"(",
"$",
"file",
"===",
"false",
")",
"{",
"return",
";",
"}",
"$",
"cachedFile",
"=",
"$",
"this",
"->",
"generateCachedFile",
"(",
"$",
"type",
",",
"$",
"file",
"->",
"getFileName",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"getUrlToTheAssetLoader",
"(",
"$",
"cachedFile",
"[",
"'file'",
"]",
")",
";",
"}"
] | Returns the url for one asset.
@access public
@param string $type
@param string $assetName
@return string | [
"Returns",
"the",
"url",
"for",
"one",
"asset",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L315-L326 |
11,821 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.generateCachedFile | public function generateCachedFile($type, $fileName)
{
$isValid = $this->validateCache($fileName);
// If the cache isn't valid, we build the cache
$result = $isValid;
if (!$isValid) {
$result = $this->buildFileCache($type, $fileName);
}
// If the cache is valid, load the file
if ($result) {
$hash = $this->getHash($fileName);
return $this->cachedFiles[$hash];
}
return false;
} | php | public function generateCachedFile($type, $fileName)
{
$isValid = $this->validateCache($fileName);
// If the cache isn't valid, we build the cache
$result = $isValid;
if (!$isValid) {
$result = $this->buildFileCache($type, $fileName);
}
// If the cache is valid, load the file
if ($result) {
$hash = $this->getHash($fileName);
return $this->cachedFiles[$hash];
}
return false;
} | [
"public",
"function",
"generateCachedFile",
"(",
"$",
"type",
",",
"$",
"fileName",
")",
"{",
"$",
"isValid",
"=",
"$",
"this",
"->",
"validateCache",
"(",
"$",
"fileName",
")",
";",
"// If the cache isn't valid, we build the cache",
"$",
"result",
"=",
"$",
"isValid",
";",
"if",
"(",
"!",
"$",
"isValid",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"buildFileCache",
"(",
"$",
"type",
",",
"$",
"fileName",
")",
";",
"}",
"// If the cache is valid, load the file",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"hash",
"=",
"$",
"this",
"->",
"getHash",
"(",
"$",
"fileName",
")",
";",
"return",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Generates a cached file for the given type and base file.
@access public
@param string $type
@param string $fileName
@return string|false | [
"Generates",
"a",
"cached",
"file",
"for",
"the",
"given",
"type",
"and",
"base",
"file",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L336-L353 |
11,822 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.clearAssetCache | public function clearAssetCache()
{
foreach ($this->cachedFiles as $hash => $fileData) {
if (!$this->fileBackend->isWritable($fileData['file'])) {
continue;
}
$this->fileBackend->deleteFile($fileData['file']);
}
$this->cachedFiles = array();
$this->saveAssetsCache();
} | php | public function clearAssetCache()
{
foreach ($this->cachedFiles as $hash => $fileData) {
if (!$this->fileBackend->isWritable($fileData['file'])) {
continue;
}
$this->fileBackend->deleteFile($fileData['file']);
}
$this->cachedFiles = array();
$this->saveAssetsCache();
} | [
"public",
"function",
"clearAssetCache",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"cachedFiles",
"as",
"$",
"hash",
"=>",
"$",
"fileData",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"fileBackend",
"->",
"isWritable",
"(",
"$",
"fileData",
"[",
"'file'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"fileBackend",
"->",
"deleteFile",
"(",
"$",
"fileData",
"[",
"'file'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"cachedFiles",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"saveAssetsCache",
"(",
")",
";",
"}"
] | Clears the asset cache.
@access public | [
"Clears",
"the",
"asset",
"cache",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L374-L386 |
11,823 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.buildTypeCache | protected function buildTypeCache($type, $files)
{
$typeContent = '';
$fileHashs = array();
// Generate the content for all the files
foreach ($files as $file) {
$fileName = $file->getFileName();
if (!file_exists($fileName)) {
continue;
}
// Load the content
$content = $this->fileBackend->loadFromFile($fileName);
// Optimze the content
$content = $this->optimizeContent($type, $fileName, $content);
// Add the content and save the file hash
$typeContent .= $content;
$fileHashs[$this->getHash($fileName)] = md5_file($fileName);
}
// Minify the content, if possible and activated
if (($type === AssetManager::CSS || $type === AssetManager::JS) && $this->minifyAssets) {
$typeContent = $this->minifyContent($type, $typeContent);
}
// Generate the hash and the new file name
$hash = $this->getTypeHash($type);
$version = $type . '-' . uniqid() . '.' . $this->getExtensionForType($type);
$targetFile = $this->buildFilePath($type, $hash, $version);
// Save the cached file
$this->removeOldTypeCacheFile($type);
$this->fileBackend->saveToFile($typeContent, $targetFile);
// Save the cached files in the data array
$this->cachedFiles[$hash] = array(
'file' => $targetFile,
'checksums' => $fileHashs,
'timestamp' => time()
);
$this->saveAssetsCache();
return $targetFile;
} | php | protected function buildTypeCache($type, $files)
{
$typeContent = '';
$fileHashs = array();
// Generate the content for all the files
foreach ($files as $file) {
$fileName = $file->getFileName();
if (!file_exists($fileName)) {
continue;
}
// Load the content
$content = $this->fileBackend->loadFromFile($fileName);
// Optimze the content
$content = $this->optimizeContent($type, $fileName, $content);
// Add the content and save the file hash
$typeContent .= $content;
$fileHashs[$this->getHash($fileName)] = md5_file($fileName);
}
// Minify the content, if possible and activated
if (($type === AssetManager::CSS || $type === AssetManager::JS) && $this->minifyAssets) {
$typeContent = $this->minifyContent($type, $typeContent);
}
// Generate the hash and the new file name
$hash = $this->getTypeHash($type);
$version = $type . '-' . uniqid() . '.' . $this->getExtensionForType($type);
$targetFile = $this->buildFilePath($type, $hash, $version);
// Save the cached file
$this->removeOldTypeCacheFile($type);
$this->fileBackend->saveToFile($typeContent, $targetFile);
// Save the cached files in the data array
$this->cachedFiles[$hash] = array(
'file' => $targetFile,
'checksums' => $fileHashs,
'timestamp' => time()
);
$this->saveAssetsCache();
return $targetFile;
} | [
"protected",
"function",
"buildTypeCache",
"(",
"$",
"type",
",",
"$",
"files",
")",
"{",
"$",
"typeContent",
"=",
"''",
";",
"$",
"fileHashs",
"=",
"array",
"(",
")",
";",
"// Generate the content for all the files",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"fileName",
"=",
"$",
"file",
"->",
"getFileName",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"continue",
";",
"}",
"// Load the content",
"$",
"content",
"=",
"$",
"this",
"->",
"fileBackend",
"->",
"loadFromFile",
"(",
"$",
"fileName",
")",
";",
"// Optimze the content",
"$",
"content",
"=",
"$",
"this",
"->",
"optimizeContent",
"(",
"$",
"type",
",",
"$",
"fileName",
",",
"$",
"content",
")",
";",
"// Add the content and save the file hash",
"$",
"typeContent",
".=",
"$",
"content",
";",
"$",
"fileHashs",
"[",
"$",
"this",
"->",
"getHash",
"(",
"$",
"fileName",
")",
"]",
"=",
"md5_file",
"(",
"$",
"fileName",
")",
";",
"}",
"// Minify the content, if possible and activated",
"if",
"(",
"(",
"$",
"type",
"===",
"AssetManager",
"::",
"CSS",
"||",
"$",
"type",
"===",
"AssetManager",
"::",
"JS",
")",
"&&",
"$",
"this",
"->",
"minifyAssets",
")",
"{",
"$",
"typeContent",
"=",
"$",
"this",
"->",
"minifyContent",
"(",
"$",
"type",
",",
"$",
"typeContent",
")",
";",
"}",
"// Generate the hash and the new file name",
"$",
"hash",
"=",
"$",
"this",
"->",
"getTypeHash",
"(",
"$",
"type",
")",
";",
"$",
"version",
"=",
"$",
"type",
".",
"'-'",
".",
"uniqid",
"(",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"getExtensionForType",
"(",
"$",
"type",
")",
";",
"$",
"targetFile",
"=",
"$",
"this",
"->",
"buildFilePath",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
";",
"// Save the cached file",
"$",
"this",
"->",
"removeOldTypeCacheFile",
"(",
"$",
"type",
")",
";",
"$",
"this",
"->",
"fileBackend",
"->",
"saveToFile",
"(",
"$",
"typeContent",
",",
"$",
"targetFile",
")",
";",
"// Save the cached files in the data array",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
"=",
"array",
"(",
"'file'",
"=>",
"$",
"targetFile",
",",
"'checksums'",
"=>",
"$",
"fileHashs",
",",
"'timestamp'",
"=>",
"time",
"(",
")",
")",
";",
"$",
"this",
"->",
"saveAssetsCache",
"(",
")",
";",
"return",
"$",
"targetFile",
";",
"}"
] | Builds the cache for an asset type
@access protected
@param string $type
@param array $files
@return string | [
"Builds",
"the",
"cache",
"for",
"an",
"asset",
"type"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L396-L442 |
11,824 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.buildFileCache | protected function buildFileCache($type, $fileName)
{
if (!file_exists($fileName)) {
return false;
}
// Load the content
$content = $this->fileBackend->loadFromFile($fileName);
// Optimze the content
$content = $this->optimizeContent($type, $fileName, $content);
// Minify the content, if possible and activated
if (($type === AssetManager::CSS || $type === AssetManager::JS) && $this->minifyAssets) {
$content = $this->minifyContent($type, $content);
}
// Generate the new file name
$fileInfo = pathinfo($fileName);
$hash = $this->getHash($fileName);
$version = $fileInfo['filename'] . '-' . uniqid() . '.' . $fileInfo['extension'];
$targetFile = $this->buildFilePath($type, $hash, $version);
// Save the cached file
$this->removeOldCacheFile($fileName);
$this->fileBackend->saveToFile($content, $targetFile);
// Save the cached files in the data array
$this->cachedFiles[$hash] = array(
'file' => $targetFile,
'checksum' => md5_file($fileName),
'timestamp' => time()
);
$this->saveAssetsCache();
return $targetFile;
} | php | protected function buildFileCache($type, $fileName)
{
if (!file_exists($fileName)) {
return false;
}
// Load the content
$content = $this->fileBackend->loadFromFile($fileName);
// Optimze the content
$content = $this->optimizeContent($type, $fileName, $content);
// Minify the content, if possible and activated
if (($type === AssetManager::CSS || $type === AssetManager::JS) && $this->minifyAssets) {
$content = $this->minifyContent($type, $content);
}
// Generate the new file name
$fileInfo = pathinfo($fileName);
$hash = $this->getHash($fileName);
$version = $fileInfo['filename'] . '-' . uniqid() . '.' . $fileInfo['extension'];
$targetFile = $this->buildFilePath($type, $hash, $version);
// Save the cached file
$this->removeOldCacheFile($fileName);
$this->fileBackend->saveToFile($content, $targetFile);
// Save the cached files in the data array
$this->cachedFiles[$hash] = array(
'file' => $targetFile,
'checksum' => md5_file($fileName),
'timestamp' => time()
);
$this->saveAssetsCache();
return $targetFile;
} | [
"protected",
"function",
"buildFileCache",
"(",
"$",
"type",
",",
"$",
"fileName",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Load the content",
"$",
"content",
"=",
"$",
"this",
"->",
"fileBackend",
"->",
"loadFromFile",
"(",
"$",
"fileName",
")",
";",
"// Optimze the content",
"$",
"content",
"=",
"$",
"this",
"->",
"optimizeContent",
"(",
"$",
"type",
",",
"$",
"fileName",
",",
"$",
"content",
")",
";",
"// Minify the content, if possible and activated",
"if",
"(",
"(",
"$",
"type",
"===",
"AssetManager",
"::",
"CSS",
"||",
"$",
"type",
"===",
"AssetManager",
"::",
"JS",
")",
"&&",
"$",
"this",
"->",
"minifyAssets",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"minifyContent",
"(",
"$",
"type",
",",
"$",
"content",
")",
";",
"}",
"// Generate the new file name",
"$",
"fileInfo",
"=",
"pathinfo",
"(",
"$",
"fileName",
")",
";",
"$",
"hash",
"=",
"$",
"this",
"->",
"getHash",
"(",
"$",
"fileName",
")",
";",
"$",
"version",
"=",
"$",
"fileInfo",
"[",
"'filename'",
"]",
".",
"'-'",
".",
"uniqid",
"(",
")",
".",
"'.'",
".",
"$",
"fileInfo",
"[",
"'extension'",
"]",
";",
"$",
"targetFile",
"=",
"$",
"this",
"->",
"buildFilePath",
"(",
"$",
"type",
",",
"$",
"hash",
",",
"$",
"version",
")",
";",
"// Save the cached file",
"$",
"this",
"->",
"removeOldCacheFile",
"(",
"$",
"fileName",
")",
";",
"$",
"this",
"->",
"fileBackend",
"->",
"saveToFile",
"(",
"$",
"content",
",",
"$",
"targetFile",
")",
";",
"// Save the cached files in the data array",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
"=",
"array",
"(",
"'file'",
"=>",
"$",
"targetFile",
",",
"'checksum'",
"=>",
"md5_file",
"(",
"$",
"fileName",
")",
",",
"'timestamp'",
"=>",
"time",
"(",
")",
")",
";",
"$",
"this",
"->",
"saveAssetsCache",
"(",
")",
";",
"return",
"$",
"targetFile",
";",
"}"
] | Generates the cache for the given files.
@access protected
@param string $type
@param string $fileName
@return false|string | [
"Generates",
"the",
"cache",
"for",
"the",
"given",
"files",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L452-L488 |
11,825 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.removeCacheFile | protected function removeCacheFile($hash)
{
if (!$this->hasCachedFile($hash)) {
return false;
}
$fileData = $this->cachedFiles[$hash];
$this->fileBackend->deleteFile($fileData['file']);
} | php | protected function removeCacheFile($hash)
{
if (!$this->hasCachedFile($hash)) {
return false;
}
$fileData = $this->cachedFiles[$hash];
$this->fileBackend->deleteFile($fileData['file']);
} | [
"protected",
"function",
"removeCacheFile",
"(",
"$",
"hash",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCachedFile",
"(",
"$",
"hash",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fileData",
"=",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
";",
"$",
"this",
"->",
"fileBackend",
"->",
"deleteFile",
"(",
"$",
"fileData",
"[",
"'file'",
"]",
")",
";",
"}"
] | Deletes the cache file for the given hash
@param string $hash
@return boolean | [
"Deletes",
"the",
"cache",
"file",
"for",
"the",
"given",
"hash"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L579-L587 |
11,826 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.validateCache | protected function validateCache($fileName)
{
$hash = $this->getHash($fileName);
if (!file_exists($fileName) || !isset($this->cachedFiles[$hash])) {
return false;
}
$fileChecksum = md5_file($fileName);
$cachedChecksum = $this->cachedFiles[$hash]['checksum'];
if ($fileChecksum != $cachedChecksum) {
return false;
}
return true;
} | php | protected function validateCache($fileName)
{
$hash = $this->getHash($fileName);
if (!file_exists($fileName) || !isset($this->cachedFiles[$hash])) {
return false;
}
$fileChecksum = md5_file($fileName);
$cachedChecksum = $this->cachedFiles[$hash]['checksum'];
if ($fileChecksum != $cachedChecksum) {
return false;
}
return true;
} | [
"protected",
"function",
"validateCache",
"(",
"$",
"fileName",
")",
"{",
"$",
"hash",
"=",
"$",
"this",
"->",
"getHash",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fileChecksum",
"=",
"md5_file",
"(",
"$",
"fileName",
")",
";",
"$",
"cachedChecksum",
"=",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
"[",
"'checksum'",
"]",
";",
"if",
"(",
"$",
"fileChecksum",
"!=",
"$",
"cachedChecksum",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Returns false, if the cached version of the given
file isn't up to date.
@access protected
@param string $fileName
@return boolean | [
"Returns",
"false",
"if",
"the",
"cached",
"version",
"of",
"the",
"given",
"file",
"isn",
"t",
"up",
"to",
"date",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L597-L612 |
11,827 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.validateTypeCache | protected function validateTypeCache($type, $files)
{
// If the files isn't cached we have to cache the file
$hash = $this->getTypeHash($type);
if (!isset($this->cachedFiles[$hash])) {
return false;
}
$data = $this->cachedFiles[$hash];
$checksums = $data['checksums'];
// Are all files existing?
foreach ($files as $file) {
if (!file_exists($file->getFileName())) {
return false;
}
$fileHash = $this->getHash($file->getFileName());
$contentHash = md5_file($file->getFileName());
if (!isset($checksums[$fileHash]) || $contentHash !== $checksums[$fileHash]) {
return false;
}
}
return true;
} | php | protected function validateTypeCache($type, $files)
{
// If the files isn't cached we have to cache the file
$hash = $this->getTypeHash($type);
if (!isset($this->cachedFiles[$hash])) {
return false;
}
$data = $this->cachedFiles[$hash];
$checksums = $data['checksums'];
// Are all files existing?
foreach ($files as $file) {
if (!file_exists($file->getFileName())) {
return false;
}
$fileHash = $this->getHash($file->getFileName());
$contentHash = md5_file($file->getFileName());
if (!isset($checksums[$fileHash]) || $contentHash !== $checksums[$fileHash]) {
return false;
}
}
return true;
} | [
"protected",
"function",
"validateTypeCache",
"(",
"$",
"type",
",",
"$",
"files",
")",
"{",
"// If the files isn't cached we have to cache the file",
"$",
"hash",
"=",
"$",
"this",
"->",
"getTypeHash",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"cachedFiles",
"[",
"$",
"hash",
"]",
";",
"$",
"checksums",
"=",
"$",
"data",
"[",
"'checksums'",
"]",
";",
"// Are all files existing?",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
"->",
"getFileName",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fileHash",
"=",
"$",
"this",
"->",
"getHash",
"(",
"$",
"file",
"->",
"getFileName",
"(",
")",
")",
";",
"$",
"contentHash",
"=",
"md5_file",
"(",
"$",
"file",
"->",
"getFileName",
"(",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"checksums",
"[",
"$",
"fileHash",
"]",
")",
"||",
"$",
"contentHash",
"!==",
"$",
"checksums",
"[",
"$",
"fileHash",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates the cache for an asset type. Return false, if the
cache isn't valid.
@access protected
@param string $type
@param array $files
@return boolean | [
"Validates",
"the",
"cache",
"for",
"an",
"asset",
"type",
".",
"Return",
"false",
"if",
"the",
"cache",
"isn",
"t",
"valid",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L623-L648 |
11,828 | zepi/turbo-base | Zepi/Web/General/src/Manager/AssetCacheManager.php | AssetCacheManager.generateHtmlCode | protected function generateHtmlCode($type, $file)
{
// Generate the url
$url = $this->getUrlToTheAssetLoader($file);
// Return the correct html tag
if ($type === AssetManager::CSS) {
return '<link rel="stylesheet" type="text/css" href="' . $url . '">' . PHP_EOL;
} else if ($type === AssetManager::JS) {
return '<script type="text/javascript" src="' . $url . '"></script>' . PHP_EOL;
}
} | php | protected function generateHtmlCode($type, $file)
{
// Generate the url
$url = $this->getUrlToTheAssetLoader($file);
// Return the correct html tag
if ($type === AssetManager::CSS) {
return '<link rel="stylesheet" type="text/css" href="' . $url . '">' . PHP_EOL;
} else if ($type === AssetManager::JS) {
return '<script type="text/javascript" src="' . $url . '"></script>' . PHP_EOL;
}
} | [
"protected",
"function",
"generateHtmlCode",
"(",
"$",
"type",
",",
"$",
"file",
")",
"{",
"// Generate the url",
"$",
"url",
"=",
"$",
"this",
"->",
"getUrlToTheAssetLoader",
"(",
"$",
"file",
")",
";",
"// Return the correct html tag",
"if",
"(",
"$",
"type",
"===",
"AssetManager",
"::",
"CSS",
")",
"{",
"return",
"'<link rel=\"stylesheet\" type=\"text/css\" href=\"'",
".",
"$",
"url",
".",
"'\">'",
".",
"PHP_EOL",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"AssetManager",
"::",
"JS",
")",
"{",
"return",
"'<script type=\"text/javascript\" src=\"'",
".",
"$",
"url",
".",
"'\"></script>'",
".",
"PHP_EOL",
";",
"}",
"}"
] | Generates the html code for the given asset
@access protected
@param string $type
@param string $file
@return string | [
"Generates",
"the",
"html",
"code",
"for",
"the",
"given",
"asset"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/General/src/Manager/AssetCacheManager.php#L674-L685 |
11,829 | Briareos/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php | ClassMetadataInfo.setDiscriminatorField | public function setDiscriminatorField($discriminatorField)
{
if ($discriminatorField === null) {
$this->discriminatorField = null;
return;
}
// Handle array argument with name/fieldName keys for BC
if (is_array($discriminatorField)) {
if (isset($discriminatorField['name'])) {
$discriminatorField = $discriminatorField['name'];
} elseif (isset($discriminatorField['fieldName'])) {
$discriminatorField = $discriminatorField['fieldName'];
}
}
foreach ($this->fieldMappings as $fieldMapping) {
if ($discriminatorField == $fieldMapping['name']) {
throw MappingException::discriminatorFieldConflict($this->name, $discriminatorField);
}
}
$this->discriminatorField = $discriminatorField;
} | php | public function setDiscriminatorField($discriminatorField)
{
if ($discriminatorField === null) {
$this->discriminatorField = null;
return;
}
// Handle array argument with name/fieldName keys for BC
if (is_array($discriminatorField)) {
if (isset($discriminatorField['name'])) {
$discriminatorField = $discriminatorField['name'];
} elseif (isset($discriminatorField['fieldName'])) {
$discriminatorField = $discriminatorField['fieldName'];
}
}
foreach ($this->fieldMappings as $fieldMapping) {
if ($discriminatorField == $fieldMapping['name']) {
throw MappingException::discriminatorFieldConflict($this->name, $discriminatorField);
}
}
$this->discriminatorField = $discriminatorField;
} | [
"public",
"function",
"setDiscriminatorField",
"(",
"$",
"discriminatorField",
")",
"{",
"if",
"(",
"$",
"discriminatorField",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"discriminatorField",
"=",
"null",
";",
"return",
";",
"}",
"// Handle array argument with name/fieldName keys for BC",
"if",
"(",
"is_array",
"(",
"$",
"discriminatorField",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"discriminatorField",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"discriminatorField",
"=",
"$",
"discriminatorField",
"[",
"'name'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"discriminatorField",
"[",
"'fieldName'",
"]",
")",
")",
"{",
"$",
"discriminatorField",
"=",
"$",
"discriminatorField",
"[",
"'fieldName'",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"fieldMappings",
"as",
"$",
"fieldMapping",
")",
"{",
"if",
"(",
"$",
"discriminatorField",
"==",
"$",
"fieldMapping",
"[",
"'name'",
"]",
")",
"{",
"throw",
"MappingException",
"::",
"discriminatorFieldConflict",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"discriminatorField",
")",
";",
"}",
"}",
"$",
"this",
"->",
"discriminatorField",
"=",
"$",
"discriminatorField",
";",
"}"
] | Sets the discriminator field.
The field name is the the unmapped database field. Discriminator values
are only used to discern the hydration class and are not mapped to class
properties.
@param string $discriminatorField
@throws MappingException If the discriminator field conflicts with the
"name" attribute of a mapped field. | [
"Sets",
"the",
"discriminator",
"field",
"."
] | 29e28bed9a265efd7d05473b0a909fb7c83f76e0 | https://github.com/Briareos/mongodb-odm/blob/29e28bed9a265efd7d05473b0a909fb7c83f76e0/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php#L635-L659 |
11,830 | agalbourdin/agl-core | src/Data/Dir.php | Dir.deleteRecursive | public static function deleteRecursive($pDir)
{
$files = glob($pDir . '*', GLOB_MARK);
foreach ($files as $file) {
if (substr($file, -1) == '/') {
self::deleteRecursive($file);
} else {
unlink($file);
}
}
if (is_dir($pDir)) {
rmdir($pDir);
}
return true;
} | php | public static function deleteRecursive($pDir)
{
$files = glob($pDir . '*', GLOB_MARK);
foreach ($files as $file) {
if (substr($file, -1) == '/') {
self::deleteRecursive($file);
} else {
unlink($file);
}
}
if (is_dir($pDir)) {
rmdir($pDir);
}
return true;
} | [
"public",
"static",
"function",
"deleteRecursive",
"(",
"$",
"pDir",
")",
"{",
"$",
"files",
"=",
"glob",
"(",
"$",
"pDir",
".",
"'*'",
",",
"GLOB_MARK",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"-",
"1",
")",
"==",
"'/'",
")",
"{",
"self",
"::",
"deleteRecursive",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"unlink",
"(",
"$",
"file",
")",
";",
"}",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"pDir",
")",
")",
"{",
"rmdir",
"(",
"$",
"pDir",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Recursive deletion of a directory.
@param string $pDir
@return bool | [
"Recursive",
"deletion",
"of",
"a",
"directory",
"."
] | 1db556f9a49488aa9fab6887fefb7141a79ad97d | https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Data/Dir.php#L25-L41 |
11,831 | agalbourdin/agl-core | src/Data/Dir.php | Dir.chmod | public static function chmod($pDir, $pMode)
{
if (strpos($pMode, '0') !== 0) {
$mode = octdec('0' . $pMode);
} else {
$mode = octdec($pMode);
}
return chmod($pDir, $mode);
} | php | public static function chmod($pDir, $pMode)
{
if (strpos($pMode, '0') !== 0) {
$mode = octdec('0' . $pMode);
} else {
$mode = octdec($pMode);
}
return chmod($pDir, $mode);
} | [
"public",
"static",
"function",
"chmod",
"(",
"$",
"pDir",
",",
"$",
"pMode",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"pMode",
",",
"'0'",
")",
"!==",
"0",
")",
"{",
"$",
"mode",
"=",
"octdec",
"(",
"'0'",
".",
"$",
"pMode",
")",
";",
"}",
"else",
"{",
"$",
"mode",
"=",
"octdec",
"(",
"$",
"pMode",
")",
";",
"}",
"return",
"chmod",
"(",
"$",
"pDir",
",",
"$",
"mode",
")",
";",
"}"
] | CHMOD a directory.
@param string $pDir
@param mixed $pMode
@return bool | [
"CHMOD",
"a",
"directory",
"."
] | 1db556f9a49488aa9fab6887fefb7141a79ad97d | https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Data/Dir.php#L126-L135 |
11,832 | scholtz/AsyncWeb | src/AsyncWeb/Text/Texts.php | Texts.word_substr | public static function word_substr($text, $from, $minlength, $maxlength) {
$text = mb_substr($text, $from, $maxlength);
$p1 = strrpos($text, ' ');
if ($p1 >= $minlength) {
return mb_substr($text, 0, $p1);
}
return $text;
} | php | public static function word_substr($text, $from, $minlength, $maxlength) {
$text = mb_substr($text, $from, $maxlength);
$p1 = strrpos($text, ' ');
if ($p1 >= $minlength) {
return mb_substr($text, 0, $p1);
}
return $text;
} | [
"public",
"static",
"function",
"word_substr",
"(",
"$",
"text",
",",
"$",
"from",
",",
"$",
"minlength",
",",
"$",
"maxlength",
")",
"{",
"$",
"text",
"=",
"mb_substr",
"(",
"$",
"text",
",",
"$",
"from",
",",
"$",
"maxlength",
")",
";",
"$",
"p1",
"=",
"strrpos",
"(",
"$",
"text",
",",
"' '",
")",
";",
"if",
"(",
"$",
"p1",
">=",
"$",
"minlength",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"text",
",",
"0",
",",
"$",
"p1",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | This function does the substr function, but does not end the string in the middle of the word if the end is between min and max length. | [
"This",
"function",
"does",
"the",
"substr",
"function",
"but",
"does",
"not",
"end",
"the",
"string",
"in",
"the",
"middle",
"of",
"the",
"word",
"if",
"the",
"end",
"is",
"between",
"min",
"and",
"max",
"length",
"."
] | 66a906298080c2c66d8f0fb85211b6100b3776bf | https://github.com/scholtz/AsyncWeb/blob/66a906298080c2c66d8f0fb85211b6100b3776bf/src/AsyncWeb/Text/Texts.php#L7-L14 |
11,833 | gentry-php/gentry | src/Generator.php | Generator.generate | public function generate(ReflectionClass $class, array $methods, array $uncovered) : void
{
$this->objectUnderTest = $class;
$this->features = [];
foreach ($methods as $method) {
if (isset($uncovered[$method->name]) && $uncovered[$method->name]) {
$this->addFeature($class, $method, $uncovered[$method->name]);
}
}
$this->write();
} | php | public function generate(ReflectionClass $class, array $methods, array $uncovered) : void
{
$this->objectUnderTest = $class;
$this->features = [];
foreach ($methods as $method) {
if (isset($uncovered[$method->name]) && $uncovered[$method->name]) {
$this->addFeature($class, $method, $uncovered[$method->name]);
}
}
$this->write();
} | [
"public",
"function",
"generate",
"(",
"ReflectionClass",
"$",
"class",
",",
"array",
"$",
"methods",
",",
"array",
"$",
"uncovered",
")",
":",
"void",
"{",
"$",
"this",
"->",
"objectUnderTest",
"=",
"$",
"class",
";",
"$",
"this",
"->",
"features",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"uncovered",
"[",
"$",
"method",
"->",
"name",
"]",
")",
"&&",
"$",
"uncovered",
"[",
"$",
"method",
"->",
"name",
"]",
")",
"{",
"$",
"this",
"->",
"addFeature",
"(",
"$",
"class",
",",
"$",
"method",
",",
"$",
"uncovered",
"[",
"$",
"method",
"->",
"name",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"write",
"(",
")",
";",
"}"
] | Generates stub test methods for all found features.
@param ReflectionClass $class The reflection of the object or trait under
test.
@param array $methods Array of reflected methods to generate test
skeletons for.
@param array $uncovered Array of uncovered method calls.
@return void | [
"Generates",
"stub",
"test",
"methods",
"for",
"all",
"found",
"features",
"."
] | 1e6a909f63cdf653e640540b116c92885c3329cf | https://github.com/gentry-php/gentry/blob/1e6a909f63cdf653e640540b116c92885c3329cf/src/Generator.php#L48-L58 |
11,834 | gentry-php/gentry | src/Generator.php | Generator.addFeature | private function addFeature(ReflectionClass $class, ReflectionMethod $method, array $calls) : void
{
Formatter::out("<gray> Adding tests for feature <magenta>{$class->name}::{$method->name}\n");
$tested = $method->name;
$this->features[$method->name] = (object)['calls' => []];
foreach ($calls as $call) {
$arglist = [];
foreach ($call as $idx => $p) {
if ($p == 'NULL') {
$arglist[] = 'null';
} elseif (isset($arguments[$idx + 1])) {
preg_match('@\$\w+@', "{$arguments[$idx + 1]}", $matches);
$arglist[] = $matches[0];
} else {
$arglist[] = $this->getDefaultForType($p, self::AS_INSTANCE);
}
}
$mt = $method->isStatic() ? '::' : '->';
$expectedResult = 'true';
if ($method->hasReturnType()) {
$type = $method->getReturnType()->__toString();
$expectedResult = $this->getDefaultForType($type, self::AS_RETURNCHECK);
}
$this->features[$method->name]->calls[] = (object)[
'name' => $method->name,
'parameters' => implode(', ', $arglist),
'expectedResult' => $expectedResult,
];
}
} | php | private function addFeature(ReflectionClass $class, ReflectionMethod $method, array $calls) : void
{
Formatter::out("<gray> Adding tests for feature <magenta>{$class->name}::{$method->name}\n");
$tested = $method->name;
$this->features[$method->name] = (object)['calls' => []];
foreach ($calls as $call) {
$arglist = [];
foreach ($call as $idx => $p) {
if ($p == 'NULL') {
$arglist[] = 'null';
} elseif (isset($arguments[$idx + 1])) {
preg_match('@\$\w+@', "{$arguments[$idx + 1]}", $matches);
$arglist[] = $matches[0];
} else {
$arglist[] = $this->getDefaultForType($p, self::AS_INSTANCE);
}
}
$mt = $method->isStatic() ? '::' : '->';
$expectedResult = 'true';
if ($method->hasReturnType()) {
$type = $method->getReturnType()->__toString();
$expectedResult = $this->getDefaultForType($type, self::AS_RETURNCHECK);
}
$this->features[$method->name]->calls[] = (object)[
'name' => $method->name,
'parameters' => implode(', ', $arglist),
'expectedResult' => $expectedResult,
];
}
} | [
"private",
"function",
"addFeature",
"(",
"ReflectionClass",
"$",
"class",
",",
"ReflectionMethod",
"$",
"method",
",",
"array",
"$",
"calls",
")",
":",
"void",
"{",
"Formatter",
"::",
"out",
"(",
"\"<gray> Adding tests for feature <magenta>{$class->name}::{$method->name}\\n\"",
")",
";",
"$",
"tested",
"=",
"$",
"method",
"->",
"name",
";",
"$",
"this",
"->",
"features",
"[",
"$",
"method",
"->",
"name",
"]",
"=",
"(",
"object",
")",
"[",
"'calls'",
"=>",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"calls",
"as",
"$",
"call",
")",
"{",
"$",
"arglist",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"call",
"as",
"$",
"idx",
"=>",
"$",
"p",
")",
"{",
"if",
"(",
"$",
"p",
"==",
"'NULL'",
")",
"{",
"$",
"arglist",
"[",
"]",
"=",
"'null'",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"arguments",
"[",
"$",
"idx",
"+",
"1",
"]",
")",
")",
"{",
"preg_match",
"(",
"'@\\$\\w+@'",
",",
"\"{$arguments[$idx + 1]}\"",
",",
"$",
"matches",
")",
";",
"$",
"arglist",
"[",
"]",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"arglist",
"[",
"]",
"=",
"$",
"this",
"->",
"getDefaultForType",
"(",
"$",
"p",
",",
"self",
"::",
"AS_INSTANCE",
")",
";",
"}",
"}",
"$",
"mt",
"=",
"$",
"method",
"->",
"isStatic",
"(",
")",
"?",
"'::'",
":",
"'->'",
";",
"$",
"expectedResult",
"=",
"'true'",
";",
"if",
"(",
"$",
"method",
"->",
"hasReturnType",
"(",
")",
")",
"{",
"$",
"type",
"=",
"$",
"method",
"->",
"getReturnType",
"(",
")",
"->",
"__toString",
"(",
")",
";",
"$",
"expectedResult",
"=",
"$",
"this",
"->",
"getDefaultForType",
"(",
"$",
"type",
",",
"self",
"::",
"AS_RETURNCHECK",
")",
";",
"}",
"$",
"this",
"->",
"features",
"[",
"$",
"method",
"->",
"name",
"]",
"->",
"calls",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"method",
"->",
"name",
",",
"'parameters'",
"=>",
"implode",
"(",
"', '",
",",
"$",
"arglist",
")",
",",
"'expectedResult'",
"=>",
"$",
"expectedResult",
",",
"]",
";",
"}",
"}"
] | Internal method to add a testable feature.
@param string The reflection of the object or trait to test a feature on.
@param ReflectionMethod $method Reflection of the feature to test.
@param array $calls Array of possible types of calls.
@return void | [
"Internal",
"method",
"to",
"add",
"a",
"testable",
"feature",
"."
] | 1e6a909f63cdf653e640540b116c92885c3329cf | https://github.com/gentry-php/gentry/blob/1e6a909f63cdf653e640540b116c92885c3329cf/src/Generator.php#L68-L97 |
11,835 | gentry-php/gentry | src/Generator.php | Generator.write | public function write() : void
{
if (!$this->features) {
return;
}
$i = 0;
while (true) {
$file = sprintf('%s/%s%s.php', $this->config->output, $this->normalize($this->objectUnderTest->getName()), $i ? ".$i" : '');
if (!file_exists($file)) {
break;
}
++$i;
}
file_put_contents($file, $this->render());
} | php | public function write() : void
{
if (!$this->features) {
return;
}
$i = 0;
while (true) {
$file = sprintf('%s/%s%s.php', $this->config->output, $this->normalize($this->objectUnderTest->getName()), $i ? ".$i" : '');
if (!file_exists($file)) {
break;
}
++$i;
}
file_put_contents($file, $this->render());
} | [
"public",
"function",
"write",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"features",
")",
"{",
"return",
";",
"}",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"true",
")",
"{",
"$",
"file",
"=",
"sprintf",
"(",
"'%s/%s%s.php'",
",",
"$",
"this",
"->",
"config",
"->",
"output",
",",
"$",
"this",
"->",
"normalize",
"(",
"$",
"this",
"->",
"objectUnderTest",
"->",
"getName",
"(",
")",
")",
",",
"$",
"i",
"?",
"\".$i\"",
":",
"''",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"break",
";",
"}",
"++",
"$",
"i",
";",
"}",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"render",
"(",
")",
")",
";",
"}"
] | Actually write the generated stubs to file. If a file by the name of the
feature already exists, a number is appended.
@return void | [
"Actually",
"write",
"the",
"generated",
"stubs",
"to",
"file",
".",
"If",
"a",
"file",
"by",
"the",
"name",
"of",
"the",
"feature",
"already",
"exists",
"a",
"number",
"is",
"appended",
"."
] | 1e6a909f63cdf653e640540b116c92885c3329cf | https://github.com/gentry-php/gentry/blob/1e6a909f63cdf653e640540b116c92885c3329cf/src/Generator.php#L105-L119 |
11,836 | gentry-php/gentry | src/Generator.php | Generator.render | private function render() : string
{
return $this->twig->render('template.html.twig', [
'namespace' => $this->config->namespace ?? null,
'objectUnderTest' => $this->objectUnderTest->name,
'features' => $this->features,
]);
} | php | private function render() : string
{
return $this->twig->render('template.html.twig', [
'namespace' => $this->config->namespace ?? null,
'objectUnderTest' => $this->objectUnderTest->name,
'features' => $this->features,
]);
} | [
"private",
"function",
"render",
"(",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"'template.html.twig'",
",",
"[",
"'namespace'",
"=>",
"$",
"this",
"->",
"config",
"->",
"namespace",
"??",
"null",
",",
"'objectUnderTest'",
"=>",
"$",
"this",
"->",
"objectUnderTest",
"->",
"name",
",",
"'features'",
"=>",
"$",
"this",
"->",
"features",
",",
"]",
")",
";",
"}"
] | Renders the testing code according to the supplied template.
@return string | [
"Renders",
"the",
"testing",
"code",
"according",
"to",
"the",
"supplied",
"template",
"."
] | 1e6a909f63cdf653e640540b116c92885c3329cf | https://github.com/gentry-php/gentry/blob/1e6a909f63cdf653e640540b116c92885c3329cf/src/Generator.php#L126-L133 |
11,837 | gentry-php/gentry | src/Generator.php | Generator.getDefaultForType | private function getDefaultForType(string $type, int $mode = 0) : string
{
$isClass = false;
switch ($type) {
case 'string': $value = "'blarps'"; break;
case 'int': $value = '1'; break;
case 'float': $value = '1.1'; break;
case 'mixed': $value = "'MIXED'"; break;
case 'callable': $value = 'function () {}'; break;
case 'bool': $value = 'true'; break;
case 'array': $value = '[]'; break;
default:
if (class_exists($type)) {
$isClass = true;
}
$value = $type;
}
switch ($mode) {
case self::AS_INSTANCE:
if ($isClass) {
return "new $value";
} else {
return $value;
}
case self::AS_RETURNCHECK:
if ($isClass) {
return "\$result instanceof $value";
} elseif ($value === 'array') {
return "is_array(\$result)";
} elseif ($value == 'callable') {
return "is_callable(\$result)";
} else {
return "\$result === $value";
}
default: return $type;
}
} | php | private function getDefaultForType(string $type, int $mode = 0) : string
{
$isClass = false;
switch ($type) {
case 'string': $value = "'blarps'"; break;
case 'int': $value = '1'; break;
case 'float': $value = '1.1'; break;
case 'mixed': $value = "'MIXED'"; break;
case 'callable': $value = 'function () {}'; break;
case 'bool': $value = 'true'; break;
case 'array': $value = '[]'; break;
default:
if (class_exists($type)) {
$isClass = true;
}
$value = $type;
}
switch ($mode) {
case self::AS_INSTANCE:
if ($isClass) {
return "new $value";
} else {
return $value;
}
case self::AS_RETURNCHECK:
if ($isClass) {
return "\$result instanceof $value";
} elseif ($value === 'array') {
return "is_array(\$result)";
} elseif ($value == 'callable') {
return "is_callable(\$result)";
} else {
return "\$result === $value";
}
default: return $type;
}
} | [
"private",
"function",
"getDefaultForType",
"(",
"string",
"$",
"type",
",",
"int",
"$",
"mode",
"=",
"0",
")",
":",
"string",
"{",
"$",
"isClass",
"=",
"false",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'string'",
":",
"$",
"value",
"=",
"\"'blarps'\"",
";",
"break",
";",
"case",
"'int'",
":",
"$",
"value",
"=",
"'1'",
";",
"break",
";",
"case",
"'float'",
":",
"$",
"value",
"=",
"'1.1'",
";",
"break",
";",
"case",
"'mixed'",
":",
"$",
"value",
"=",
"\"'MIXED'\"",
";",
"break",
";",
"case",
"'callable'",
":",
"$",
"value",
"=",
"'function () {}'",
";",
"break",
";",
"case",
"'bool'",
":",
"$",
"value",
"=",
"'true'",
";",
"break",
";",
"case",
"'array'",
":",
"$",
"value",
"=",
"'[]'",
";",
"break",
";",
"default",
":",
"if",
"(",
"class_exists",
"(",
"$",
"type",
")",
")",
"{",
"$",
"isClass",
"=",
"true",
";",
"}",
"$",
"value",
"=",
"$",
"type",
";",
"}",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"self",
"::",
"AS_INSTANCE",
":",
"if",
"(",
"$",
"isClass",
")",
"{",
"return",
"\"new $value\"",
";",
"}",
"else",
"{",
"return",
"$",
"value",
";",
"}",
"case",
"self",
"::",
"AS_RETURNCHECK",
":",
"if",
"(",
"$",
"isClass",
")",
"{",
"return",
"\"\\$result instanceof $value\"",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"'array'",
")",
"{",
"return",
"\"is_array(\\$result)\"",
";",
"}",
"elseif",
"(",
"$",
"value",
"==",
"'callable'",
")",
"{",
"return",
"\"is_callable(\\$result)\"",
";",
"}",
"else",
"{",
"return",
"\"\\$result === $value\"",
";",
"}",
"default",
":",
"return",
"$",
"type",
";",
"}",
"}"
] | Get a string representation of a default value for a given type.
@param string $type
@param int $mode
@return string | [
"Get",
"a",
"string",
"representation",
"of",
"a",
"default",
"value",
"for",
"a",
"given",
"type",
"."
] | 1e6a909f63cdf653e640540b116c92885c3329cf | https://github.com/gentry-php/gentry/blob/1e6a909f63cdf653e640540b116c92885c3329cf/src/Generator.php#L142-L178 |
11,838 | lengthofrope/create-jsonld-tiny | src/Elements/ElementGroup.php | ElementGroup.remove | public function remove(Interfaces\IElement $element)
{
if ($this->elements->contains($element)) {
$this->elements->detach($element);
}
return $this;
} | php | public function remove(Interfaces\IElement $element)
{
if ($this->elements->contains($element)) {
$this->elements->detach($element);
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"Interfaces",
"\\",
"IElement",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"elements",
"->",
"contains",
"(",
"$",
"element",
")",
")",
"{",
"$",
"this",
"->",
"elements",
"->",
"detach",
"(",
"$",
"element",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove a JSONLD element
@param Interfaces\IElement $element
@return ElementGroup | [
"Remove",
"a",
"JSONLD",
"element"
] | 7abf2e46b8eb4a5e886949ef737588c67c65acd9 | https://github.com/lengthofrope/create-jsonld-tiny/blob/7abf2e46b8eb4a5e886949ef737588c67c65acd9/src/Elements/ElementGroup.php#L66-L73 |
11,839 | AnonymPHP/Anonym-Library | src/Anonym/Html/Form/ExpressionFactory.php | ExpressionFactory.replaceTokens | public function replaceTokens($tokens){
$keys = array_keys($tokens);
$values = array_values($tokens);
return str_replace($keys, $values, $this->getExpression());
} | php | public function replaceTokens($tokens){
$keys = array_keys($tokens);
$values = array_values($tokens);
return str_replace($keys, $values, $this->getExpression());
} | [
"public",
"function",
"replaceTokens",
"(",
"$",
"tokens",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"tokens",
")",
";",
"$",
"values",
"=",
"array_values",
"(",
"$",
"tokens",
")",
";",
"return",
"str_replace",
"(",
"$",
"keys",
",",
"$",
"values",
",",
"$",
"this",
"->",
"getExpression",
"(",
")",
")",
";",
"}"
] | replace tokens and return new string
@param array $tokens
@return mixed | [
"replace",
"tokens",
"and",
"return",
"new",
"string"
] | c967ad804f84e8fb204593a0959cda2fed5ae075 | https://github.com/AnonymPHP/Anonym-Library/blob/c967ad804f84e8fb204593a0959cda2fed5ae075/src/Anonym/Html/Form/ExpressionFactory.php#L84-L89 |
11,840 | samokspv/CakePHP-DBConfigure | Utility/DBConfigure.php | DBConfigure._getEngine | protected static function _getEngine() {
if (!self::$_Engine) {
self::$_Engine = ClassRegistry::init('DBConfigure.' . self::$_EngineName);
}
return self::$_Engine;
} | php | protected static function _getEngine() {
if (!self::$_Engine) {
self::$_Engine = ClassRegistry::init('DBConfigure.' . self::$_EngineName);
}
return self::$_Engine;
} | [
"protected",
"static",
"function",
"_getEngine",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"_Engine",
")",
"{",
"self",
"::",
"$",
"_Engine",
"=",
"ClassRegistry",
"::",
"init",
"(",
"'DBConfigure.'",
".",
"self",
"::",
"$",
"_EngineName",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_Engine",
";",
"}"
] | Return engine instance
@return object | [
"Return",
"engine",
"instance"
] | e288c3f2bff9c621f57c141f7e61315bf270ce28 | https://github.com/samokspv/CakePHP-DBConfigure/blob/e288c3f2bff9c621f57c141f7e61315bf270ce28/Utility/DBConfigure.php#L92-L98 |
11,841 | samokspv/CakePHP-DBConfigure | Utility/DBConfigure.php | DBConfigure._buildWriteParams | protected static function _buildWriteParams($params = array()) {
$writeParams['equalKeysOnly'] = (
isset($params['equalKeysOnly']) &&
empty($params['equalKeysOnly']) ? false : true
);
return $writeParams;
} | php | protected static function _buildWriteParams($params = array()) {
$writeParams['equalKeysOnly'] = (
isset($params['equalKeysOnly']) &&
empty($params['equalKeysOnly']) ? false : true
);
return $writeParams;
} | [
"protected",
"static",
"function",
"_buildWriteParams",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"writeParams",
"[",
"'equalKeysOnly'",
"]",
"=",
"(",
"isset",
"(",
"$",
"params",
"[",
"'equalKeysOnly'",
"]",
")",
"&&",
"empty",
"(",
"$",
"params",
"[",
"'equalKeysOnly'",
"]",
")",
"?",
"false",
":",
"true",
")",
";",
"return",
"$",
"writeParams",
";",
"}"
] | Build write params
@param array $params
@return array | [
"Build",
"write",
"params"
] | e288c3f2bff9c621f57c141f7e61315bf270ce28 | https://github.com/samokspv/CakePHP-DBConfigure/blob/e288c3f2bff9c621f57c141f7e61315bf270ce28/Utility/DBConfigure.php#L121-L128 |
11,842 | mfrost503/Snaggle | src/Client/Header/Header.php | Header.createAuthorizationHeader | public function createAuthorizationHeader($includePrefix = false)
{
$headerParams = array(
'oauth_signature' => $this->signature->sign(),
'oauth_nonce' => $this->signature->getNonce(),
'oauth_signature_method' => $this->signature->getSignatureMethod(),
'oauth_timestamp' => $this->signature->getTimestamp(),
'oauth_consumer_key' => $this->signature->getConsumer()->getIdentifier(),
'oauth_token' => $this->signature->getUser()->getIdentifier(),
'oauth_version' => $this->signature->getVersion()
);
if (($callback = $this->signature->getCallback()) !== '') {
$headerParams['oauth_callback'] = $callback;
}
if (($verifier = $this->signature->getVerifier()) !== '') {
$headerParams['oauth_verifier'] = $verifier;
}
$tempArray = array();
ksort($headerParams);
foreach ($headerParams as $key => $value) {
$tempArray[] = $key . '="' . rawurlencode($value) . '"';
}
$prefix = "Authorization: ";
$headerString = 'OAuth ' . implode(', ', $tempArray);
return ($includePrefix) ? $prefix . $headerString : $headerString;
} | php | public function createAuthorizationHeader($includePrefix = false)
{
$headerParams = array(
'oauth_signature' => $this->signature->sign(),
'oauth_nonce' => $this->signature->getNonce(),
'oauth_signature_method' => $this->signature->getSignatureMethod(),
'oauth_timestamp' => $this->signature->getTimestamp(),
'oauth_consumer_key' => $this->signature->getConsumer()->getIdentifier(),
'oauth_token' => $this->signature->getUser()->getIdentifier(),
'oauth_version' => $this->signature->getVersion()
);
if (($callback = $this->signature->getCallback()) !== '') {
$headerParams['oauth_callback'] = $callback;
}
if (($verifier = $this->signature->getVerifier()) !== '') {
$headerParams['oauth_verifier'] = $verifier;
}
$tempArray = array();
ksort($headerParams);
foreach ($headerParams as $key => $value) {
$tempArray[] = $key . '="' . rawurlencode($value) . '"';
}
$prefix = "Authorization: ";
$headerString = 'OAuth ' . implode(', ', $tempArray);
return ($includePrefix) ? $prefix . $headerString : $headerString;
} | [
"public",
"function",
"createAuthorizationHeader",
"(",
"$",
"includePrefix",
"=",
"false",
")",
"{",
"$",
"headerParams",
"=",
"array",
"(",
"'oauth_signature'",
"=>",
"$",
"this",
"->",
"signature",
"->",
"sign",
"(",
")",
",",
"'oauth_nonce'",
"=>",
"$",
"this",
"->",
"signature",
"->",
"getNonce",
"(",
")",
",",
"'oauth_signature_method'",
"=>",
"$",
"this",
"->",
"signature",
"->",
"getSignatureMethod",
"(",
")",
",",
"'oauth_timestamp'",
"=>",
"$",
"this",
"->",
"signature",
"->",
"getTimestamp",
"(",
")",
",",
"'oauth_consumer_key'",
"=>",
"$",
"this",
"->",
"signature",
"->",
"getConsumer",
"(",
")",
"->",
"getIdentifier",
"(",
")",
",",
"'oauth_token'",
"=>",
"$",
"this",
"->",
"signature",
"->",
"getUser",
"(",
")",
"->",
"getIdentifier",
"(",
")",
",",
"'oauth_version'",
"=>",
"$",
"this",
"->",
"signature",
"->",
"getVersion",
"(",
")",
")",
";",
"if",
"(",
"(",
"$",
"callback",
"=",
"$",
"this",
"->",
"signature",
"->",
"getCallback",
"(",
")",
")",
"!==",
"''",
")",
"{",
"$",
"headerParams",
"[",
"'oauth_callback'",
"]",
"=",
"$",
"callback",
";",
"}",
"if",
"(",
"(",
"$",
"verifier",
"=",
"$",
"this",
"->",
"signature",
"->",
"getVerifier",
"(",
")",
")",
"!==",
"''",
")",
"{",
"$",
"headerParams",
"[",
"'oauth_verifier'",
"]",
"=",
"$",
"verifier",
";",
"}",
"$",
"tempArray",
"=",
"array",
"(",
")",
";",
"ksort",
"(",
"$",
"headerParams",
")",
";",
"foreach",
"(",
"$",
"headerParams",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"tempArray",
"[",
"]",
"=",
"$",
"key",
".",
"'=\"'",
".",
"rawurlencode",
"(",
"$",
"value",
")",
".",
"'\"'",
";",
"}",
"$",
"prefix",
"=",
"\"Authorization: \"",
";",
"$",
"headerString",
"=",
"'OAuth '",
".",
"implode",
"(",
"', '",
",",
"$",
"tempArray",
")",
";",
"return",
"(",
"$",
"includePrefix",
")",
"?",
"$",
"prefix",
".",
"$",
"headerString",
":",
"$",
"headerString",
";",
"}"
] | Build the authorization header
@return string | [
"Build",
"the",
"authorization",
"header"
] | 20990fe94b12b2013bca22689cde3b231eac4380 | https://github.com/mfrost503/Snaggle/blob/20990fe94b12b2013bca22689cde3b231eac4380/src/Client/Header/Header.php#L29-L58 |
11,843 | bkdotcom/Toolbox | src/DateTimeUtil.php | DateTimeUtil.getDateTime | public static function getDateTime($datetime = null)
{
if ($datetime instanceof \DateTime) {
return clone $datetime;
}
if ($datetime instanceof \DateTimeImmutable) {
return new \DateTime($datetime->format(\DateTime::ATOM));
}
if (\is_string($datetime)) {
if (\is_numeric($datetime)) {
/*
check if datetime is an int of the the form YYYYMMDD or YYYYMMDDHHMMSS
Debug::_log('datetime', $datetime)
*/
$isTs = !preg_match('/^(19|20)\d{2}(0[1-9]|1[0-2])[0-3][0-9](([01]\d|2[0-3])\d[0-5]\d[0-5]\d)?$/', $datetime);
if ($isTs) {
$datetime = '@'.$datetime;
}
}
Debug::_log('datetime', $datetime);
return new \DateTime($datetime);
}
if (\is_int($datetime) || \is_float($datetime)) {
$dateTime = new \DateTime();
$dateTime->setTimestamp($datetime);
return $dateTime;
}
return new \DateTime();
} | php | public static function getDateTime($datetime = null)
{
if ($datetime instanceof \DateTime) {
return clone $datetime;
}
if ($datetime instanceof \DateTimeImmutable) {
return new \DateTime($datetime->format(\DateTime::ATOM));
}
if (\is_string($datetime)) {
if (\is_numeric($datetime)) {
/*
check if datetime is an int of the the form YYYYMMDD or YYYYMMDDHHMMSS
Debug::_log('datetime', $datetime)
*/
$isTs = !preg_match('/^(19|20)\d{2}(0[1-9]|1[0-2])[0-3][0-9](([01]\d|2[0-3])\d[0-5]\d[0-5]\d)?$/', $datetime);
if ($isTs) {
$datetime = '@'.$datetime;
}
}
Debug::_log('datetime', $datetime);
return new \DateTime($datetime);
}
if (\is_int($datetime) || \is_float($datetime)) {
$dateTime = new \DateTime();
$dateTime->setTimestamp($datetime);
return $dateTime;
}
return new \DateTime();
} | [
"public",
"static",
"function",
"getDateTime",
"(",
"$",
"datetime",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"datetime",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"clone",
"$",
"datetime",
";",
"}",
"if",
"(",
"$",
"datetime",
"instanceof",
"\\",
"DateTimeImmutable",
")",
"{",
"return",
"new",
"\\",
"DateTime",
"(",
"$",
"datetime",
"->",
"format",
"(",
"\\",
"DateTime",
"::",
"ATOM",
")",
")",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"datetime",
")",
")",
"{",
"if",
"(",
"\\",
"is_numeric",
"(",
"$",
"datetime",
")",
")",
"{",
"/*\n check if datetime is an int of the the form YYYYMMDD or YYYYMMDDHHMMSS\n Debug::_log('datetime', $datetime)\n */",
"$",
"isTs",
"=",
"!",
"preg_match",
"(",
"'/^(19|20)\\d{2}(0[1-9]|1[0-2])[0-3][0-9](([01]\\d|2[0-3])\\d[0-5]\\d[0-5]\\d)?$/'",
",",
"$",
"datetime",
")",
";",
"if",
"(",
"$",
"isTs",
")",
"{",
"$",
"datetime",
"=",
"'@'",
".",
"$",
"datetime",
";",
"}",
"}",
"Debug",
"::",
"_log",
"(",
"'datetime'",
",",
"$",
"datetime",
")",
";",
"return",
"new",
"\\",
"DateTime",
"(",
"$",
"datetime",
")",
";",
"}",
"if",
"(",
"\\",
"is_int",
"(",
"$",
"datetime",
")",
"||",
"\\",
"is_float",
"(",
"$",
"datetime",
")",
")",
"{",
"$",
"dateTime",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"dateTime",
"->",
"setTimestamp",
"(",
"$",
"datetime",
")",
";",
"return",
"$",
"dateTime",
";",
"}",
"return",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}"
] | Return a datetime obj
@param mixed $datetime DateTime, DatetimeImmutable, int, or string
@return DateTime | [
"Return",
"a",
"datetime",
"obj"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/DateTimeUtil.php#L113-L141 |
11,844 | bkdotcom/Toolbox | src/DateTimeUtil.php | DateTimeUtil.getNextBusinessDay | public static function getNextBusinessDay($datetime, $holidays = array())
{
$dateParts = self::getdate($datetime);
// Add 1 day to begin with
$ts = \mktime(0, 0, 0, $dateParts['mon'], $dateParts['mday']+1, $dateParts['year']);
$goodDate = false;
while (!$goodDate) {
$dateParts = \getdate($ts);
if ($dateParts['weekday'] == 'Saturday') {
// Add 2 days
$ts = \mktime(0, 0, 0, $dateParts['mon'], $dateParts['mday']+2, $dateParts['year']);
} elseif ($dateParts['weekday'] == 'Sunday') {
// Add 1 day
$ts = \mktime(0, 0, 0, $dateParts['mon'], $dateParts['mday']+1, $dateParts['year']);
} elseif (\in_array(\date('Ymd', $ts), $holidays)) {
// Add 1 day
$ts = \mktime(0, 0, 0, $dateParts['mon'], $dateParts['mday']+1, $dateParts['year']);
} else {
$goodDate = true;
}
}
return self::getDateTime($ts);
} | php | public static function getNextBusinessDay($datetime, $holidays = array())
{
$dateParts = self::getdate($datetime);
// Add 1 day to begin with
$ts = \mktime(0, 0, 0, $dateParts['mon'], $dateParts['mday']+1, $dateParts['year']);
$goodDate = false;
while (!$goodDate) {
$dateParts = \getdate($ts);
if ($dateParts['weekday'] == 'Saturday') {
// Add 2 days
$ts = \mktime(0, 0, 0, $dateParts['mon'], $dateParts['mday']+2, $dateParts['year']);
} elseif ($dateParts['weekday'] == 'Sunday') {
// Add 1 day
$ts = \mktime(0, 0, 0, $dateParts['mon'], $dateParts['mday']+1, $dateParts['year']);
} elseif (\in_array(\date('Ymd', $ts), $holidays)) {
// Add 1 day
$ts = \mktime(0, 0, 0, $dateParts['mon'], $dateParts['mday']+1, $dateParts['year']);
} else {
$goodDate = true;
}
}
return self::getDateTime($ts);
} | [
"public",
"static",
"function",
"getNextBusinessDay",
"(",
"$",
"datetime",
",",
"$",
"holidays",
"=",
"array",
"(",
")",
")",
"{",
"$",
"dateParts",
"=",
"self",
"::",
"getdate",
"(",
"$",
"datetime",
")",
";",
"// Add 1 day to begin with",
"$",
"ts",
"=",
"\\",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"$",
"dateParts",
"[",
"'mon'",
"]",
",",
"$",
"dateParts",
"[",
"'mday'",
"]",
"+",
"1",
",",
"$",
"dateParts",
"[",
"'year'",
"]",
")",
";",
"$",
"goodDate",
"=",
"false",
";",
"while",
"(",
"!",
"$",
"goodDate",
")",
"{",
"$",
"dateParts",
"=",
"\\",
"getdate",
"(",
"$",
"ts",
")",
";",
"if",
"(",
"$",
"dateParts",
"[",
"'weekday'",
"]",
"==",
"'Saturday'",
")",
"{",
"// Add 2 days",
"$",
"ts",
"=",
"\\",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"$",
"dateParts",
"[",
"'mon'",
"]",
",",
"$",
"dateParts",
"[",
"'mday'",
"]",
"+",
"2",
",",
"$",
"dateParts",
"[",
"'year'",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"dateParts",
"[",
"'weekday'",
"]",
"==",
"'Sunday'",
")",
"{",
"// Add 1 day",
"$",
"ts",
"=",
"\\",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"$",
"dateParts",
"[",
"'mon'",
"]",
",",
"$",
"dateParts",
"[",
"'mday'",
"]",
"+",
"1",
",",
"$",
"dateParts",
"[",
"'year'",
"]",
")",
";",
"}",
"elseif",
"(",
"\\",
"in_array",
"(",
"\\",
"date",
"(",
"'Ymd'",
",",
"$",
"ts",
")",
",",
"$",
"holidays",
")",
")",
"{",
"// Add 1 day",
"$",
"ts",
"=",
"\\",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"$",
"dateParts",
"[",
"'mon'",
"]",
",",
"$",
"dateParts",
"[",
"'mday'",
"]",
"+",
"1",
",",
"$",
"dateParts",
"[",
"'year'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"goodDate",
"=",
"true",
";",
"}",
"}",
"return",
"self",
"::",
"getDateTime",
"(",
"$",
"ts",
")",
";",
"}"
] | Given passed datetime return DateTime of next business day
@param mixed $datetime DateTime, string, or timestamp
@param array $holidays array() Optional array of dates (formatted yyyymmdd) that will be skipped
@return DateTime | [
"Given",
"passed",
"datetime",
"return",
"DateTime",
"of",
"next",
"business",
"day"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/DateTimeUtil.php#L151-L173 |
11,845 | bkdotcom/Toolbox | src/DateTimeUtil.php | DateTimeUtil.getRelTime | public static function getRelTime($datetime, $datetimeFrom = null)
{
$ret = '';
$dateTime = self::getDateTime($datetime);
$dateTimeFrom = self::getDateTime($datetimeFrom);
$dateTimeSameDay = clone $dateTimeFrom;
$dateTimeSameDay->setTime(0, 0, 0);
$diffSec = $dateTimeFrom->getTimestamp() - $dateTime->getTimestamp();
if ($dateTime > $dateTimeFrom) {
// Future
$dateTimeTest = clone $dateTimeSameDay;
if ($dateTime < $dateTimeTest->modify('tomorrow')) {
$ret = 'Today at '.$dateTime->format('g:ia');
} elseif ($dateTime < $dateTimeTest->modify('+2 days')) {
$ret = 'Tomorrow at '.$dateTime->format('g:ia');
} else {
$ret = $dateTime->format('F jS');
}
} elseif ($diffSec < 60) {
// within a min
$ret = 'Just now';
} elseif ($diffSec < 3600) {
// within an hour
$ret = \round(($diffSec)/60) .' min ago';
} elseif ($diffSec < 3600*6) {
// within 6 hours
$hrs = \round(($diffSec)/3600);
$ret = $hrs.' '.Str::plural($hrs, 'hour').' ago';
} elseif ($dateTime > $dateTimeSameDay) { // since midnight so it's today
$ret = 'Today at '.$dateTime->format('g:ia');
} elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400) {
$ret = 'Yesterday at '.$dateTime->format('g:ia');
} elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400*7) {
$ret = $dateTime->format('l \a\t g:ia');
} elseif ($dateTime->getTimestamp() > \mktime(0, 0, 0, 1, 1)) {// since 1st Jan so it's this year
$ret = $dateTime->format('F jS');
} else { // last year..
$ret = $dateTime->format('F jS, Y');
}
$ret = \str_replace(' at 12:00am', '', $ret);
return $ret;
} | php | public static function getRelTime($datetime, $datetimeFrom = null)
{
$ret = '';
$dateTime = self::getDateTime($datetime);
$dateTimeFrom = self::getDateTime($datetimeFrom);
$dateTimeSameDay = clone $dateTimeFrom;
$dateTimeSameDay->setTime(0, 0, 0);
$diffSec = $dateTimeFrom->getTimestamp() - $dateTime->getTimestamp();
if ($dateTime > $dateTimeFrom) {
// Future
$dateTimeTest = clone $dateTimeSameDay;
if ($dateTime < $dateTimeTest->modify('tomorrow')) {
$ret = 'Today at '.$dateTime->format('g:ia');
} elseif ($dateTime < $dateTimeTest->modify('+2 days')) {
$ret = 'Tomorrow at '.$dateTime->format('g:ia');
} else {
$ret = $dateTime->format('F jS');
}
} elseif ($diffSec < 60) {
// within a min
$ret = 'Just now';
} elseif ($diffSec < 3600) {
// within an hour
$ret = \round(($diffSec)/60) .' min ago';
} elseif ($diffSec < 3600*6) {
// within 6 hours
$hrs = \round(($diffSec)/3600);
$ret = $hrs.' '.Str::plural($hrs, 'hour').' ago';
} elseif ($dateTime > $dateTimeSameDay) { // since midnight so it's today
$ret = 'Today at '.$dateTime->format('g:ia');
} elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400) {
$ret = 'Yesterday at '.$dateTime->format('g:ia');
} elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400*7) {
$ret = $dateTime->format('l \a\t g:ia');
} elseif ($dateTime->getTimestamp() > \mktime(0, 0, 0, 1, 1)) {// since 1st Jan so it's this year
$ret = $dateTime->format('F jS');
} else { // last year..
$ret = $dateTime->format('F jS, Y');
}
$ret = \str_replace(' at 12:00am', '', $ret);
return $ret;
} | [
"public",
"static",
"function",
"getRelTime",
"(",
"$",
"datetime",
",",
"$",
"datetimeFrom",
"=",
"null",
")",
"{",
"$",
"ret",
"=",
"''",
";",
"$",
"dateTime",
"=",
"self",
"::",
"getDateTime",
"(",
"$",
"datetime",
")",
";",
"$",
"dateTimeFrom",
"=",
"self",
"::",
"getDateTime",
"(",
"$",
"datetimeFrom",
")",
";",
"$",
"dateTimeSameDay",
"=",
"clone",
"$",
"dateTimeFrom",
";",
"$",
"dateTimeSameDay",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"$",
"diffSec",
"=",
"$",
"dateTimeFrom",
"->",
"getTimestamp",
"(",
")",
"-",
"$",
"dateTime",
"->",
"getTimestamp",
"(",
")",
";",
"if",
"(",
"$",
"dateTime",
">",
"$",
"dateTimeFrom",
")",
"{",
"// Future",
"$",
"dateTimeTest",
"=",
"clone",
"$",
"dateTimeSameDay",
";",
"if",
"(",
"$",
"dateTime",
"<",
"$",
"dateTimeTest",
"->",
"modify",
"(",
"'tomorrow'",
")",
")",
"{",
"$",
"ret",
"=",
"'Today at '",
".",
"$",
"dateTime",
"->",
"format",
"(",
"'g:ia'",
")",
";",
"}",
"elseif",
"(",
"$",
"dateTime",
"<",
"$",
"dateTimeTest",
"->",
"modify",
"(",
"'+2 days'",
")",
")",
"{",
"$",
"ret",
"=",
"'Tomorrow at '",
".",
"$",
"dateTime",
"->",
"format",
"(",
"'g:ia'",
")",
";",
"}",
"else",
"{",
"$",
"ret",
"=",
"$",
"dateTime",
"->",
"format",
"(",
"'F jS'",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"diffSec",
"<",
"60",
")",
"{",
"// within a min",
"$",
"ret",
"=",
"'Just now'",
";",
"}",
"elseif",
"(",
"$",
"diffSec",
"<",
"3600",
")",
"{",
"// within an hour",
"$",
"ret",
"=",
"\\",
"round",
"(",
"(",
"$",
"diffSec",
")",
"/",
"60",
")",
".",
"' min ago'",
";",
"}",
"elseif",
"(",
"$",
"diffSec",
"<",
"3600",
"*",
"6",
")",
"{",
"// within 6 hours",
"$",
"hrs",
"=",
"\\",
"round",
"(",
"(",
"$",
"diffSec",
")",
"/",
"3600",
")",
";",
"$",
"ret",
"=",
"$",
"hrs",
".",
"' '",
".",
"Str",
"::",
"plural",
"(",
"$",
"hrs",
",",
"'hour'",
")",
".",
"' ago'",
";",
"}",
"elseif",
"(",
"$",
"dateTime",
">",
"$",
"dateTimeSameDay",
")",
"{",
"// since midnight so it's today",
"$",
"ret",
"=",
"'Today at '",
".",
"$",
"dateTime",
"->",
"format",
"(",
"'g:ia'",
")",
";",
"}",
"elseif",
"(",
"$",
"dateTime",
"->",
"getTimestamp",
"(",
")",
">=",
"$",
"dateTimeSameDay",
"->",
"getTimestamp",
"(",
")",
"-",
"86400",
")",
"{",
"$",
"ret",
"=",
"'Yesterday at '",
".",
"$",
"dateTime",
"->",
"format",
"(",
"'g:ia'",
")",
";",
"}",
"elseif",
"(",
"$",
"dateTime",
"->",
"getTimestamp",
"(",
")",
">=",
"$",
"dateTimeSameDay",
"->",
"getTimestamp",
"(",
")",
"-",
"86400",
"*",
"7",
")",
"{",
"$",
"ret",
"=",
"$",
"dateTime",
"->",
"format",
"(",
"'l \\a\\t g:ia'",
")",
";",
"}",
"elseif",
"(",
"$",
"dateTime",
"->",
"getTimestamp",
"(",
")",
">",
"\\",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
")",
")",
"{",
"// since 1st Jan so it's this year",
"$",
"ret",
"=",
"$",
"dateTime",
"->",
"format",
"(",
"'F jS'",
")",
";",
"}",
"else",
"{",
"// last year..",
"$",
"ret",
"=",
"$",
"dateTime",
"->",
"format",
"(",
"'F jS, Y'",
")",
";",
"}",
"$",
"ret",
"=",
"\\",
"str_replace",
"(",
"' at 12:00am'",
",",
"''",
",",
"$",
"ret",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Return a "3 hours ago" type string for passed timestamp
@param mixed $datetime DateTime, string, or timestamp
@param mixed $datetimeFrom (default = now) DateTime, string, or timestamp
@return string | [
"Return",
"a",
"3",
"hours",
"ago",
"type",
"string",
"for",
"passed",
"timestamp"
] | 2f9d34fd57bd8382baee4c29aac13a6710e3a994 | https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/DateTimeUtil.php#L266-L307 |
11,846 | snapwp/snap-debug | src/Handlers/General.php | General.get_handler | public function get_handler()
{
$handler = new PrettyPageHandler();
$handler->addDataTableCallback('$wp_query', [$this, 'add_query']);
$handler->addDataTableCallback('$post', [$this, 'add_post']);
$handler->addDataTableCallback('$wp', [$this, 'add_wp']);
return $handler;
} | php | public function get_handler()
{
$handler = new PrettyPageHandler();
$handler->addDataTableCallback('$wp_query', [$this, 'add_query']);
$handler->addDataTableCallback('$post', [$this, 'add_post']);
$handler->addDataTableCallback('$wp', [$this, 'add_wp']);
return $handler;
} | [
"public",
"function",
"get_handler",
"(",
")",
"{",
"$",
"handler",
"=",
"new",
"PrettyPageHandler",
"(",
")",
";",
"$",
"handler",
"->",
"addDataTableCallback",
"(",
"'$wp_query'",
",",
"[",
"$",
"this",
",",
"'add_query'",
"]",
")",
";",
"$",
"handler",
"->",
"addDataTableCallback",
"(",
"'$post'",
",",
"[",
"$",
"this",
",",
"'add_post'",
"]",
")",
";",
"$",
"handler",
"->",
"addDataTableCallback",
"(",
"'$wp'",
",",
"[",
"$",
"this",
",",
"'add_wp'",
"]",
")",
";",
"return",
"$",
"handler",
";",
"}"
] | Return the Whoops PrettyPageHandler.
@since 1.0.0
@return PrettyPageHandler | [
"Return",
"the",
"Whoops",
"PrettyPageHandler",
"."
] | 49c0c258ce50098a3fca076ce122adf57571f2e2 | https://github.com/snapwp/snap-debug/blob/49c0c258ce50098a3fca076ce122adf57571f2e2/src/Handlers/General.php#L22-L33 |
11,847 | snapwp/snap-debug | src/Handlers/General.php | General.add_query | public function add_query()
{
global $wp_query;
if (! $wp_query instanceof WP_Query) {
return [];
}
$output = \get_object_vars($wp_query);
$output['query_vars'] = \array_filter($output['query_vars']);
unset($output['posts'], $output['post']);
return \array_filter($output);
} | php | public function add_query()
{
global $wp_query;
if (! $wp_query instanceof WP_Query) {
return [];
}
$output = \get_object_vars($wp_query);
$output['query_vars'] = \array_filter($output['query_vars']);
unset($output['posts'], $output['post']);
return \array_filter($output);
} | [
"public",
"function",
"add_query",
"(",
")",
"{",
"global",
"$",
"wp_query",
";",
"if",
"(",
"!",
"$",
"wp_query",
"instanceof",
"WP_Query",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"output",
"=",
"\\",
"get_object_vars",
"(",
"$",
"wp_query",
")",
";",
"$",
"output",
"[",
"'query_vars'",
"]",
"=",
"\\",
"array_filter",
"(",
"$",
"output",
"[",
"'query_vars'",
"]",
")",
";",
"unset",
"(",
"$",
"output",
"[",
"'posts'",
"]",
",",
"$",
"output",
"[",
"'post'",
"]",
")",
";",
"return",
"\\",
"array_filter",
"(",
"$",
"output",
")",
";",
"}"
] | Add the WP_Query global to Whoops data list.
@since 1.0.0
@return array | [
"Add",
"the",
"WP_Query",
"global",
"to",
"Whoops",
"data",
"list",
"."
] | 49c0c258ce50098a3fca076ce122adf57571f2e2 | https://github.com/snapwp/snap-debug/blob/49c0c258ce50098a3fca076ce122adf57571f2e2/src/Handlers/General.php#L42-L57 |
11,848 | snapwp/snap-debug | src/Handlers/General.php | General.add_wp | public function add_wp()
{
global $wp;
if (! $wp instanceof WP) {
return array();
}
$output = \get_object_vars($wp);
unset($output['private_query_vars'], $output['public_query_vars']);
return \array_filter($output);
} | php | public function add_wp()
{
global $wp;
if (! $wp instanceof WP) {
return array();
}
$output = \get_object_vars($wp);
unset($output['private_query_vars'], $output['public_query_vars']);
return \array_filter($output);
} | [
"public",
"function",
"add_wp",
"(",
")",
"{",
"global",
"$",
"wp",
";",
"if",
"(",
"!",
"$",
"wp",
"instanceof",
"WP",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"output",
"=",
"\\",
"get_object_vars",
"(",
"$",
"wp",
")",
";",
"unset",
"(",
"$",
"output",
"[",
"'private_query_vars'",
"]",
",",
"$",
"output",
"[",
"'public_query_vars'",
"]",
")",
";",
"return",
"\\",
"array_filter",
"(",
"$",
"output",
")",
";",
"}"
] | Add the WP global to Whoops data list.
@since 1.0.0
@return array | [
"Add",
"the",
"WP",
"global",
"to",
"Whoops",
"data",
"list",
"."
] | 49c0c258ce50098a3fca076ce122adf57571f2e2 | https://github.com/snapwp/snap-debug/blob/49c0c258ce50098a3fca076ce122adf57571f2e2/src/Handlers/General.php#L84-L97 |
11,849 | rozaverta/cmf | core/Event/EventManager.php | EventManager.dispatcher | public static function dispatcher($name)
{
static $all = [];
if(! isset($all[$name]))
{
// system has been installed
// use default mode
if(Helper::isSystemInstall())
{
$cache = new Cache($name, 'events');
if( $cache->ready() )
{
$data = $cache->import();
}
else
{
$event = new EventFactory($name);
if( $event->load() === false )
{
throw new NotFoundException("Event '{$name}' is not registered in system");
}
$data = $event->getContentData();
if(! $cache->export($data))
{
throw new WriteException("Can't write cache data for the '{$name}' event");
}
}
}
else
{
$data = (new EventFactory($name))->getContentData();
}
$manager = new Dispatcher(
$data["name"],
$data["completable"],
function (Dispatcher $manager) use ($data) {
foreach($data["classes"] as $class_name)
{
/** @var \EApp\Event\Interfaces\EventPrepareInterface $class */
$class = new $class_name($data["name"]);
$class->prepare($manager);
}
});
$all[$name] = $manager;
}
return $all[$name];
} | php | public static function dispatcher($name)
{
static $all = [];
if(! isset($all[$name]))
{
// system has been installed
// use default mode
if(Helper::isSystemInstall())
{
$cache = new Cache($name, 'events');
if( $cache->ready() )
{
$data = $cache->import();
}
else
{
$event = new EventFactory($name);
if( $event->load() === false )
{
throw new NotFoundException("Event '{$name}' is not registered in system");
}
$data = $event->getContentData();
if(! $cache->export($data))
{
throw new WriteException("Can't write cache data for the '{$name}' event");
}
}
}
else
{
$data = (new EventFactory($name))->getContentData();
}
$manager = new Dispatcher(
$data["name"],
$data["completable"],
function (Dispatcher $manager) use ($data) {
foreach($data["classes"] as $class_name)
{
/** @var \EApp\Event\Interfaces\EventPrepareInterface $class */
$class = new $class_name($data["name"]);
$class->prepare($manager);
}
});
$all[$name] = $manager;
}
return $all[$name];
} | [
"public",
"static",
"function",
"dispatcher",
"(",
"$",
"name",
")",
"{",
"static",
"$",
"all",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"all",
"[",
"$",
"name",
"]",
")",
")",
"{",
"// system has been installed",
"// use default mode",
"if",
"(",
"Helper",
"::",
"isSystemInstall",
"(",
")",
")",
"{",
"$",
"cache",
"=",
"new",
"Cache",
"(",
"$",
"name",
",",
"'events'",
")",
";",
"if",
"(",
"$",
"cache",
"->",
"ready",
"(",
")",
")",
"{",
"$",
"data",
"=",
"$",
"cache",
"->",
"import",
"(",
")",
";",
"}",
"else",
"{",
"$",
"event",
"=",
"new",
"EventFactory",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"event",
"->",
"load",
"(",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"Event '{$name}' is not registered in system\"",
")",
";",
"}",
"$",
"data",
"=",
"$",
"event",
"->",
"getContentData",
"(",
")",
";",
"if",
"(",
"!",
"$",
"cache",
"->",
"export",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"WriteException",
"(",
"\"Can't write cache data for the '{$name}' event\"",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"data",
"=",
"(",
"new",
"EventFactory",
"(",
"$",
"name",
")",
")",
"->",
"getContentData",
"(",
")",
";",
"}",
"$",
"manager",
"=",
"new",
"Dispatcher",
"(",
"$",
"data",
"[",
"\"name\"",
"]",
",",
"$",
"data",
"[",
"\"completable\"",
"]",
",",
"function",
"(",
"Dispatcher",
"$",
"manager",
")",
"use",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"[",
"\"classes\"",
"]",
"as",
"$",
"class_name",
")",
"{",
"/** @var \\EApp\\Event\\Interfaces\\EventPrepareInterface $class */",
"$",
"class",
"=",
"new",
"$",
"class_name",
"(",
"$",
"data",
"[",
"\"name\"",
"]",
")",
";",
"$",
"class",
"->",
"prepare",
"(",
"$",
"manager",
")",
";",
"}",
"}",
")",
";",
"$",
"all",
"[",
"$",
"name",
"]",
"=",
"$",
"manager",
";",
"}",
"return",
"$",
"all",
"[",
"$",
"name",
"]",
";",
"}"
] | Get event manager element from cache
@param $name
@return \EApp\Event\Dispatcher
@throws \Exception | [
"Get",
"event",
"manager",
"element",
"from",
"cache"
] | 95ed38362e397d1c700ee255f7200234ef98d356 | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Event/EventManager.php#L26-L78 |
11,850 | monomelodies/dabble | src/Query.php | Query.error | protected function error($msg, array $bind = [])
{
foreach ($bind as $key => $value) {
if (is_null($value)) {
$value = 'NULL';
} elseif (is_bool($value)) {
$value = $value ? 'true' : 'false';
}
$msg .= "$key => $value\n";
}
return $msg;
} | php | protected function error($msg, array $bind = [])
{
foreach ($bind as $key => $value) {
if (is_null($value)) {
$value = 'NULL';
} elseif (is_bool($value)) {
$value = $value ? 'true' : 'false';
}
$msg .= "$key => $value\n";
}
return $msg;
} | [
"protected",
"function",
"error",
"(",
"$",
"msg",
",",
"array",
"$",
"bind",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"bind",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"'NULL'",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"?",
"'true'",
":",
"'false'",
";",
"}",
"$",
"msg",
".=",
"\"$key => $value\\n\"",
";",
"}",
"return",
"$",
"msg",
";",
"}"
] | Internal helper to correctly format error messages.
@param string $msg The original error message.
@param array $bind Array of bound values.
@return string Formatted error message. | [
"Internal",
"helper",
"to",
"correctly",
"format",
"error",
"messages",
"."
] | 4ba771cf90116b61821af8d15652cb6e5665e4b7 | https://github.com/monomelodies/dabble/blob/4ba771cf90116b61821af8d15652cb6e5665e4b7/src/Query.php#L91-L102 |
11,851 | yuanqing/extract | src/Extract.php | Extract.parseCapturingGroup | private function parseCapturingGroup($group, $charBefore, $charAfter)
{
$split = explode(':', $group); # split on ':'
# $key is before the ':''
$key = trim($split[0]);
if ($key === '' || $key == '.') {
throw new \InvalidArgumentException('Invalid capturing group');
}
$this->keys[] = $key;
# $specifier is after the ':'
if (!isset($split[1])) { # no $specifier
if ($charAfter !== '' || $charBefore !== '') {
return sprintf('([^%s]+)', preg_quote($charAfter !== '' ? $charAfter : $charBefore, '/'));
}
return '(.+)';
}
$specifier = trim($split[1]);
if ($specifier === '0') {
throw new \InvalidArgumentException('Invalid length specifier: 0');
}
# last char of $specifier is the $type
$type = substr($specifier, -1);
switch ($type) {
case 'd': # integer
case 's': # string
$len = trim(substr($specifier, 0, -1));
if ($len === '') {
$len = '1,';
} else {
if (!$this->canCastToInteger($len) || intval($len) === 0) {
throw new \InvalidArgumentException(sprintf('Invalid length specifier: %s', $len));
}
}
break;
case 'f': # float
$len = trim(substr($specifier, 0, -1));
if ($len === '') { # ie. no length specified
$lenBeforeDec = $lenAfterDec = '1,';
} else {
if ($len[0] == '.') { # first char is '.'
$lenBeforeDec = '0,';
$lenAfterDec = substr($len, 1);
} else if (substr($len, -1) == '.') { # last char is '.'
$lenBeforeDec = substr($len, 0, -1);
$lenAfterDec = '0,';
} else {
if ($len === '0.0' || $len === '0') {
throw new \InvalidArgumentException('Invalid length specifier: 0.0');
}
$split = explode('.', $len);
$lenBeforeDec = trim($split[0]);
$lenAfterDec = trim($split[1]);
}
}
break;
default: # no type
$len = $specifier;
if (!$this->canCastToInteger($len)) {
throw new \InvalidArgumentException(sprintf('Invalid length specifier: %s', $specifier));
}
}
# finally, return the capturing group
switch ($type) {
case 'd':
return sprintf('(\d{%s})', $len);
case 'f':
return sprintf('([-+]?\d{%s}\.\d{%s})', $lenBeforeDec, $lenAfterDec);
default:
return sprintf('(.{%s})', $len);
}
} | php | private function parseCapturingGroup($group, $charBefore, $charAfter)
{
$split = explode(':', $group); # split on ':'
# $key is before the ':''
$key = trim($split[0]);
if ($key === '' || $key == '.') {
throw new \InvalidArgumentException('Invalid capturing group');
}
$this->keys[] = $key;
# $specifier is after the ':'
if (!isset($split[1])) { # no $specifier
if ($charAfter !== '' || $charBefore !== '') {
return sprintf('([^%s]+)', preg_quote($charAfter !== '' ? $charAfter : $charBefore, '/'));
}
return '(.+)';
}
$specifier = trim($split[1]);
if ($specifier === '0') {
throw new \InvalidArgumentException('Invalid length specifier: 0');
}
# last char of $specifier is the $type
$type = substr($specifier, -1);
switch ($type) {
case 'd': # integer
case 's': # string
$len = trim(substr($specifier, 0, -1));
if ($len === '') {
$len = '1,';
} else {
if (!$this->canCastToInteger($len) || intval($len) === 0) {
throw new \InvalidArgumentException(sprintf('Invalid length specifier: %s', $len));
}
}
break;
case 'f': # float
$len = trim(substr($specifier, 0, -1));
if ($len === '') { # ie. no length specified
$lenBeforeDec = $lenAfterDec = '1,';
} else {
if ($len[0] == '.') { # first char is '.'
$lenBeforeDec = '0,';
$lenAfterDec = substr($len, 1);
} else if (substr($len, -1) == '.') { # last char is '.'
$lenBeforeDec = substr($len, 0, -1);
$lenAfterDec = '0,';
} else {
if ($len === '0.0' || $len === '0') {
throw new \InvalidArgumentException('Invalid length specifier: 0.0');
}
$split = explode('.', $len);
$lenBeforeDec = trim($split[0]);
$lenAfterDec = trim($split[1]);
}
}
break;
default: # no type
$len = $specifier;
if (!$this->canCastToInteger($len)) {
throw new \InvalidArgumentException(sprintf('Invalid length specifier: %s', $specifier));
}
}
# finally, return the capturing group
switch ($type) {
case 'd':
return sprintf('(\d{%s})', $len);
case 'f':
return sprintf('([-+]?\d{%s}\.\d{%s})', $lenBeforeDec, $lenAfterDec);
default:
return sprintf('(.{%s})', $len);
}
} | [
"private",
"function",
"parseCapturingGroup",
"(",
"$",
"group",
",",
"$",
"charBefore",
",",
"$",
"charAfter",
")",
"{",
"$",
"split",
"=",
"explode",
"(",
"':'",
",",
"$",
"group",
")",
";",
"# split on ':'",
"# $key is before the ':''",
"$",
"key",
"=",
"trim",
"(",
"$",
"split",
"[",
"0",
"]",
")",
";",
"if",
"(",
"$",
"key",
"===",
"''",
"||",
"$",
"key",
"==",
"'.'",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid capturing group'",
")",
";",
"}",
"$",
"this",
"->",
"keys",
"[",
"]",
"=",
"$",
"key",
";",
"# $specifier is after the ':'",
"if",
"(",
"!",
"isset",
"(",
"$",
"split",
"[",
"1",
"]",
")",
")",
"{",
"# no $specifier",
"if",
"(",
"$",
"charAfter",
"!==",
"''",
"||",
"$",
"charBefore",
"!==",
"''",
")",
"{",
"return",
"sprintf",
"(",
"'([^%s]+)'",
",",
"preg_quote",
"(",
"$",
"charAfter",
"!==",
"''",
"?",
"$",
"charAfter",
":",
"$",
"charBefore",
",",
"'/'",
")",
")",
";",
"}",
"return",
"'(.+)'",
";",
"}",
"$",
"specifier",
"=",
"trim",
"(",
"$",
"split",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"specifier",
"===",
"'0'",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid length specifier: 0'",
")",
";",
"}",
"# last char of $specifier is the $type",
"$",
"type",
"=",
"substr",
"(",
"$",
"specifier",
",",
"-",
"1",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'d'",
":",
"# integer",
"case",
"'s'",
":",
"# string",
"$",
"len",
"=",
"trim",
"(",
"substr",
"(",
"$",
"specifier",
",",
"0",
",",
"-",
"1",
")",
")",
";",
"if",
"(",
"$",
"len",
"===",
"''",
")",
"{",
"$",
"len",
"=",
"'1,'",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"canCastToInteger",
"(",
"$",
"len",
")",
"||",
"intval",
"(",
"$",
"len",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid length specifier: %s'",
",",
"$",
"len",
")",
")",
";",
"}",
"}",
"break",
";",
"case",
"'f'",
":",
"# float",
"$",
"len",
"=",
"trim",
"(",
"substr",
"(",
"$",
"specifier",
",",
"0",
",",
"-",
"1",
")",
")",
";",
"if",
"(",
"$",
"len",
"===",
"''",
")",
"{",
"# ie. no length specified",
"$",
"lenBeforeDec",
"=",
"$",
"lenAfterDec",
"=",
"'1,'",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"len",
"[",
"0",
"]",
"==",
"'.'",
")",
"{",
"# first char is '.'",
"$",
"lenBeforeDec",
"=",
"'0,'",
";",
"$",
"lenAfterDec",
"=",
"substr",
"(",
"$",
"len",
",",
"1",
")",
";",
"}",
"else",
"if",
"(",
"substr",
"(",
"$",
"len",
",",
"-",
"1",
")",
"==",
"'.'",
")",
"{",
"# last char is '.'",
"$",
"lenBeforeDec",
"=",
"substr",
"(",
"$",
"len",
",",
"0",
",",
"-",
"1",
")",
";",
"$",
"lenAfterDec",
"=",
"'0,'",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"len",
"===",
"'0.0'",
"||",
"$",
"len",
"===",
"'0'",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid length specifier: 0.0'",
")",
";",
"}",
"$",
"split",
"=",
"explode",
"(",
"'.'",
",",
"$",
"len",
")",
";",
"$",
"lenBeforeDec",
"=",
"trim",
"(",
"$",
"split",
"[",
"0",
"]",
")",
";",
"$",
"lenAfterDec",
"=",
"trim",
"(",
"$",
"split",
"[",
"1",
"]",
")",
";",
"}",
"}",
"break",
";",
"default",
":",
"# no type",
"$",
"len",
"=",
"$",
"specifier",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"canCastToInteger",
"(",
"$",
"len",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid length specifier: %s'",
",",
"$",
"specifier",
")",
")",
";",
"}",
"}",
"# finally, return the capturing group",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'d'",
":",
"return",
"sprintf",
"(",
"'(\\d{%s})'",
",",
"$",
"len",
")",
";",
"case",
"'f'",
":",
"return",
"sprintf",
"(",
"'([-+]?\\d{%s}\\.\\d{%s})'",
",",
"$",
"lenBeforeDec",
",",
"$",
"lenAfterDec",
")",
";",
"default",
":",
"return",
"sprintf",
"(",
"'(.{%s})'",
",",
"$",
"len",
")",
";",
"}",
"}"
] | Parses a raw capturing group into a RegEx capturing group
@param string $group The string between the opening braces and closing braces
@param string $charBefore The character immediately before the opening braces
@param string $charAfter The character immediately after the closing braces
@throws UnexpectedValueException | [
"Parses",
"a",
"raw",
"capturing",
"group",
"into",
"a",
"RegEx",
"capturing",
"group"
] | c1c207e19ce50bb244485c262ce7741ca36a0b8c | https://github.com/yuanqing/extract/blob/c1c207e19ce50bb244485c262ce7741ca36a0b8c/src/Extract.php#L81-L156 |
11,852 | sebastianmonzel/webfiles-framework-php | source/core/datatypes/time/MTimestampHelper.php | MTimestampHelper.getMonthEnd | public static function getMonthEnd($month = -1, $year = -1)
{
if ($month == -1) {
$month = date("n");
}
if ($year == -1) {
$year = date("Y");
}
//gets the number of days in the actual month
$tempTime = mktime(0, 0, 0, $month, 1, $year);
$tempTime = date("t", $tempTime);
return mktime(23, 59, 59, $month, $tempTime, $year);
} | php | public static function getMonthEnd($month = -1, $year = -1)
{
if ($month == -1) {
$month = date("n");
}
if ($year == -1) {
$year = date("Y");
}
//gets the number of days in the actual month
$tempTime = mktime(0, 0, 0, $month, 1, $year);
$tempTime = date("t", $tempTime);
return mktime(23, 59, 59, $month, $tempTime, $year);
} | [
"public",
"static",
"function",
"getMonthEnd",
"(",
"$",
"month",
"=",
"-",
"1",
",",
"$",
"year",
"=",
"-",
"1",
")",
"{",
"if",
"(",
"$",
"month",
"==",
"-",
"1",
")",
"{",
"$",
"month",
"=",
"date",
"(",
"\"n\"",
")",
";",
"}",
"if",
"(",
"$",
"year",
"==",
"-",
"1",
")",
"{",
"$",
"year",
"=",
"date",
"(",
"\"Y\"",
")",
";",
"}",
"//gets the number of days in the actual month",
"$",
"tempTime",
"=",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"$",
"month",
",",
"1",
",",
"$",
"year",
")",
";",
"$",
"tempTime",
"=",
"date",
"(",
"\"t\"",
",",
"$",
"tempTime",
")",
";",
"return",
"mktime",
"(",
"23",
",",
"59",
",",
"59",
",",
"$",
"month",
",",
"$",
"tempTime",
",",
"$",
"year",
")",
";",
"}"
] | returns a timestamp of the end of a month
@param int $month
@param int $year
@return false|int | [
"returns",
"a",
"timestamp",
"of",
"the",
"end",
"of",
"a",
"month"
] | 5ac1fc99e8e9946080e3ba877b2320cd6a3e5b5d | https://github.com/sebastianmonzel/webfiles-framework-php/blob/5ac1fc99e8e9946080e3ba877b2320cd6a3e5b5d/source/core/datatypes/time/MTimestampHelper.php#L35-L49 |
11,853 | sebastianmonzel/webfiles-framework-php | source/core/datatypes/time/MTimestampHelper.php | MTimestampHelper.getFormatedDate | public static function getFormatedDate($timestamp)
{
return MTimestampHelper::getDay($timestamp) . "." . MTimestampHelper::getMonth($timestamp) . "." . MTimestampHelper::getYear($timestamp);
} | php | public static function getFormatedDate($timestamp)
{
return MTimestampHelper::getDay($timestamp) . "." . MTimestampHelper::getMonth($timestamp) . "." . MTimestampHelper::getYear($timestamp);
} | [
"public",
"static",
"function",
"getFormatedDate",
"(",
"$",
"timestamp",
")",
"{",
"return",
"MTimestampHelper",
"::",
"getDay",
"(",
"$",
"timestamp",
")",
".",
"\".\"",
".",
"MTimestampHelper",
"::",
"getMonth",
"(",
"$",
"timestamp",
")",
".",
"\".\"",
".",
"MTimestampHelper",
"::",
"getYear",
"(",
"$",
"timestamp",
")",
";",
"}"
] | returns the given timestamp in a manner like
@param duration duration in seconds
@return string | [
"returns",
"the",
"given",
"timestamp",
"in",
"a",
"manner",
"like"
] | 5ac1fc99e8e9946080e3ba877b2320cd6a3e5b5d | https://github.com/sebastianmonzel/webfiles-framework-php/blob/5ac1fc99e8e9946080e3ba877b2320cd6a3e5b5d/source/core/datatypes/time/MTimestampHelper.php#L143-L146 |
11,854 | bugadani/DBTiny | src/Driver.php | Driver.inTransaction | public function inTransaction(callable $function)
{
if (!is_callable($function)) {
throw new InvalidArgumentException('$function must be callable.');
}
$this->beginTransaction();
try {
if (func_num_args() === 1) {
$returnValue = $function($this);
} else {
$args = func_get_args();
$args[0] = $this;
$returnValue = call_user_func_array($function, $args);
}
$this->commit();
return $returnValue;
} catch (\PDOException $e) {
$this->rollBack();
throw $e;
}
} | php | public function inTransaction(callable $function)
{
if (!is_callable($function)) {
throw new InvalidArgumentException('$function must be callable.');
}
$this->beginTransaction();
try {
if (func_num_args() === 1) {
$returnValue = $function($this);
} else {
$args = func_get_args();
$args[0] = $this;
$returnValue = call_user_func_array($function, $args);
}
$this->commit();
return $returnValue;
} catch (\PDOException $e) {
$this->rollBack();
throw $e;
}
} | [
"public",
"function",
"inTransaction",
"(",
"callable",
"$",
"function",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"function",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$function must be callable.'",
")",
";",
"}",
"$",
"this",
"->",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"1",
")",
"{",
"$",
"returnValue",
"=",
"$",
"function",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"args",
"[",
"0",
"]",
"=",
"$",
"this",
";",
"$",
"returnValue",
"=",
"call_user_func_array",
"(",
"$",
"function",
",",
"$",
"args",
")",
";",
"}",
"$",
"this",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"returnValue",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"rollBack",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] | Call a function guarded by a transaction.
@param callable $function The function to guard. First argument is the driver, the rest are the arguments
passed to the method.
@return mixed The return value of the guarded function | [
"Call",
"a",
"function",
"guarded",
"by",
"a",
"transaction",
"."
] | c25af0ae6234084cc4466bedea14b670b2169b34 | https://github.com/bugadani/DBTiny/blob/c25af0ae6234084cc4466bedea14b670b2169b34/src/Driver.php#L53-L73 |
11,855 | jamesmcfadden/gen | src/Layout.php | Layout.render | public function render(Page $page)
{
return $this->doRender(
$this->getRawContent(),
$this->getAttributes() + ['content' => $page->getRenderedContent()]
);
} | php | public function render(Page $page)
{
return $this->doRender(
$this->getRawContent(),
$this->getAttributes() + ['content' => $page->getRenderedContent()]
);
} | [
"public",
"function",
"render",
"(",
"Page",
"$",
"page",
")",
"{",
"return",
"$",
"this",
"->",
"doRender",
"(",
"$",
"this",
"->",
"getRawContent",
"(",
")",
",",
"$",
"this",
"->",
"getAttributes",
"(",
")",
"+",
"[",
"'content'",
"=>",
"$",
"page",
"->",
"getRenderedContent",
"(",
")",
"]",
")",
";",
"}"
] | Render the layout with a given Page.
@param Page $page
@return string | [
"Render",
"the",
"layout",
"with",
"a",
"given",
"Page",
"."
] | 2c7a7da1c3a04e10463c956722f85f5da13dc179 | https://github.com/jamesmcfadden/gen/blob/2c7a7da1c3a04e10463c956722f85f5da13dc179/src/Layout.php#L58-L64 |
11,856 | vox-tecnologia/functions | src/Functions/AbstractFunctions.php | AbstractFunctions.parameterTypeCheck | public function parameterTypeCheck($param, string $type = 'string'): bool
{
$type = 'is_'.$type;
return (bool) ($type($param) && ! empty($param));
} | php | public function parameterTypeCheck($param, string $type = 'string'): bool
{
$type = 'is_'.$type;
return (bool) ($type($param) && ! empty($param));
} | [
"public",
"function",
"parameterTypeCheck",
"(",
"$",
"param",
",",
"string",
"$",
"type",
"=",
"'string'",
")",
":",
"bool",
"{",
"$",
"type",
"=",
"'is_'",
".",
"$",
"type",
";",
"return",
"(",
"bool",
")",
"(",
"$",
"type",
"(",
"$",
"param",
")",
"&&",
"!",
"empty",
"(",
"$",
"param",
")",
")",
";",
"}"
] | Parameter type check.
@param mixed $param The input parameter
@param string $type The type of parameter [bool, float, int, string, array, object]
@return bool
@api | [
"Parameter",
"type",
"check",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/AbstractFunctions.php#L110-L115 |
11,857 | vox-tecnologia/functions | src/Functions/AbstractFunctions.php | AbstractFunctions.arrayKeyExistsRecursive | public function arrayKeyExistsRecursive(string $needle, array $haystack): bool
{
$result = array_key_exists($needle, $haystack);
if (true === $result) {
return $result;
}
$this->arrayKeyExistsRecursiveExtended($needle, $haystack);
return $result;
} | php | public function arrayKeyExistsRecursive(string $needle, array $haystack): bool
{
$result = array_key_exists($needle, $haystack);
if (true === $result) {
return $result;
}
$this->arrayKeyExistsRecursiveExtended($needle, $haystack);
return $result;
} | [
"public",
"function",
"arrayKeyExistsRecursive",
"(",
"string",
"$",
"needle",
",",
"array",
"$",
"haystack",
")",
":",
"bool",
"{",
"$",
"result",
"=",
"array_key_exists",
"(",
"$",
"needle",
",",
"$",
"haystack",
")",
";",
"if",
"(",
"true",
"===",
"$",
"result",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"this",
"->",
"arrayKeyExistsRecursiveExtended",
"(",
"$",
"needle",
",",
"$",
"haystack",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Recursive version of array_key_exists.
The PHP funcction 'array_key_exists' does NOT work recursively, so this
can be used to find a key nested in a multidimensional array.
Another option is to use the 'array_walk_recursive' function since PHP 5.3.
@param string $needle The search string
@param array $haystack The space indented setting
@return bool The set of formatted <link> stylesheet tags
@api | [
"Recursive",
"version",
"of",
"array_key_exists",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/AbstractFunctions.php#L133-L142 |
11,858 | vox-tecnologia/functions | src/Functions/AbstractFunctions.php | AbstractFunctions.arrayKeyExistsRecursiveExtended | public function arrayKeyExistsRecursiveExtended(string $needle, array $haystack): bool
{
$result = false;
foreach ($haystack as $value) {
if (true === is_array($value)) {
$result = $this->arrayKeyExistsRecursive($needle, $value);
}
if (true === $result) {
return $result;
}
}
return $result;
} | php | public function arrayKeyExistsRecursiveExtended(string $needle, array $haystack): bool
{
$result = false;
foreach ($haystack as $value) {
if (true === is_array($value)) {
$result = $this->arrayKeyExistsRecursive($needle, $value);
}
if (true === $result) {
return $result;
}
}
return $result;
} | [
"public",
"function",
"arrayKeyExistsRecursiveExtended",
"(",
"string",
"$",
"needle",
",",
"array",
"$",
"haystack",
")",
":",
"bool",
"{",
"$",
"result",
"=",
"false",
";",
"foreach",
"(",
"$",
"haystack",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"arrayKeyExistsRecursive",
"(",
"$",
"needle",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"result",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Recursive version extended sub-function.
@param string $needle The search string
@param array $haystack The space indented setting
@return bool
@api | [
"Recursive",
"version",
"extended",
"sub",
"-",
"function",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/AbstractFunctions.php#L156-L169 |
11,859 | vox-tecnologia/functions | src/Functions/AbstractFunctions.php | AbstractFunctions.getTitledItem | public function getTitledItem(string $str, string $item = null, string $delimiter = ';'): string
{
return (null === $item)
? trim(substr(trim(substr($str, 0)), 0, $this->getStringPositionX(trim(substr($str, 0)), $delimiter, 1)))
: trim(substr(trim(substr($str, $this->getStringPositionX($str, $item, 1) + strlen($item))), 0, $this->getStringPositionX(trim(substr($str, $this->getStringPositionX($str, $item, 1) + strlen($item))), $delimiter, 1)));
} | php | public function getTitledItem(string $str, string $item = null, string $delimiter = ';'): string
{
return (null === $item)
? trim(substr(trim(substr($str, 0)), 0, $this->getStringPositionX(trim(substr($str, 0)), $delimiter, 1)))
: trim(substr(trim(substr($str, $this->getStringPositionX($str, $item, 1) + strlen($item))), 0, $this->getStringPositionX(trim(substr($str, $this->getStringPositionX($str, $item, 1) + strlen($item))), $delimiter, 1)));
} | [
"public",
"function",
"getTitledItem",
"(",
"string",
"$",
"str",
",",
"string",
"$",
"item",
"=",
"null",
",",
"string",
"$",
"delimiter",
"=",
"';'",
")",
":",
"string",
"{",
"return",
"(",
"null",
"===",
"$",
"item",
")",
"?",
"trim",
"(",
"substr",
"(",
"trim",
"(",
"substr",
"(",
"$",
"str",
",",
"0",
")",
")",
",",
"0",
",",
"$",
"this",
"->",
"getStringPositionX",
"(",
"trim",
"(",
"substr",
"(",
"$",
"str",
",",
"0",
")",
")",
",",
"$",
"delimiter",
",",
"1",
")",
")",
")",
":",
"trim",
"(",
"substr",
"(",
"trim",
"(",
"substr",
"(",
"$",
"str",
",",
"$",
"this",
"->",
"getStringPositionX",
"(",
"$",
"str",
",",
"$",
"item",
",",
"1",
")",
"+",
"strlen",
"(",
"$",
"item",
")",
")",
")",
",",
"0",
",",
"$",
"this",
"->",
"getStringPositionX",
"(",
"trim",
"(",
"substr",
"(",
"$",
"str",
",",
"$",
"this",
"->",
"getStringPositionX",
"(",
"$",
"str",
",",
"$",
"item",
",",
"1",
")",
"+",
"strlen",
"(",
"$",
"item",
")",
")",
")",
",",
"$",
"delimiter",
",",
"1",
")",
")",
")",
";",
"}"
] | A parser for title delimited data.
@param string $str The string data used to parse
@param string $item The defined title item to find
@param string $delimiter The default ending delimiter
@return string
@api | [
"A",
"parser",
"for",
"title",
"delimited",
"data",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/AbstractFunctions.php#L184-L189 |
11,860 | vox-tecnologia/functions | src/Functions/AbstractFunctions.php | AbstractFunctions.sftpCreateDirectory | protected function sftpCreateDirectory(): FunctionsInterface
{
/* the directory structure on remote host must exist to SFTP */
if (true === $this->get('_createRemoteDirectory')) {
(file_exists($this->get('_localCacheFilePath')) && $this->get('_localFileSize') > 0)
? $this->get('_sftp')->deleteDirectory($this->get('_remoteDirectoryPath'), true)->createDirectory($this->get('_remoteDirectoryPath'))
: $this->get('_sftp')->deleteDirectory($this->get('_remoteDirectoryPath'), true);
}
return $this;
} | php | protected function sftpCreateDirectory(): FunctionsInterface
{
/* the directory structure on remote host must exist to SFTP */
if (true === $this->get('_createRemoteDirectory')) {
(file_exists($this->get('_localCacheFilePath')) && $this->get('_localFileSize') > 0)
? $this->get('_sftp')->deleteDirectory($this->get('_remoteDirectoryPath'), true)->createDirectory($this->get('_remoteDirectoryPath'))
: $this->get('_sftp')->deleteDirectory($this->get('_remoteDirectoryPath'), true);
}
return $this;
} | [
"protected",
"function",
"sftpCreateDirectory",
"(",
")",
":",
"FunctionsInterface",
"{",
"/* the directory structure on remote host must exist to SFTP */",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"get",
"(",
"'_createRemoteDirectory'",
")",
")",
"{",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"get",
"(",
"'_localCacheFilePath'",
")",
")",
"&&",
"$",
"this",
"->",
"get",
"(",
"'_localFileSize'",
")",
">",
"0",
")",
"?",
"$",
"this",
"->",
"get",
"(",
"'_sftp'",
")",
"->",
"deleteDirectory",
"(",
"$",
"this",
"->",
"get",
"(",
"'_remoteDirectoryPath'",
")",
",",
"true",
")",
"->",
"createDirectory",
"(",
"$",
"this",
"->",
"get",
"(",
"'_remoteDirectoryPath'",
")",
")",
":",
"$",
"this",
"->",
"get",
"(",
"'_sftp'",
")",
"->",
"deleteDirectory",
"(",
"$",
"this",
"->",
"get",
"(",
"'_remoteDirectoryPath'",
")",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Handling new directory creation.
@return FunctionsInterface
@api | [
"Handling",
"new",
"directory",
"creation",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/AbstractFunctions.php#L219-L229 |
11,861 | vox-tecnologia/functions | src/Functions/AbstractFunctions.php | AbstractFunctions.sftpTransport | protected function sftpTransport(ServiceRequestContainer $service, string $account): FunctionsInterface
{
$this->set('_account', $account)
->set('_sftp', $service->Sftp)
->set('_persist', $service->Persistence)
->set('_localCacheFilePath', $this->get('localCacheFilePath'))
->set('_remoteFilePath', $service->Database->viewData['remoteFilePath'])
->set('_remoteDirectoryPath', $service->Database->viewData['remoteDirectoryPath'])
->set('_createRemoteDirectory', $service->Database->viewData['sftpCreateRemoteDirectory'])
->set('_accountSettings', $service->ConfigurationVault->openVaultFile('account', $account)->all())
->set('_localFileSize', (file_exists($this->get('_localCacheFilePath')) ? filesize($this->get('_localCacheFilePath')) : 0));
$this->get('_sftp')->connect($this->get('_accountSettings'));
return $this->sftpCreateDirectory()->sftpUploadFile()->sftpRecordFileSizes()->sftpCompareFileSizes();
} | php | protected function sftpTransport(ServiceRequestContainer $service, string $account): FunctionsInterface
{
$this->set('_account', $account)
->set('_sftp', $service->Sftp)
->set('_persist', $service->Persistence)
->set('_localCacheFilePath', $this->get('localCacheFilePath'))
->set('_remoteFilePath', $service->Database->viewData['remoteFilePath'])
->set('_remoteDirectoryPath', $service->Database->viewData['remoteDirectoryPath'])
->set('_createRemoteDirectory', $service->Database->viewData['sftpCreateRemoteDirectory'])
->set('_accountSettings', $service->ConfigurationVault->openVaultFile('account', $account)->all())
->set('_localFileSize', (file_exists($this->get('_localCacheFilePath')) ? filesize($this->get('_localCacheFilePath')) : 0));
$this->get('_sftp')->connect($this->get('_accountSettings'));
return $this->sftpCreateDirectory()->sftpUploadFile()->sftpRecordFileSizes()->sftpCompareFileSizes();
} | [
"protected",
"function",
"sftpTransport",
"(",
"ServiceRequestContainer",
"$",
"service",
",",
"string",
"$",
"account",
")",
":",
"FunctionsInterface",
"{",
"$",
"this",
"->",
"set",
"(",
"'_account'",
",",
"$",
"account",
")",
"->",
"set",
"(",
"'_sftp'",
",",
"$",
"service",
"->",
"Sftp",
")",
"->",
"set",
"(",
"'_persist'",
",",
"$",
"service",
"->",
"Persistence",
")",
"->",
"set",
"(",
"'_localCacheFilePath'",
",",
"$",
"this",
"->",
"get",
"(",
"'localCacheFilePath'",
")",
")",
"->",
"set",
"(",
"'_remoteFilePath'",
",",
"$",
"service",
"->",
"Database",
"->",
"viewData",
"[",
"'remoteFilePath'",
"]",
")",
"->",
"set",
"(",
"'_remoteDirectoryPath'",
",",
"$",
"service",
"->",
"Database",
"->",
"viewData",
"[",
"'remoteDirectoryPath'",
"]",
")",
"->",
"set",
"(",
"'_createRemoteDirectory'",
",",
"$",
"service",
"->",
"Database",
"->",
"viewData",
"[",
"'sftpCreateRemoteDirectory'",
"]",
")",
"->",
"set",
"(",
"'_accountSettings'",
",",
"$",
"service",
"->",
"ConfigurationVault",
"->",
"openVaultFile",
"(",
"'account'",
",",
"$",
"account",
")",
"->",
"all",
"(",
")",
")",
"->",
"set",
"(",
"'_localFileSize'",
",",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"get",
"(",
"'_localCacheFilePath'",
")",
")",
"?",
"filesize",
"(",
"$",
"this",
"->",
"get",
"(",
"'_localCacheFilePath'",
")",
")",
":",
"0",
")",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'_sftp'",
")",
"->",
"connect",
"(",
"$",
"this",
"->",
"get",
"(",
"'_accountSettings'",
")",
")",
";",
"return",
"$",
"this",
"->",
"sftpCreateDirectory",
"(",
")",
"->",
"sftpUploadFile",
"(",
")",
"->",
"sftpRecordFileSizes",
"(",
")",
"->",
"sftpCompareFileSizes",
"(",
")",
";",
"}"
] | Upload file to remote server.
@param ServiceRequestContainer $service The ServiceRequestContainer Instance
@param string $account The account on remote host for SFTP transfer
@return FunctionsInterface
@api | [
"Upload",
"file",
"to",
"remote",
"server",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/AbstractFunctions.php#L285-L300 |
11,862 | vox-tecnologia/functions | src/Functions/AbstractFunctions.php | AbstractFunctions.setLocalCache | protected function setLocalCache(FilesystemInterface $filesystem, string $absoluteFilePath, $content): FunctionsInterface
{
$this->set(
'localCacheFilePath',
$this->get('localCacheDirectory').'/'.
sha1(Config::APPLICATION_KEY).'/'.
sha1($absoluteFilePath).'.'.
$this->getFileExtension($absoluteFilePath)
);
$filesystem->write($this->get('localCacheFilePath'), (string) $content);
return $this;
} | php | protected function setLocalCache(FilesystemInterface $filesystem, string $absoluteFilePath, $content): FunctionsInterface
{
$this->set(
'localCacheFilePath',
$this->get('localCacheDirectory').'/'.
sha1(Config::APPLICATION_KEY).'/'.
sha1($absoluteFilePath).'.'.
$this->getFileExtension($absoluteFilePath)
);
$filesystem->write($this->get('localCacheFilePath'), (string) $content);
return $this;
} | [
"protected",
"function",
"setLocalCache",
"(",
"FilesystemInterface",
"$",
"filesystem",
",",
"string",
"$",
"absoluteFilePath",
",",
"$",
"content",
")",
":",
"FunctionsInterface",
"{",
"$",
"this",
"->",
"set",
"(",
"'localCacheFilePath'",
",",
"$",
"this",
"->",
"get",
"(",
"'localCacheDirectory'",
")",
".",
"'/'",
".",
"sha1",
"(",
"Config",
"::",
"APPLICATION_KEY",
")",
".",
"'/'",
".",
"sha1",
"(",
"$",
"absoluteFilePath",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"getFileExtension",
"(",
"$",
"absoluteFilePath",
")",
")",
";",
"$",
"filesystem",
"->",
"write",
"(",
"$",
"this",
"->",
"get",
"(",
"'localCacheFilePath'",
")",
",",
"(",
"string",
")",
"$",
"content",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Cache a local file to disk.
@param FilesystemInterface $filesystem The FilesystemInterface
@param string $absoluteFilePath The absolute file path (e.g., the full unique filename)
@param TemplateFactoryInterface|string $content The TemplateFactory Interface or a string-type
@return FunctionsInterface
@api | [
"Cache",
"a",
"local",
"file",
"to",
"disk",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/AbstractFunctions.php#L315-L328 |
11,863 | studyportals/SQL | src/QueryBuilder.php | QueryBuilder._checkType | protected function _checkType($value, $type){
// Integers and floats are allowed be NULL
if($value === null && $type != 'bool'){
return true;
}
switch($type){
case 'int':
$reducer = function($result, $value){
if(!is_int($value)){
$result = false;
}
return $result;
};
break;
case 'float':
$reducer = function($result, $value){
if(!is_float($value)){
$result = false;
}
return $result;
};
break;
case 'bool':
$reducer = function($result, $value){
if(!is_bool($value)){
$result = false;
}
return $result;
};
break;
default:
ExceptionHandler::notice("Invalid property type $type");
return false;
}
if(is_array($value)){
$result = array_reduce($value, $reducer, true);
}
else{
$result = $reducer(true, $value);
}
return $result;
} | php | protected function _checkType($value, $type){
// Integers and floats are allowed be NULL
if($value === null && $type != 'bool'){
return true;
}
switch($type){
case 'int':
$reducer = function($result, $value){
if(!is_int($value)){
$result = false;
}
return $result;
};
break;
case 'float':
$reducer = function($result, $value){
if(!is_float($value)){
$result = false;
}
return $result;
};
break;
case 'bool':
$reducer = function($result, $value){
if(!is_bool($value)){
$result = false;
}
return $result;
};
break;
default:
ExceptionHandler::notice("Invalid property type $type");
return false;
}
if(is_array($value)){
$result = array_reduce($value, $reducer, true);
}
else{
$result = $reducer(true, $value);
}
return $result;
} | [
"protected",
"function",
"_checkType",
"(",
"$",
"value",
",",
"$",
"type",
")",
"{",
"// Integers and floats are allowed be NULL",
"if",
"(",
"$",
"value",
"===",
"null",
"&&",
"$",
"type",
"!=",
"'bool'",
")",
"{",
"return",
"true",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'int'",
":",
"$",
"reducer",
"=",
"function",
"(",
"$",
"result",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}",
";",
"break",
";",
"case",
"'float'",
":",
"$",
"reducer",
"=",
"function",
"(",
"$",
"result",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_float",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}",
";",
"break",
";",
"case",
"'bool'",
":",
"$",
"reducer",
"=",
"function",
"(",
"$",
"result",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}",
";",
"break",
";",
"default",
":",
"ExceptionHandler",
"::",
"notice",
"(",
"\"Invalid property type $type\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"=",
"array_reduce",
"(",
"$",
"value",
",",
"$",
"reducer",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"reducer",
"(",
"true",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Check the type of the provided value.
<p>Checks whether the provided {@link $value} is of the provided {@link
$type}. When {@link $value} is an array the check is performed on all
elements of the array. The check fails if any of the array-elements (or
the value itself) are not of the specified type.</p>
@param mixed $value
@param string $type [int|float|bool]
@return boolean | [
"Check",
"the",
"type",
"of",
"the",
"provided",
"value",
"."
] | 4f038ced9a3738c1d4ad562f93547812931d9ed4 | https://github.com/studyportals/SQL/blob/4f038ced9a3738c1d4ad562f93547812931d9ed4/src/QueryBuilder.php#L135-L205 |
11,864 | studyportals/SQL | src/QueryBuilder.php | QueryBuilder._parseMarker | protected function _parseMarker($marker, $parameter, $brace){
$brace = strtolower($brace);
$result = [
'uid' => md5(uniqid($parameter, true)),
'force-type' => null,
'identifier' => false
];
// Integer quick-marker (#parameter# => @[int]parameter@)
if($marker == '#'){
assert('$brace == \'\'');
$brace = 'int';
}
// Identifier quick-marker ($parameter$ => @[ident]parameter@)
elseif($marker == '$'){
assert('$brace == \'\'');
$brace = 'identifier';
}
switch($brace){
case 'int':
case 'float':
case 'bool':
$result['force-type'] = $brace;
break;
case 'ident':
case 'identifier':
$result['identifier'] = true;
break;
default:
if($brace != ''){
throw new InvalidSyntaxException("Invalid type-hint '$brace' encountered");
}
}
if($parameter == ''){
throw new InvalidSyntaxException('Invalid parameter name');
}
$result['parameter'] = $parameter;
return $result;
} | php | protected function _parseMarker($marker, $parameter, $brace){
$brace = strtolower($brace);
$result = [
'uid' => md5(uniqid($parameter, true)),
'force-type' => null,
'identifier' => false
];
// Integer quick-marker (#parameter# => @[int]parameter@)
if($marker == '#'){
assert('$brace == \'\'');
$brace = 'int';
}
// Identifier quick-marker ($parameter$ => @[ident]parameter@)
elseif($marker == '$'){
assert('$brace == \'\'');
$brace = 'identifier';
}
switch($brace){
case 'int':
case 'float':
case 'bool':
$result['force-type'] = $brace;
break;
case 'ident':
case 'identifier':
$result['identifier'] = true;
break;
default:
if($brace != ''){
throw new InvalidSyntaxException("Invalid type-hint '$brace' encountered");
}
}
if($parameter == ''){
throw new InvalidSyntaxException('Invalid parameter name');
}
$result['parameter'] = $parameter;
return $result;
} | [
"protected",
"function",
"_parseMarker",
"(",
"$",
"marker",
",",
"$",
"parameter",
",",
"$",
"brace",
")",
"{",
"$",
"brace",
"=",
"strtolower",
"(",
"$",
"brace",
")",
";",
"$",
"result",
"=",
"[",
"'uid'",
"=>",
"md5",
"(",
"uniqid",
"(",
"$",
"parameter",
",",
"true",
")",
")",
",",
"'force-type'",
"=>",
"null",
",",
"'identifier'",
"=>",
"false",
"]",
";",
"// Integer quick-marker (#parameter# => @[int]parameter@)",
"if",
"(",
"$",
"marker",
"==",
"'#'",
")",
"{",
"assert",
"(",
"'$brace == \\'\\''",
")",
";",
"$",
"brace",
"=",
"'int'",
";",
"}",
"// Identifier quick-marker ($parameter$ => @[ident]parameter@)",
"elseif",
"(",
"$",
"marker",
"==",
"'$'",
")",
"{",
"assert",
"(",
"'$brace == \\'\\''",
")",
";",
"$",
"brace",
"=",
"'identifier'",
";",
"}",
"switch",
"(",
"$",
"brace",
")",
"{",
"case",
"'int'",
":",
"case",
"'float'",
":",
"case",
"'bool'",
":",
"$",
"result",
"[",
"'force-type'",
"]",
"=",
"$",
"brace",
";",
"break",
";",
"case",
"'ident'",
":",
"case",
"'identifier'",
":",
"$",
"result",
"[",
"'identifier'",
"]",
"=",
"true",
";",
"break",
";",
"default",
":",
"if",
"(",
"$",
"brace",
"!=",
"''",
")",
"{",
"throw",
"new",
"InvalidSyntaxException",
"(",
"\"Invalid type-hint '$brace' encountered\"",
")",
";",
"}",
"}",
"if",
"(",
"$",
"parameter",
"==",
"''",
")",
"{",
"throw",
"new",
"InvalidSyntaxException",
"(",
"'Invalid parameter name'",
")",
";",
"}",
"$",
"result",
"[",
"'parameter'",
"]",
"=",
"$",
"parameter",
";",
"return",
"$",
"result",
";",
"}"
] | Parse the contents of a QueryBuilder marker.
@param string $marker
@param string $parameter
@param string $brace
@return array
@throws InvalidSyntaxException | [
"Parse",
"the",
"contents",
"of",
"a",
"QueryBuilder",
"marker",
"."
] | 4f038ced9a3738c1d4ad562f93547812931d9ed4 | https://github.com/studyportals/SQL/blob/4f038ced9a3738c1d4ad562f93547812931d9ed4/src/QueryBuilder.php#L508-L567 |
11,865 | studyportals/SQL | src/QueryBuilder.php | QueryBuilder.compose | public function compose(SQL $SQL){
$tokens = [];
$query_string = '';
foreach($this->_values as $name => $value){
// Throws an exception on invalid name/value
$this->_checkParameter($name, $value);
assert('is_array($this->_parameters[$name])');
$prepared_value = $this->_prepareValue($value, $SQL,
$this->_parameters[$name]['identifier']);
$tokens[$this->_parameters[$name]['uid']] = $prepared_value;
}
foreach($this->_query as $query_part){
list($token, $value) = explode(' ', $query_part, 2);
switch($token){
case 'P':
if(isset($tokens[$value])){
$query_string .= $tokens[$value];
}
break;
case 'T':
$query_string .= $value;
break;
default: ExceptionHandler::notice("Invalid token $token");
}
}
return $query_string;
} | php | public function compose(SQL $SQL){
$tokens = [];
$query_string = '';
foreach($this->_values as $name => $value){
// Throws an exception on invalid name/value
$this->_checkParameter($name, $value);
assert('is_array($this->_parameters[$name])');
$prepared_value = $this->_prepareValue($value, $SQL,
$this->_parameters[$name]['identifier']);
$tokens[$this->_parameters[$name]['uid']] = $prepared_value;
}
foreach($this->_query as $query_part){
list($token, $value) = explode(' ', $query_part, 2);
switch($token){
case 'P':
if(isset($tokens[$value])){
$query_string .= $tokens[$value];
}
break;
case 'T':
$query_string .= $value;
break;
default: ExceptionHandler::notice("Invalid token $token");
}
}
return $query_string;
} | [
"public",
"function",
"compose",
"(",
"SQL",
"$",
"SQL",
")",
"{",
"$",
"tokens",
"=",
"[",
"]",
";",
"$",
"query_string",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"_values",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"// Throws an exception on invalid name/value",
"$",
"this",
"->",
"_checkParameter",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"assert",
"(",
"'is_array($this->_parameters[$name])'",
")",
";",
"$",
"prepared_value",
"=",
"$",
"this",
"->",
"_prepareValue",
"(",
"$",
"value",
",",
"$",
"SQL",
",",
"$",
"this",
"->",
"_parameters",
"[",
"$",
"name",
"]",
"[",
"'identifier'",
"]",
")",
";",
"$",
"tokens",
"[",
"$",
"this",
"->",
"_parameters",
"[",
"$",
"name",
"]",
"[",
"'uid'",
"]",
"]",
"=",
"$",
"prepared_value",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_query",
"as",
"$",
"query_part",
")",
"{",
"list",
"(",
"$",
"token",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"query_part",
",",
"2",
")",
";",
"switch",
"(",
"$",
"token",
")",
"{",
"case",
"'P'",
":",
"if",
"(",
"isset",
"(",
"$",
"tokens",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"query_string",
".=",
"$",
"tokens",
"[",
"$",
"value",
"]",
";",
"}",
"break",
";",
"case",
"'T'",
":",
"$",
"query_string",
".=",
"$",
"value",
";",
"break",
";",
"default",
":",
"ExceptionHandler",
"::",
"notice",
"(",
"\"Invalid token $token\"",
")",
";",
"}",
"}",
"return",
"$",
"query_string",
";",
"}"
] | Composes the query present in this QueryBuilder instance.
@param SQL $SQL
@return string
@throws QueryBuilderException | [
"Composes",
"the",
"query",
"present",
"in",
"this",
"QueryBuilder",
"instance",
"."
] | 4f038ced9a3738c1d4ad562f93547812931d9ed4 | https://github.com/studyportals/SQL/blob/4f038ced9a3738c1d4ad562f93547812931d9ed4/src/QueryBuilder.php#L577-L621 |
11,866 | studyportals/SQL | src/QueryBuilder.php | QueryBuilder._prepareValue | protected function _prepareValue($value, SQL $SQL, $identifier = false){
// Identifier should be string (purely a sanity-check, enforced elsewhere)
assert('!(!is_string($value) && $identifier)');
// String
if(is_string($value)){
// NULL
if(strtoupper($value) == 'NULL'){
$value = 'NULL';
}
// Identifier string
elseif($identifier){
/*
* Surround the identifier with "identifier quote characters"
* (either backtick or double quote, depending on SQL mode) and
* escape all further occurences of said character with itself.
*/
$quote = self::IDENTIFIER_QUOTE;
$value = str_replace($quote, $quote . $quote, $value);
$value = $quote . $value . $quote;
}
// Regular string
else{
$value = '\'' . $SQL->escapeString($value) . '\'';
}
}
// Integer
elseif(is_int($value)){
$value = (string) $value;
}
// Floating-point
elseif(is_float($value)){
$value = (string) $value;
// Ensure no (other) invalid characters are present
assert('!preg_match(\'/[^\d.e+\-]/i\', $value)');
$value = preg_replace('/[^\d.e+\-]/i', '', $value);
}
// Boolean (interpreted as INT(1))
elseif(is_bool($value)){
// Don't convert directly to string, (int) false === ''!
$value = (string) ((int) $value);
}
// NULL
elseif($value === null){
$value = 'NULL';
}
// Array (interpret either as SET or as a list of ID's)
elseif(is_array($value)){
$is_string = null;
$callback = function($value) use($SQL, &$is_string){
// Values should be either string or integer
assert('is_string($value) || is_int($value)');
if(!is_int($value)) $value = (string) $value;
// All values should be of the same type, no "mixed bags"
assert('$is_string === null || is_string($value) === $is_string');
if(is_string($value)) $is_string = true;
return $SQL->escapeString($value);
};
array_map($callback, $value);
$value = implode(',', $value);
if($is_string) $value = "'{$value}'";
}
// Object
elseif(is_object($value)){
$value = '\'' . $SQL->escapeString(serialize($value)) . '\'';
}
// Invalid
else{
throw new QueryBuilderException('Data of type "' . gettype($value)
. '" cannot be used in an SQL-query');
}
return $value;
} | php | protected function _prepareValue($value, SQL $SQL, $identifier = false){
// Identifier should be string (purely a sanity-check, enforced elsewhere)
assert('!(!is_string($value) && $identifier)');
// String
if(is_string($value)){
// NULL
if(strtoupper($value) == 'NULL'){
$value = 'NULL';
}
// Identifier string
elseif($identifier){
/*
* Surround the identifier with "identifier quote characters"
* (either backtick or double quote, depending on SQL mode) and
* escape all further occurences of said character with itself.
*/
$quote = self::IDENTIFIER_QUOTE;
$value = str_replace($quote, $quote . $quote, $value);
$value = $quote . $value . $quote;
}
// Regular string
else{
$value = '\'' . $SQL->escapeString($value) . '\'';
}
}
// Integer
elseif(is_int($value)){
$value = (string) $value;
}
// Floating-point
elseif(is_float($value)){
$value = (string) $value;
// Ensure no (other) invalid characters are present
assert('!preg_match(\'/[^\d.e+\-]/i\', $value)');
$value = preg_replace('/[^\d.e+\-]/i', '', $value);
}
// Boolean (interpreted as INT(1))
elseif(is_bool($value)){
// Don't convert directly to string, (int) false === ''!
$value = (string) ((int) $value);
}
// NULL
elseif($value === null){
$value = 'NULL';
}
// Array (interpret either as SET or as a list of ID's)
elseif(is_array($value)){
$is_string = null;
$callback = function($value) use($SQL, &$is_string){
// Values should be either string or integer
assert('is_string($value) || is_int($value)');
if(!is_int($value)) $value = (string) $value;
// All values should be of the same type, no "mixed bags"
assert('$is_string === null || is_string($value) === $is_string');
if(is_string($value)) $is_string = true;
return $SQL->escapeString($value);
};
array_map($callback, $value);
$value = implode(',', $value);
if($is_string) $value = "'{$value}'";
}
// Object
elseif(is_object($value)){
$value = '\'' . $SQL->escapeString(serialize($value)) . '\'';
}
// Invalid
else{
throw new QueryBuilderException('Data of type "' . gettype($value)
. '" cannot be used in an SQL-query');
}
return $value;
} | [
"protected",
"function",
"_prepareValue",
"(",
"$",
"value",
",",
"SQL",
"$",
"SQL",
",",
"$",
"identifier",
"=",
"false",
")",
"{",
"// Identifier should be string (purely a sanity-check, enforced elsewhere)",
"assert",
"(",
"'!(!is_string($value) && $identifier)'",
")",
";",
"// String",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"// NULL",
"if",
"(",
"strtoupper",
"(",
"$",
"value",
")",
"==",
"'NULL'",
")",
"{",
"$",
"value",
"=",
"'NULL'",
";",
"}",
"// Identifier string",
"elseif",
"(",
"$",
"identifier",
")",
"{",
"/*\n\t\t\t\t * Surround the identifier with \"identifier quote characters\"\n\t\t\t\t * (either backtick or double quote, depending on SQL mode) and\n\t\t\t\t * escape all further occurences of said character with itself.\n\t\t\t\t */",
"$",
"quote",
"=",
"self",
"::",
"IDENTIFIER_QUOTE",
";",
"$",
"value",
"=",
"str_replace",
"(",
"$",
"quote",
",",
"$",
"quote",
".",
"$",
"quote",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"quote",
".",
"$",
"value",
".",
"$",
"quote",
";",
"}",
"// Regular string",
"else",
"{",
"$",
"value",
"=",
"'\\''",
".",
"$",
"SQL",
"->",
"escapeString",
"(",
"$",
"value",
")",
".",
"'\\''",
";",
"}",
"}",
"// Integer",
"elseif",
"(",
"is_int",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"// Floating-point",
"elseif",
"(",
"is_float",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"// Ensure no (other) invalid characters are present",
"assert",
"(",
"'!preg_match(\\'/[^\\d.e+\\-]/i\\', $value)'",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'/[^\\d.e+\\-]/i'",
",",
"''",
",",
"$",
"value",
")",
";",
"}",
"// Boolean (interpreted as INT(1))",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"// Don't convert directly to string, (int) false === ''!",
"$",
"value",
"=",
"(",
"string",
")",
"(",
"(",
"int",
")",
"$",
"value",
")",
";",
"}",
"// NULL",
"elseif",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"value",
"=",
"'NULL'",
";",
"}",
"// Array (interpret either as SET or as a list of ID's)",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"is_string",
"=",
"null",
";",
"$",
"callback",
"=",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"SQL",
",",
"&",
"$",
"is_string",
")",
"{",
"// Values should be either string or integer",
"assert",
"(",
"'is_string($value) || is_int($value)'",
")",
";",
"if",
"(",
"!",
"is_int",
"(",
"$",
"value",
")",
")",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"// All values should be of the same type, no \"mixed bags\"",
"assert",
"(",
"'$is_string === null || is_string($value) === $is_string'",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"$",
"is_string",
"=",
"true",
";",
"return",
"$",
"SQL",
"->",
"escapeString",
"(",
"$",
"value",
")",
";",
"}",
";",
"array_map",
"(",
"$",
"callback",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"implode",
"(",
"','",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"is_string",
")",
"$",
"value",
"=",
"\"'{$value}'\"",
";",
"}",
"// Object",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"'\\''",
".",
"$",
"SQL",
"->",
"escapeString",
"(",
"serialize",
"(",
"$",
"value",
")",
")",
".",
"'\\''",
";",
"}",
"// Invalid",
"else",
"{",
"throw",
"new",
"QueryBuilderException",
"(",
"'Data of type \"'",
".",
"gettype",
"(",
"$",
"value",
")",
".",
"'\" cannot be used in an SQL-query'",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Prepares a variable to be inserted into an SQL Query.
@param mixed $value
@param SQL $SQL
@param boolean $identifier Use the value as an SQL "identifier"
@return string
@throws QueryBuilderException | [
"Prepares",
"a",
"variable",
"to",
"be",
"inserted",
"into",
"an",
"SQL",
"Query",
"."
] | 4f038ced9a3738c1d4ad562f93547812931d9ed4 | https://github.com/studyportals/SQL/blob/4f038ced9a3738c1d4ad562f93547812931d9ed4/src/QueryBuilder.php#L633-L754 |
11,867 | studyportals/SQL | src/QueryBuilder.php | QueryBuilder.execute | public function execute(SQL $SQL, $return_set = false, $buffered = true){
$query_string = $this->compose($SQL);
$this->reset();
return $SQL->Query($query_string, $return_set, $buffered);
} | php | public function execute(SQL $SQL, $return_set = false, $buffered = true){
$query_string = $this->compose($SQL);
$this->reset();
return $SQL->Query($query_string, $return_set, $buffered);
} | [
"public",
"function",
"execute",
"(",
"SQL",
"$",
"SQL",
",",
"$",
"return_set",
"=",
"false",
",",
"$",
"buffered",
"=",
"true",
")",
"{",
"$",
"query_string",
"=",
"$",
"this",
"->",
"compose",
"(",
"$",
"SQL",
")",
";",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"return",
"$",
"SQL",
"->",
"Query",
"(",
"$",
"query_string",
",",
"$",
"return_set",
",",
"$",
"buffered",
")",
";",
"}"
] | Execute the query and reset the object's state.
<p>For details on the optional arguments to this method, see the
documentation of the {@link SQL::Query()} method.</p>
@param SQL $SQL
@param boolean $return_set
@param boolean $buffered
@throws QueryBuilderException
@return SQLResult
@see SQL::Query() | [
"Execute",
"the",
"query",
"and",
"reset",
"the",
"object",
"s",
"state",
"."
] | 4f038ced9a3738c1d4ad562f93547812931d9ed4 | https://github.com/studyportals/SQL/blob/4f038ced9a3738c1d4ad562f93547812931d9ed4/src/QueryBuilder.php#L771-L778 |
11,868 | benkle-libs/doctrine-adoption | src/MetadataListener.php | MetadataListener.loadClassMetadata | public function loadClassMetadata(LoadClassMetadataEventArgs $class)
{
$metaData = $class->getClassMetadata();
$adoptees = $this->collector->getAdoptees($metaData->name);
foreach ($adoptees as $discriminator => $adoptee) {
$metaData->discriminatorMap[$discriminator] = $adoptee;
}
} | php | public function loadClassMetadata(LoadClassMetadataEventArgs $class)
{
$metaData = $class->getClassMetadata();
$adoptees = $this->collector->getAdoptees($metaData->name);
foreach ($adoptees as $discriminator => $adoptee) {
$metaData->discriminatorMap[$discriminator] = $adoptee;
}
} | [
"public",
"function",
"loadClassMetadata",
"(",
"LoadClassMetadataEventArgs",
"$",
"class",
")",
"{",
"$",
"metaData",
"=",
"$",
"class",
"->",
"getClassMetadata",
"(",
")",
";",
"$",
"adoptees",
"=",
"$",
"this",
"->",
"collector",
"->",
"getAdoptees",
"(",
"$",
"metaData",
"->",
"name",
")",
";",
"foreach",
"(",
"$",
"adoptees",
"as",
"$",
"discriminator",
"=>",
"$",
"adoptee",
")",
"{",
"$",
"metaData",
"->",
"discriminatorMap",
"[",
"$",
"discriminator",
"]",
"=",
"$",
"adoptee",
";",
"}",
"}"
] | Handle LoadClassMetadataEvents to inject adoptees.
@param LoadClassMetadataEventArgs $class | [
"Handle",
"LoadClassMetadataEvents",
"to",
"inject",
"adoptees",
"."
] | 01dcb48d7224c7003fa0acbac5c2ddd54d860fd4 | https://github.com/benkle-libs/doctrine-adoption/blob/01dcb48d7224c7003fa0acbac5c2ddd54d860fd4/src/MetadataListener.php#L46-L53 |
11,869 | axypro/callbacks | Helper.php | Helper.toNative | public static function toNative($callback)
{
if (!is_array($callback)) {
return self::getNative($callback);
}
if (!array_key_exists('0', $callback)) {
return self::getFromDict($callback);
}
if (!array_key_exists(2, $callback)) {
return self::getNative($callback);
}
return self::getFromList($callback);
} | php | public static function toNative($callback)
{
if (!is_array($callback)) {
return self::getNative($callback);
}
if (!array_key_exists('0', $callback)) {
return self::getFromDict($callback);
}
if (!array_key_exists(2, $callback)) {
return self::getNative($callback);
}
return self::getFromList($callback);
} | [
"public",
"static",
"function",
"toNative",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"self",
"::",
"getNative",
"(",
"$",
"callback",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'0'",
",",
"$",
"callback",
")",
")",
"{",
"return",
"self",
"::",
"getFromDict",
"(",
"$",
"callback",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"2",
",",
"$",
"callback",
")",
")",
"{",
"return",
"self",
"::",
"getNative",
"(",
"$",
"callback",
")",
";",
"}",
"return",
"self",
"::",
"getFromList",
"(",
"$",
"callback",
")",
";",
"}"
] | Separates a native callback and bound arguments
@param mixed $callback
a callback in the extended format
@return array
[native => ..., args => array]
@throws \axy\callbacks\errors\InvalidFormat
the callback has invalid format | [
"Separates",
"a",
"native",
"callback",
"and",
"bound",
"arguments"
] | 210981a2a864aff696ef4e34ba856dc229c4ec8f | https://github.com/axypro/callbacks/blob/210981a2a864aff696ef4e34ba856dc229c4ec8f/Helper.php#L26-L38 |
11,870 | axypro/callbacks | Helper.php | Helper.bindInstance | public static function bindInstance($instance, $methodName, $args = null)
{
$helper = new self();
return $helper->createClosure($methodName, $args)->bindTo($instance, get_class($instance));
} | php | public static function bindInstance($instance, $methodName, $args = null)
{
$helper = new self();
return $helper->createClosure($methodName, $args)->bindTo($instance, get_class($instance));
} | [
"public",
"static",
"function",
"bindInstance",
"(",
"$",
"instance",
",",
"$",
"methodName",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"helper",
"=",
"new",
"self",
"(",
")",
";",
"return",
"$",
"helper",
"->",
"createClosure",
"(",
"$",
"methodName",
",",
"$",
"args",
")",
"->",
"bindTo",
"(",
"$",
"instance",
",",
"get_class",
"(",
"$",
"instance",
")",
")",
";",
"}"
] | Binds an instance with its method
@param object $instance
@param string $methodName
@param array $args [optional]
@return \Closure | [
"Binds",
"an",
"instance",
"with",
"its",
"method"
] | 210981a2a864aff696ef4e34ba856dc229c4ec8f | https://github.com/axypro/callbacks/blob/210981a2a864aff696ef4e34ba856dc229c4ec8f/Helper.php#L48-L52 |
11,871 | axypro/callbacks | Helper.php | Helper.bindStatic | public static function bindStatic($className, $methodName, $args = null)
{
if (empty($args)) {
$args = null;
}
$native = [$className, $methodName];
$callback = function () use ($native, $args) {
$a = func_get_args();
if ($args !== null) {
$a = array_merge($a, $args);
}
return call_user_func_array($native, $a);
};
return $callback->bindTo(null, $className);
} | php | public static function bindStatic($className, $methodName, $args = null)
{
if (empty($args)) {
$args = null;
}
$native = [$className, $methodName];
$callback = function () use ($native, $args) {
$a = func_get_args();
if ($args !== null) {
$a = array_merge($a, $args);
}
return call_user_func_array($native, $a);
};
return $callback->bindTo(null, $className);
} | [
"public",
"static",
"function",
"bindStatic",
"(",
"$",
"className",
",",
"$",
"methodName",
",",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"args",
")",
")",
"{",
"$",
"args",
"=",
"null",
";",
"}",
"$",
"native",
"=",
"[",
"$",
"className",
",",
"$",
"methodName",
"]",
";",
"$",
"callback",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"native",
",",
"$",
"args",
")",
"{",
"$",
"a",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"$",
"args",
"!==",
"null",
")",
"{",
"$",
"a",
"=",
"array_merge",
"(",
"$",
"a",
",",
"$",
"args",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"$",
"native",
",",
"$",
"a",
")",
";",
"}",
";",
"return",
"$",
"callback",
"->",
"bindTo",
"(",
"null",
",",
"$",
"className",
")",
";",
"}"
] | Binds a class with its static method
@param string $className
@param string $methodName
@param array $args [optional]
@return \Closure | [
"Binds",
"a",
"class",
"with",
"its",
"static",
"method"
] | 210981a2a864aff696ef4e34ba856dc229c4ec8f | https://github.com/axypro/callbacks/blob/210981a2a864aff696ef4e34ba856dc229c4ec8f/Helper.php#L62-L76 |
11,872 | common-libs/user | src/user.php | user.find | public static function find($usernameOrId, string $password = "") {
self::check();
if (is_numeric($usernameOrId)) {
$bean = R::load('user', $usernameOrId);
}
else {
$userdbname = setup::getValidation("username");
if ($password != "") {
$pwdbname = setup::getValidation("password");
$bean = R::findOne('user', ' ' . $userdbname . ' = ? AND ' . $pwdbname . ' = ? ', [
$usernameOrId,
setup::doHash($password)
]);
}
else {
$bean = R::findOne('user', ' ' . $userdbname . ' = ? ', [$usernameOrId]);
}
}
if (!is_null($bean)) {
return new self("", $bean);
}
return false;
} | php | public static function find($usernameOrId, string $password = "") {
self::check();
if (is_numeric($usernameOrId)) {
$bean = R::load('user', $usernameOrId);
}
else {
$userdbname = setup::getValidation("username");
if ($password != "") {
$pwdbname = setup::getValidation("password");
$bean = R::findOne('user', ' ' . $userdbname . ' = ? AND ' . $pwdbname . ' = ? ', [
$usernameOrId,
setup::doHash($password)
]);
}
else {
$bean = R::findOne('user', ' ' . $userdbname . ' = ? ', [$usernameOrId]);
}
}
if (!is_null($bean)) {
return new self("", $bean);
}
return false;
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"usernameOrId",
",",
"string",
"$",
"password",
"=",
"\"\"",
")",
"{",
"self",
"::",
"check",
"(",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"usernameOrId",
")",
")",
"{",
"$",
"bean",
"=",
"R",
"::",
"load",
"(",
"'user'",
",",
"$",
"usernameOrId",
")",
";",
"}",
"else",
"{",
"$",
"userdbname",
"=",
"setup",
"::",
"getValidation",
"(",
"\"username\"",
")",
";",
"if",
"(",
"$",
"password",
"!=",
"\"\"",
")",
"{",
"$",
"pwdbname",
"=",
"setup",
"::",
"getValidation",
"(",
"\"password\"",
")",
";",
"$",
"bean",
"=",
"R",
"::",
"findOne",
"(",
"'user'",
",",
"' '",
".",
"$",
"userdbname",
".",
"' = ? AND '",
".",
"$",
"pwdbname",
".",
"' = ? '",
",",
"[",
"$",
"usernameOrId",
",",
"setup",
"::",
"doHash",
"(",
"$",
"password",
")",
"]",
")",
";",
"}",
"else",
"{",
"$",
"bean",
"=",
"R",
"::",
"findOne",
"(",
"'user'",
",",
"' '",
".",
"$",
"userdbname",
".",
"' = ? '",
",",
"[",
"$",
"usernameOrId",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"bean",
")",
")",
"{",
"return",
"new",
"self",
"(",
"\"\"",
",",
"$",
"bean",
")",
";",
"}",
"return",
"false",
";",
"}"
] | find a user
@param string|int $usernameOrId
@param string $password
@return bool|\common\user\user | [
"find",
"a",
"user"
] | 820fce6748a59e8d692bf613b4694f903d9db6c1 | https://github.com/common-libs/user/blob/820fce6748a59e8d692bf613b4694f903d9db6c1/src/user.php#L89-L112 |
11,873 | common-libs/user | src/user.php | user.guest | public static function guest(): user {
self::check();
$userdbname = setup::getValidation("username");
return new self("", R::findOne('user', ' ' . $userdbname . ' = ? ', ["guest"]));
} | php | public static function guest(): user {
self::check();
$userdbname = setup::getValidation("username");
return new self("", R::findOne('user', ' ' . $userdbname . ' = ? ', ["guest"]));
} | [
"public",
"static",
"function",
"guest",
"(",
")",
":",
"user",
"{",
"self",
"::",
"check",
"(",
")",
";",
"$",
"userdbname",
"=",
"setup",
"::",
"getValidation",
"(",
"\"username\"",
")",
";",
"return",
"new",
"self",
"(",
"\"\"",
",",
"R",
"::",
"findOne",
"(",
"'user'",
",",
"' '",
".",
"$",
"userdbname",
".",
"' = ? '",
",",
"[",
"\"guest\"",
"]",
")",
")",
";",
"}"
] | return a guest user
@return \common\user\user | [
"return",
"a",
"guest",
"user"
] | 820fce6748a59e8d692bf613b4694f903d9db6c1 | https://github.com/common-libs/user/blob/820fce6748a59e8d692bf613b4694f903d9db6c1/src/user.php#L119-L124 |
11,874 | common-libs/user | src/user.php | user.setRole | public function setRole(string $role) {
$this->user->role = role::get($role);
R::store($this->user);
} | php | public function setRole(string $role) {
$this->user->role = role::get($role);
R::store($this->user);
} | [
"public",
"function",
"setRole",
"(",
"string",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"user",
"->",
"role",
"=",
"role",
"::",
"get",
"(",
"$",
"role",
")",
";",
"R",
"::",
"store",
"(",
"$",
"this",
"->",
"user",
")",
";",
"}"
] | set role of user
@param string $role rolename | [
"set",
"role",
"of",
"user"
] | 820fce6748a59e8d692bf613b4694f903d9db6c1 | https://github.com/common-libs/user/blob/820fce6748a59e8d692bf613b4694f903d9db6c1/src/user.php#L140-L143 |
11,875 | quantaphp/class-names | src/BlacklistedClassNameCollection.php | BlacklistedClassNameCollection.filter | private function filter(string $class): bool
{
foreach ($this->patterns as $pattern) {
if (preg_match($pattern, $class) === 1) {
return false;
}
}
return true;
} | php | private function filter(string $class): bool
{
foreach ($this->patterns as $pattern) {
if (preg_match($pattern, $class) === 1) {
return false;
}
}
return true;
} | [
"private",
"function",
"filter",
"(",
"string",
"$",
"class",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"patterns",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"class",
")",
"===",
"1",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Return whether the given class name is not matching any pattern.
@param string $class
@return bool | [
"Return",
"whether",
"the",
"given",
"class",
"name",
"is",
"not",
"matching",
"any",
"pattern",
"."
] | 2c0aea13ff82aa70df0fe6f78247415d15a994d1 | https://github.com/quantaphp/class-names/blob/2c0aea13ff82aa70df0fe6f78247415d15a994d1/src/BlacklistedClassNameCollection.php#L50-L59 |
11,876 | dlabas/DlcBase | src/DlcBase/Code/Reflection/Closure.php | Closure.getSourceCode | public function getSourceCode($initialIdent = 4)
{
$file = explode(PHP_EOL, file_get_contents($this->getFileName()));
$funcOpenLine = $file[$this->getStartLine()-1];
$funcOpenLine = rtrim(substr($funcOpenLine, strpos($funcOpenLine, 'function')));
$funcCloseLine = $file[$this->getEndLine()-1];
$funcCloseLine = ltrim(substr($funcCloseLine, 0, strpos($funcCloseLine, '}')+1));
$source = $funcOpenLine
. $this->getContents($initialIdent, false)
. $funcCloseLine;
return $source;
} | php | public function getSourceCode($initialIdent = 4)
{
$file = explode(PHP_EOL, file_get_contents($this->getFileName()));
$funcOpenLine = $file[$this->getStartLine()-1];
$funcOpenLine = rtrim(substr($funcOpenLine, strpos($funcOpenLine, 'function')));
$funcCloseLine = $file[$this->getEndLine()-1];
$funcCloseLine = ltrim(substr($funcCloseLine, 0, strpos($funcCloseLine, '}')+1));
$source = $funcOpenLine
. $this->getContents($initialIdent, false)
. $funcCloseLine;
return $source;
} | [
"public",
"function",
"getSourceCode",
"(",
"$",
"initialIdent",
"=",
"4",
")",
"{",
"$",
"file",
"=",
"explode",
"(",
"PHP_EOL",
",",
"file_get_contents",
"(",
"$",
"this",
"->",
"getFileName",
"(",
")",
")",
")",
";",
"$",
"funcOpenLine",
"=",
"$",
"file",
"[",
"$",
"this",
"->",
"getStartLine",
"(",
")",
"-",
"1",
"]",
";",
"$",
"funcOpenLine",
"=",
"rtrim",
"(",
"substr",
"(",
"$",
"funcOpenLine",
",",
"strpos",
"(",
"$",
"funcOpenLine",
",",
"'function'",
")",
")",
")",
";",
"$",
"funcCloseLine",
"=",
"$",
"file",
"[",
"$",
"this",
"->",
"getEndLine",
"(",
")",
"-",
"1",
"]",
";",
"$",
"funcCloseLine",
"=",
"ltrim",
"(",
"substr",
"(",
"$",
"funcCloseLine",
",",
"0",
",",
"strpos",
"(",
"$",
"funcCloseLine",
",",
"'}'",
")",
"+",
"1",
")",
")",
";",
"$",
"source",
"=",
"$",
"funcOpenLine",
".",
"$",
"this",
"->",
"getContents",
"(",
"$",
"initialIdent",
",",
"false",
")",
".",
"$",
"funcCloseLine",
";",
"return",
"$",
"source",
";",
"}"
] | Get source code of closure
@return string | [
"Get",
"source",
"code",
"of",
"closure"
] | 0f6b1056a670c68fffa0055901e209cc45621599 | https://github.com/dlabas/DlcBase/blob/0f6b1056a670c68fffa0055901e209cc45621599/src/DlcBase/Code/Reflection/Closure.php#L16-L31 |
11,877 | dlabas/DlcBase | src/DlcBase/Code/Reflection/Closure.php | Closure.getContents | public function getContents($initialIdent = 4, $trimFirstAndLastLineBreak = true)
{
$file = explode(PHP_EOL, file_get_contents($this->getFileName()));
$startLine = $this->getStartLine();
$endLine = $this->getEndLine()-1;
$contents = PHP_EOL;
$subStrStart = false;
while ($startLine<$endLine) {
$line = $file[$startLine];
if (!$subStrStart) {
$numberOfWhiteSpace = strspn($line, ' ');
$subStrStart = $numberOfWhiteSpace - $initialIdent;
}
$contents .= substr(rtrim($line), $subStrStart) . PHP_EOL;
$startLine++;
}
if ($trimFirstAndLastLineBreak) {
$contents = ltrim(rtrim($contents, PHP_EOL), PHP_EOL);
}
return $contents;
} | php | public function getContents($initialIdent = 4, $trimFirstAndLastLineBreak = true)
{
$file = explode(PHP_EOL, file_get_contents($this->getFileName()));
$startLine = $this->getStartLine();
$endLine = $this->getEndLine()-1;
$contents = PHP_EOL;
$subStrStart = false;
while ($startLine<$endLine) {
$line = $file[$startLine];
if (!$subStrStart) {
$numberOfWhiteSpace = strspn($line, ' ');
$subStrStart = $numberOfWhiteSpace - $initialIdent;
}
$contents .= substr(rtrim($line), $subStrStart) . PHP_EOL;
$startLine++;
}
if ($trimFirstAndLastLineBreak) {
$contents = ltrim(rtrim($contents, PHP_EOL), PHP_EOL);
}
return $contents;
} | [
"public",
"function",
"getContents",
"(",
"$",
"initialIdent",
"=",
"4",
",",
"$",
"trimFirstAndLastLineBreak",
"=",
"true",
")",
"{",
"$",
"file",
"=",
"explode",
"(",
"PHP_EOL",
",",
"file_get_contents",
"(",
"$",
"this",
"->",
"getFileName",
"(",
")",
")",
")",
";",
"$",
"startLine",
"=",
"$",
"this",
"->",
"getStartLine",
"(",
")",
";",
"$",
"endLine",
"=",
"$",
"this",
"->",
"getEndLine",
"(",
")",
"-",
"1",
";",
"$",
"contents",
"=",
"PHP_EOL",
";",
"$",
"subStrStart",
"=",
"false",
";",
"while",
"(",
"$",
"startLine",
"<",
"$",
"endLine",
")",
"{",
"$",
"line",
"=",
"$",
"file",
"[",
"$",
"startLine",
"]",
";",
"if",
"(",
"!",
"$",
"subStrStart",
")",
"{",
"$",
"numberOfWhiteSpace",
"=",
"strspn",
"(",
"$",
"line",
",",
"' '",
")",
";",
"$",
"subStrStart",
"=",
"$",
"numberOfWhiteSpace",
"-",
"$",
"initialIdent",
";",
"}",
"$",
"contents",
".=",
"substr",
"(",
"rtrim",
"(",
"$",
"line",
")",
",",
"$",
"subStrStart",
")",
".",
"PHP_EOL",
";",
"$",
"startLine",
"++",
";",
"}",
"if",
"(",
"$",
"trimFirstAndLastLineBreak",
")",
"{",
"$",
"contents",
"=",
"ltrim",
"(",
"rtrim",
"(",
"$",
"contents",
",",
"PHP_EOL",
")",
",",
"PHP_EOL",
")",
";",
"}",
"return",
"$",
"contents",
";",
"}"
] | Get contents of closure
@return string | [
"Get",
"contents",
"of",
"closure"
] | 0f6b1056a670c68fffa0055901e209cc45621599 | https://github.com/dlabas/DlcBase/blob/0f6b1056a670c68fffa0055901e209cc45621599/src/DlcBase/Code/Reflection/Closure.php#L38-L64 |
11,878 | vinala/kernel | src/Atomium/Compiler/AtomiumCompileComments.php | AtomiumCompileComments.hide | public static function hide($script, $openTag, $closeTag)
{
$data = Strings::splite($script, $openTag);
//
$output = $data[0];
//
for ($i = 1; $i < Collection::count($data); $i++) {
$output .= '';
//
$next = Strings::splite($data[$i], $closeTag);
$output .= '';
//
for ($j = 1; $j < Collection::count($next); $j++) {
if ($j == (Collection::count($next) - 1)) {
$output .= $next[$j];
} else {
$output .= $next[$j].$closeTag;
}
}
}
return $output;
} | php | public static function hide($script, $openTag, $closeTag)
{
$data = Strings::splite($script, $openTag);
//
$output = $data[0];
//
for ($i = 1; $i < Collection::count($data); $i++) {
$output .= '';
//
$next = Strings::splite($data[$i], $closeTag);
$output .= '';
//
for ($j = 1; $j < Collection::count($next); $j++) {
if ($j == (Collection::count($next) - 1)) {
$output .= $next[$j];
} else {
$output .= $next[$j].$closeTag;
}
}
}
return $output;
} | [
"public",
"static",
"function",
"hide",
"(",
"$",
"script",
",",
"$",
"openTag",
",",
"$",
"closeTag",
")",
"{",
"$",
"data",
"=",
"Strings",
"::",
"splite",
"(",
"$",
"script",
",",
"$",
"openTag",
")",
";",
"//",
"$",
"output",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"//",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"Collection",
"::",
"count",
"(",
"$",
"data",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"output",
".=",
"''",
";",
"//",
"$",
"next",
"=",
"Strings",
"::",
"splite",
"(",
"$",
"data",
"[",
"$",
"i",
"]",
",",
"$",
"closeTag",
")",
";",
"$",
"output",
".=",
"''",
";",
"//",
"for",
"(",
"$",
"j",
"=",
"1",
";",
"$",
"j",
"<",
"Collection",
"::",
"count",
"(",
"$",
"next",
")",
";",
"$",
"j",
"++",
")",
"{",
"if",
"(",
"$",
"j",
"==",
"(",
"Collection",
"::",
"count",
"(",
"$",
"next",
")",
"-",
"1",
")",
")",
"{",
"$",
"output",
".=",
"$",
"next",
"[",
"$",
"j",
"]",
";",
"}",
"else",
"{",
"$",
"output",
".=",
"$",
"next",
"[",
"$",
"j",
"]",
".",
"$",
"closeTag",
";",
"}",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | To hide de comment that user write.
@return string | [
"To",
"hide",
"de",
"comment",
"that",
"user",
"write",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Atomium/Compiler/AtomiumCompileComments.php#L34-L56 |
11,879 | uuur86/ubdb | src/ubdb.php | ubdb.search_term | private function search_term($table, $colname, $term){
$searchio = $this->readdb( $table, $colname );
$returnrows = array();
foreach( $searchio as $drowname=>$drowval ){
if( empty($term) || count($term)<1 ){continue;}
$termcounter = $this->matches($drowval, $term);
if( $termcounter>0 ){
$returnrows[$drowname] = $termcounter;
}
}
return $returnrows;
} | php | private function search_term($table, $colname, $term){
$searchio = $this->readdb( $table, $colname );
$returnrows = array();
foreach( $searchio as $drowname=>$drowval ){
if( empty($term) || count($term)<1 ){continue;}
$termcounter = $this->matches($drowval, $term);
if( $termcounter>0 ){
$returnrows[$drowname] = $termcounter;
}
}
return $returnrows;
} | [
"private",
"function",
"search_term",
"(",
"$",
"table",
",",
"$",
"colname",
",",
"$",
"term",
")",
"{",
"$",
"searchio",
"=",
"$",
"this",
"->",
"readdb",
"(",
"$",
"table",
",",
"$",
"colname",
")",
";",
"$",
"returnrows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"searchio",
"as",
"$",
"drowname",
"=>",
"$",
"drowval",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"term",
")",
"||",
"count",
"(",
"$",
"term",
")",
"<",
"1",
")",
"{",
"continue",
";",
"}",
"$",
"termcounter",
"=",
"$",
"this",
"->",
"matches",
"(",
"$",
"drowval",
",",
"$",
"term",
")",
";",
"if",
"(",
"$",
"termcounter",
">",
"0",
")",
"{",
"$",
"returnrows",
"[",
"$",
"drowname",
"]",
"=",
"$",
"termcounter",
";",
"}",
"}",
"return",
"$",
"returnrows",
";",
"}"
] | Will be return as array contains row key => how many time matched | [
"Will",
"be",
"return",
"as",
"array",
"contains",
"row",
"key",
"=",
">",
"how",
"many",
"time",
"matched"
] | 4f8fd8c331422455240a882d11be812c24f3a36d | https://github.com/uuur86/ubdb/blob/4f8fd8c331422455240a882d11be812c24f3a36d/src/ubdb.php#L220-L237 |
11,880 | uuur86/ubdb | src/ubdb.php | ubdb.add | public function add($table, $rowArr){
$editId = $this->rows($table);
if($this->edit_id != null){
$editId = $this->edit_id;
}
foreach($this->cols[$table] as $colname){
$this->rows[$table][$colname][$editId] = $rowArr[$colname];
}
return $editId;
} | php | public function add($table, $rowArr){
$editId = $this->rows($table);
if($this->edit_id != null){
$editId = $this->edit_id;
}
foreach($this->cols[$table] as $colname){
$this->rows[$table][$colname][$editId] = $rowArr[$colname];
}
return $editId;
} | [
"public",
"function",
"add",
"(",
"$",
"table",
",",
"$",
"rowArr",
")",
"{",
"$",
"editId",
"=",
"$",
"this",
"->",
"rows",
"(",
"$",
"table",
")",
";",
"if",
"(",
"$",
"this",
"->",
"edit_id",
"!=",
"null",
")",
"{",
"$",
"editId",
"=",
"$",
"this",
"->",
"edit_id",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"cols",
"[",
"$",
"table",
"]",
"as",
"$",
"colname",
")",
"{",
"$",
"this",
"->",
"rows",
"[",
"$",
"table",
"]",
"[",
"$",
"colname",
"]",
"[",
"$",
"editId",
"]",
"=",
"$",
"rowArr",
"[",
"$",
"colname",
"]",
";",
"}",
"return",
"$",
"editId",
";",
"}"
] | Add new row | [
"Add",
"new",
"row"
] | 4f8fd8c331422455240a882d11be812c24f3a36d | https://github.com/uuur86/ubdb/blob/4f8fd8c331422455240a882d11be812c24f3a36d/src/ubdb.php#L251-L263 |
11,881 | uuur86/ubdb | src/ubdb.php | ubdb.edit | public function edit($table, $rowArr, $id){
$this->edit_id = $id;
$this->add($table, $rowArr);
} | php | public function edit($table, $rowArr, $id){
$this->edit_id = $id;
$this->add($table, $rowArr);
} | [
"public",
"function",
"edit",
"(",
"$",
"table",
",",
"$",
"rowArr",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"edit_id",
"=",
"$",
"id",
";",
"$",
"this",
"->",
"add",
"(",
"$",
"table",
",",
"$",
"rowArr",
")",
";",
"}"
] | Edit to exists row | [
"Edit",
"to",
"exists",
"row"
] | 4f8fd8c331422455240a882d11be812c24f3a36d | https://github.com/uuur86/ubdb/blob/4f8fd8c331422455240a882d11be812c24f3a36d/src/ubdb.php#L267-L270 |
11,882 | uuur86/ubdb | src/ubdb.php | ubdb.save | public function save(){
foreach ($this->cols as $table => $prkey){
foreach($prkey as $prkey_){
if(strlen($prkey_)<3){continue;}
$this->writedb($table, $prkey_);
}
//more table records
$this->rows[$table]['index'] = $this->indexData[$table];
try{
$this->writedb($table, 'index');
}
catch(Exception $aa){
return false;
}
}
return true;
} | php | public function save(){
foreach ($this->cols as $table => $prkey){
foreach($prkey as $prkey_){
if(strlen($prkey_)<3){continue;}
$this->writedb($table, $prkey_);
}
//more table records
$this->rows[$table]['index'] = $this->indexData[$table];
try{
$this->writedb($table, 'index');
}
catch(Exception $aa){
return false;
}
}
return true;
} | [
"public",
"function",
"save",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"cols",
"as",
"$",
"table",
"=>",
"$",
"prkey",
")",
"{",
"foreach",
"(",
"$",
"prkey",
"as",
"$",
"prkey_",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"prkey_",
")",
"<",
"3",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"writedb",
"(",
"$",
"table",
",",
"$",
"prkey_",
")",
";",
"}",
"//more table records",
"$",
"this",
"->",
"rows",
"[",
"$",
"table",
"]",
"[",
"'index'",
"]",
"=",
"$",
"this",
"->",
"indexData",
"[",
"$",
"table",
"]",
";",
"try",
"{",
"$",
"this",
"->",
"writedb",
"(",
"$",
"table",
",",
"'index'",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"aa",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | running one more time. | [
"running",
"one",
"more",
"time",
"."
] | 4f8fd8c331422455240a882d11be812c24f3a36d | https://github.com/uuur86/ubdb/blob/4f8fd8c331422455240a882d11be812c24f3a36d/src/ubdb.php#L279-L301 |
11,883 | uuur86/ubdb | src/ubdb.php | ubdb.check | public function check($table, $colname, $val){
$oldvals = $this->readdb($table, $colname);
if($oldvals && is_array($oldvals)){
$oldvals = array_flip($oldvals);
}
if(isset($oldvals[$val])){
return true;
}
return false;
} | php | public function check($table, $colname, $val){
$oldvals = $this->readdb($table, $colname);
if($oldvals && is_array($oldvals)){
$oldvals = array_flip($oldvals);
}
if(isset($oldvals[$val])){
return true;
}
return false;
} | [
"public",
"function",
"check",
"(",
"$",
"table",
",",
"$",
"colname",
",",
"$",
"val",
")",
"{",
"$",
"oldvals",
"=",
"$",
"this",
"->",
"readdb",
"(",
"$",
"table",
",",
"$",
"colname",
")",
";",
"if",
"(",
"$",
"oldvals",
"&&",
"is_array",
"(",
"$",
"oldvals",
")",
")",
"{",
"$",
"oldvals",
"=",
"array_flip",
"(",
"$",
"oldvals",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"oldvals",
"[",
"$",
"val",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Return as boolean | [
"Return",
"as",
"boolean"
] | 4f8fd8c331422455240a882d11be812c24f3a36d | https://github.com/uuur86/ubdb/blob/4f8fd8c331422455240a882d11be812c24f3a36d/src/ubdb.php#L328-L340 |
11,884 | gintonicweb/users | src/Controller/Api/UsersController.php | UsersController.index | public function index()
{
$this->Crud->on('beforePaginate', function (Event $event) {
$query = $this->Users->find('search', $this->request->query);
$query = $query->select(['id', 'username']);
$event->subject->query = $query;
});
$this->Crud->execute();
} | php | public function index()
{
$this->Crud->on('beforePaginate', function (Event $event) {
$query = $this->Users->find('search', $this->request->query);
$query = $query->select(['id', 'username']);
$event->subject->query = $query;
});
$this->Crud->execute();
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"this",
"->",
"Crud",
"->",
"on",
"(",
"'beforePaginate'",
",",
"function",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"Users",
"->",
"find",
"(",
"'search'",
",",
"$",
"this",
"->",
"request",
"->",
"query",
")",
";",
"$",
"query",
"=",
"$",
"query",
"->",
"select",
"(",
"[",
"'id'",
",",
"'username'",
"]",
")",
";",
"$",
"event",
"->",
"subject",
"->",
"query",
"=",
"$",
"query",
";",
"}",
")",
";",
"$",
"this",
"->",
"Crud",
"->",
"execute",
"(",
")",
";",
"}"
] | Currently used as a search function uses 'username' as the param
e.g. http://example.com/api/users.json?usernam=phil
@return void | [
"Currently",
"used",
"as",
"a",
"search",
"function",
"uses",
"username",
"as",
"the",
"param"
] | 822b5f640969020ff8165d8d376680ef33d1f9ac | https://github.com/gintonicweb/users/blob/822b5f640969020ff8165d8d376680ef33d1f9ac/src/Controller/Api/UsersController.php#L46-L54 |
11,885 | gintonicweb/users | src/Controller/Api/UsersController.php | UsersController.add | public function add()
{
$this->Crud->on('afterSave', function (Event $event) {
if ($event->subject->created) {
$token = [
'id' => $event->subject->entity->id,
'exp' => time() + 60 * 60 * 24 * 7,
];
$this->set('data', [
'id' => $event->subject->entity->id,
'token' => JWT::encode($token, Security::salt())
]);
$this->Crud->action()->config('serialize.data', 'data');
}
$signupEvent = new Event('Users.afterSignup', $event->subject());
$this->eventManager()->dispatch($signupEvent);
});
return $this->Crud->execute();
} | php | public function add()
{
$this->Crud->on('afterSave', function (Event $event) {
if ($event->subject->created) {
$token = [
'id' => $event->subject->entity->id,
'exp' => time() + 60 * 60 * 24 * 7,
];
$this->set('data', [
'id' => $event->subject->entity->id,
'token' => JWT::encode($token, Security::salt())
]);
$this->Crud->action()->config('serialize.data', 'data');
}
$signupEvent = new Event('Users.afterSignup', $event->subject());
$this->eventManager()->dispatch($signupEvent);
});
return $this->Crud->execute();
} | [
"public",
"function",
"add",
"(",
")",
"{",
"$",
"this",
"->",
"Crud",
"->",
"on",
"(",
"'afterSave'",
",",
"function",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"subject",
"->",
"created",
")",
"{",
"$",
"token",
"=",
"[",
"'id'",
"=>",
"$",
"event",
"->",
"subject",
"->",
"entity",
"->",
"id",
",",
"'exp'",
"=>",
"time",
"(",
")",
"+",
"60",
"*",
"60",
"*",
"24",
"*",
"7",
",",
"]",
";",
"$",
"this",
"->",
"set",
"(",
"'data'",
",",
"[",
"'id'",
"=>",
"$",
"event",
"->",
"subject",
"->",
"entity",
"->",
"id",
",",
"'token'",
"=>",
"JWT",
"::",
"encode",
"(",
"$",
"token",
",",
"Security",
"::",
"salt",
"(",
")",
")",
"]",
")",
";",
"$",
"this",
"->",
"Crud",
"->",
"action",
"(",
")",
"->",
"config",
"(",
"'serialize.data'",
",",
"'data'",
")",
";",
"}",
"$",
"signupEvent",
"=",
"new",
"Event",
"(",
"'Users.afterSignup'",
",",
"$",
"event",
"->",
"subject",
"(",
")",
")",
";",
"$",
"this",
"->",
"eventManager",
"(",
")",
"->",
"dispatch",
"(",
"$",
"signupEvent",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"Crud",
"->",
"execute",
"(",
")",
";",
"}"
] | Regular register method now also returns a token upon registration
token expiration is set for 1 week
@return \Cake\Network\Response | [
"Regular",
"register",
"method",
"now",
"also",
"returns",
"a",
"token",
"upon",
"registration",
"token",
"expiration",
"is",
"set",
"for",
"1",
"week"
] | 822b5f640969020ff8165d8d376680ef33d1f9ac | https://github.com/gintonicweb/users/blob/822b5f640969020ff8165d8d376680ef33d1f9ac/src/Controller/Api/UsersController.php#L62-L80 |
11,886 | gintonicweb/users | src/Controller/Api/UsersController.php | UsersController.token | public function token()
{
$user = $this->Auth->identify();
if (!$user) {
throw new UnauthorizedException('Invalid username or password');
}
$token = [
'id' => $user['id'],
'exp' => time() + 60 * 60 * 24 * 7
];
$this->set([
'success' => true,
'data' => ['token' => JWT::encode($token, Security::salt())],
'_serialize' => ['success', 'data']
]);
} | php | public function token()
{
$user = $this->Auth->identify();
if (!$user) {
throw new UnauthorizedException('Invalid username or password');
}
$token = [
'id' => $user['id'],
'exp' => time() + 60 * 60 * 24 * 7
];
$this->set([
'success' => true,
'data' => ['token' => JWT::encode($token, Security::salt())],
'_serialize' => ['success', 'data']
]);
} | [
"public",
"function",
"token",
"(",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"Auth",
"->",
"identify",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"throw",
"new",
"UnauthorizedException",
"(",
"'Invalid username or password'",
")",
";",
"}",
"$",
"token",
"=",
"[",
"'id'",
"=>",
"$",
"user",
"[",
"'id'",
"]",
",",
"'exp'",
"=>",
"time",
"(",
")",
"+",
"60",
"*",
"60",
"*",
"24",
"*",
"7",
"]",
";",
"$",
"this",
"->",
"set",
"(",
"[",
"'success'",
"=>",
"true",
",",
"'data'",
"=>",
"[",
"'token'",
"=>",
"JWT",
"::",
"encode",
"(",
"$",
"token",
",",
"Security",
"::",
"salt",
"(",
")",
")",
"]",
",",
"'_serialize'",
"=>",
"[",
"'success'",
",",
"'data'",
"]",
"]",
")",
";",
"}"
] | Tries to authentify user based on POST data and returns a private token
@return void | [
"Tries",
"to",
"authentify",
"user",
"based",
"on",
"POST",
"data",
"and",
"returns",
"a",
"private",
"token"
] | 822b5f640969020ff8165d8d376680ef33d1f9ac | https://github.com/gintonicweb/users/blob/822b5f640969020ff8165d8d376680ef33d1f9ac/src/Controller/Api/UsersController.php#L87-L104 |
11,887 | mlebkowski/kunstmaan-static-site-bundle | src/Service/Response/StaticFiles/MimeTypeGuesser.php | MimeTypeGuesser.guess | public function guess($path)
{
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (isset($this->extensions[$ext])) {
return $this->extensions[$ext];
}
return $this->parent->guess($path);
} | php | public function guess($path)
{
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (isset($this->extensions[$ext])) {
return $this->extensions[$ext];
}
return $this->parent->guess($path);
} | [
"public",
"function",
"guess",
"(",
"$",
"path",
")",
"{",
"$",
"ext",
"=",
"strtolower",
"(",
"pathinfo",
"(",
"$",
"path",
",",
"PATHINFO_EXTENSION",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"extensions",
"[",
"$",
"ext",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"extensions",
"[",
"$",
"ext",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"parent",
"->",
"guess",
"(",
"$",
"path",
")",
";",
"}"
] | Guesses the mime type of the file with the given path.
@param string $path The path to the file
@return string The mime type or NULL, if none could be guessed
@throws FileNotFoundException If the file does not exist
@throws AccessDeniedException If the file could not be read | [
"Guesses",
"the",
"mime",
"type",
"of",
"the",
"file",
"with",
"the",
"given",
"path",
"."
] | 86d3b0146ef8c065379d0136864094c5f109396e | https://github.com/mlebkowski/kunstmaan-static-site-bundle/blob/86d3b0146ef8c065379d0136864094c5f109396e/src/Service/Response/StaticFiles/MimeTypeGuesser.php#L38-L47 |
11,888 | lhs168/fasim | src/Fasim/Cache/simulate/Memcached.php | Memcached.addServer | public function addServer($host, $port = 11211, $weight = 0)
{
$key = $this->getServerKey($host, $port, $weight);
if (isset($this->server[$key])) {
// Dup
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'Server duplicate.';
return false;
} else {
$this->server[$key] = array(
'host' => $host,
'port' => $port,
'weight' => $weight,
);
$this->connect();
return true;
}
} | php | public function addServer($host, $port = 11211, $weight = 0)
{
$key = $this->getServerKey($host, $port, $weight);
if (isset($this->server[$key])) {
// Dup
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'Server duplicate.';
return false;
} else {
$this->server[$key] = array(
'host' => $host,
'port' => $port,
'weight' => $weight,
);
$this->connect();
return true;
}
} | [
"public",
"function",
"addServer",
"(",
"$",
"host",
",",
"$",
"port",
"=",
"11211",
",",
"$",
"weight",
"=",
"0",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getServerKey",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"weight",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"server",
"[",
"$",
"key",
"]",
")",
")",
"{",
"// Dup",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_FAILURE",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"'Server duplicate.'",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"server",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"'host'",
"=>",
"$",
"host",
",",
"'port'",
"=>",
"$",
"port",
",",
"'weight'",
"=>",
"$",
"weight",
",",
")",
";",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"return",
"true",
";",
"}",
"}"
] | Add a serer to the server pool
@param string $host
@param int $port
@param int $weight
@return boolean | [
"Add",
"a",
"serer",
"to",
"the",
"server",
"pool"
] | df31e249593380421785f0be342cfb92cbb1d1d7 | https://github.com/lhs168/fasim/blob/df31e249593380421785f0be342cfb92cbb1d1d7/src/Fasim/Cache/simulate/Memcached.php#L184-L203 |
11,889 | lhs168/fasim | src/Fasim/Cache/simulate/Memcached.php | Memcached.addServers | public function addServers($servers)
{
foreach ((array)$servers as $svr) {
$host = array_shift($svr);
$port = array_shift($svr);
if (is_null($port)) {
$port = 11211;
}
$weight = array_shift($svr);
if (is_null($weight)) {
$weight = 0;
}
$this->addServer($host, $port, $weight);
}
return true;
} | php | public function addServers($servers)
{
foreach ((array)$servers as $svr) {
$host = array_shift($svr);
$port = array_shift($svr);
if (is_null($port)) {
$port = 11211;
}
$weight = array_shift($svr);
if (is_null($weight)) {
$weight = 0;
}
$this->addServer($host, $port, $weight);
}
return true;
} | [
"public",
"function",
"addServers",
"(",
"$",
"servers",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"servers",
"as",
"$",
"svr",
")",
"{",
"$",
"host",
"=",
"array_shift",
"(",
"$",
"svr",
")",
";",
"$",
"port",
"=",
"array_shift",
"(",
"$",
"svr",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"port",
")",
")",
"{",
"$",
"port",
"=",
"11211",
";",
"}",
"$",
"weight",
"=",
"array_shift",
"(",
"$",
"svr",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"weight",
")",
")",
"{",
"$",
"weight",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"addServer",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"weight",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Add multiple servers to the server pool
@param array $servers
@return boolean | [
"Add",
"multiple",
"servers",
"to",
"the",
"server",
"pool"
] | df31e249593380421785f0be342cfb92cbb1d1d7 | https://github.com/lhs168/fasim/blob/df31e249593380421785f0be342cfb92cbb1d1d7/src/Fasim/Cache/simulate/Memcached.php#L212-L231 |
11,890 | lhs168/fasim | src/Fasim/Cache/simulate/Memcached.php | Memcached.connect | protected function connect()
{
$rs = false;
foreach ((array)$this->server as $svr) {
$error = 0;
$errstr = '';
$rs = @fsockopen($svr['host'], $svr['port'], $error, $errstr);
if ($rs) {
$this->socket = $rs;
} else {
$key = $this->getServerKey(
$svr['host'],
$svr['port'],
$svr['weight']
);
$s = "Connect to $key error:" . PHP_EOL .
" [$error] $errstr";
error_log($s);
}
}
if (is_null($this->socket)) {
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'No server avaliable.';
return false;
} else {
$this->resultCode = Memcached::RES_SUCCESS;
$this->resultMessage = '';
return true;
}
} | php | protected function connect()
{
$rs = false;
foreach ((array)$this->server as $svr) {
$error = 0;
$errstr = '';
$rs = @fsockopen($svr['host'], $svr['port'], $error, $errstr);
if ($rs) {
$this->socket = $rs;
} else {
$key = $this->getServerKey(
$svr['host'],
$svr['port'],
$svr['weight']
);
$s = "Connect to $key error:" . PHP_EOL .
" [$error] $errstr";
error_log($s);
}
}
if (is_null($this->socket)) {
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'No server avaliable.';
return false;
} else {
$this->resultCode = Memcached::RES_SUCCESS;
$this->resultMessage = '';
return true;
}
} | [
"protected",
"function",
"connect",
"(",
")",
"{",
"$",
"rs",
"=",
"false",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"server",
"as",
"$",
"svr",
")",
"{",
"$",
"error",
"=",
"0",
";",
"$",
"errstr",
"=",
"''",
";",
"$",
"rs",
"=",
"@",
"fsockopen",
"(",
"$",
"svr",
"[",
"'host'",
"]",
",",
"$",
"svr",
"[",
"'port'",
"]",
",",
"$",
"error",
",",
"$",
"errstr",
")",
";",
"if",
"(",
"$",
"rs",
")",
"{",
"$",
"this",
"->",
"socket",
"=",
"$",
"rs",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getServerKey",
"(",
"$",
"svr",
"[",
"'host'",
"]",
",",
"$",
"svr",
"[",
"'port'",
"]",
",",
"$",
"svr",
"[",
"'weight'",
"]",
")",
";",
"$",
"s",
"=",
"\"Connect to $key error:\"",
".",
"PHP_EOL",
".",
"\" [$error] $errstr\"",
";",
"error_log",
"(",
"$",
"s",
")",
";",
"}",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"socket",
")",
")",
"{",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_FAILURE",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"'No server avaliable.'",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_SUCCESS",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"''",
";",
"return",
"true",
";",
"}",
"}"
] | Connect to memcached server
@return boolean | [
"Connect",
"to",
"memcached",
"server"
] | df31e249593380421785f0be342cfb92cbb1d1d7 | https://github.com/lhs168/fasim/blob/df31e249593380421785f0be342cfb92cbb1d1d7/src/Fasim/Cache/simulate/Memcached.php#L239-L273 |
11,891 | lhs168/fasim | src/Fasim/Cache/simulate/Memcached.php | Memcached.get | public function get($key, $cache_cb = null, $cas_token = null)
{
$keyString = $this->getKey($key);
$this->writeSocket("get $keyString");
$s = $this->readSocket();
if (is_null($s) || 'VALUE' != substr($s, 0, 5)) {
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'Get fail.';
return false;
} else {
$s_result = '';
$s = $this->readSocket();
while ('END' != $s) {
$s_result .= $s;
$s = $this->readSocket();
}
$this->resultCode = Memcached::RES_SUCCESS;
$this->resultMessage = '';
return unserialize($s_result);
}
} | php | public function get($key, $cache_cb = null, $cas_token = null)
{
$keyString = $this->getKey($key);
$this->writeSocket("get $keyString");
$s = $this->readSocket();
if (is_null($s) || 'VALUE' != substr($s, 0, 5)) {
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'Get fail.';
return false;
} else {
$s_result = '';
$s = $this->readSocket();
while ('END' != $s) {
$s_result .= $s;
$s = $this->readSocket();
}
$this->resultCode = Memcached::RES_SUCCESS;
$this->resultMessage = '';
return unserialize($s_result);
}
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"cache_cb",
"=",
"null",
",",
"$",
"cas_token",
"=",
"null",
")",
"{",
"$",
"keyString",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"writeSocket",
"(",
"\"get $keyString\"",
")",
";",
"$",
"s",
"=",
"$",
"this",
"->",
"readSocket",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"s",
")",
"||",
"'VALUE'",
"!=",
"substr",
"(",
"$",
"s",
",",
"0",
",",
"5",
")",
")",
"{",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_FAILURE",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"'Get fail.'",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"s_result",
"=",
"''",
";",
"$",
"s",
"=",
"$",
"this",
"->",
"readSocket",
"(",
")",
";",
"while",
"(",
"'END'",
"!=",
"$",
"s",
")",
"{",
"$",
"s_result",
".=",
"$",
"s",
";",
"$",
"s",
"=",
"$",
"this",
"->",
"readSocket",
"(",
")",
";",
"}",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_SUCCESS",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"''",
";",
"return",
"unserialize",
"(",
"$",
"s_result",
")",
";",
"}",
"}"
] | Retrieve an item
@param string $key
@param callable $cache_cb Ignored
@param float $cas_token Ignored
@return mixed | [
"Retrieve",
"an",
"item"
] | df31e249593380421785f0be342cfb92cbb1d1d7 | https://github.com/lhs168/fasim/blob/df31e249593380421785f0be342cfb92cbb1d1d7/src/Fasim/Cache/simulate/Memcached.php#L310-L334 |
11,892 | lhs168/fasim | src/Fasim/Cache/simulate/Memcached.php | Memcached.getOption | public function getOption($option)
{
if (isset($this->option[$option])) {
$this->resultCode = Memcached::RES_SUCCESS;
$this->resultMessage = '';
return $this->option[$option];
} else {
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'Option not seted.';
return false;
}
} | php | public function getOption($option)
{
if (isset($this->option[$option])) {
$this->resultCode = Memcached::RES_SUCCESS;
$this->resultMessage = '';
return $this->option[$option];
} else {
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'Option not seted.';
return false;
}
} | [
"public",
"function",
"getOption",
"(",
"$",
"option",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"option",
"[",
"$",
"option",
"]",
")",
")",
"{",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_SUCCESS",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"''",
";",
"return",
"$",
"this",
"->",
"option",
"[",
"$",
"option",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_FAILURE",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"'Option not seted.'",
";",
"return",
"false",
";",
"}",
"}"
] | Get a memcached option value
@param int $option
@return mixed | [
"Get",
"a",
"memcached",
"option",
"value"
] | df31e249593380421785f0be342cfb92cbb1d1d7 | https://github.com/lhs168/fasim/blob/df31e249593380421785f0be342cfb92cbb1d1d7/src/Fasim/Cache/simulate/Memcached.php#L355-L367 |
11,893 | lhs168/fasim | src/Fasim/Cache/simulate/Memcached.php | Memcached.set | public function set($key, $val, $expt = 0)
{
$valueString = serialize($val);
$keyString = $this->getKey($key);
$this->writeSocket(
"set $keyString 0 $expt " . strlen($valueString)
);
$s = $this->writeSocket($valueString, true);
if ('STORED' == $s) {
$this->resultCode = Memcached::RES_SUCCESS;
$this->resultMessage = '';
return true;
} else {
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'Set fail.';
return false;
}
} | php | public function set($key, $val, $expt = 0)
{
$valueString = serialize($val);
$keyString = $this->getKey($key);
$this->writeSocket(
"set $keyString 0 $expt " . strlen($valueString)
);
$s = $this->writeSocket($valueString, true);
if ('STORED' == $s) {
$this->resultCode = Memcached::RES_SUCCESS;
$this->resultMessage = '';
return true;
} else {
$this->resultCode = Memcached::RES_FAILURE;
$this->resultMessage = 'Set fail.';
return false;
}
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"val",
",",
"$",
"expt",
"=",
"0",
")",
"{",
"$",
"valueString",
"=",
"serialize",
"(",
"$",
"val",
")",
";",
"$",
"keyString",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"writeSocket",
"(",
"\"set $keyString 0 $expt \"",
".",
"strlen",
"(",
"$",
"valueString",
")",
")",
";",
"$",
"s",
"=",
"$",
"this",
"->",
"writeSocket",
"(",
"$",
"valueString",
",",
"true",
")",
";",
"if",
"(",
"'STORED'",
"==",
"$",
"s",
")",
"{",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_SUCCESS",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"''",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"resultCode",
"=",
"Memcached",
"::",
"RES_FAILURE",
";",
"$",
"this",
"->",
"resultMessage",
"=",
"'Set fail.'",
";",
"return",
"false",
";",
"}",
"}"
] | Store an item
@param string $key
@param mixed $val
@param int $expt
@return boolean | [
"Store",
"an",
"item"
] | df31e249593380421785f0be342cfb92cbb1d1d7 | https://github.com/lhs168/fasim/blob/df31e249593380421785f0be342cfb92cbb1d1d7/src/Fasim/Cache/simulate/Memcached.php#L443-L463 |
11,894 | lhs168/fasim | src/Fasim/Cache/simulate/Memcached.php | Memcached.increment | public function increment($key, $offset = 1, $initial_value = 0, $expiry = 0)
{
if (($prevVal = $this->get($key))) {
if (!is_numeric($prevVal)) {
return false;
}
$newVal = $prevVal + $offset;
} else {
$newVal = $initial_value;
}
$this->set($key, $newVal, $expiry);
return $newVal;
} | php | public function increment($key, $offset = 1, $initial_value = 0, $expiry = 0)
{
if (($prevVal = $this->get($key))) {
if (!is_numeric($prevVal)) {
return false;
}
$newVal = $prevVal + $offset;
} else {
$newVal = $initial_value;
}
$this->set($key, $newVal, $expiry);
return $newVal;
} | [
"public",
"function",
"increment",
"(",
"$",
"key",
",",
"$",
"offset",
"=",
"1",
",",
"$",
"initial_value",
"=",
"0",
",",
"$",
"expiry",
"=",
"0",
")",
"{",
"if",
"(",
"(",
"$",
"prevVal",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
")",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"prevVal",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"newVal",
"=",
"$",
"prevVal",
"+",
"$",
"offset",
";",
"}",
"else",
"{",
"$",
"newVal",
"=",
"$",
"initial_value",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"newVal",
",",
"$",
"expiry",
")",
";",
"return",
"$",
"newVal",
";",
"}"
] | Increment numeric item's value
@param string $key The key of the item to increment.
@param int $offset The amount by which to increment the item's value.
@param int $initial_value The value to set the item to if it doesn't currently exist.
@param int $expiry The expiry time to set on the item.
@return mixed Returns new item's value on success or FALSE on failure. | [
"Increment",
"numeric",
"item",
"s",
"value"
] | df31e249593380421785f0be342cfb92cbb1d1d7 | https://github.com/lhs168/fasim/blob/df31e249593380421785f0be342cfb92cbb1d1d7/src/Fasim/Cache/simulate/Memcached.php#L502-L517 |
11,895 | canis-io/yii2-canis-lib | lib/console/controllers/PhpDocController.php | PhpDocController.actionFix | public function actionFix($root = null)
{
$files = $this->findFiles($root);
$nFilesTotal = 0;
$nFilesUpdated = 0;
foreach ($files as $file) {
$contents = file_get_contents($file);
$sha = sha1($contents);
// fix line endings
$lines = preg_split('/(\r\n|\n|\r)/', $contents);
$this->fixFileDoc($lines, $file);
$newContent = implode("\n", $lines);
if ($sha !== sha1($newContent)) {
$nFilesUpdated++;
}
file_put_contents($file, $newContent);
$nFilesTotal++;
}
$this->stdout("\nParsed $nFilesTotal files.\n");
$this->stdout("Updated $nFilesUpdated files.\n");
} | php | public function actionFix($root = null)
{
$files = $this->findFiles($root);
$nFilesTotal = 0;
$nFilesUpdated = 0;
foreach ($files as $file) {
$contents = file_get_contents($file);
$sha = sha1($contents);
// fix line endings
$lines = preg_split('/(\r\n|\n|\r)/', $contents);
$this->fixFileDoc($lines, $file);
$newContent = implode("\n", $lines);
if ($sha !== sha1($newContent)) {
$nFilesUpdated++;
}
file_put_contents($file, $newContent);
$nFilesTotal++;
}
$this->stdout("\nParsed $nFilesTotal files.\n");
$this->stdout("Updated $nFilesUpdated files.\n");
} | [
"public",
"function",
"actionFix",
"(",
"$",
"root",
"=",
"null",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"findFiles",
"(",
"$",
"root",
")",
";",
"$",
"nFilesTotal",
"=",
"0",
";",
"$",
"nFilesUpdated",
"=",
"0",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"$",
"sha",
"=",
"sha1",
"(",
"$",
"contents",
")",
";",
"// fix line endings",
"$",
"lines",
"=",
"preg_split",
"(",
"'/(\\r\\n|\\n|\\r)/'",
",",
"$",
"contents",
")",
";",
"$",
"this",
"->",
"fixFileDoc",
"(",
"$",
"lines",
",",
"$",
"file",
")",
";",
"$",
"newContent",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"if",
"(",
"$",
"sha",
"!==",
"sha1",
"(",
"$",
"newContent",
")",
")",
"{",
"$",
"nFilesUpdated",
"++",
";",
"}",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"newContent",
")",
";",
"$",
"nFilesTotal",
"++",
";",
"}",
"$",
"this",
"->",
"stdout",
"(",
"\"\\nParsed $nFilesTotal files.\\n\"",
")",
";",
"$",
"this",
"->",
"stdout",
"(",
"\"Updated $nFilesUpdated files.\\n\"",
")",
";",
"}"
] | Fix some issues with PHPdoc in files.
@param string $root the directory to parse files from. Defaults to YII_PATH. | [
"Fix",
"some",
"issues",
"with",
"PHPdoc",
"in",
"files",
"."
] | 97d533521f65b084dc805c5f312c364b469142d2 | https://github.com/canis-io/yii2-canis-lib/blob/97d533521f65b084dc805c5f312c364b469142d2/lib/console/controllers/PhpDocController.php#L93-L118 |
11,896 | emmanix2002/dorcas-sdk-php | src/SendsHttpRequestTrait.php | SendsHttpRequestTrait.prefillHeader | protected function prefillHeader()
{
if ($this->requiresAuthorization() && !empty($this->getAuthorizationHeader())) {
$this->headers['Authorization'] = $this->getAuthorizationHeader();
}
return $this;
} | php | protected function prefillHeader()
{
if ($this->requiresAuthorization() && !empty($this->getAuthorizationHeader())) {
$this->headers['Authorization'] = $this->getAuthorizationHeader();
}
return $this;
} | [
"protected",
"function",
"prefillHeader",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requiresAuthorization",
"(",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"getAuthorizationHeader",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"'Authorization'",
"]",
"=",
"$",
"this",
"->",
"getAuthorizationHeader",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Pre-fills the request header with some default values as required.
@return $this | [
"Pre",
"-",
"fills",
"the",
"request",
"header",
"with",
"some",
"default",
"values",
"as",
"required",
"."
] | 1b68df62da1ed5f993f9e2687633402b96ab7f64 | https://github.com/emmanix2002/dorcas-sdk-php/blob/1b68df62da1ed5f993f9e2687633402b96ab7f64/src/SendsHttpRequestTrait.php#L67-L73 |
11,897 | emmanix2002/dorcas-sdk-php | src/SendsHttpRequestTrait.php | SendsHttpRequestTrait.addBodyParam | public function addBodyParam(string $name, $value, bool $overwrite = false)
{
$keyExists = array_key_exists($name, $this->body);
# check if the key already exists
if ($keyExists && !$overwrite) {
return $this;
}
if (is_null($value)) {
if ($keyExists) {
unset($this->body[$name]);
}
return $this;
}
if (is_null($value)) {
unset($this->query[$name]);
return $this;
}
$this->body[$name] = $value;
return $this;
} | php | public function addBodyParam(string $name, $value, bool $overwrite = false)
{
$keyExists = array_key_exists($name, $this->body);
# check if the key already exists
if ($keyExists && !$overwrite) {
return $this;
}
if (is_null($value)) {
if ($keyExists) {
unset($this->body[$name]);
}
return $this;
}
if (is_null($value)) {
unset($this->query[$name]);
return $this;
}
$this->body[$name] = $value;
return $this;
} | [
"public",
"function",
"addBodyParam",
"(",
"string",
"$",
"name",
",",
"$",
"value",
",",
"bool",
"$",
"overwrite",
"=",
"false",
")",
"{",
"$",
"keyExists",
"=",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"body",
")",
";",
"# check if the key already exists",
"if",
"(",
"$",
"keyExists",
"&&",
"!",
"$",
"overwrite",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"keyExists",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"body",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"query",
"[",
"$",
"name",
"]",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"body",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a parameter to the body of the request.
@param string $name
@param $value
@param bool $overwrite
@return $this | [
"Adds",
"a",
"parameter",
"to",
"the",
"body",
"of",
"the",
"request",
"."
] | 1b68df62da1ed5f993f9e2687633402b96ab7f64 | https://github.com/emmanix2002/dorcas-sdk-php/blob/1b68df62da1ed5f993f9e2687633402b96ab7f64/src/SendsHttpRequestTrait.php#L96-L115 |
11,898 | emmanix2002/dorcas-sdk-php | src/SendsHttpRequestTrait.php | SendsHttpRequestTrait.addMultipartParam | public function addMultipartParam(string $name, $content, string $filename = null, bool $overwrite = false)
{
if (array_key_exists($name, $this->multipart) && !$overwrite) {
return $this;
}
$part = ['name' => $name, 'contents' => $content];
if (!empty($filename)) {
$part['filename'] = $filename;
}
$this->multipart[] = $part;
return $this;
} | php | public function addMultipartParam(string $name, $content, string $filename = null, bool $overwrite = false)
{
if (array_key_exists($name, $this->multipart) && !$overwrite) {
return $this;
}
$part = ['name' => $name, 'contents' => $content];
if (!empty($filename)) {
$part['filename'] = $filename;
}
$this->multipart[] = $part;
return $this;
} | [
"public",
"function",
"addMultipartParam",
"(",
"string",
"$",
"name",
",",
"$",
"content",
",",
"string",
"$",
"filename",
"=",
"null",
",",
"bool",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"multipart",
")",
"&&",
"!",
"$",
"overwrite",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"part",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'contents'",
"=>",
"$",
"content",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"part",
"[",
"'filename'",
"]",
"=",
"$",
"filename",
";",
"}",
"$",
"this",
"->",
"multipart",
"[",
"]",
"=",
"$",
"part",
";",
"return",
"$",
"this",
";",
"}"
] | Adds some multipart data to the request body.
@param string $name
@param string|resource $content the string content for the key; or resource gotten from fopen()
@param string|null $filename
@param bool $overwrite
@return $this | [
"Adds",
"some",
"multipart",
"data",
"to",
"the",
"request",
"body",
"."
] | 1b68df62da1ed5f993f9e2687633402b96ab7f64 | https://github.com/emmanix2002/dorcas-sdk-php/blob/1b68df62da1ed5f993f9e2687633402b96ab7f64/src/SendsHttpRequestTrait.php#L127-L138 |
11,899 | emmanix2002/dorcas-sdk-php | src/SendsHttpRequestTrait.php | SendsHttpRequestTrait.send | public function send(string $method, Client $httpClient, array $path = []): DorcasResponse
{
$this->prefillHeader();
$this->prefillBody();
if (strtolower($method) !== 'get') {
# we don't validate GEt requests
$this->validate();
}
$uri = static::getRequestUrl($path);
$url = $uri->getScheme() . '://' . $uri->getAuthority() . $uri->getPath();
# set the URL
try {
$options = [];
# the request data
if (!empty($this->headers)) {
$options[RequestOptions::HEADERS] = $this->headers;
}
if (!empty($uri->getQuery())) {
# some query parameters are present in the URL
$options[RequestOptions::QUERY] = parse_query_parameters($uri->getQuery());
}
if (strtolower($method) !== 'get') {
# not a get request
if (!empty($this->multipart)) {
# check if we have some multipart data first
foreach ($this->body as $key => $value) {
# add the requested body params to the multipart data
$this->multipart[] = ['name' => $key, 'contents' => $value];
}
$options[RequestOptions::MULTIPART] = $this->multipart;
} elseif (static::isJsonRequest() && !empty($this->body)) {
# a JSON request
$options[RequestOptions::JSON] = $this->body;
} elseif (!empty($this->body)) {
# we switch to an application/www-form-urlencoded type
$options[RequestOptions::FORM_PARAMS] = $this->body;
}
}
$response = $httpClient->request($method, $url, $options);
return new DorcasResponse((string) $response->getBody());
} catch (BadResponseException $e) {
// in the case of a failure, let's know the status
return new DorcasResponse((string) $e->getResponse()->getBody(), $e->getResponse()->getStatusCode(), $e->getRequest());
} catch (ConnectException $e) {
return new DorcasResponse('{"status": "error", "data": "'.$e->getMessage().'"}', 0);
}
} | php | public function send(string $method, Client $httpClient, array $path = []): DorcasResponse
{
$this->prefillHeader();
$this->prefillBody();
if (strtolower($method) !== 'get') {
# we don't validate GEt requests
$this->validate();
}
$uri = static::getRequestUrl($path);
$url = $uri->getScheme() . '://' . $uri->getAuthority() . $uri->getPath();
# set the URL
try {
$options = [];
# the request data
if (!empty($this->headers)) {
$options[RequestOptions::HEADERS] = $this->headers;
}
if (!empty($uri->getQuery())) {
# some query parameters are present in the URL
$options[RequestOptions::QUERY] = parse_query_parameters($uri->getQuery());
}
if (strtolower($method) !== 'get') {
# not a get request
if (!empty($this->multipart)) {
# check if we have some multipart data first
foreach ($this->body as $key => $value) {
# add the requested body params to the multipart data
$this->multipart[] = ['name' => $key, 'contents' => $value];
}
$options[RequestOptions::MULTIPART] = $this->multipart;
} elseif (static::isJsonRequest() && !empty($this->body)) {
# a JSON request
$options[RequestOptions::JSON] = $this->body;
} elseif (!empty($this->body)) {
# we switch to an application/www-form-urlencoded type
$options[RequestOptions::FORM_PARAMS] = $this->body;
}
}
$response = $httpClient->request($method, $url, $options);
return new DorcasResponse((string) $response->getBody());
} catch (BadResponseException $e) {
// in the case of a failure, let's know the status
return new DorcasResponse((string) $e->getResponse()->getBody(), $e->getResponse()->getStatusCode(), $e->getRequest());
} catch (ConnectException $e) {
return new DorcasResponse('{"status": "error", "data": "'.$e->getMessage().'"}', 0);
}
} | [
"public",
"function",
"send",
"(",
"string",
"$",
"method",
",",
"Client",
"$",
"httpClient",
",",
"array",
"$",
"path",
"=",
"[",
"]",
")",
":",
"DorcasResponse",
"{",
"$",
"this",
"->",
"prefillHeader",
"(",
")",
";",
"$",
"this",
"->",
"prefillBody",
"(",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"method",
")",
"!==",
"'get'",
")",
"{",
"# we don't validate GEt requests",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"}",
"$",
"uri",
"=",
"static",
"::",
"getRequestUrl",
"(",
"$",
"path",
")",
";",
"$",
"url",
"=",
"$",
"uri",
"->",
"getScheme",
"(",
")",
".",
"'://'",
".",
"$",
"uri",
"->",
"getAuthority",
"(",
")",
".",
"$",
"uri",
"->",
"getPath",
"(",
")",
";",
"# set the URL",
"try",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"# the request data",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"headers",
")",
")",
"{",
"$",
"options",
"[",
"RequestOptions",
"::",
"HEADERS",
"]",
"=",
"$",
"this",
"->",
"headers",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"uri",
"->",
"getQuery",
"(",
")",
")",
")",
"{",
"# some query parameters are present in the URL",
"$",
"options",
"[",
"RequestOptions",
"::",
"QUERY",
"]",
"=",
"parse_query_parameters",
"(",
"$",
"uri",
"->",
"getQuery",
"(",
")",
")",
";",
"}",
"if",
"(",
"strtolower",
"(",
"$",
"method",
")",
"!==",
"'get'",
")",
"{",
"# not a get request",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"multipart",
")",
")",
"{",
"# check if we have some multipart data first",
"foreach",
"(",
"$",
"this",
"->",
"body",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"# add the requested body params to the multipart data",
"$",
"this",
"->",
"multipart",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"key",
",",
"'contents'",
"=>",
"$",
"value",
"]",
";",
"}",
"$",
"options",
"[",
"RequestOptions",
"::",
"MULTIPART",
"]",
"=",
"$",
"this",
"->",
"multipart",
";",
"}",
"elseif",
"(",
"static",
"::",
"isJsonRequest",
"(",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"body",
")",
")",
"{",
"# a JSON request",
"$",
"options",
"[",
"RequestOptions",
"::",
"JSON",
"]",
"=",
"$",
"this",
"->",
"body",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"body",
")",
")",
"{",
"# we switch to an application/www-form-urlencoded type",
"$",
"options",
"[",
"RequestOptions",
"::",
"FORM_PARAMS",
"]",
"=",
"$",
"this",
"->",
"body",
";",
"}",
"}",
"$",
"response",
"=",
"$",
"httpClient",
"->",
"request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"options",
")",
";",
"return",
"new",
"DorcasResponse",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BadResponseException",
"$",
"e",
")",
"{",
"// in the case of a failure, let's know the status",
"return",
"new",
"DorcasResponse",
"(",
"(",
"string",
")",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
",",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"e",
"->",
"getRequest",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ConnectException",
"$",
"e",
")",
"{",
"return",
"new",
"DorcasResponse",
"(",
"'{\"status\": \"error\", \"data\": \"'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'\"}'",
",",
"0",
")",
";",
"}",
"}"
] | Sends a HTTP request.
@param string $method
@param Client $httpClient
@param array $path additional components for the path; e.g.: [$id, 'prices']
@return DorcasResponse
@throws \GuzzleHttp\Exception\GuzzleException | [
"Sends",
"a",
"HTTP",
"request",
"."
] | 1b68df62da1ed5f993f9e2687633402b96ab7f64 | https://github.com/emmanix2002/dorcas-sdk-php/blob/1b68df62da1ed5f993f9e2687633402b96ab7f64/src/SendsHttpRequestTrait.php#L158-L208 |
Subsets and Splits