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
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
236,100
|
vgrdominik/VGRElasticsearchHttpFoundationBundle
|
Security/Http/Firewall/ElasticsearchContextListener.php
|
ElasticsearchContextListener.refreshUser
|
private function refreshUser(TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return $token;
}
if (null !== $this->logger) {
$this->logger->debug(sprintf('Reloading user from user provider.'));
}
foreach ($this->userProviders as $provider) {
try {
$refreshedUser = $provider->refreshUser($user);
$token->setUser($refreshedUser);
if (null !== $this->logger) {
$this->logger->debug(sprintf('Username "%s" was reloaded from user provider.', $refreshedUser->getUsername()));
}
return $token;
} catch (UnsupportedUserException $unsupported) {
// let's try the next user provider
} catch (UsernameNotFoundException $notFound) {
if (null !== $this->logger) {
$this->logger->warning(sprintf('Username "%s" could not be found.', $notFound->getUsername()));
}
return;
}
}
throw new \RuntimeException(sprintf('There is no user provider for user "%s".', get_class($user)));
}
|
php
|
private function refreshUser(TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return $token;
}
if (null !== $this->logger) {
$this->logger->debug(sprintf('Reloading user from user provider.'));
}
foreach ($this->userProviders as $provider) {
try {
$refreshedUser = $provider->refreshUser($user);
$token->setUser($refreshedUser);
if (null !== $this->logger) {
$this->logger->debug(sprintf('Username "%s" was reloaded from user provider.', $refreshedUser->getUsername()));
}
return $token;
} catch (UnsupportedUserException $unsupported) {
// let's try the next user provider
} catch (UsernameNotFoundException $notFound) {
if (null !== $this->logger) {
$this->logger->warning(sprintf('Username "%s" could not be found.', $notFound->getUsername()));
}
return;
}
}
throw new \RuntimeException(sprintf('There is no user provider for user "%s".', get_class($user)));
}
|
[
"private",
"function",
"refreshUser",
"(",
"TokenInterface",
"$",
"token",
")",
"{",
"$",
"user",
"=",
"$",
"token",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"instanceof",
"UserInterface",
")",
"{",
"return",
"$",
"token",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'Reloading user from user provider.'",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"userProviders",
"as",
"$",
"provider",
")",
"{",
"try",
"{",
"$",
"refreshedUser",
"=",
"$",
"provider",
"->",
"refreshUser",
"(",
"$",
"user",
")",
";",
"$",
"token",
"->",
"setUser",
"(",
"$",
"refreshedUser",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'Username \"%s\" was reloaded from user provider.'",
",",
"$",
"refreshedUser",
"->",
"getUsername",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"token",
";",
"}",
"catch",
"(",
"UnsupportedUserException",
"$",
"unsupported",
")",
"{",
"// let's try the next user provider",
"}",
"catch",
"(",
"UsernameNotFoundException",
"$",
"notFound",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"sprintf",
"(",
"'Username \"%s\" could not be found.'",
",",
"$",
"notFound",
"->",
"getUsername",
"(",
")",
")",
")",
";",
"}",
"return",
";",
"}",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'There is no user provider for user \"%s\".'",
",",
"get_class",
"(",
"$",
"user",
")",
")",
")",
";",
"}"
] |
Refreshes the user by reloading it from the user provider
@param TokenInterface $token
@return TokenInterface|null
@throws \RuntimeException
|
[
"Refreshes",
"the",
"user",
"by",
"reloading",
"it",
"from",
"the",
"user",
"provider"
] |
06fad4b3619bfaf481b3141800d0b9eb5ae45b07
|
https://github.com/vgrdominik/VGRElasticsearchHttpFoundationBundle/blob/06fad4b3619bfaf481b3141800d0b9eb5ae45b07/Security/Http/Firewall/ElasticsearchContextListener.php#L175-L208
|
236,101
|
bishopb/vanilla
|
applications/vanilla/controllers/class.discussionscontroller.php
|
DiscussionsController.Table
|
public function Table($Page = '0') {
if ($this->SyndicationMethod == SYNDICATION_NONE)
$this->View = 'table';
$this->Index($Page);
}
|
php
|
public function Table($Page = '0') {
if ($this->SyndicationMethod == SYNDICATION_NONE)
$this->View = 'table';
$this->Index($Page);
}
|
[
"public",
"function",
"Table",
"(",
"$",
"Page",
"=",
"'0'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"SyndicationMethod",
"==",
"SYNDICATION_NONE",
")",
"$",
"this",
"->",
"View",
"=",
"'table'",
";",
"$",
"this",
"->",
"Index",
"(",
"$",
"Page",
")",
";",
"}"
] |
"Table" layout for discussions. Mimics more traditional forum discussion layout.
@param int $Page Multiplied by PerPage option to determine offset.
|
[
"Table",
"layout",
"for",
"discussions",
".",
"Mimics",
"more",
"traditional",
"forum",
"discussion",
"layout",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/controllers/class.discussionscontroller.php#L58-L62
|
236,102
|
bishopb/vanilla
|
applications/vanilla/controllers/class.discussionscontroller.php
|
DiscussionsController.Bookmarked
|
public function Bookmarked($Page = '0') {
$this->Permission('Garden.SignIn.Allow');
Gdn_Theme::Section('DiscussionList');
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = C('Vanilla.Discussions.Layout');
switch($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE)
$this->View = 'table';
break;
default:
$this->View = 'index';
break;
}
// Determine offset from $Page
list($Page, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$this->CanonicalUrl(Url(ConcatSep('/', 'discussions', 'bookmarked', PageNumber($Page, $Limit, TRUE, FALSE)), TRUE));
// Validate $Page
if (!is_numeric($Page) || $Page < 0)
$Page = 0;
$DiscussionModel = new DiscussionModel();
$Wheres = array(
'w.Bookmarked' => '1',
'w.UserID' => Gdn::Session()->UserID
);
$this->DiscussionData = $DiscussionModel->Get($Page, $Limit, $Wheres);
$this->SetData('Discussions', $this->DiscussionData);
$CountDiscussions = $DiscussionModel->GetCount($Wheres);
$this->SetData('CountDiscussions', $CountDiscussions);
$this->Category = FALSE;
$this->SetJson('Loading', $Page . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->FireEvent('BeforeBuildBookmarkedPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure(
$Page,
$Limit,
$CountDiscussions,
'discussions/bookmarked/%1$s'
);
if (!$this->Data('_PagerUrl'))
$this->SetData('_PagerUrl', 'discussions/bookmarked/{Page}');
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->FireEvent('AfterBuildBookmarkedPager');
// Deliver JSON data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'discussions';
}
// Add modules
$this->AddModule('DiscussionFilterModule');
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
// Render default view (discussions/bookmarked.php)
$this->SetData('Title', T('My Bookmarks'));
$this->SetData('Breadcrumbs', array(array('Name' => T('My Bookmarks'), 'Url' => '/discussions/bookmarked')));
$this->Render();
}
|
php
|
public function Bookmarked($Page = '0') {
$this->Permission('Garden.SignIn.Allow');
Gdn_Theme::Section('DiscussionList');
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = C('Vanilla.Discussions.Layout');
switch($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE)
$this->View = 'table';
break;
default:
$this->View = 'index';
break;
}
// Determine offset from $Page
list($Page, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$this->CanonicalUrl(Url(ConcatSep('/', 'discussions', 'bookmarked', PageNumber($Page, $Limit, TRUE, FALSE)), TRUE));
// Validate $Page
if (!is_numeric($Page) || $Page < 0)
$Page = 0;
$DiscussionModel = new DiscussionModel();
$Wheres = array(
'w.Bookmarked' => '1',
'w.UserID' => Gdn::Session()->UserID
);
$this->DiscussionData = $DiscussionModel->Get($Page, $Limit, $Wheres);
$this->SetData('Discussions', $this->DiscussionData);
$CountDiscussions = $DiscussionModel->GetCount($Wheres);
$this->SetData('CountDiscussions', $CountDiscussions);
$this->Category = FALSE;
$this->SetJson('Loading', $Page . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->FireEvent('BeforeBuildBookmarkedPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure(
$Page,
$Limit,
$CountDiscussions,
'discussions/bookmarked/%1$s'
);
if (!$this->Data('_PagerUrl'))
$this->SetData('_PagerUrl', 'discussions/bookmarked/{Page}');
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->FireEvent('AfterBuildBookmarkedPager');
// Deliver JSON data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'discussions';
}
// Add modules
$this->AddModule('DiscussionFilterModule');
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
// Render default view (discussions/bookmarked.php)
$this->SetData('Title', T('My Bookmarks'));
$this->SetData('Breadcrumbs', array(array('Name' => T('My Bookmarks'), 'Url' => '/discussions/bookmarked')));
$this->Render();
}
|
[
"public",
"function",
"Bookmarked",
"(",
"$",
"Page",
"=",
"'0'",
")",
"{",
"$",
"this",
"->",
"Permission",
"(",
"'Garden.SignIn.Allow'",
")",
";",
"Gdn_Theme",
"::",
"Section",
"(",
"'DiscussionList'",
")",
";",
"// Figure out which discussions layout to choose (Defined on \"Homepage\" settings page).",
"$",
"Layout",
"=",
"C",
"(",
"'Vanilla.Discussions.Layout'",
")",
";",
"switch",
"(",
"$",
"Layout",
")",
"{",
"case",
"'table'",
":",
"if",
"(",
"$",
"this",
"->",
"SyndicationMethod",
"==",
"SYNDICATION_NONE",
")",
"$",
"this",
"->",
"View",
"=",
"'table'",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"View",
"=",
"'index'",
";",
"break",
";",
"}",
"// Determine offset from $Page",
"list",
"(",
"$",
"Page",
",",
"$",
"Limit",
")",
"=",
"OffsetLimit",
"(",
"$",
"Page",
",",
"C",
"(",
"'Vanilla.Discussions.PerPage'",
",",
"30",
")",
")",
";",
"$",
"this",
"->",
"CanonicalUrl",
"(",
"Url",
"(",
"ConcatSep",
"(",
"'/'",
",",
"'discussions'",
",",
"'bookmarked'",
",",
"PageNumber",
"(",
"$",
"Page",
",",
"$",
"Limit",
",",
"TRUE",
",",
"FALSE",
")",
")",
",",
"TRUE",
")",
")",
";",
"// Validate $Page",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"Page",
")",
"||",
"$",
"Page",
"<",
"0",
")",
"$",
"Page",
"=",
"0",
";",
"$",
"DiscussionModel",
"=",
"new",
"DiscussionModel",
"(",
")",
";",
"$",
"Wheres",
"=",
"array",
"(",
"'w.Bookmarked'",
"=>",
"'1'",
",",
"'w.UserID'",
"=>",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"UserID",
")",
";",
"$",
"this",
"->",
"DiscussionData",
"=",
"$",
"DiscussionModel",
"->",
"Get",
"(",
"$",
"Page",
",",
"$",
"Limit",
",",
"$",
"Wheres",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'Discussions'",
",",
"$",
"this",
"->",
"DiscussionData",
")",
";",
"$",
"CountDiscussions",
"=",
"$",
"DiscussionModel",
"->",
"GetCount",
"(",
"$",
"Wheres",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'CountDiscussions'",
",",
"$",
"CountDiscussions",
")",
";",
"$",
"this",
"->",
"Category",
"=",
"FALSE",
";",
"$",
"this",
"->",
"SetJson",
"(",
"'Loading'",
",",
"$",
"Page",
".",
"' to '",
".",
"$",
"Limit",
")",
";",
"// Build a pager",
"$",
"PagerFactory",
"=",
"new",
"Gdn_PagerFactory",
"(",
")",
";",
"$",
"this",
"->",
"EventArguments",
"[",
"'PagerType'",
"]",
"=",
"'Pager'",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeBuildBookmarkedPager'",
")",
";",
"$",
"this",
"->",
"Pager",
"=",
"$",
"PagerFactory",
"->",
"GetPager",
"(",
"$",
"this",
"->",
"EventArguments",
"[",
"'PagerType'",
"]",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"Pager",
"->",
"ClientID",
"=",
"'Pager'",
";",
"$",
"this",
"->",
"Pager",
"->",
"Configure",
"(",
"$",
"Page",
",",
"$",
"Limit",
",",
"$",
"CountDiscussions",
",",
"'discussions/bookmarked/%1$s'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"Data",
"(",
"'_PagerUrl'",
")",
")",
"$",
"this",
"->",
"SetData",
"(",
"'_PagerUrl'",
",",
"'discussions/bookmarked/{Page}'",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_Page'",
",",
"$",
"Page",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_Limit'",
",",
"$",
"Limit",
")",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'AfterBuildBookmarkedPager'",
")",
";",
"// Deliver JSON data if necessary",
"if",
"(",
"$",
"this",
"->",
"_DeliveryType",
"!=",
"DELIVERY_TYPE_ALL",
")",
"{",
"$",
"this",
"->",
"SetJson",
"(",
"'LessRow'",
",",
"$",
"this",
"->",
"Pager",
"->",
"ToString",
"(",
"'less'",
")",
")",
";",
"$",
"this",
"->",
"SetJson",
"(",
"'MoreRow'",
",",
"$",
"this",
"->",
"Pager",
"->",
"ToString",
"(",
"'more'",
")",
")",
";",
"$",
"this",
"->",
"View",
"=",
"'discussions'",
";",
"}",
"// Add modules",
"$",
"this",
"->",
"AddModule",
"(",
"'DiscussionFilterModule'",
")",
";",
"$",
"this",
"->",
"AddModule",
"(",
"'NewDiscussionModule'",
")",
";",
"$",
"this",
"->",
"AddModule",
"(",
"'CategoriesModule'",
")",
";",
"// Render default view (discussions/bookmarked.php)",
"$",
"this",
"->",
"SetData",
"(",
"'Title'",
",",
"T",
"(",
"'My Bookmarks'",
")",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'Breadcrumbs'",
",",
"array",
"(",
"array",
"(",
"'Name'",
"=>",
"T",
"(",
"'My Bookmarks'",
")",
",",
"'Url'",
"=>",
"'/discussions/bookmarked'",
")",
")",
")",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] |
Display discussions the user has bookmarked.
@since 2.0.0
@access public
@param int $Offset Number of discussions to skip.
|
[
"Display",
"discussions",
"the",
"user",
"has",
"bookmarked",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/controllers/class.discussionscontroller.php#L298-L371
|
236,103
|
bishopb/vanilla
|
applications/vanilla/controllers/class.discussionscontroller.php
|
DiscussionsController.Mine
|
public function Mine($Page = 'p1') {
$this->Permission('Garden.SignIn.Allow');
Gdn_Theme::Section('DiscussionList');
// Set criteria & get discussions data
list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$Session = Gdn::Session();
$Wheres = array('d.InsertUserID' => $Session->UserID);
$DiscussionModel = new DiscussionModel();
$this->DiscussionData = $DiscussionModel->Get($Offset, $Limit, $Wheres);
$this->SetData('Discussions', $this->DiscussionData);
$CountDiscussions = $this->SetData('CountDiscussions', $DiscussionModel->GetCount($Wheres));
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'MorePager';
$this->FireEvent('BeforeBuildMinePager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->MoreCode = 'More Discussions';
$this->Pager->LessCode = 'Newer Discussions';
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure(
$Offset,
$Limit,
$CountDiscussions,
'discussions/mine/%1$s'
);
$this->SetData('_PagerUrl', 'discussions/mine/{Page}');
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->FireEvent('AfterBuildMinePager');
// Deliver JSON data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'discussions';
}
// Add modules
$this->AddModule('DiscussionFilterModule');
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$this->AddModule('BookmarkedModule');
// Render default view (discussions/mine.php)
$this->SetData('Title', T('My Discussions'));
$this->SetData('Breadcrumbs', array(array('Name' => T('My Discussions'), 'Url' => '/discussions/mine')));
$this->Render('Index');
}
|
php
|
public function Mine($Page = 'p1') {
$this->Permission('Garden.SignIn.Allow');
Gdn_Theme::Section('DiscussionList');
// Set criteria & get discussions data
list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$Session = Gdn::Session();
$Wheres = array('d.InsertUserID' => $Session->UserID);
$DiscussionModel = new DiscussionModel();
$this->DiscussionData = $DiscussionModel->Get($Offset, $Limit, $Wheres);
$this->SetData('Discussions', $this->DiscussionData);
$CountDiscussions = $this->SetData('CountDiscussions', $DiscussionModel->GetCount($Wheres));
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'MorePager';
$this->FireEvent('BeforeBuildMinePager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->MoreCode = 'More Discussions';
$this->Pager->LessCode = 'Newer Discussions';
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure(
$Offset,
$Limit,
$CountDiscussions,
'discussions/mine/%1$s'
);
$this->SetData('_PagerUrl', 'discussions/mine/{Page}');
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->FireEvent('AfterBuildMinePager');
// Deliver JSON data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'discussions';
}
// Add modules
$this->AddModule('DiscussionFilterModule');
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$this->AddModule('BookmarkedModule');
// Render default view (discussions/mine.php)
$this->SetData('Title', T('My Discussions'));
$this->SetData('Breadcrumbs', array(array('Name' => T('My Discussions'), 'Url' => '/discussions/mine')));
$this->Render('Index');
}
|
[
"public",
"function",
"Mine",
"(",
"$",
"Page",
"=",
"'p1'",
")",
"{",
"$",
"this",
"->",
"Permission",
"(",
"'Garden.SignIn.Allow'",
")",
";",
"Gdn_Theme",
"::",
"Section",
"(",
"'DiscussionList'",
")",
";",
"// Set criteria & get discussions data",
"list",
"(",
"$",
"Offset",
",",
"$",
"Limit",
")",
"=",
"OffsetLimit",
"(",
"$",
"Page",
",",
"C",
"(",
"'Vanilla.Discussions.PerPage'",
",",
"30",
")",
")",
";",
"$",
"Session",
"=",
"Gdn",
"::",
"Session",
"(",
")",
";",
"$",
"Wheres",
"=",
"array",
"(",
"'d.InsertUserID'",
"=>",
"$",
"Session",
"->",
"UserID",
")",
";",
"$",
"DiscussionModel",
"=",
"new",
"DiscussionModel",
"(",
")",
";",
"$",
"this",
"->",
"DiscussionData",
"=",
"$",
"DiscussionModel",
"->",
"Get",
"(",
"$",
"Offset",
",",
"$",
"Limit",
",",
"$",
"Wheres",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'Discussions'",
",",
"$",
"this",
"->",
"DiscussionData",
")",
";",
"$",
"CountDiscussions",
"=",
"$",
"this",
"->",
"SetData",
"(",
"'CountDiscussions'",
",",
"$",
"DiscussionModel",
"->",
"GetCount",
"(",
"$",
"Wheres",
")",
")",
";",
"// Build a pager",
"$",
"PagerFactory",
"=",
"new",
"Gdn_PagerFactory",
"(",
")",
";",
"$",
"this",
"->",
"EventArguments",
"[",
"'PagerType'",
"]",
"=",
"'MorePager'",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeBuildMinePager'",
")",
";",
"$",
"this",
"->",
"Pager",
"=",
"$",
"PagerFactory",
"->",
"GetPager",
"(",
"$",
"this",
"->",
"EventArguments",
"[",
"'PagerType'",
"]",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"Pager",
"->",
"MoreCode",
"=",
"'More Discussions'",
";",
"$",
"this",
"->",
"Pager",
"->",
"LessCode",
"=",
"'Newer Discussions'",
";",
"$",
"this",
"->",
"Pager",
"->",
"ClientID",
"=",
"'Pager'",
";",
"$",
"this",
"->",
"Pager",
"->",
"Configure",
"(",
"$",
"Offset",
",",
"$",
"Limit",
",",
"$",
"CountDiscussions",
",",
"'discussions/mine/%1$s'",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_PagerUrl'",
",",
"'discussions/mine/{Page}'",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_Page'",
",",
"$",
"Page",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_Limit'",
",",
"$",
"Limit",
")",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'AfterBuildMinePager'",
")",
";",
"// Deliver JSON data if necessary",
"if",
"(",
"$",
"this",
"->",
"_DeliveryType",
"!=",
"DELIVERY_TYPE_ALL",
")",
"{",
"$",
"this",
"->",
"SetJson",
"(",
"'LessRow'",
",",
"$",
"this",
"->",
"Pager",
"->",
"ToString",
"(",
"'less'",
")",
")",
";",
"$",
"this",
"->",
"SetJson",
"(",
"'MoreRow'",
",",
"$",
"this",
"->",
"Pager",
"->",
"ToString",
"(",
"'more'",
")",
")",
";",
"$",
"this",
"->",
"View",
"=",
"'discussions'",
";",
"}",
"// Add modules",
"$",
"this",
"->",
"AddModule",
"(",
"'DiscussionFilterModule'",
")",
";",
"$",
"this",
"->",
"AddModule",
"(",
"'NewDiscussionModule'",
")",
";",
"$",
"this",
"->",
"AddModule",
"(",
"'CategoriesModule'",
")",
";",
"$",
"this",
"->",
"AddModule",
"(",
"'BookmarkedModule'",
")",
";",
"// Render default view (discussions/mine.php)",
"$",
"this",
"->",
"SetData",
"(",
"'Title'",
",",
"T",
"(",
"'My Discussions'",
")",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'Breadcrumbs'",
",",
"array",
"(",
"array",
"(",
"'Name'",
"=>",
"T",
"(",
"'My Discussions'",
")",
",",
"'Url'",
"=>",
"'/discussions/mine'",
")",
")",
")",
";",
"$",
"this",
"->",
"Render",
"(",
"'Index'",
")",
";",
"}"
] |
Display discussions started by the user.
@since 2.0.0
@access public
@param int $Offset Number of discussions to skip.
|
[
"Display",
"discussions",
"started",
"by",
"the",
"user",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/controllers/class.discussionscontroller.php#L396-L447
|
236,104
|
bishopb/vanilla
|
applications/vanilla/controllers/class.discussionscontroller.php
|
DiscussionsController.GetCommentCounts
|
public function GetCommentCounts() {
$this->AllowJSONP(TRUE);
$vanilla_identifier = GetValue('vanilla_identifier', $_GET);
if (!is_array($vanilla_identifier))
$vanilla_identifier = array($vanilla_identifier);
$vanilla_identifier = array_unique($vanilla_identifier);
$FinalData = array_fill_keys($vanilla_identifier, 0);
$Misses = array();
$CacheKey = 'embed.comments.count.%s';
$OriginalIDs = array();
foreach ($vanilla_identifier as $ForeignID) {
$HashedForeignID = ForeignIDHash($ForeignID);
// Keep record of non-hashed identifiers for the reply
$OriginalIDs[$HashedForeignID] = $ForeignID;
$RealCacheKey = sprintf($CacheKey, $HashedForeignID);
$Comments = Gdn::Cache()->Get($RealCacheKey);
if ($Comments !== Gdn_Cache::CACHEOP_FAILURE)
$FinalData[$ForeignID] = $Comments;
else
$Misses[] = $HashedForeignID;
}
if (sizeof($Misses)) {
$CountData = Gdn::SQL()
->Select('ForeignID, CountComments')
->From('Discussion')
->Where('Type', 'page')
->WhereIn('ForeignID', $Misses)
->Get()->ResultArray();
foreach ($CountData as $Row) {
// Get original identifier to send back
$ForeignID = $OriginalIDs[$Row['ForeignID']];
$FinalData[$ForeignID] = $Row['CountComments'];
// Cache using the hashed identifier
$RealCacheKey = sprintf($CacheKey, $Row['ForeignID']);
Gdn::Cache()->Store($RealCacheKey, $Row['CountComments'], array(
Gdn_Cache::FEATURE_EXPIRY => 60
));
}
}
$this->SetData('CountData', $FinalData);
$this->DeliveryMethod = DELIVERY_METHOD_JSON;
$this->DeliveryType = DELIVERY_TYPE_DATA;
$this->Render();
}
|
php
|
public function GetCommentCounts() {
$this->AllowJSONP(TRUE);
$vanilla_identifier = GetValue('vanilla_identifier', $_GET);
if (!is_array($vanilla_identifier))
$vanilla_identifier = array($vanilla_identifier);
$vanilla_identifier = array_unique($vanilla_identifier);
$FinalData = array_fill_keys($vanilla_identifier, 0);
$Misses = array();
$CacheKey = 'embed.comments.count.%s';
$OriginalIDs = array();
foreach ($vanilla_identifier as $ForeignID) {
$HashedForeignID = ForeignIDHash($ForeignID);
// Keep record of non-hashed identifiers for the reply
$OriginalIDs[$HashedForeignID] = $ForeignID;
$RealCacheKey = sprintf($CacheKey, $HashedForeignID);
$Comments = Gdn::Cache()->Get($RealCacheKey);
if ($Comments !== Gdn_Cache::CACHEOP_FAILURE)
$FinalData[$ForeignID] = $Comments;
else
$Misses[] = $HashedForeignID;
}
if (sizeof($Misses)) {
$CountData = Gdn::SQL()
->Select('ForeignID, CountComments')
->From('Discussion')
->Where('Type', 'page')
->WhereIn('ForeignID', $Misses)
->Get()->ResultArray();
foreach ($CountData as $Row) {
// Get original identifier to send back
$ForeignID = $OriginalIDs[$Row['ForeignID']];
$FinalData[$ForeignID] = $Row['CountComments'];
// Cache using the hashed identifier
$RealCacheKey = sprintf($CacheKey, $Row['ForeignID']);
Gdn::Cache()->Store($RealCacheKey, $Row['CountComments'], array(
Gdn_Cache::FEATURE_EXPIRY => 60
));
}
}
$this->SetData('CountData', $FinalData);
$this->DeliveryMethod = DELIVERY_METHOD_JSON;
$this->DeliveryType = DELIVERY_TYPE_DATA;
$this->Render();
}
|
[
"public",
"function",
"GetCommentCounts",
"(",
")",
"{",
"$",
"this",
"->",
"AllowJSONP",
"(",
"TRUE",
")",
";",
"$",
"vanilla_identifier",
"=",
"GetValue",
"(",
"'vanilla_identifier'",
",",
"$",
"_GET",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"vanilla_identifier",
")",
")",
"$",
"vanilla_identifier",
"=",
"array",
"(",
"$",
"vanilla_identifier",
")",
";",
"$",
"vanilla_identifier",
"=",
"array_unique",
"(",
"$",
"vanilla_identifier",
")",
";",
"$",
"FinalData",
"=",
"array_fill_keys",
"(",
"$",
"vanilla_identifier",
",",
"0",
")",
";",
"$",
"Misses",
"=",
"array",
"(",
")",
";",
"$",
"CacheKey",
"=",
"'embed.comments.count.%s'",
";",
"$",
"OriginalIDs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"vanilla_identifier",
"as",
"$",
"ForeignID",
")",
"{",
"$",
"HashedForeignID",
"=",
"ForeignIDHash",
"(",
"$",
"ForeignID",
")",
";",
"// Keep record of non-hashed identifiers for the reply",
"$",
"OriginalIDs",
"[",
"$",
"HashedForeignID",
"]",
"=",
"$",
"ForeignID",
";",
"$",
"RealCacheKey",
"=",
"sprintf",
"(",
"$",
"CacheKey",
",",
"$",
"HashedForeignID",
")",
";",
"$",
"Comments",
"=",
"Gdn",
"::",
"Cache",
"(",
")",
"->",
"Get",
"(",
"$",
"RealCacheKey",
")",
";",
"if",
"(",
"$",
"Comments",
"!==",
"Gdn_Cache",
"::",
"CACHEOP_FAILURE",
")",
"$",
"FinalData",
"[",
"$",
"ForeignID",
"]",
"=",
"$",
"Comments",
";",
"else",
"$",
"Misses",
"[",
"]",
"=",
"$",
"HashedForeignID",
";",
"}",
"if",
"(",
"sizeof",
"(",
"$",
"Misses",
")",
")",
"{",
"$",
"CountData",
"=",
"Gdn",
"::",
"SQL",
"(",
")",
"->",
"Select",
"(",
"'ForeignID, CountComments'",
")",
"->",
"From",
"(",
"'Discussion'",
")",
"->",
"Where",
"(",
"'Type'",
",",
"'page'",
")",
"->",
"WhereIn",
"(",
"'ForeignID'",
",",
"$",
"Misses",
")",
"->",
"Get",
"(",
")",
"->",
"ResultArray",
"(",
")",
";",
"foreach",
"(",
"$",
"CountData",
"as",
"$",
"Row",
")",
"{",
"// Get original identifier to send back",
"$",
"ForeignID",
"=",
"$",
"OriginalIDs",
"[",
"$",
"Row",
"[",
"'ForeignID'",
"]",
"]",
";",
"$",
"FinalData",
"[",
"$",
"ForeignID",
"]",
"=",
"$",
"Row",
"[",
"'CountComments'",
"]",
";",
"// Cache using the hashed identifier",
"$",
"RealCacheKey",
"=",
"sprintf",
"(",
"$",
"CacheKey",
",",
"$",
"Row",
"[",
"'ForeignID'",
"]",
")",
";",
"Gdn",
"::",
"Cache",
"(",
")",
"->",
"Store",
"(",
"$",
"RealCacheKey",
",",
"$",
"Row",
"[",
"'CountComments'",
"]",
",",
"array",
"(",
"Gdn_Cache",
"::",
"FEATURE_EXPIRY",
"=>",
"60",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"SetData",
"(",
"'CountData'",
",",
"$",
"FinalData",
")",
";",
"$",
"this",
"->",
"DeliveryMethod",
"=",
"DELIVERY_METHOD_JSON",
";",
"$",
"this",
"->",
"DeliveryType",
"=",
"DELIVERY_TYPE_DATA",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] |
Takes a set of discussion identifiers and returns their comment counts in the same order.
|
[
"Takes",
"a",
"set",
"of",
"discussion",
"identifiers",
"and",
"returns",
"their",
"comment",
"counts",
"in",
"the",
"same",
"order",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/controllers/class.discussionscontroller.php#L484-L536
|
236,105
|
bishopb/vanilla
|
applications/vanilla/controllers/class.discussionscontroller.php
|
DiscussionsController.Sort
|
public function Sort($Target = '') {
if (!Gdn::Session()->IsValid())
throw PermissionException();
if (!$this->Request->IsAuthenticatedPostBack())
throw ForbiddenException('GET');
// Get param
$SortField = Gdn::Request()->Post('DiscussionSort');
$SortField = 'd.'.StringBeginsWith($SortField, 'd.', TRUE, TRUE);
// Use whitelist here too to keep database clean
if (!in_array($SortField, DiscussionModel::AllowedSortFields())) {
throw new Gdn_UserException("Unknown sort $SortField.");
}
// Set user pref
Gdn::UserModel()->SavePreference(Gdn::Session()->UserID, 'Discussions.SortField', $SortField);
if ($Target)
Redirect($Target);
// Send sorted discussions.
$this->DeliveryMethod(DELIVERY_METHOD_JSON);
$this->Render();
}
|
php
|
public function Sort($Target = '') {
if (!Gdn::Session()->IsValid())
throw PermissionException();
if (!$this->Request->IsAuthenticatedPostBack())
throw ForbiddenException('GET');
// Get param
$SortField = Gdn::Request()->Post('DiscussionSort');
$SortField = 'd.'.StringBeginsWith($SortField, 'd.', TRUE, TRUE);
// Use whitelist here too to keep database clean
if (!in_array($SortField, DiscussionModel::AllowedSortFields())) {
throw new Gdn_UserException("Unknown sort $SortField.");
}
// Set user pref
Gdn::UserModel()->SavePreference(Gdn::Session()->UserID, 'Discussions.SortField', $SortField);
if ($Target)
Redirect($Target);
// Send sorted discussions.
$this->DeliveryMethod(DELIVERY_METHOD_JSON);
$this->Render();
}
|
[
"public",
"function",
"Sort",
"(",
"$",
"Target",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"IsValid",
"(",
")",
")",
"throw",
"PermissionException",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"Request",
"->",
"IsAuthenticatedPostBack",
"(",
")",
")",
"throw",
"ForbiddenException",
"(",
"'GET'",
")",
";",
"// Get param",
"$",
"SortField",
"=",
"Gdn",
"::",
"Request",
"(",
")",
"->",
"Post",
"(",
"'DiscussionSort'",
")",
";",
"$",
"SortField",
"=",
"'d.'",
".",
"StringBeginsWith",
"(",
"$",
"SortField",
",",
"'d.'",
",",
"TRUE",
",",
"TRUE",
")",
";",
"// Use whitelist here too to keep database clean",
"if",
"(",
"!",
"in_array",
"(",
"$",
"SortField",
",",
"DiscussionModel",
"::",
"AllowedSortFields",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Gdn_UserException",
"(",
"\"Unknown sort $SortField.\"",
")",
";",
"}",
"// Set user pref",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"SavePreference",
"(",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"UserID",
",",
"'Discussions.SortField'",
",",
"$",
"SortField",
")",
";",
"if",
"(",
"$",
"Target",
")",
"Redirect",
"(",
"$",
"Target",
")",
";",
"// Send sorted discussions.",
"$",
"this",
"->",
"DeliveryMethod",
"(",
"DELIVERY_METHOD_JSON",
")",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] |
Set user preference for sorting discussions.
|
[
"Set",
"user",
"preference",
"for",
"sorting",
"discussions",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/controllers/class.discussionscontroller.php#L541-L566
|
236,106
|
CampusUnion/Sked
|
src/SkeFormInput.php
|
SkeFormInput.defineType
|
protected function defineType(string $strType)
{
switch ($strType) {
case 'select':
case 'textarea':
$this->strElementType = $strType;
break;
case 'checkbox':
case 'hidden':
case 'radio':
case 'text':
default:
$this->strElementType = 'input';
$this->aAttribs['type'] = $strType;
break;
}
}
|
php
|
protected function defineType(string $strType)
{
switch ($strType) {
case 'select':
case 'textarea':
$this->strElementType = $strType;
break;
case 'checkbox':
case 'hidden':
case 'radio':
case 'text':
default:
$this->strElementType = 'input';
$this->aAttribs['type'] = $strType;
break;
}
}
|
[
"protected",
"function",
"defineType",
"(",
"string",
"$",
"strType",
")",
"{",
"switch",
"(",
"$",
"strType",
")",
"{",
"case",
"'select'",
":",
"case",
"'textarea'",
":",
"$",
"this",
"->",
"strElementType",
"=",
"$",
"strType",
";",
"break",
";",
"case",
"'checkbox'",
":",
"case",
"'hidden'",
":",
"case",
"'radio'",
":",
"case",
"'text'",
":",
"default",
":",
"$",
"this",
"->",
"strElementType",
"=",
"'input'",
";",
"$",
"this",
"->",
"aAttribs",
"[",
"'type'",
"]",
"=",
"$",
"strType",
";",
"break",
";",
"}",
"}"
] |
Init the HTML element type.
@param string $strType Type of HTML element.
|
[
"Init",
"the",
"HTML",
"element",
"type",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/SkeFormInput.php#L95-L111
|
236,107
|
CampusUnion/Sked
|
src/SkeFormInput.php
|
SkeFormInput.renderInput
|
public function renderInput(array $aAttribs = [])
{
$this->aAttribs += $aAttribs;
$strElement = $this->isMulti() ? $this->renderMulti() : $this->renderSingle();
$strSuffix = $this->strSuffix ? ' ' . $this->strSuffix : '';
return $strElement . $strSuffix;
}
|
php
|
public function renderInput(array $aAttribs = [])
{
$this->aAttribs += $aAttribs;
$strElement = $this->isMulti() ? $this->renderMulti() : $this->renderSingle();
$strSuffix = $this->strSuffix ? ' ' . $this->strSuffix : '';
return $strElement . $strSuffix;
}
|
[
"public",
"function",
"renderInput",
"(",
"array",
"$",
"aAttribs",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"aAttribs",
"+=",
"$",
"aAttribs",
";",
"$",
"strElement",
"=",
"$",
"this",
"->",
"isMulti",
"(",
")",
"?",
"$",
"this",
"->",
"renderMulti",
"(",
")",
":",
"$",
"this",
"->",
"renderSingle",
"(",
")",
";",
"$",
"strSuffix",
"=",
"$",
"this",
"->",
"strSuffix",
"?",
"' '",
".",
"$",
"this",
"->",
"strSuffix",
":",
"''",
";",
"return",
"$",
"strElement",
".",
"$",
"strSuffix",
";",
"}"
] |
Render the input element.
@param array $aAttribs Array of element attributes.
@return string HTML
|
[
"Render",
"the",
"input",
"element",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/SkeFormInput.php#L207-L213
|
236,108
|
CampusUnion/Sked
|
src/SkeFormInput.php
|
SkeFormInput.renderSingle
|
protected function renderSingle()
{
$strHtml = '';
// Apply label?
if (in_array($this->getType(), ['checkbox', 'radio']))
$strHtml .= '<label class="sked-input-multi">';
// Build opening tag
$strHtml .= '<' . $this->strElementType . ' ' . $this->renderAttribs() . '>';
// Optional - Build inner HTML
if (!empty($this->aOptions)) {
// An indexed array means use the label as the value also.
$bLabelIsValue = isset($this->aOptions[0]);
foreach ($this->aOptions as $mValue => $strLabel) {
if ($bLabelIsValue)
$mValue = $strLabel;
$strSelected = isset($this->mValue) && (string)$this->mValue === (string)$mValue
? ' selected' : '';
$strHtml .= '<option value="' . $mValue . '"' . $strSelected . '>'
. $strLabel . '</option>';
}
} elseif ('textarea' === $this->strElementType) {
$strHtml .= $this->mValue;
}
// Optional - Build closing tag
if ('input' !== $this->strElementType)
$strHtml .= '</' . $this->strElementType . '>';
// Close label?
if (in_array($this->getType(), ['checkbox', 'radio']))
$strHtml .= '</label>';
return $strHtml;
}
|
php
|
protected function renderSingle()
{
$strHtml = '';
// Apply label?
if (in_array($this->getType(), ['checkbox', 'radio']))
$strHtml .= '<label class="sked-input-multi">';
// Build opening tag
$strHtml .= '<' . $this->strElementType . ' ' . $this->renderAttribs() . '>';
// Optional - Build inner HTML
if (!empty($this->aOptions)) {
// An indexed array means use the label as the value also.
$bLabelIsValue = isset($this->aOptions[0]);
foreach ($this->aOptions as $mValue => $strLabel) {
if ($bLabelIsValue)
$mValue = $strLabel;
$strSelected = isset($this->mValue) && (string)$this->mValue === (string)$mValue
? ' selected' : '';
$strHtml .= '<option value="' . $mValue . '"' . $strSelected . '>'
. $strLabel . '</option>';
}
} elseif ('textarea' === $this->strElementType) {
$strHtml .= $this->mValue;
}
// Optional - Build closing tag
if ('input' !== $this->strElementType)
$strHtml .= '</' . $this->strElementType . '>';
// Close label?
if (in_array($this->getType(), ['checkbox', 'radio']))
$strHtml .= '</label>';
return $strHtml;
}
|
[
"protected",
"function",
"renderSingle",
"(",
")",
"{",
"$",
"strHtml",
"=",
"''",
";",
"// Apply label?",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
",",
"[",
"'checkbox'",
",",
"'radio'",
"]",
")",
")",
"$",
"strHtml",
".=",
"'<label class=\"sked-input-multi\">'",
";",
"// Build opening tag",
"$",
"strHtml",
".=",
"'<'",
".",
"$",
"this",
"->",
"strElementType",
".",
"' '",
".",
"$",
"this",
"->",
"renderAttribs",
"(",
")",
".",
"'>'",
";",
"// Optional - Build inner HTML",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"aOptions",
")",
")",
"{",
"// An indexed array means use the label as the value also.",
"$",
"bLabelIsValue",
"=",
"isset",
"(",
"$",
"this",
"->",
"aOptions",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"aOptions",
"as",
"$",
"mValue",
"=>",
"$",
"strLabel",
")",
"{",
"if",
"(",
"$",
"bLabelIsValue",
")",
"$",
"mValue",
"=",
"$",
"strLabel",
";",
"$",
"strSelected",
"=",
"isset",
"(",
"$",
"this",
"->",
"mValue",
")",
"&&",
"(",
"string",
")",
"$",
"this",
"->",
"mValue",
"===",
"(",
"string",
")",
"$",
"mValue",
"?",
"' selected'",
":",
"''",
";",
"$",
"strHtml",
".=",
"'<option value=\"'",
".",
"$",
"mValue",
".",
"'\"'",
".",
"$",
"strSelected",
".",
"'>'",
".",
"$",
"strLabel",
".",
"'</option>'",
";",
"}",
"}",
"elseif",
"(",
"'textarea'",
"===",
"$",
"this",
"->",
"strElementType",
")",
"{",
"$",
"strHtml",
".=",
"$",
"this",
"->",
"mValue",
";",
"}",
"// Optional - Build closing tag",
"if",
"(",
"'input'",
"!==",
"$",
"this",
"->",
"strElementType",
")",
"$",
"strHtml",
".=",
"'</'",
".",
"$",
"this",
"->",
"strElementType",
".",
"'>'",
";",
"// Close label?",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
",",
"[",
"'checkbox'",
",",
"'radio'",
"]",
")",
")",
"$",
"strHtml",
".=",
"'</label>'",
";",
"return",
"$",
"strHtml",
";",
"}"
] |
Render a single element.
@return string HTML
|
[
"Render",
"a",
"single",
"element",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/SkeFormInput.php#L220-L256
|
236,109
|
CampusUnion/Sked
|
src/SkeFormInput.php
|
SkeFormInput.renderMulti
|
protected function renderMulti()
{
$strHtml = '';
// An indexed array means use the label as the value also.
$bLabelIsValue = isset($this->aOptions[0]);
foreach ($this->aOptions as $mValue => $strLabel) {
if ($bLabelIsValue)
$mValue = $strLabel;
$strSelected = isset($this->mValue) && in_array($strLabel, (array)$this->mValue)
? ' checked' : '';
$strHtml .= '<label class="sked-input-multi">'
. '<input value="' . $mValue . '" ' . $this->renderAttribs() . $strSelected . '> '
. $strLabel . '</label>';
}
return $strHtml;
}
|
php
|
protected function renderMulti()
{
$strHtml = '';
// An indexed array means use the label as the value also.
$bLabelIsValue = isset($this->aOptions[0]);
foreach ($this->aOptions as $mValue => $strLabel) {
if ($bLabelIsValue)
$mValue = $strLabel;
$strSelected = isset($this->mValue) && in_array($strLabel, (array)$this->mValue)
? ' checked' : '';
$strHtml .= '<label class="sked-input-multi">'
. '<input value="' . $mValue . '" ' . $this->renderAttribs() . $strSelected . '> '
. $strLabel . '</label>';
}
return $strHtml;
}
|
[
"protected",
"function",
"renderMulti",
"(",
")",
"{",
"$",
"strHtml",
"=",
"''",
";",
"// An indexed array means use the label as the value also.",
"$",
"bLabelIsValue",
"=",
"isset",
"(",
"$",
"this",
"->",
"aOptions",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"aOptions",
"as",
"$",
"mValue",
"=>",
"$",
"strLabel",
")",
"{",
"if",
"(",
"$",
"bLabelIsValue",
")",
"$",
"mValue",
"=",
"$",
"strLabel",
";",
"$",
"strSelected",
"=",
"isset",
"(",
"$",
"this",
"->",
"mValue",
")",
"&&",
"in_array",
"(",
"$",
"strLabel",
",",
"(",
"array",
")",
"$",
"this",
"->",
"mValue",
")",
"?",
"' checked'",
":",
"''",
";",
"$",
"strHtml",
".=",
"'<label class=\"sked-input-multi\">'",
".",
"'<input value=\"'",
".",
"$",
"mValue",
".",
"'\" '",
".",
"$",
"this",
"->",
"renderAttribs",
"(",
")",
".",
"$",
"strSelected",
".",
"'> '",
".",
"$",
"strLabel",
".",
"'</label>'",
";",
"}",
"return",
"$",
"strHtml",
";",
"}"
] |
Render multiple related elements.
@return string HTML
|
[
"Render",
"multiple",
"related",
"elements",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/SkeFormInput.php#L263-L280
|
236,110
|
cobonto/module
|
src/Classes/Actions/Event.php
|
Event.add
|
public function add()
{
if($moduleEvents = $this->module->events())
{
$systemEvents = $this->load();
if(isset($moduleEvents['listen']))
// for listen event we must check if exists merge if not add it
foreach ($moduleEvents['listen'] as $event => $listens)
{
if(isset($systemEvents['listen'][$event]))
$systemEvents['listen'][$event] = array_merge($systemEvents['listen'][$event],$listens);
else
$systemEvents['listen'][$event] = $listens;
}
// for subscribe
if(isset($moduleEvents['subscribe']))
$systemEvents['subscribe'][] = $moduleEvents['subscribe'];
return $this->set($systemEvents);
}
return true;
}
|
php
|
public function add()
{
if($moduleEvents = $this->module->events())
{
$systemEvents = $this->load();
if(isset($moduleEvents['listen']))
// for listen event we must check if exists merge if not add it
foreach ($moduleEvents['listen'] as $event => $listens)
{
if(isset($systemEvents['listen'][$event]))
$systemEvents['listen'][$event] = array_merge($systemEvents['listen'][$event],$listens);
else
$systemEvents['listen'][$event] = $listens;
}
// for subscribe
if(isset($moduleEvents['subscribe']))
$systemEvents['subscribe'][] = $moduleEvents['subscribe'];
return $this->set($systemEvents);
}
return true;
}
|
[
"public",
"function",
"add",
"(",
")",
"{",
"if",
"(",
"$",
"moduleEvents",
"=",
"$",
"this",
"->",
"module",
"->",
"events",
"(",
")",
")",
"{",
"$",
"systemEvents",
"=",
"$",
"this",
"->",
"load",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"moduleEvents",
"[",
"'listen'",
"]",
")",
")",
"// for listen event we must check if exists merge if not add it",
"foreach",
"(",
"$",
"moduleEvents",
"[",
"'listen'",
"]",
"as",
"$",
"event",
"=>",
"$",
"listens",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"systemEvents",
"[",
"'listen'",
"]",
"[",
"$",
"event",
"]",
")",
")",
"$",
"systemEvents",
"[",
"'listen'",
"]",
"[",
"$",
"event",
"]",
"=",
"array_merge",
"(",
"$",
"systemEvents",
"[",
"'listen'",
"]",
"[",
"$",
"event",
"]",
",",
"$",
"listens",
")",
";",
"else",
"$",
"systemEvents",
"[",
"'listen'",
"]",
"[",
"$",
"event",
"]",
"=",
"$",
"listens",
";",
"}",
"// for subscribe",
"if",
"(",
"isset",
"(",
"$",
"moduleEvents",
"[",
"'subscribe'",
"]",
")",
")",
"$",
"systemEvents",
"[",
"'subscribe'",
"]",
"[",
"]",
"=",
"$",
"moduleEvents",
"[",
"'subscribe'",
"]",
";",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"systemEvents",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
add events to events.php in cache
|
[
"add",
"events",
"to",
"events",
".",
"php",
"in",
"cache"
] |
0978b5305c3d6f13ef7e0e5297855bd09eee6b76
|
https://github.com/cobonto/module/blob/0978b5305c3d6f13ef7e0e5297855bd09eee6b76/src/Classes/Actions/Event.php#L11-L31
|
236,111
|
cobonto/module
|
src/Classes/Actions/Event.php
|
Event.remove
|
public function remove()
{
if($moduleEvents = $this->module->events())
{
$systemEvents = $this->load();
if (isset($moduleEvents['listen']))
// for listen event we must check if exists merge if not add it
foreach ($moduleEvents['listen'] as $event => $listens)
{
if (isset($systemEvents['listen'][$event]))
{
foreach ($listens as $listen)
{
$key = array_search($listen, $systemEvents['listen'][$event]);
if ($key !== false)
unset($listen, $systemEvents['listen'][$event][$key]);
}
}
}
// for subscribe
if (isset($moduleEvents['subscribe']))
{
$key = array_search($moduleEvents['subscribe'], $systemEvents['subscribe'][$event]);
if($key !==false)
unset($systemEvents['subscribe'][$key]);
}
return $this->set($systemEvents);
}
return true;
}
|
php
|
public function remove()
{
if($moduleEvents = $this->module->events())
{
$systemEvents = $this->load();
if (isset($moduleEvents['listen']))
// for listen event we must check if exists merge if not add it
foreach ($moduleEvents['listen'] as $event => $listens)
{
if (isset($systemEvents['listen'][$event]))
{
foreach ($listens as $listen)
{
$key = array_search($listen, $systemEvents['listen'][$event]);
if ($key !== false)
unset($listen, $systemEvents['listen'][$event][$key]);
}
}
}
// for subscribe
if (isset($moduleEvents['subscribe']))
{
$key = array_search($moduleEvents['subscribe'], $systemEvents['subscribe'][$event]);
if($key !==false)
unset($systemEvents['subscribe'][$key]);
}
return $this->set($systemEvents);
}
return true;
}
|
[
"public",
"function",
"remove",
"(",
")",
"{",
"if",
"(",
"$",
"moduleEvents",
"=",
"$",
"this",
"->",
"module",
"->",
"events",
"(",
")",
")",
"{",
"$",
"systemEvents",
"=",
"$",
"this",
"->",
"load",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"moduleEvents",
"[",
"'listen'",
"]",
")",
")",
"// for listen event we must check if exists merge if not add it",
"foreach",
"(",
"$",
"moduleEvents",
"[",
"'listen'",
"]",
"as",
"$",
"event",
"=>",
"$",
"listens",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"systemEvents",
"[",
"'listen'",
"]",
"[",
"$",
"event",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"listens",
"as",
"$",
"listen",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"listen",
",",
"$",
"systemEvents",
"[",
"'listen'",
"]",
"[",
"$",
"event",
"]",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"unset",
"(",
"$",
"listen",
",",
"$",
"systemEvents",
"[",
"'listen'",
"]",
"[",
"$",
"event",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"// for subscribe",
"if",
"(",
"isset",
"(",
"$",
"moduleEvents",
"[",
"'subscribe'",
"]",
")",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"moduleEvents",
"[",
"'subscribe'",
"]",
",",
"$",
"systemEvents",
"[",
"'subscribe'",
"]",
"[",
"$",
"event",
"]",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"unset",
"(",
"$",
"systemEvents",
"[",
"'subscribe'",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"systemEvents",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
remove events from system
|
[
"remove",
"events",
"from",
"system"
] |
0978b5305c3d6f13ef7e0e5297855bd09eee6b76
|
https://github.com/cobonto/module/blob/0978b5305c3d6f13ef7e0e5297855bd09eee6b76/src/Classes/Actions/Event.php#L33-L62
|
236,112
|
zepi/turbo-base
|
Zepi/Web/AccessControl/src/EventHandler/GenerateNewPassword.php
|
GenerateNewPassword.execute
|
public function execute(Framework $framework, WebRequest $request, Response $response)
{
// Set the title for the page
$this->setTitle($this->translate('Generate a new password', '\\Zepi\\Web\\AccessControl'));
// Generate a new password
$result = $this->generateNewPassword($framework, $request, $response);
// Display the successful saved message
$response->setOutput($this->render('\\Zepi\\Web\\AccessControl\\Templates\\GenerateNewPasswordFinished', array(
'title' => $this->getTitle(),
'result' => $result['result'],
'message' => $result['message']
)));
}
|
php
|
public function execute(Framework $framework, WebRequest $request, Response $response)
{
// Set the title for the page
$this->setTitle($this->translate('Generate a new password', '\\Zepi\\Web\\AccessControl'));
// Generate a new password
$result = $this->generateNewPassword($framework, $request, $response);
// Display the successful saved message
$response->setOutput($this->render('\\Zepi\\Web\\AccessControl\\Templates\\GenerateNewPasswordFinished', array(
'title' => $this->getTitle(),
'result' => $result['result'],
'message' => $result['message']
)));
}
|
[
"public",
"function",
"execute",
"(",
"Framework",
"$",
"framework",
",",
"WebRequest",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"// Set the title for the page",
"$",
"this",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"translate",
"(",
"'Generate a new password'",
",",
"'\\\\Zepi\\\\Web\\\\AccessControl'",
")",
")",
";",
"// Generate a new password",
"$",
"result",
"=",
"$",
"this",
"->",
"generateNewPassword",
"(",
"$",
"framework",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"// Display the successful saved message",
"$",
"response",
"->",
"setOutput",
"(",
"$",
"this",
"->",
"render",
"(",
"'\\\\Zepi\\\\Web\\\\AccessControl\\\\Templates\\\\GenerateNewPasswordFinished'",
",",
"array",
"(",
"'title'",
"=>",
"$",
"this",
"->",
"getTitle",
"(",
")",
",",
"'result'",
"=>",
"$",
"result",
"[",
"'result'",
"]",
",",
"'message'",
"=>",
"$",
"result",
"[",
"'message'",
"]",
")",
")",
")",
";",
"}"
] |
Handles the whole registration process
@access public
@param \Zepi\Turbo\Framework $framework
@param \Zepi\Turbo\Request\WebRequest $request
@param \Zepi\Turbo\Response\Response $response
|
[
"Handles",
"the",
"whole",
"registration",
"process"
] |
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
|
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/AccessControl/src/EventHandler/GenerateNewPassword.php#L66-L80
|
236,113
|
zepi/turbo-base
|
Zepi/Web/AccessControl/src/EventHandler/GenerateNewPassword.php
|
GenerateNewPassword.generateRandomPassword
|
protected function generateRandomPassword()
{
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+*=-_/()!?[]{}';
$password = array();
$alphabetLength = strlen($alphabet) - 1;
for ($i = 0; $i < 10; $i++) {
$charIndex = mt_rand(0, $alphabetLength);
$password[] = $alphabet[$charIndex];
}
$password = implode('', $password);
if (!preg_match('/\d/', $password)) {
$password = mt_rand(0, 9) . $password . mt_rand(0, 9);
}
return $password;
}
|
php
|
protected function generateRandomPassword()
{
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+*=-_/()!?[]{}';
$password = array();
$alphabetLength = strlen($alphabet) - 1;
for ($i = 0; $i < 10; $i++) {
$charIndex = mt_rand(0, $alphabetLength);
$password[] = $alphabet[$charIndex];
}
$password = implode('', $password);
if (!preg_match('/\d/', $password)) {
$password = mt_rand(0, 9) . $password . mt_rand(0, 9);
}
return $password;
}
|
[
"protected",
"function",
"generateRandomPassword",
"(",
")",
"{",
"$",
"alphabet",
"=",
"'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+*=-_/()!?[]{}'",
";",
"$",
"password",
"=",
"array",
"(",
")",
";",
"$",
"alphabetLength",
"=",
"strlen",
"(",
"$",
"alphabet",
")",
"-",
"1",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"10",
";",
"$",
"i",
"++",
")",
"{",
"$",
"charIndex",
"=",
"mt_rand",
"(",
"0",
",",
"$",
"alphabetLength",
")",
";",
"$",
"password",
"[",
"]",
"=",
"$",
"alphabet",
"[",
"$",
"charIndex",
"]",
";",
"}",
"$",
"password",
"=",
"implode",
"(",
"''",
",",
"$",
"password",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/\\d/'",
",",
"$",
"password",
")",
")",
"{",
"$",
"password",
"=",
"mt_rand",
"(",
"0",
",",
"9",
")",
".",
"$",
"password",
".",
"mt_rand",
"(",
"0",
",",
"9",
")",
";",
"}",
"return",
"$",
"password",
";",
"}"
] |
Generates a new random password
@access protected
@return string
|
[
"Generates",
"a",
"new",
"random",
"password"
] |
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
|
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/AccessControl/src/EventHandler/GenerateNewPassword.php#L155-L173
|
236,114
|
ilya-dev/block
|
src/Block/Block.php
|
Block.setObject
|
public function setObject($object)
{
if ( ! is_object($object))
{
throw new InvalidArgumentException(
'Expected an object, but got '.gettype($object)
);
}
$this->object = new ReflectionClass($object);
}
|
php
|
public function setObject($object)
{
if ( ! is_object($object))
{
throw new InvalidArgumentException(
'Expected an object, but got '.gettype($object)
);
}
$this->object = new ReflectionClass($object);
}
|
[
"public",
"function",
"setObject",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Expected an object, but got '",
".",
"gettype",
"(",
"$",
"object",
")",
")",
";",
"}",
"$",
"this",
"->",
"object",
"=",
"new",
"ReflectionClass",
"(",
"$",
"object",
")",
";",
"}"
] |
Set the object you want to work with.
@throws InvalidArgumentException
@param mixed $object
@return void
|
[
"Set",
"the",
"object",
"you",
"want",
"to",
"work",
"with",
"."
] |
46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8
|
https://github.com/ilya-dev/block/blob/46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8/src/Block/Block.php#L46-L56
|
236,115
|
ilya-dev/block
|
src/Block/Block.php
|
Block.property
|
public function property($name)
{
if ( ! $this->object->hasProperty($name))
{
throw new UnexpectedValueException(
"Property {$name} does not exist"
);
}
return $this->extractComment($this->object->getProperty($name));
}
|
php
|
public function property($name)
{
if ( ! $this->object->hasProperty($name))
{
throw new UnexpectedValueException(
"Property {$name} does not exist"
);
}
return $this->extractComment($this->object->getProperty($name));
}
|
[
"public",
"function",
"property",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"object",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"\"Property {$name} does not exist\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"extractComment",
"(",
"$",
"this",
"->",
"object",
"->",
"getProperty",
"(",
"$",
"name",
")",
")",
";",
"}"
] |
Fetch a property comment.
@throws UnexpectedValueException
@param string $name
@return Comment
|
[
"Fetch",
"a",
"property",
"comment",
"."
] |
46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8
|
https://github.com/ilya-dev/block/blob/46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8/src/Block/Block.php#L75-L85
|
236,116
|
ilya-dev/block
|
src/Block/Block.php
|
Block.properties
|
public function properties($filter = null)
{
if (is_null($filter))
{
$properties = $this->object->getProperties();
}
else
{
$properties = $this->object->getProperties($filter);
}
return array_map([$this, 'extractComment'], $properties);
}
|
php
|
public function properties($filter = null)
{
if (is_null($filter))
{
$properties = $this->object->getProperties();
}
else
{
$properties = $this->object->getProperties($filter);
}
return array_map([$this, 'extractComment'], $properties);
}
|
[
"public",
"function",
"properties",
"(",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"object",
"->",
"getProperties",
"(",
")",
";",
"}",
"else",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"object",
"->",
"getProperties",
"(",
"$",
"filter",
")",
";",
"}",
"return",
"array_map",
"(",
"[",
"$",
"this",
",",
"'extractComment'",
"]",
",",
"$",
"properties",
")",
";",
"}"
] |
Get the comments for all properties.
@param integer|null $filter
@return array
|
[
"Get",
"the",
"comments",
"for",
"all",
"properties",
"."
] |
46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8
|
https://github.com/ilya-dev/block/blob/46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8/src/Block/Block.php#L93-L105
|
236,117
|
ilya-dev/block
|
src/Block/Block.php
|
Block.method
|
public function method($name)
{
if ( ! $this->object->hasMethod($name))
{
throw new UnexpectedValueException(
"Method {$name} does not exist"
);
}
return $this->extractComment($this->object->getMethod($name));
}
|
php
|
public function method($name)
{
if ( ! $this->object->hasMethod($name))
{
throw new UnexpectedValueException(
"Method {$name} does not exist"
);
}
return $this->extractComment($this->object->getMethod($name));
}
|
[
"public",
"function",
"method",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"object",
"->",
"hasMethod",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"\"Method {$name} does not exist\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"extractComment",
"(",
"$",
"this",
"->",
"object",
"->",
"getMethod",
"(",
"$",
"name",
")",
")",
";",
"}"
] |
Get the method comment.
@throws UnexpectedValueException
@param string $name
@return Comment
|
[
"Get",
"the",
"method",
"comment",
"."
] |
46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8
|
https://github.com/ilya-dev/block/blob/46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8/src/Block/Block.php#L114-L124
|
236,118
|
ilya-dev/block
|
src/Block/Block.php
|
Block.methods
|
public function methods($filter = null)
{
if (is_null($filter))
{
$methods = $this->object->getMethods();
}
else
{
$methods = $this->object->getMethods($filter);
}
return array_map([$this, 'extractComment'], $methods);
}
|
php
|
public function methods($filter = null)
{
if (is_null($filter))
{
$methods = $this->object->getMethods();
}
else
{
$methods = $this->object->getMethods($filter);
}
return array_map([$this, 'extractComment'], $methods);
}
|
[
"public",
"function",
"methods",
"(",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"methods",
"=",
"$",
"this",
"->",
"object",
"->",
"getMethods",
"(",
")",
";",
"}",
"else",
"{",
"$",
"methods",
"=",
"$",
"this",
"->",
"object",
"->",
"getMethods",
"(",
"$",
"filter",
")",
";",
"}",
"return",
"array_map",
"(",
"[",
"$",
"this",
",",
"'extractComment'",
"]",
",",
"$",
"methods",
")",
";",
"}"
] |
Get the comments for all methods.
@param integer|null $filter
@return array
|
[
"Get",
"the",
"comments",
"for",
"all",
"methods",
"."
] |
46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8
|
https://github.com/ilya-dev/block/blob/46aeff9abd1e61a4247e1cf3aed3f8c7561e2bd8/src/Block/Block.php#L132-L144
|
236,119
|
flowcode/AmulenNewsBundle
|
src/Flowcode/NewsBundle/Controller/AdminCategoryController.php
|
AdminCategoryController.indexAction
|
public function indexAction() {
$em = $this->getDoctrine()->getManager();
$rootName = $this->container->getParameter('flowcode_news.root_category');
$root = $em->getRepository('AmulenClassificationBundle:Category')->findOneBy(array("name" => $rootName));
$entities = $em->getRepository('AmulenClassificationBundle:Category')->getChildren($root);
return array(
'entities' => $entities,
'rootcategory' => $root,
);
}
|
php
|
public function indexAction() {
$em = $this->getDoctrine()->getManager();
$rootName = $this->container->getParameter('flowcode_news.root_category');
$root = $em->getRepository('AmulenClassificationBundle:Category')->findOneBy(array("name" => $rootName));
$entities = $em->getRepository('AmulenClassificationBundle:Category')->getChildren($root);
return array(
'entities' => $entities,
'rootcategory' => $root,
);
}
|
[
"public",
"function",
"indexAction",
"(",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"rootName",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'flowcode_news.root_category'",
")",
";",
"$",
"root",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'AmulenClassificationBundle:Category'",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"\"name\"",
"=>",
"$",
"rootName",
")",
")",
";",
"$",
"entities",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'AmulenClassificationBundle:Category'",
")",
"->",
"getChildren",
"(",
"$",
"root",
")",
";",
"return",
"array",
"(",
"'entities'",
"=>",
"$",
"entities",
",",
"'rootcategory'",
"=>",
"$",
"root",
",",
")",
";",
"}"
] |
Lists all Category entities.
@Route("/", name="admin_news_category")
@Method("GET")
@Template()
|
[
"Lists",
"all",
"Category",
"entities",
"."
] |
e870d2f09b629affeddf9a53ed43205300b66933
|
https://github.com/flowcode/AmulenNewsBundle/blob/e870d2f09b629affeddf9a53ed43205300b66933/src/Flowcode/NewsBundle/Controller/AdminCategoryController.php#L27-L37
|
236,120
|
flowcode/AmulenNewsBundle
|
src/Flowcode/NewsBundle/Controller/AdminCategoryController.php
|
AdminCategoryController.childrensAction
|
public function childrensAction($id) {
$em = $this->getDoctrine()->getManager();
$parent = $em->getRepository('AmulenClassificationBundle:Category')->findOneBy(array("id" => $id));
$childrens = $em->getRepository('AmulenClassificationBundle:Category')->getChildren($parent, true);
return array(
'entities' => $childrens,
'parent' => $parent,
);
}
|
php
|
public function childrensAction($id) {
$em = $this->getDoctrine()->getManager();
$parent = $em->getRepository('AmulenClassificationBundle:Category')->findOneBy(array("id" => $id));
$childrens = $em->getRepository('AmulenClassificationBundle:Category')->getChildren($parent, true);
return array(
'entities' => $childrens,
'parent' => $parent,
);
}
|
[
"public",
"function",
"childrensAction",
"(",
"$",
"id",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'AmulenClassificationBundle:Category'",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"\"id\"",
"=>",
"$",
"id",
")",
")",
";",
"$",
"childrens",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'AmulenClassificationBundle:Category'",
")",
"->",
"getChildren",
"(",
"$",
"parent",
",",
"true",
")",
";",
"return",
"array",
"(",
"'entities'",
"=>",
"$",
"childrens",
",",
"'parent'",
"=>",
"$",
"parent",
",",
")",
";",
"}"
] |
Select parent.
@Route("/childrens/{id}", name="admin_news_category_children")
@Method("GET")
@Template()
|
[
"Select",
"parent",
"."
] |
e870d2f09b629affeddf9a53ed43205300b66933
|
https://github.com/flowcode/AmulenNewsBundle/blob/e870d2f09b629affeddf9a53ed43205300b66933/src/Flowcode/NewsBundle/Controller/AdminCategoryController.php#L113-L123
|
236,121
|
flowcode/AmulenNewsBundle
|
src/Flowcode/NewsBundle/Controller/AdminCategoryController.php
|
AdminCategoryController.createDeleteForm
|
private function createDeleteForm($id) {
return $this->createFormBuilder()
->setAction($this->generateUrl('admin_news_category_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete',
'attr' => array(
'onclick' => 'return confirm("Estás seguro?")'
)))
->getForm()
;
}
|
php
|
private function createDeleteForm($id) {
return $this->createFormBuilder()
->setAction($this->generateUrl('admin_news_category_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete',
'attr' => array(
'onclick' => 'return confirm("Estás seguro?")'
)))
->getForm()
;
}
|
[
"private",
"function",
"createDeleteForm",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"createFormBuilder",
"(",
")",
"->",
"setAction",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'admin_news_category_delete'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
")",
"->",
"setMethod",
"(",
"'DELETE'",
")",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'Delete'",
",",
"'attr'",
"=>",
"array",
"(",
"'onclick'",
"=>",
"'return confirm(\"Estás seguro?\")'",
")",
")",
")",
"->",
"getForm",
"(",
")",
";",
"}"
] |
Creates a form to delete a Category entity by id.
@param mixed $id The entity id
@return Form The form
|
[
"Creates",
"a",
"form",
"to",
"delete",
"a",
"Category",
"entity",
"by",
"id",
"."
] |
e870d2f09b629affeddf9a53ed43205300b66933
|
https://github.com/flowcode/AmulenNewsBundle/blob/e870d2f09b629affeddf9a53ed43205300b66933/src/Flowcode/NewsBundle/Controller/AdminCategoryController.php#L258-L268
|
236,122
|
bereczkybalazs/brick-core
|
src/RouteDispatcher.php
|
RouteDispatcher.parseFilters
|
protected function parseFilters($filters)
{
$beforeFilter = array();
$afterFilter = array();
if (isset($filters[Route::BEFORE])) {
$beforeFilter = array_intersect_key($this->filters, array_flip((array)$filters[Route::BEFORE]));
}
if (isset($filters[Route::AFTER])) {
$afterFilter = array_intersect_key($this->filters, array_flip((array)$filters[Route::AFTER]));
}
return array($beforeFilter, $afterFilter);
}
|
php
|
protected function parseFilters($filters)
{
$beforeFilter = array();
$afterFilter = array();
if (isset($filters[Route::BEFORE])) {
$beforeFilter = array_intersect_key($this->filters, array_flip((array)$filters[Route::BEFORE]));
}
if (isset($filters[Route::AFTER])) {
$afterFilter = array_intersect_key($this->filters, array_flip((array)$filters[Route::AFTER]));
}
return array($beforeFilter, $afterFilter);
}
|
[
"protected",
"function",
"parseFilters",
"(",
"$",
"filters",
")",
"{",
"$",
"beforeFilter",
"=",
"array",
"(",
")",
";",
"$",
"afterFilter",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"filters",
"[",
"Route",
"::",
"BEFORE",
"]",
")",
")",
"{",
"$",
"beforeFilter",
"=",
"array_intersect_key",
"(",
"$",
"this",
"->",
"filters",
",",
"array_flip",
"(",
"(",
"array",
")",
"$",
"filters",
"[",
"Route",
"::",
"BEFORE",
"]",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"filters",
"[",
"Route",
"::",
"AFTER",
"]",
")",
")",
"{",
"$",
"afterFilter",
"=",
"array_intersect_key",
"(",
"$",
"this",
"->",
"filters",
",",
"array_flip",
"(",
"(",
"array",
")",
"$",
"filters",
"[",
"Route",
"::",
"AFTER",
"]",
")",
")",
";",
"}",
"return",
"array",
"(",
"$",
"beforeFilter",
",",
"$",
"afterFilter",
")",
";",
"}"
] |
Normalise the array filters attached to the route and merge with any global filters.
@param $filters
@return array
|
[
"Normalise",
"the",
"array",
"filters",
"attached",
"to",
"the",
"route",
"and",
"merge",
"with",
"any",
"global",
"filters",
"."
] |
6528c127d6aa2e506813891c6147fb341ed80e7c
|
https://github.com/bereczkybalazs/brick-core/blob/6528c127d6aa2e506813891c6147fb341ed80e7c/src/RouteDispatcher.php#L148-L162
|
236,123
|
bereczkybalazs/brick-core
|
src/RouteDispatcher.php
|
RouteDispatcher.dispatchRoute
|
protected function dispatchRoute($httpMethod, $uri)
{
if (isset($this->staticRouteMap[$uri])) {
return $this->dispatchStaticRoute($httpMethod, $uri);
}
return $this->dispatchVariableRoute($httpMethod, $uri);
}
|
php
|
protected function dispatchRoute($httpMethod, $uri)
{
if (isset($this->staticRouteMap[$uri])) {
return $this->dispatchStaticRoute($httpMethod, $uri);
}
return $this->dispatchVariableRoute($httpMethod, $uri);
}
|
[
"protected",
"function",
"dispatchRoute",
"(",
"$",
"httpMethod",
",",
"$",
"uri",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"staticRouteMap",
"[",
"$",
"uri",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"dispatchStaticRoute",
"(",
"$",
"httpMethod",
",",
"$",
"uri",
")",
";",
"}",
"return",
"$",
"this",
"->",
"dispatchVariableRoute",
"(",
"$",
"httpMethod",
",",
"$",
"uri",
")",
";",
"}"
] |
Perform the route dispatching. Check static routes first followed by variable routes.
@param $httpMethod
@param $uri
@throws HttpRouteNotFoundException
|
[
"Perform",
"the",
"route",
"dispatching",
".",
"Check",
"static",
"routes",
"first",
"followed",
"by",
"variable",
"routes",
"."
] |
6528c127d6aa2e506813891c6147fb341ed80e7c
|
https://github.com/bereczkybalazs/brick-core/blob/6528c127d6aa2e506813891c6147fb341ed80e7c/src/RouteDispatcher.php#L171-L178
|
236,124
|
bereczkybalazs/brick-core
|
src/RouteDispatcher.php
|
RouteDispatcher.dispatchStaticRoute
|
protected function dispatchStaticRoute($httpMethod, $uri)
{
$routes = $this->staticRouteMap[$uri];
if (!isset($routes[$httpMethod])) {
$httpMethod = $this->checkFallbacks($routes, $httpMethod);
}
return $routes[$httpMethod];
}
|
php
|
protected function dispatchStaticRoute($httpMethod, $uri)
{
$routes = $this->staticRouteMap[$uri];
if (!isset($routes[$httpMethod])) {
$httpMethod = $this->checkFallbacks($routes, $httpMethod);
}
return $routes[$httpMethod];
}
|
[
"protected",
"function",
"dispatchStaticRoute",
"(",
"$",
"httpMethod",
",",
"$",
"uri",
")",
"{",
"$",
"routes",
"=",
"$",
"this",
"->",
"staticRouteMap",
"[",
"$",
"uri",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"routes",
"[",
"$",
"httpMethod",
"]",
")",
")",
"{",
"$",
"httpMethod",
"=",
"$",
"this",
"->",
"checkFallbacks",
"(",
"$",
"routes",
",",
"$",
"httpMethod",
")",
";",
"}",
"return",
"$",
"routes",
"[",
"$",
"httpMethod",
"]",
";",
"}"
] |
Handle the dispatching of static routes.
@param $httpMethod
@param $uri
@return mixed
@throws HttpMethodNotAllowedException
|
[
"Handle",
"the",
"dispatching",
"of",
"static",
"routes",
"."
] |
6528c127d6aa2e506813891c6147fb341ed80e7c
|
https://github.com/bereczkybalazs/brick-core/blob/6528c127d6aa2e506813891c6147fb341ed80e7c/src/RouteDispatcher.php#L188-L197
|
236,125
|
bereczkybalazs/brick-core
|
src/RouteDispatcher.php
|
RouteDispatcher.dispatchVariableRoute
|
protected function dispatchVariableRoute($httpMethod, $uri)
{
foreach ($this->variableRouteData as $data) {
if (!preg_match($data['regex'], $uri, $matches)) {
continue;
}
$count = count($matches);
while (!isset($data['routeMap'][$count++])) {
;
}
$routes = $data['routeMap'][$count - 1];
if (!isset($routes[$httpMethod])) {
$httpMethod = $this->checkFallbacks($routes, $httpMethod);
}
foreach (array_values($routes[$httpMethod][2]) as $i => $varName) {
if (!isset($matches[$i + 1]) || $matches[$i + 1] === '') {
unset($routes[$httpMethod][2][$varName]);
} else {
$routes[$httpMethod][2][$varName] = $matches[$i + 1];
}
}
return $routes[$httpMethod];
}
throw new HttpRouteNotFoundException('Route ' . $uri . ' does not exist');
}
|
php
|
protected function dispatchVariableRoute($httpMethod, $uri)
{
foreach ($this->variableRouteData as $data) {
if (!preg_match($data['regex'], $uri, $matches)) {
continue;
}
$count = count($matches);
while (!isset($data['routeMap'][$count++])) {
;
}
$routes = $data['routeMap'][$count - 1];
if (!isset($routes[$httpMethod])) {
$httpMethod = $this->checkFallbacks($routes, $httpMethod);
}
foreach (array_values($routes[$httpMethod][2]) as $i => $varName) {
if (!isset($matches[$i + 1]) || $matches[$i + 1] === '') {
unset($routes[$httpMethod][2][$varName]);
} else {
$routes[$httpMethod][2][$varName] = $matches[$i + 1];
}
}
return $routes[$httpMethod];
}
throw new HttpRouteNotFoundException('Route ' . $uri . ' does not exist');
}
|
[
"protected",
"function",
"dispatchVariableRoute",
"(",
"$",
"httpMethod",
",",
"$",
"uri",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"variableRouteData",
"as",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"data",
"[",
"'regex'",
"]",
",",
"$",
"uri",
",",
"$",
"matches",
")",
")",
"{",
"continue",
";",
"}",
"$",
"count",
"=",
"count",
"(",
"$",
"matches",
")",
";",
"while",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'routeMap'",
"]",
"[",
"$",
"count",
"++",
"]",
")",
")",
"{",
";",
"}",
"$",
"routes",
"=",
"$",
"data",
"[",
"'routeMap'",
"]",
"[",
"$",
"count",
"-",
"1",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"routes",
"[",
"$",
"httpMethod",
"]",
")",
")",
"{",
"$",
"httpMethod",
"=",
"$",
"this",
"->",
"checkFallbacks",
"(",
"$",
"routes",
",",
"$",
"httpMethod",
")",
";",
"}",
"foreach",
"(",
"array_values",
"(",
"$",
"routes",
"[",
"$",
"httpMethod",
"]",
"[",
"2",
"]",
")",
"as",
"$",
"i",
"=>",
"$",
"varName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"matches",
"[",
"$",
"i",
"+",
"1",
"]",
")",
"||",
"$",
"matches",
"[",
"$",
"i",
"+",
"1",
"]",
"===",
"''",
")",
"{",
"unset",
"(",
"$",
"routes",
"[",
"$",
"httpMethod",
"]",
"[",
"2",
"]",
"[",
"$",
"varName",
"]",
")",
";",
"}",
"else",
"{",
"$",
"routes",
"[",
"$",
"httpMethod",
"]",
"[",
"2",
"]",
"[",
"$",
"varName",
"]",
"=",
"$",
"matches",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"}",
"}",
"return",
"$",
"routes",
"[",
"$",
"httpMethod",
"]",
";",
"}",
"throw",
"new",
"HttpRouteNotFoundException",
"(",
"'Route '",
".",
"$",
"uri",
".",
"' does not exist'",
")",
";",
"}"
] |
Handle the dispatching of variable routes.
@param $httpMethod
@param $uri
@throws HttpMethodNotAllowedException
@throws HttpRouteNotFoundException
|
[
"Handle",
"the",
"dispatching",
"of",
"variable",
"routes",
"."
] |
6528c127d6aa2e506813891c6147fb341ed80e7c
|
https://github.com/bereczkybalazs/brick-core/blob/6528c127d6aa2e506813891c6147fb341ed80e7c/src/RouteDispatcher.php#L233-L264
|
236,126
|
CampusUnion/Sked
|
src/Database/SkeModelPDO.php
|
SkeModelPDO.find
|
public function find(int $iId)
{
$oSelect = $this->oConnector->prepare('SELECT * FROM sked_events WHERE id = :id');
if (!$oSelect->execute([':id' => $iId]))
throw new \Exception(__METHOD__ . ' - ' . $oSelect->errorInfo()[2]);
return $oSelect->fetch(\PDO::FETCH_ASSOC);
}
|
php
|
public function find(int $iId)
{
$oSelect = $this->oConnector->prepare('SELECT * FROM sked_events WHERE id = :id');
if (!$oSelect->execute([':id' => $iId]))
throw new \Exception(__METHOD__ . ' - ' . $oSelect->errorInfo()[2]);
return $oSelect->fetch(\PDO::FETCH_ASSOC);
}
|
[
"public",
"function",
"find",
"(",
"int",
"$",
"iId",
")",
"{",
"$",
"oSelect",
"=",
"$",
"this",
"->",
"oConnector",
"->",
"prepare",
"(",
"'SELECT * FROM sked_events WHERE id = :id'",
")",
";",
"if",
"(",
"!",
"$",
"oSelect",
"->",
"execute",
"(",
"[",
"':id'",
"=>",
"$",
"iId",
"]",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"__METHOD__",
".",
"' - '",
".",
"$",
"oSelect",
"->",
"errorInfo",
"(",
")",
"[",
"2",
"]",
")",
";",
"return",
"$",
"oSelect",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] |
Retrieve an event from the database.
@param int $iId
@return array
|
[
"Retrieve",
"an",
"event",
"from",
"the",
"database",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/Database/SkeModelPDO.php#L46-L52
|
236,127
|
CampusUnion/Sked
|
src/Database/SkeModelPDO.php
|
SkeModelPDO.queryDay
|
protected function queryDay(string $strDateStart, string $strDateEnd)
{
$strQuery = $this->querySelectFrom($strDateStart)
. $this->queryJoin()
. $this->queryWhereNotExpired();
// Happening today
$strQuery .= ' AND (';
// Original date matches
$strQuery .= ' sked_events.starts_at BETWEEN :date_start AND :date_end';
// Or it's already started and...
$strQuery .= ' OR (sked_events.starts_at <= :date_start AND (';
// Daily
$strQuery .= ' (
sked_events.interval = "1"
AND (
DATEDIFF(
:date_start_NOTIME,
DATE_FORMAT(sked_events.starts_at, "%Y-%m-%d")
)/sked_events.frequency
) % 1 =0
)';
// Day of week matches for weekly events
$strQuery .= ' OR (
sked_events.interval = "7"
AND sked_events.' . date('D', strtotime($strDateStart)) . ' = 1
AND (
DATEDIFF(
:date_start_NOTIME,
DATE_FORMAT(sked_events.starts_at, "%Y-%m-%d")
)/7
) % sked_events.frequency = 0
)';
// Monthly by day of week
// Calculate how many months since first session, see if it's an exact match for today
$strQuery .= ' OR (
sked_events.interval = "Monthly"
AND sked_events.' . date('D', strtotime($strDateStart)) . ' = 1
AND TIMESTAMPADD(
MONTH,
ROUND(DATEDIFF(:date_start, DATE_FORMAT(sked_events.starts_at, "%Y-%m-%d"))/30),
sked_events.starts_at
) BETWEEN :date_start AND :date_end
)';
// Monthly by date
$strQuery .= ' OR (
sked_events.interval = "Monthly"
AND sked_events.Mon = 0
AND sked_events.Tue = 0
AND sked_events.Wed = 0
AND sked_events.Thu = 0
AND sked_events.Fri = 0
AND sked_events.Sat = 0
AND sked_events.Sun = 0
AND DAYOFMONTH(sked_events.starts_at) = :date_start_DAYOFMONTH
AND (:date_start_YEARMONTH - EXTRACT(YEAR_MONTH FROM sked_events.starts_at))
% sked_events.frequency = 0
)';
$strQuery .= '))';
$strQuery .= ')' . $this->queryGroupAndOrder();
// PDO
return $this->queryPDO($strQuery, $this->aQueryParams + [
':date_start' => $strDateStart,
':date_start_NOTIME' => date('Y-m-d', strtotime($strDateStart)),
':date_start_DAYOFMONTH' => date('d', strtotime($strDateStart)),
':date_start_YEARMONTH' => date('Ym', strtotime($strDateStart)),
':date_end' => $strDateEnd,
]);
}
|
php
|
protected function queryDay(string $strDateStart, string $strDateEnd)
{
$strQuery = $this->querySelectFrom($strDateStart)
. $this->queryJoin()
. $this->queryWhereNotExpired();
// Happening today
$strQuery .= ' AND (';
// Original date matches
$strQuery .= ' sked_events.starts_at BETWEEN :date_start AND :date_end';
// Or it's already started and...
$strQuery .= ' OR (sked_events.starts_at <= :date_start AND (';
// Daily
$strQuery .= ' (
sked_events.interval = "1"
AND (
DATEDIFF(
:date_start_NOTIME,
DATE_FORMAT(sked_events.starts_at, "%Y-%m-%d")
)/sked_events.frequency
) % 1 =0
)';
// Day of week matches for weekly events
$strQuery .= ' OR (
sked_events.interval = "7"
AND sked_events.' . date('D', strtotime($strDateStart)) . ' = 1
AND (
DATEDIFF(
:date_start_NOTIME,
DATE_FORMAT(sked_events.starts_at, "%Y-%m-%d")
)/7
) % sked_events.frequency = 0
)';
// Monthly by day of week
// Calculate how many months since first session, see if it's an exact match for today
$strQuery .= ' OR (
sked_events.interval = "Monthly"
AND sked_events.' . date('D', strtotime($strDateStart)) . ' = 1
AND TIMESTAMPADD(
MONTH,
ROUND(DATEDIFF(:date_start, DATE_FORMAT(sked_events.starts_at, "%Y-%m-%d"))/30),
sked_events.starts_at
) BETWEEN :date_start AND :date_end
)';
// Monthly by date
$strQuery .= ' OR (
sked_events.interval = "Monthly"
AND sked_events.Mon = 0
AND sked_events.Tue = 0
AND sked_events.Wed = 0
AND sked_events.Thu = 0
AND sked_events.Fri = 0
AND sked_events.Sat = 0
AND sked_events.Sun = 0
AND DAYOFMONTH(sked_events.starts_at) = :date_start_DAYOFMONTH
AND (:date_start_YEARMONTH - EXTRACT(YEAR_MONTH FROM sked_events.starts_at))
% sked_events.frequency = 0
)';
$strQuery .= '))';
$strQuery .= ')' . $this->queryGroupAndOrder();
// PDO
return $this->queryPDO($strQuery, $this->aQueryParams + [
':date_start' => $strDateStart,
':date_start_NOTIME' => date('Y-m-d', strtotime($strDateStart)),
':date_start_DAYOFMONTH' => date('d', strtotime($strDateStart)),
':date_start_YEARMONTH' => date('Ym', strtotime($strDateStart)),
':date_end' => $strDateEnd,
]);
}
|
[
"protected",
"function",
"queryDay",
"(",
"string",
"$",
"strDateStart",
",",
"string",
"$",
"strDateEnd",
")",
"{",
"$",
"strQuery",
"=",
"$",
"this",
"->",
"querySelectFrom",
"(",
"$",
"strDateStart",
")",
".",
"$",
"this",
"->",
"queryJoin",
"(",
")",
".",
"$",
"this",
"->",
"queryWhereNotExpired",
"(",
")",
";",
"// Happening today",
"$",
"strQuery",
".=",
"' AND ('",
";",
"// Original date matches",
"$",
"strQuery",
".=",
"' sked_events.starts_at BETWEEN :date_start AND :date_end'",
";",
"// Or it's already started and...",
"$",
"strQuery",
".=",
"' OR (sked_events.starts_at <= :date_start AND ('",
";",
"// Daily",
"$",
"strQuery",
".=",
"' (\n sked_events.interval = \"1\"\n AND (\n DATEDIFF(\n :date_start_NOTIME,\n DATE_FORMAT(sked_events.starts_at, \"%Y-%m-%d\")\n )/sked_events.frequency\n ) % 1 =0\n )'",
";",
"// Day of week matches for weekly events",
"$",
"strQuery",
".=",
"' OR (\n sked_events.interval = \"7\"\n AND sked_events.'",
".",
"date",
"(",
"'D'",
",",
"strtotime",
"(",
"$",
"strDateStart",
")",
")",
".",
"' = 1\n AND (\n DATEDIFF(\n :date_start_NOTIME,\n DATE_FORMAT(sked_events.starts_at, \"%Y-%m-%d\")\n )/7\n ) % sked_events.frequency = 0\n )'",
";",
"// Monthly by day of week",
"// Calculate how many months since first session, see if it's an exact match for today",
"$",
"strQuery",
".=",
"' OR (\n sked_events.interval = \"Monthly\"\n AND sked_events.'",
".",
"date",
"(",
"'D'",
",",
"strtotime",
"(",
"$",
"strDateStart",
")",
")",
".",
"' = 1\n AND TIMESTAMPADD(\n MONTH,\n ROUND(DATEDIFF(:date_start, DATE_FORMAT(sked_events.starts_at, \"%Y-%m-%d\"))/30),\n sked_events.starts_at\n ) BETWEEN :date_start AND :date_end\n )'",
";",
"// Monthly by date",
"$",
"strQuery",
".=",
"' OR (\n sked_events.interval = \"Monthly\"\n AND sked_events.Mon = 0\n AND sked_events.Tue = 0\n AND sked_events.Wed = 0\n AND sked_events.Thu = 0\n AND sked_events.Fri = 0\n AND sked_events.Sat = 0\n AND sked_events.Sun = 0\n AND DAYOFMONTH(sked_events.starts_at) = :date_start_DAYOFMONTH\n AND (:date_start_YEARMONTH - EXTRACT(YEAR_MONTH FROM sked_events.starts_at))\n % sked_events.frequency = 0\n )'",
";",
"$",
"strQuery",
".=",
"'))'",
";",
"$",
"strQuery",
".=",
"')'",
".",
"$",
"this",
"->",
"queryGroupAndOrder",
"(",
")",
";",
"// PDO",
"return",
"$",
"this",
"->",
"queryPDO",
"(",
"$",
"strQuery",
",",
"$",
"this",
"->",
"aQueryParams",
"+",
"[",
"':date_start'",
"=>",
"$",
"strDateStart",
",",
"':date_start_NOTIME'",
"=>",
"date",
"(",
"'Y-m-d'",
",",
"strtotime",
"(",
"$",
"strDateStart",
")",
")",
",",
"':date_start_DAYOFMONTH'",
"=>",
"date",
"(",
"'d'",
",",
"strtotime",
"(",
"$",
"strDateStart",
")",
")",
",",
"':date_start_YEARMONTH'",
"=>",
"date",
"(",
"'Ym'",
",",
"strtotime",
"(",
"$",
"strDateStart",
")",
")",
",",
"':date_end'",
"=>",
"$",
"strDateEnd",
",",
"]",
")",
";",
"}"
] |
Build the events query for today.
@param string $strDateStart Datetime that today starts.
@param string $strDateEnd Datetime that today ends.
@return array
|
[
"Build",
"the",
"events",
"query",
"for",
"today",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/Database/SkeModelPDO.php#L61-L138
|
236,128
|
CampusUnion/Sked
|
src/Database/SkeModelPDO.php
|
SkeModelPDO.queryPDO
|
private function queryPDO(string $strQuery, array $aParams = [])
{
$oStmt = $this->oConnector->prepare($strQuery);
if (!$oStmt->execute($aParams))
throw new \Exception(__METHOD__ . ' - ' . $oStmt->errorInfo()[2]);
list($strMethod) = explode(' ', trim($strQuery));
switch (strtoupper($strMethod)) {
case 'SELECT':
return $oStmt->fetchAll(\PDO::FETCH_ASSOC);
break;
case 'INSERT':
return $this->oConnector->lastInsertId();
break;
case 'UPDATE':
return $aParams[':id_value'];
break;
case 'DELETE':
default:
return true;
break;
}
}
|
php
|
private function queryPDO(string $strQuery, array $aParams = [])
{
$oStmt = $this->oConnector->prepare($strQuery);
if (!$oStmt->execute($aParams))
throw new \Exception(__METHOD__ . ' - ' . $oStmt->errorInfo()[2]);
list($strMethod) = explode(' ', trim($strQuery));
switch (strtoupper($strMethod)) {
case 'SELECT':
return $oStmt->fetchAll(\PDO::FETCH_ASSOC);
break;
case 'INSERT':
return $this->oConnector->lastInsertId();
break;
case 'UPDATE':
return $aParams[':id_value'];
break;
case 'DELETE':
default:
return true;
break;
}
}
|
[
"private",
"function",
"queryPDO",
"(",
"string",
"$",
"strQuery",
",",
"array",
"$",
"aParams",
"=",
"[",
"]",
")",
"{",
"$",
"oStmt",
"=",
"$",
"this",
"->",
"oConnector",
"->",
"prepare",
"(",
"$",
"strQuery",
")",
";",
"if",
"(",
"!",
"$",
"oStmt",
"->",
"execute",
"(",
"$",
"aParams",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"__METHOD__",
".",
"' - '",
".",
"$",
"oStmt",
"->",
"errorInfo",
"(",
")",
"[",
"2",
"]",
")",
";",
"list",
"(",
"$",
"strMethod",
")",
"=",
"explode",
"(",
"' '",
",",
"trim",
"(",
"$",
"strQuery",
")",
")",
";",
"switch",
"(",
"strtoupper",
"(",
"$",
"strMethod",
")",
")",
"{",
"case",
"'SELECT'",
":",
"return",
"$",
"oStmt",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"break",
";",
"case",
"'INSERT'",
":",
"return",
"$",
"this",
"->",
"oConnector",
"->",
"lastInsertId",
"(",
")",
";",
"break",
";",
"case",
"'UPDATE'",
":",
"return",
"$",
"aParams",
"[",
"':id_value'",
"]",
";",
"break",
";",
"case",
"'DELETE'",
":",
"default",
":",
"return",
"true",
";",
"break",
";",
"}",
"}"
] |
Execute the query with PDO and return results.
@param string $strQuery SQL query.
@param array $aParams Array of parameters to bind.
@return array|int|bool
|
[
"Execute",
"the",
"query",
"with",
"PDO",
"and",
"return",
"results",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/Database/SkeModelPDO.php#L310-L336
|
236,129
|
CampusUnion/Sked
|
src/Database/SkeModelPDO.php
|
SkeModelPDO.saveEventMembers
|
protected function saveEventMembers(int $iEventId, array $aMembers)
{
if (!empty($aMembers)) {
$aExecParams[':sked_event_id'] = $iEventId;
$strQuery = 'INSERT IGNORE INTO `sked_event_members`
(`sked_event_id`, `member_id`, `owner`, `lead_time`, `created_at`) VALUES ';
$aValueSets = [];
foreach ($aMembers as $iMemberId => $aSettings) {
$strMemberParam = ':member_id_' . $iMemberId;
$strOwnerParam = ':owner_' . $iMemberId;
$strLeadTimeParam = ':lead_time_' . $iMemberId;
$aValueSets[] = '(:sked_event_id, ' . $strMemberParam . ', '
. $strOwnerParam . ', ' . $strLeadTimeParam . ', NOW())';
$aExecParams[$strMemberParam] = $iMemberId;
$aExecParams[$strOwnerParam] = $aSettings['owner'] ?? 0;
$aExecParams[$strLeadTimeParam] = $aSettings['lead_time'] ?? 0;
}
$strQuery .= implode(',', $aValueSets) . ' ON DUPLICATE KEY UPDATE'
. ' `owner` = VALUES(`owner`), `lead_time` = VALUES(`lead_time`)';
$this->queryPDO($strQuery, $aExecParams);
}
return true;
}
|
php
|
protected function saveEventMembers(int $iEventId, array $aMembers)
{
if (!empty($aMembers)) {
$aExecParams[':sked_event_id'] = $iEventId;
$strQuery = 'INSERT IGNORE INTO `sked_event_members`
(`sked_event_id`, `member_id`, `owner`, `lead_time`, `created_at`) VALUES ';
$aValueSets = [];
foreach ($aMembers as $iMemberId => $aSettings) {
$strMemberParam = ':member_id_' . $iMemberId;
$strOwnerParam = ':owner_' . $iMemberId;
$strLeadTimeParam = ':lead_time_' . $iMemberId;
$aValueSets[] = '(:sked_event_id, ' . $strMemberParam . ', '
. $strOwnerParam . ', ' . $strLeadTimeParam . ', NOW())';
$aExecParams[$strMemberParam] = $iMemberId;
$aExecParams[$strOwnerParam] = $aSettings['owner'] ?? 0;
$aExecParams[$strLeadTimeParam] = $aSettings['lead_time'] ?? 0;
}
$strQuery .= implode(',', $aValueSets) . ' ON DUPLICATE KEY UPDATE'
. ' `owner` = VALUES(`owner`), `lead_time` = VALUES(`lead_time`)';
$this->queryPDO($strQuery, $aExecParams);
}
return true;
}
|
[
"protected",
"function",
"saveEventMembers",
"(",
"int",
"$",
"iEventId",
",",
"array",
"$",
"aMembers",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aMembers",
")",
")",
"{",
"$",
"aExecParams",
"[",
"':sked_event_id'",
"]",
"=",
"$",
"iEventId",
";",
"$",
"strQuery",
"=",
"'INSERT IGNORE INTO `sked_event_members`\n (`sked_event_id`, `member_id`, `owner`, `lead_time`, `created_at`) VALUES '",
";",
"$",
"aValueSets",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aMembers",
"as",
"$",
"iMemberId",
"=>",
"$",
"aSettings",
")",
"{",
"$",
"strMemberParam",
"=",
"':member_id_'",
".",
"$",
"iMemberId",
";",
"$",
"strOwnerParam",
"=",
"':owner_'",
".",
"$",
"iMemberId",
";",
"$",
"strLeadTimeParam",
"=",
"':lead_time_'",
".",
"$",
"iMemberId",
";",
"$",
"aValueSets",
"[",
"]",
"=",
"'(:sked_event_id, '",
".",
"$",
"strMemberParam",
".",
"', '",
".",
"$",
"strOwnerParam",
".",
"', '",
".",
"$",
"strLeadTimeParam",
".",
"', NOW())'",
";",
"$",
"aExecParams",
"[",
"$",
"strMemberParam",
"]",
"=",
"$",
"iMemberId",
";",
"$",
"aExecParams",
"[",
"$",
"strOwnerParam",
"]",
"=",
"$",
"aSettings",
"[",
"'owner'",
"]",
"??",
"0",
";",
"$",
"aExecParams",
"[",
"$",
"strLeadTimeParam",
"]",
"=",
"$",
"aSettings",
"[",
"'lead_time'",
"]",
"??",
"0",
";",
"}",
"$",
"strQuery",
".=",
"implode",
"(",
"','",
",",
"$",
"aValueSets",
")",
".",
"' ON DUPLICATE KEY UPDATE'",
".",
"' `owner` = VALUES(`owner`), `lead_time` = VALUES(`lead_time`)'",
";",
"$",
"this",
"->",
"queryPDO",
"(",
"$",
"strQuery",
",",
"$",
"aExecParams",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Persist event member data to the database.
@param int $iEventId Event that owns the tags.
@param array $aMembers Array of data to persist.
@return bool Success/failure.
|
[
"Persist",
"event",
"member",
"data",
"to",
"the",
"database",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/Database/SkeModelPDO.php#L394-L420
|
236,130
|
CampusUnion/Sked
|
src/Database/SkeModelPDO.php
|
SkeModelPDO.saveEventTags
|
protected function saveEventTags(int $iEventId, array $aTags)
{
// Delete existing tags
$this->queryPDO(
'DELETE FROM `sked_event_tags` WHERE `sked_event_id` = ?',
[$iEventId]
);
// Create new tags
if (!empty($aTags)) {
$aValueSets = [];
$aExecParams[':sked_event_id'] = $iEventId;
$strQuery = 'INSERT INTO `sked_event_tags` (`sked_event_id`, `tag_id`, `value`, `created_at`) VALUES ';
foreach ($aTags as $iTagId => $mTagValue) {
$strTagParam = ':tag_id_' . $iTagId;
$strValueParam = ':value_' . $iTagId;
$aValueSets[] = '(:sked_event_id, ' . $strTagParam . ', ' . $strValueParam . ', NOW())';
$aExecParams[$strTagParam] = $iTagId;
$aExecParams[$strValueParam] = $mTagValue;
}
$strQuery .= implode(',', $aValueSets);
$this->queryPDO($strQuery, $aExecParams);
}
return true;
}
|
php
|
protected function saveEventTags(int $iEventId, array $aTags)
{
// Delete existing tags
$this->queryPDO(
'DELETE FROM `sked_event_tags` WHERE `sked_event_id` = ?',
[$iEventId]
);
// Create new tags
if (!empty($aTags)) {
$aValueSets = [];
$aExecParams[':sked_event_id'] = $iEventId;
$strQuery = 'INSERT INTO `sked_event_tags` (`sked_event_id`, `tag_id`, `value`, `created_at`) VALUES ';
foreach ($aTags as $iTagId => $mTagValue) {
$strTagParam = ':tag_id_' . $iTagId;
$strValueParam = ':value_' . $iTagId;
$aValueSets[] = '(:sked_event_id, ' . $strTagParam . ', ' . $strValueParam . ', NOW())';
$aExecParams[$strTagParam] = $iTagId;
$aExecParams[$strValueParam] = $mTagValue;
}
$strQuery .= implode(',', $aValueSets);
$this->queryPDO($strQuery, $aExecParams);
}
return true;
}
|
[
"protected",
"function",
"saveEventTags",
"(",
"int",
"$",
"iEventId",
",",
"array",
"$",
"aTags",
")",
"{",
"// Delete existing tags",
"$",
"this",
"->",
"queryPDO",
"(",
"'DELETE FROM `sked_event_tags` WHERE `sked_event_id` = ?'",
",",
"[",
"$",
"iEventId",
"]",
")",
";",
"// Create new tags",
"if",
"(",
"!",
"empty",
"(",
"$",
"aTags",
")",
")",
"{",
"$",
"aValueSets",
"=",
"[",
"]",
";",
"$",
"aExecParams",
"[",
"':sked_event_id'",
"]",
"=",
"$",
"iEventId",
";",
"$",
"strQuery",
"=",
"'INSERT INTO `sked_event_tags` (`sked_event_id`, `tag_id`, `value`, `created_at`) VALUES '",
";",
"foreach",
"(",
"$",
"aTags",
"as",
"$",
"iTagId",
"=>",
"$",
"mTagValue",
")",
"{",
"$",
"strTagParam",
"=",
"':tag_id_'",
".",
"$",
"iTagId",
";",
"$",
"strValueParam",
"=",
"':value_'",
".",
"$",
"iTagId",
";",
"$",
"aValueSets",
"[",
"]",
"=",
"'(:sked_event_id, '",
".",
"$",
"strTagParam",
".",
"', '",
".",
"$",
"strValueParam",
".",
"', NOW())'",
";",
"$",
"aExecParams",
"[",
"$",
"strTagParam",
"]",
"=",
"$",
"iTagId",
";",
"$",
"aExecParams",
"[",
"$",
"strValueParam",
"]",
"=",
"$",
"mTagValue",
";",
"}",
"$",
"strQuery",
".=",
"implode",
"(",
"','",
",",
"$",
"aValueSets",
")",
";",
"$",
"this",
"->",
"queryPDO",
"(",
"$",
"strQuery",
",",
"$",
"aExecParams",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Persist event tag data to the database.
@param int $iEventId Event that owns the tags.
@param array $aTags Array of data to persist.
@return bool true On success.
@throws \Exception On failure.
|
[
"Persist",
"event",
"tag",
"data",
"to",
"the",
"database",
"."
] |
5b51afdb56c0f607e54364635c4725627b19ecc6
|
https://github.com/CampusUnion/Sked/blob/5b51afdb56c0f607e54364635c4725627b19ecc6/src/Database/SkeModelPDO.php#L444-L470
|
236,131
|
motamonteiro/helpers
|
src/Traits/DataHelper.php
|
DataHelper.dataFormatoDestino
|
public function dataFormatoDestino($data, $formatoDestino)
{
$dataFormatada = false;
if (!$dataFormatada && $this->validarDataPorFormato($data, $this->FORMATO_DATA_SQL)) {
$dataFormatada = $this->dataFormatoOrigemDestino($data, $this->FORMATO_DATA_SQL, $formatoDestino);
}
if (!$dataFormatada && $this->validarDataPorFormato($data, $this->FORMATO_DATA_HORA_SQL)) {
$dataFormatada = $this->dataFormatoOrigemDestino($data, $this->FORMATO_DATA_HORA_SQL, $formatoDestino);
}
if (!$dataFormatada && $this->validarDataPorFormato($data, $this->FORMATO_DATA_BR)) {
$dataFormatada = $this->dataFormatoOrigemDestino($data, $this->FORMATO_DATA_BR, $formatoDestino);
}
if (!$dataFormatada && $this->validarDataPorFormato($data, $this->FORMATO_DATA_HORA_BR)) {
$dataFormatada = $this->dataFormatoOrigemDestino($data, $this->FORMATO_DATA_HORA_BR, $formatoDestino);
}
return $dataFormatada;
}
|
php
|
public function dataFormatoDestino($data, $formatoDestino)
{
$dataFormatada = false;
if (!$dataFormatada && $this->validarDataPorFormato($data, $this->FORMATO_DATA_SQL)) {
$dataFormatada = $this->dataFormatoOrigemDestino($data, $this->FORMATO_DATA_SQL, $formatoDestino);
}
if (!$dataFormatada && $this->validarDataPorFormato($data, $this->FORMATO_DATA_HORA_SQL)) {
$dataFormatada = $this->dataFormatoOrigemDestino($data, $this->FORMATO_DATA_HORA_SQL, $formatoDestino);
}
if (!$dataFormatada && $this->validarDataPorFormato($data, $this->FORMATO_DATA_BR)) {
$dataFormatada = $this->dataFormatoOrigemDestino($data, $this->FORMATO_DATA_BR, $formatoDestino);
}
if (!$dataFormatada && $this->validarDataPorFormato($data, $this->FORMATO_DATA_HORA_BR)) {
$dataFormatada = $this->dataFormatoOrigemDestino($data, $this->FORMATO_DATA_HORA_BR, $formatoDestino);
}
return $dataFormatada;
}
|
[
"public",
"function",
"dataFormatoDestino",
"(",
"$",
"data",
",",
"$",
"formatoDestino",
")",
"{",
"$",
"dataFormatada",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"dataFormatada",
"&&",
"$",
"this",
"->",
"validarDataPorFormato",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"FORMATO_DATA_SQL",
")",
")",
"{",
"$",
"dataFormatada",
"=",
"$",
"this",
"->",
"dataFormatoOrigemDestino",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"FORMATO_DATA_SQL",
",",
"$",
"formatoDestino",
")",
";",
"}",
"if",
"(",
"!",
"$",
"dataFormatada",
"&&",
"$",
"this",
"->",
"validarDataPorFormato",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"FORMATO_DATA_HORA_SQL",
")",
")",
"{",
"$",
"dataFormatada",
"=",
"$",
"this",
"->",
"dataFormatoOrigemDestino",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"FORMATO_DATA_HORA_SQL",
",",
"$",
"formatoDestino",
")",
";",
"}",
"if",
"(",
"!",
"$",
"dataFormatada",
"&&",
"$",
"this",
"->",
"validarDataPorFormato",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"FORMATO_DATA_BR",
")",
")",
"{",
"$",
"dataFormatada",
"=",
"$",
"this",
"->",
"dataFormatoOrigemDestino",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"FORMATO_DATA_BR",
",",
"$",
"formatoDestino",
")",
";",
"}",
"if",
"(",
"!",
"$",
"dataFormatada",
"&&",
"$",
"this",
"->",
"validarDataPorFormato",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"FORMATO_DATA_HORA_BR",
")",
")",
"{",
"$",
"dataFormatada",
"=",
"$",
"this",
"->",
"dataFormatoOrigemDestino",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"FORMATO_DATA_HORA_BR",
",",
"$",
"formatoDestino",
")",
";",
"}",
"return",
"$",
"dataFormatada",
";",
"}"
] |
Converter uma data identificando o formato origem para o formato destino informado.
@param \DateTime|string $data
@return false|string
|
[
"Converter",
"uma",
"data",
"identificando",
"o",
"formato",
"origem",
"para",
"o",
"formato",
"destino",
"informado",
"."
] |
4cd246d454968865758e74c5be383063e0f7ccd4
|
https://github.com/motamonteiro/helpers/blob/4cd246d454968865758e74c5be383063e0f7ccd4/src/Traits/DataHelper.php#L74-L95
|
236,132
|
motamonteiro/helpers
|
src/Traits/DataHelper.php
|
DataHelper.dataFormatoOrigemDestino
|
public function dataFormatoOrigemDestino($data, $formatoOrigem, $formatoDestino)
{
$data = $this->converterParaDateTime($data, $formatoOrigem);
if (!$data) {
return false;
}
return ($data->format($formatoDestino));
}
|
php
|
public function dataFormatoOrigemDestino($data, $formatoOrigem, $formatoDestino)
{
$data = $this->converterParaDateTime($data, $formatoOrigem);
if (!$data) {
return false;
}
return ($data->format($formatoDestino));
}
|
[
"public",
"function",
"dataFormatoOrigemDestino",
"(",
"$",
"data",
",",
"$",
"formatoOrigem",
",",
"$",
"formatoDestino",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"converterParaDateTime",
"(",
"$",
"data",
",",
"$",
"formatoOrigem",
")",
";",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"$",
"data",
"->",
"format",
"(",
"$",
"formatoDestino",
")",
")",
";",
"}"
] |
Converter uma data de um formato origem para um formato destino.
@param \DateTime|string $data
@param $formatoOrigem
@param $formatoDestino
@return false|string
|
[
"Converter",
"uma",
"data",
"de",
"um",
"formato",
"origem",
"para",
"um",
"formato",
"destino",
"."
] |
4cd246d454968865758e74c5be383063e0f7ccd4
|
https://github.com/motamonteiro/helpers/blob/4cd246d454968865758e74c5be383063e0f7ccd4/src/Traits/DataHelper.php#L105-L113
|
236,133
|
jayaregalinada/chikka
|
src/Chikka.php
|
Chikka.send
|
public function send($mobileNumber, $message, $messageId = null)
{
return $this->app['chikka.sender']->send($mobileNumber, $message, $messageId);
}
|
php
|
public function send($mobileNumber, $message, $messageId = null)
{
return $this->app['chikka.sender']->send($mobileNumber, $message, $messageId);
}
|
[
"public",
"function",
"send",
"(",
"$",
"mobileNumber",
",",
"$",
"message",
",",
"$",
"messageId",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"[",
"'chikka.sender'",
"]",
"->",
"send",
"(",
"$",
"mobileNumber",
",",
"$",
"message",
",",
"$",
"messageId",
")",
";",
"}"
] |
Send capability.
@param string $mobileNumber
@param string $message
@param string $messageId
@return \GuzzleHttp\Promise\Promise
|
[
"Send",
"capability",
"."
] |
eefd52c6a7c0e22fe82cef00c52874865456dddf
|
https://github.com/jayaregalinada/chikka/blob/eefd52c6a7c0e22fe82cef00c52874865456dddf/src/Chikka.php#L63-L66
|
236,134
|
jayaregalinada/chikka
|
src/Chikka.php
|
Chikka.sendAsync
|
public function sendAsync($mobileNumber, $message, $messageId = null)
{
return $this->app['chikka.sender']->sendAsync($mobileNumber, $message, $messageId);
}
|
php
|
public function sendAsync($mobileNumber, $message, $messageId = null)
{
return $this->app['chikka.sender']->sendAsync($mobileNumber, $message, $messageId);
}
|
[
"public",
"function",
"sendAsync",
"(",
"$",
"mobileNumber",
",",
"$",
"message",
",",
"$",
"messageId",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"[",
"'chikka.sender'",
"]",
"->",
"sendAsync",
"(",
"$",
"mobileNumber",
",",
"$",
"message",
",",
"$",
"messageId",
")",
";",
"}"
] |
Send capability without async.
@param string $mobileNumber
@param string $message
@param string $messageId [description]
@return [type] [description]
|
[
"Send",
"capability",
"without",
"async",
"."
] |
eefd52c6a7c0e22fe82cef00c52874865456dddf
|
https://github.com/jayaregalinada/chikka/blob/eefd52c6a7c0e22fe82cef00c52874865456dddf/src/Chikka.php#L75-L78
|
236,135
|
atelierspierrot/library
|
src/Library/Helper/File.php
|
File.getUniqFilename
|
public static function getUniqFilename($filename = '', $dir = null, $force_file = true, $extension = 'txt')
{
if (empty($filename)) {
return '';
}
$extension = trim($extension, '.');
if (empty($filename)){
$filename = uniqid();
if ($force_file) $filename .= '.'.$extension;
}
if (is_null($dir)) {
$dir = defined('_DIR_TMP') ? _DIR_TMP : '/tmp';
}
$dir = Directory::slashDirname($dir);
$_ext = self::getExtension($filename, true);
$_fname = str_replace($_ext, '', $filename);
$i = 0;
while (file_exists($dir.$_fname.$_ext)) {
$_fname .= ($i==0 ? '_' : '').rand(10, 99);
$i++;
}
return $_fname.$_ext;
}
|
php
|
public static function getUniqFilename($filename = '', $dir = null, $force_file = true, $extension = 'txt')
{
if (empty($filename)) {
return '';
}
$extension = trim($extension, '.');
if (empty($filename)){
$filename = uniqid();
if ($force_file) $filename .= '.'.$extension;
}
if (is_null($dir)) {
$dir = defined('_DIR_TMP') ? _DIR_TMP : '/tmp';
}
$dir = Directory::slashDirname($dir);
$_ext = self::getExtension($filename, true);
$_fname = str_replace($_ext, '', $filename);
$i = 0;
while (file_exists($dir.$_fname.$_ext)) {
$_fname .= ($i==0 ? '_' : '').rand(10, 99);
$i++;
}
return $_fname.$_ext;
}
|
[
"public",
"static",
"function",
"getUniqFilename",
"(",
"$",
"filename",
"=",
"''",
",",
"$",
"dir",
"=",
"null",
",",
"$",
"force_file",
"=",
"true",
",",
"$",
"extension",
"=",
"'txt'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"extension",
"=",
"trim",
"(",
"$",
"extension",
",",
"'.'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"filename",
"=",
"uniqid",
"(",
")",
";",
"if",
"(",
"$",
"force_file",
")",
"$",
"filename",
".=",
"'.'",
".",
"$",
"extension",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"dir",
"=",
"defined",
"(",
"'_DIR_TMP'",
")",
"?",
"_DIR_TMP",
":",
"'/tmp'",
";",
"}",
"$",
"dir",
"=",
"Directory",
"::",
"slashDirname",
"(",
"$",
"dir",
")",
";",
"$",
"_ext",
"=",
"self",
"::",
"getExtension",
"(",
"$",
"filename",
",",
"true",
")",
";",
"$",
"_fname",
"=",
"str_replace",
"(",
"$",
"_ext",
",",
"''",
",",
"$",
"filename",
")",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"file_exists",
"(",
"$",
"dir",
".",
"$",
"_fname",
".",
"$",
"_ext",
")",
")",
"{",
"$",
"_fname",
".=",
"(",
"$",
"i",
"==",
"0",
"?",
"'_'",
":",
"''",
")",
".",
"rand",
"(",
"10",
",",
"99",
")",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"_fname",
".",
"$",
"_ext",
";",
"}"
] |
Returns a filename or directory that does not exist in the destination
@param string $filename The name of the file or folder you want to create
@param string $dir The destination directory
@param boolean $force_file Should we force the creation of a file, adding an extension? (TRUE by default)
@param string $extension The extension to add in the case of a file
@return string The filename or directory, with a possible addition to be sure that it does not exist in the destination directory
|
[
"Returns",
"a",
"filename",
"or",
"directory",
"that",
"does",
"not",
"exist",
"in",
"the",
"destination"
] |
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
|
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Helper/File.php#L51-L74
|
236,136
|
atelierspierrot/library
|
src/Library/Helper/File.php
|
File.formatFilename
|
public static function formatFilename($filename = '', $lowercase = false, $delimiter = '-')
{
if (empty($filename)) {
return '';
}
$_ext = self::getExtension($filename, true);
if ($_ext) {
$filename = str_replace($_ext, '', $filename);
}
$string = $filename;
if ($lowercase) {
$string = strtolower($string);
}
$string = str_replace(" ",$delimiter,$string);
$string = preg_replace('#\-+#',$delimiter,$string);
$string = preg_replace('#([-]+)#',$delimiter,$string);
$string = trim($string,$delimiter);
$string = TextHelper::stripSpecialChars($string, $delimiter.'.');
if ($_ext) {
$string .= $_ext;
}
return $string;
}
|
php
|
public static function formatFilename($filename = '', $lowercase = false, $delimiter = '-')
{
if (empty($filename)) {
return '';
}
$_ext = self::getExtension($filename, true);
if ($_ext) {
$filename = str_replace($_ext, '', $filename);
}
$string = $filename;
if ($lowercase) {
$string = strtolower($string);
}
$string = str_replace(" ",$delimiter,$string);
$string = preg_replace('#\-+#',$delimiter,$string);
$string = preg_replace('#([-]+)#',$delimiter,$string);
$string = trim($string,$delimiter);
$string = TextHelper::stripSpecialChars($string, $delimiter.'.');
if ($_ext) {
$string .= $_ext;
}
return $string;
}
|
[
"public",
"static",
"function",
"formatFilename",
"(",
"$",
"filename",
"=",
"''",
",",
"$",
"lowercase",
"=",
"false",
",",
"$",
"delimiter",
"=",
"'-'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"_ext",
"=",
"self",
"::",
"getExtension",
"(",
"$",
"filename",
",",
"true",
")",
";",
"if",
"(",
"$",
"_ext",
")",
"{",
"$",
"filename",
"=",
"str_replace",
"(",
"$",
"_ext",
",",
"''",
",",
"$",
"filename",
")",
";",
"}",
"$",
"string",
"=",
"$",
"filename",
";",
"if",
"(",
"$",
"lowercase",
")",
"{",
"$",
"string",
"=",
"strtolower",
"(",
"$",
"string",
")",
";",
"}",
"$",
"string",
"=",
"str_replace",
"(",
"\" \"",
",",
"$",
"delimiter",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"'#\\-+#'",
",",
"$",
"delimiter",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"'#([-]+)#'",
",",
"$",
"delimiter",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
",",
"$",
"delimiter",
")",
";",
"$",
"string",
"=",
"TextHelper",
"::",
"stripSpecialChars",
"(",
"$",
"string",
",",
"$",
"delimiter",
".",
"'.'",
")",
";",
"if",
"(",
"$",
"_ext",
")",
"{",
"$",
"string",
".=",
"$",
"_ext",
";",
"}",
"return",
"$",
"string",
";",
"}"
] |
Formatting file names
@param string $filename The filename to format
@param boolean $lowercase Should we return the name un lowercase (FALSE by default)
@param string $delimiter The delimiter used for special chars substitution
@return string A filename valid on (almost) all systems
|
[
"Formatting",
"file",
"names"
] |
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
|
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Helper/File.php#L84-L112
|
236,137
|
atelierspierrot/library
|
src/Library/Helper/File.php
|
File.getExtension
|
public static function getExtension($filename = '', $dot = false)
{
if (empty($filename)) {
return '';
}
$exploded_file_name = explode('.', $filename);
return (strpos($filename, '.') ? ($dot ? '.' : '').end($exploded_file_name) : null);
}
|
php
|
public static function getExtension($filename = '', $dot = false)
{
if (empty($filename)) {
return '';
}
$exploded_file_name = explode('.', $filename);
return (strpos($filename, '.') ? ($dot ? '.' : '').end($exploded_file_name) : null);
}
|
[
"public",
"static",
"function",
"getExtension",
"(",
"$",
"filename",
"=",
"''",
",",
"$",
"dot",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"exploded_file_name",
"=",
"explode",
"(",
"'.'",
",",
"$",
"filename",
")",
";",
"return",
"(",
"strpos",
"(",
"$",
"filename",
",",
"'.'",
")",
"?",
"(",
"$",
"dot",
"?",
"'.'",
":",
"''",
")",
".",
"end",
"(",
"$",
"exploded_file_name",
")",
":",
"null",
")",
";",
"}"
] |
Returns the extension of a file name
It basically returns everything after last dot. No validation is done.
@param string $filename The file_name to work on
@param bool $dot
@return null|string The extension if found, `null` otherwise
|
[
"Returns",
"the",
"extension",
"of",
"a",
"file",
"name"
] |
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
|
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Helper/File.php#L123-L130
|
236,138
|
atelierspierrot/library
|
src/Library/Helper/File.php
|
File.touch
|
public static function touch($file_path = null, array &$logs = array())
{
if (is_null($file_path)) {
return null;
}
if (!file_exists($file_path)) {
$target_dir = dirname($file_path);
$ok = !file_exists($target_dir) ? Directory::create($target_dir) : true;
} else {
$ok = true;
}
if (touch($file_path)) {
clearstatcache();
return true;
} else {
$logs[] = sprintf('Can not touch file "%s".', $file_path);
}
return false;
}
|
php
|
public static function touch($file_path = null, array &$logs = array())
{
if (is_null($file_path)) {
return null;
}
if (!file_exists($file_path)) {
$target_dir = dirname($file_path);
$ok = !file_exists($target_dir) ? Directory::create($target_dir) : true;
} else {
$ok = true;
}
if (touch($file_path)) {
clearstatcache();
return true;
} else {
$logs[] = sprintf('Can not touch file "%s".', $file_path);
}
return false;
}
|
[
"public",
"static",
"function",
"touch",
"(",
"$",
"file_path",
"=",
"null",
",",
"array",
"&",
"$",
"logs",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"file_path",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file_path",
")",
")",
"{",
"$",
"target_dir",
"=",
"dirname",
"(",
"$",
"file_path",
")",
";",
"$",
"ok",
"=",
"!",
"file_exists",
"(",
"$",
"target_dir",
")",
"?",
"Directory",
"::",
"create",
"(",
"$",
"target_dir",
")",
":",
"true",
";",
"}",
"else",
"{",
"$",
"ok",
"=",
"true",
";",
"}",
"if",
"(",
"touch",
"(",
"$",
"file_path",
")",
")",
"{",
"clearstatcache",
"(",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"logs",
"[",
"]",
"=",
"sprintf",
"(",
"'Can not touch file \"%s\".'",
",",
"$",
"file_path",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Create an empty file or touch an existing file
@param string $file_path
@param array $logs Logs registry passed by reference
@return bool
|
[
"Create",
"an",
"empty",
"file",
"or",
"touch",
"an",
"existing",
"file"
] |
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
|
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Helper/File.php#L204-L222
|
236,139
|
atelierspierrot/library
|
src/Library/Helper/File.php
|
File.remove
|
public static function remove($file_path = null, array &$logs = array())
{
if (is_null($file_path)) {
return null;
}
if (file_exists($file_path)) {
if (unlink($file_path)) {
clearstatcache();
return true;
} else {
$logs[] = sprintf('Can not unlink file "%s".', $file_path);
}
} else {
$logs[] = sprintf('File path "%s" does not exist (can not be removed).', $file_path);
}
return false;
}
|
php
|
public static function remove($file_path = null, array &$logs = array())
{
if (is_null($file_path)) {
return null;
}
if (file_exists($file_path)) {
if (unlink($file_path)) {
clearstatcache();
return true;
} else {
$logs[] = sprintf('Can not unlink file "%s".', $file_path);
}
} else {
$logs[] = sprintf('File path "%s" does not exist (can not be removed).', $file_path);
}
return false;
}
|
[
"public",
"static",
"function",
"remove",
"(",
"$",
"file_path",
"=",
"null",
",",
"array",
"&",
"$",
"logs",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"file_path",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"file_path",
")",
")",
"{",
"if",
"(",
"unlink",
"(",
"$",
"file_path",
")",
")",
"{",
"clearstatcache",
"(",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"logs",
"[",
"]",
"=",
"sprintf",
"(",
"'Can not unlink file \"%s\".'",
",",
"$",
"file_path",
")",
";",
"}",
"}",
"else",
"{",
"$",
"logs",
"[",
"]",
"=",
"sprintf",
"(",
"'File path \"%s\" does not exist (can not be removed).'",
",",
"$",
"file_path",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Remove a file if it exists
@param string $file_path
@param array $logs Logs registry passed by reference
@return bool
|
[
"Remove",
"a",
"file",
"if",
"it",
"exists"
] |
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
|
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Helper/File.php#L231-L247
|
236,140
|
atelierspierrot/library
|
src/Library/Helper/File.php
|
File.write
|
public static function write($file_path = null, $content, $type = 'a', $force = false, array &$logs = array())
{
if (is_null($file_path)) {
return null;
}
if (!file_exists($file_path)) {
if (true===$force) {
self::touch($file_path, $logs);
} else {
$logs[] = sprintf('File path "%s" to copy was not found.', $file_path);
return false;
}
}
if (is_writable($file_path)) {
$h = fopen($file_path, $type);
if (false !== fwrite($h, $content)) {
fclose($h);
return true;
}
}
$logs[] = sprintf('Can not write in file "%s".', $file_path);
return false;
}
|
php
|
public static function write($file_path = null, $content, $type = 'a', $force = false, array &$logs = array())
{
if (is_null($file_path)) {
return null;
}
if (!file_exists($file_path)) {
if (true===$force) {
self::touch($file_path, $logs);
} else {
$logs[] = sprintf('File path "%s" to copy was not found.', $file_path);
return false;
}
}
if (is_writable($file_path)) {
$h = fopen($file_path, $type);
if (false !== fwrite($h, $content)) {
fclose($h);
return true;
}
}
$logs[] = sprintf('Can not write in file "%s".', $file_path);
return false;
}
|
[
"public",
"static",
"function",
"write",
"(",
"$",
"file_path",
"=",
"null",
",",
"$",
"content",
",",
"$",
"type",
"=",
"'a'",
",",
"$",
"force",
"=",
"false",
",",
"array",
"&",
"$",
"logs",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"file_path",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file_path",
")",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"force",
")",
"{",
"self",
"::",
"touch",
"(",
"$",
"file_path",
",",
"$",
"logs",
")",
";",
"}",
"else",
"{",
"$",
"logs",
"[",
"]",
"=",
"sprintf",
"(",
"'File path \"%s\" to copy was not found.'",
",",
"$",
"file_path",
")",
";",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"is_writable",
"(",
"$",
"file_path",
")",
")",
"{",
"$",
"h",
"=",
"fopen",
"(",
"$",
"file_path",
",",
"$",
"type",
")",
";",
"if",
"(",
"false",
"!==",
"fwrite",
"(",
"$",
"h",
",",
"$",
"content",
")",
")",
"{",
"fclose",
"(",
"$",
"h",
")",
";",
"return",
"true",
";",
"}",
"}",
"$",
"logs",
"[",
"]",
"=",
"sprintf",
"(",
"'Can not write in file \"%s\".'",
",",
"$",
"file_path",
")",
";",
"return",
"false",
";",
"}"
] |
Write a content in a file
@param string $file_path
@param string $content
@param string $type
@param bool $force
@param array $logs
@return bool
|
[
"Write",
"a",
"content",
"in",
"a",
"file"
] |
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
|
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Helper/File.php#L295-L317
|
236,141
|
webriq/core
|
module/Customize/src/Grid/Customize/Model/Sheet/Mapper.php
|
Mapper.find
|
public function find( $primaryKeys )
{
if ( is_array( $primaryKeys ) )
{
$primaryKeys = reset( $primaryKeys );
}
$rootId = ( (int) $primaryKeys ) ?: null;
return $this->createStructure( array(
'rootId' => $rootId,
'extra' => $this->getExtraMapper()
->findByRoot( $rootId ),
'rules' => $this->getRuleMapper()
->findAllByRoot(
$rootId,
$this->getRuleOrder()
),
) );
}
|
php
|
public function find( $primaryKeys )
{
if ( is_array( $primaryKeys ) )
{
$primaryKeys = reset( $primaryKeys );
}
$rootId = ( (int) $primaryKeys ) ?: null;
return $this->createStructure( array(
'rootId' => $rootId,
'extra' => $this->getExtraMapper()
->findByRoot( $rootId ),
'rules' => $this->getRuleMapper()
->findAllByRoot(
$rootId,
$this->getRuleOrder()
),
) );
}
|
[
"public",
"function",
"find",
"(",
"$",
"primaryKeys",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"primaryKeys",
")",
")",
"{",
"$",
"primaryKeys",
"=",
"reset",
"(",
"$",
"primaryKeys",
")",
";",
"}",
"$",
"rootId",
"=",
"(",
"(",
"int",
")",
"$",
"primaryKeys",
")",
"?",
":",
"null",
";",
"return",
"$",
"this",
"->",
"createStructure",
"(",
"array",
"(",
"'rootId'",
"=>",
"$",
"rootId",
",",
"'extra'",
"=>",
"$",
"this",
"->",
"getExtraMapper",
"(",
")",
"->",
"findByRoot",
"(",
"$",
"rootId",
")",
",",
"'rules'",
"=>",
"$",
"this",
"->",
"getRuleMapper",
"(",
")",
"->",
"findAllByRoot",
"(",
"$",
"rootId",
",",
"$",
"this",
"->",
"getRuleOrder",
"(",
")",
")",
",",
")",
")",
";",
"}"
] |
Find a structure by root paragraph id
@param int|array $primaryKeys
@return Structure
|
[
"Find",
"a",
"structure",
"by",
"root",
"paragraph",
"id"
] |
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
|
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Customize/src/Grid/Customize/Model/Sheet/Mapper.php#L240-L259
|
236,142
|
webriq/core
|
module/Customize/src/Grid/Customize/Model/Sheet/Mapper.php
|
Mapper.findByExtra
|
public function findByExtra( ExtraStructure $extra )
{
$rootId = $extra->rootParagraphId;
return $this->createStructure( array(
'rootId' => $rootId,
'extra' => $extra,
'rules' => $this->getRuleMapper()
->findAllByRoot(
$rootId,
$this->getRuleOrder()
),
) );
}
|
php
|
public function findByExtra( ExtraStructure $extra )
{
$rootId = $extra->rootParagraphId;
return $this->createStructure( array(
'rootId' => $rootId,
'extra' => $extra,
'rules' => $this->getRuleMapper()
->findAllByRoot(
$rootId,
$this->getRuleOrder()
),
) );
}
|
[
"public",
"function",
"findByExtra",
"(",
"ExtraStructure",
"$",
"extra",
")",
"{",
"$",
"rootId",
"=",
"$",
"extra",
"->",
"rootParagraphId",
";",
"return",
"$",
"this",
"->",
"createStructure",
"(",
"array",
"(",
"'rootId'",
"=>",
"$",
"rootId",
",",
"'extra'",
"=>",
"$",
"extra",
",",
"'rules'",
"=>",
"$",
"this",
"->",
"getRuleMapper",
"(",
")",
"->",
"findAllByRoot",
"(",
"$",
"rootId",
",",
"$",
"this",
"->",
"getRuleOrder",
"(",
")",
")",
",",
")",
")",
";",
"}"
] |
Find a structure by its extra structure
@param int|array $primaryKeys
@return Structure
|
[
"Find",
"a",
"structure",
"by",
"its",
"extra",
"structure"
] |
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
|
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Customize/src/Grid/Customize/Model/Sheet/Mapper.php#L267-L280
|
236,143
|
hschulz/data-structures
|
src/Queue/PriorityQueue.php
|
PriorityQueue.toArray
|
public function toArray(): array
{
/* Enable extraction of data and priority */
$this->setExtractFlags(self::EXTR_BOTH);
/* Prepare output */
$data = [];
/* Iterate yourself */
foreach ($this as $item) {
$data[] = $item;
}
return $data;
}
|
php
|
public function toArray(): array
{
/* Enable extraction of data and priority */
$this->setExtractFlags(self::EXTR_BOTH);
/* Prepare output */
$data = [];
/* Iterate yourself */
foreach ($this as $item) {
$data[] = $item;
}
return $data;
}
|
[
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"/* Enable extraction of data and priority */",
"$",
"this",
"->",
"setExtractFlags",
"(",
"self",
"::",
"EXTR_BOTH",
")",
";",
"/* Prepare output */",
"$",
"data",
"=",
"[",
"]",
";",
"/* Iterate yourself */",
"foreach",
"(",
"$",
"this",
"as",
"$",
"item",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Iterates the queue and returns an array containing each item with
the data and priority set.
@return array The array representation of the queue
|
[
"Iterates",
"the",
"queue",
"and",
"returns",
"an",
"array",
"containing",
"each",
"item",
"with",
"the",
"data",
"and",
"priority",
"set",
"."
] |
b563be1ecde746fe32dd8bcbf72cbbf4ea522075
|
https://github.com/hschulz/data-structures/blob/b563be1ecde746fe32dd8bcbf72cbbf4ea522075/src/Queue/PriorityQueue.php#L27-L41
|
236,144
|
hschulz/data-structures
|
src/Queue/PriorityQueue.php
|
PriorityQueue.insert
|
public function insert($data, $priority = self::PIRORITY_DEFAULT): void
{
parent::insert($data, $priority);
}
|
php
|
public function insert($data, $priority = self::PIRORITY_DEFAULT): void
{
parent::insert($data, $priority);
}
|
[
"public",
"function",
"insert",
"(",
"$",
"data",
",",
"$",
"priority",
"=",
"self",
"::",
"PIRORITY_DEFAULT",
")",
":",
"void",
"{",
"parent",
"::",
"insert",
"(",
"$",
"data",
",",
"$",
"priority",
")",
";",
"}"
] |
Allows inserting data into the queue without explicitly setting a
priority value. Inserts without a priority will use the PRIORITY_DEFAULT
value.
@param mixed $data The data to insert
@param mixed $priority The priority
@return void
|
[
"Allows",
"inserting",
"data",
"into",
"the",
"queue",
"without",
"explicitly",
"setting",
"a",
"priority",
"value",
".",
"Inserts",
"without",
"a",
"priority",
"will",
"use",
"the",
"PRIORITY_DEFAULT",
"value",
"."
] |
b563be1ecde746fe32dd8bcbf72cbbf4ea522075
|
https://github.com/hschulz/data-structures/blob/b563be1ecde746fe32dd8bcbf72cbbf4ea522075/src/Queue/PriorityQueue.php#L52-L55
|
236,145
|
hschulz/data-structures
|
src/Queue/PriorityQueue.php
|
PriorityQueue.unserialize
|
public function unserialize($queue)
{
foreach (unserialize($queue) as $item) {
$this->insert($item['data'], $item['priority']);
}
}
|
php
|
public function unserialize($queue)
{
foreach (unserialize($queue) as $item) {
$this->insert($item['data'], $item['priority']);
}
}
|
[
"public",
"function",
"unserialize",
"(",
"$",
"queue",
")",
"{",
"foreach",
"(",
"unserialize",
"(",
"$",
"queue",
")",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"insert",
"(",
"$",
"item",
"[",
"'data'",
"]",
",",
"$",
"item",
"[",
"'priority'",
"]",
")",
";",
"}",
"}"
] |
Unserializes the queue.
@param string $queue The serialized queue data
@return void
|
[
"Unserializes",
"the",
"queue",
"."
] |
b563be1ecde746fe32dd8bcbf72cbbf4ea522075
|
https://github.com/hschulz/data-structures/blob/b563be1ecde746fe32dd8bcbf72cbbf4ea522075/src/Queue/PriorityQueue.php#L73-L78
|
236,146
|
hschulz/data-structures
|
src/Queue/PriorityQueue.php
|
PriorityQueue.merge
|
public function merge(self $queue): void
{
$data = $queue->toArray();
foreach ($data as $item) {
$this->insert($item['data'], $item['priority']);
}
}
|
php
|
public function merge(self $queue): void
{
$data = $queue->toArray();
foreach ($data as $item) {
$this->insert($item['data'], $item['priority']);
}
}
|
[
"public",
"function",
"merge",
"(",
"self",
"$",
"queue",
")",
":",
"void",
"{",
"$",
"data",
"=",
"$",
"queue",
"->",
"toArray",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"insert",
"(",
"$",
"item",
"[",
"'data'",
"]",
",",
"$",
"item",
"[",
"'priority'",
"]",
")",
";",
"}",
"}"
] |
Merges the given queue data into this queue.
@param PriorityQueue $queue The queue to merge
@return void
|
[
"Merges",
"the",
"given",
"queue",
"data",
"into",
"this",
"queue",
"."
] |
b563be1ecde746fe32dd8bcbf72cbbf4ea522075
|
https://github.com/hschulz/data-structures/blob/b563be1ecde746fe32dd8bcbf72cbbf4ea522075/src/Queue/PriorityQueue.php#L86-L93
|
236,147
|
ItinerisLtd/preflight-command
|
src/CLI/ResultCollectionPresenter.php
|
ResultCollectionPresenter.display
|
public static function display(array $assocArgs, ResultCollection $resultCollection): void
{
// TODO: Use null coalescing assignment operator.
$assocArgs['fields'] = $assocArgs['fields'] ?? self::DEFAULT_FIELDS;
$formatter = new Formatter($assocArgs, $assocArgs['fields']);
$formatter->display_items(
self::toTable($resultCollection),
true
);
}
|
php
|
public static function display(array $assocArgs, ResultCollection $resultCollection): void
{
// TODO: Use null coalescing assignment operator.
$assocArgs['fields'] = $assocArgs['fields'] ?? self::DEFAULT_FIELDS;
$formatter = new Formatter($assocArgs, $assocArgs['fields']);
$formatter->display_items(
self::toTable($resultCollection),
true
);
}
|
[
"public",
"static",
"function",
"display",
"(",
"array",
"$",
"assocArgs",
",",
"ResultCollection",
"$",
"resultCollection",
")",
":",
"void",
"{",
"// TODO: Use null coalescing assignment operator.",
"$",
"assocArgs",
"[",
"'fields'",
"]",
"=",
"$",
"assocArgs",
"[",
"'fields'",
"]",
"??",
"self",
"::",
"DEFAULT_FIELDS",
";",
"$",
"formatter",
"=",
"new",
"Formatter",
"(",
"$",
"assocArgs",
",",
"$",
"assocArgs",
"[",
"'fields'",
"]",
")",
";",
"$",
"formatter",
"->",
"display_items",
"(",
"self",
"::",
"toTable",
"(",
"$",
"resultCollection",
")",
",",
"true",
")",
";",
"}"
] |
Display a result collection in a given format.
@param array $assocArgs Associative CLI argument.
@param ResultCollection $resultCollection The checker collection instance.
|
[
"Display",
"a",
"result",
"collection",
"in",
"a",
"given",
"format",
"."
] |
d1c1360ea8d7de0312b5c0c09c9c486949594049
|
https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/CLI/ResultCollectionPresenter.php#L28-L38
|
236,148
|
ItinerisLtd/preflight-command
|
src/CLI/ResultCollectionPresenter.php
|
ResultCollectionPresenter.toTable
|
private static function toTable(ResultCollection $resultCollection): array
{
return array_map(function (ResultInterface $result): array {
return self::toRow($result);
}, $resultCollection->all());
}
|
php
|
private static function toTable(ResultCollection $resultCollection): array
{
return array_map(function (ResultInterface $result): array {
return self::toRow($result);
}, $resultCollection->all());
}
|
[
"private",
"static",
"function",
"toTable",
"(",
"ResultCollection",
"$",
"resultCollection",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"ResultInterface",
"$",
"result",
")",
":",
"array",
"{",
"return",
"self",
"::",
"toRow",
"(",
"$",
"result",
")",
";",
"}",
",",
"$",
"resultCollection",
"->",
"all",
"(",
")",
")",
";",
"}"
] |
Converts the underlying results into a plain PHP array which printable on console tables.
@param ResultCollection $resultCollection The result collection instance.
@return array
|
[
"Converts",
"the",
"underlying",
"results",
"into",
"a",
"plain",
"PHP",
"array",
"which",
"printable",
"on",
"console",
"tables",
"."
] |
d1c1360ea8d7de0312b5c0c09c9c486949594049
|
https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/CLI/ResultCollectionPresenter.php#L47-L52
|
236,149
|
ItinerisLtd/preflight-command
|
src/CLI/ResultCollectionPresenter.php
|
ResultCollectionPresenter.toRow
|
private static function toRow(ResultInterface $result): array
{
$row = [
'id' => $result->getChecker()->getId(),
'link' => $result->getChecker()->getLink(),
'description' => $result->getChecker()->getDescription(),
'status' => $result->getStatus(),
'messages' => $result->getMessages(),
];
$row['status'] = self::colorize($result, $row['status']);
$row['message'] = implode(PHP_EOL, $row['messages']);
return $row;
}
|
php
|
private static function toRow(ResultInterface $result): array
{
$row = [
'id' => $result->getChecker()->getId(),
'link' => $result->getChecker()->getLink(),
'description' => $result->getChecker()->getDescription(),
'status' => $result->getStatus(),
'messages' => $result->getMessages(),
];
$row['status'] = self::colorize($result, $row['status']);
$row['message'] = implode(PHP_EOL, $row['messages']);
return $row;
}
|
[
"private",
"static",
"function",
"toRow",
"(",
"ResultInterface",
"$",
"result",
")",
":",
"array",
"{",
"$",
"row",
"=",
"[",
"'id'",
"=>",
"$",
"result",
"->",
"getChecker",
"(",
")",
"->",
"getId",
"(",
")",
",",
"'link'",
"=>",
"$",
"result",
"->",
"getChecker",
"(",
")",
"->",
"getLink",
"(",
")",
",",
"'description'",
"=>",
"$",
"result",
"->",
"getChecker",
"(",
")",
"->",
"getDescription",
"(",
")",
",",
"'status'",
"=>",
"$",
"result",
"->",
"getStatus",
"(",
")",
",",
"'messages'",
"=>",
"$",
"result",
"->",
"getMessages",
"(",
")",
",",
"]",
";",
"$",
"row",
"[",
"'status'",
"]",
"=",
"self",
"::",
"colorize",
"(",
"$",
"result",
",",
"$",
"row",
"[",
"'status'",
"]",
")",
";",
"$",
"row",
"[",
"'message'",
"]",
"=",
"implode",
"(",
"PHP_EOL",
",",
"$",
"row",
"[",
"'messages'",
"]",
")",
";",
"return",
"$",
"row",
";",
"}"
] |
Converts the underlying result into a plain PHP array which printable as console table row.
Note: One checker might yields multiple result instances.
@param ResultInterface $result The result instance.
@return array
|
[
"Converts",
"the",
"underlying",
"result",
"into",
"a",
"plain",
"PHP",
"array",
"which",
"printable",
"as",
"console",
"table",
"row",
"."
] |
d1c1360ea8d7de0312b5c0c09c9c486949594049
|
https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/CLI/ResultCollectionPresenter.php#L63-L77
|
236,150
|
ItinerisLtd/preflight-command
|
src/CLI/ResultCollectionPresenter.php
|
ResultCollectionPresenter.colorize
|
private static function colorize(ResultInterface $result, string $text): string
{
$colors = [
Success::class => '%G',
Disabled::class => '%P',
Failure::class => '%R',
Error::class => '%1%w',
'reset' => '%n',
];
$color = $colors[get_class($result)] ?? $colors['reset'];
return WP_CLI::colorize($color . $text . '%n');
}
|
php
|
private static function colorize(ResultInterface $result, string $text): string
{
$colors = [
Success::class => '%G',
Disabled::class => '%P',
Failure::class => '%R',
Error::class => '%1%w',
'reset' => '%n',
];
$color = $colors[get_class($result)] ?? $colors['reset'];
return WP_CLI::colorize($color . $text . '%n');
}
|
[
"private",
"static",
"function",
"colorize",
"(",
"ResultInterface",
"$",
"result",
",",
"string",
"$",
"text",
")",
":",
"string",
"{",
"$",
"colors",
"=",
"[",
"Success",
"::",
"class",
"=>",
"'%G'",
",",
"Disabled",
"::",
"class",
"=>",
"'%P'",
",",
"Failure",
"::",
"class",
"=>",
"'%R'",
",",
"Error",
"::",
"class",
"=>",
"'%1%w'",
",",
"'reset'",
"=>",
"'%n'",
",",
"]",
";",
"$",
"color",
"=",
"$",
"colors",
"[",
"get_class",
"(",
"$",
"result",
")",
"]",
"??",
"$",
"colors",
"[",
"'reset'",
"]",
";",
"return",
"WP_CLI",
"::",
"colorize",
"(",
"$",
"color",
".",
"$",
"text",
".",
"'%n'",
")",
";",
"}"
] |
Colorize a string for output.
@param ResultInterface $result The result instance.
@param string $text The text to be printed.
@return string
|
[
"Colorize",
"a",
"string",
"for",
"output",
"."
] |
d1c1360ea8d7de0312b5c0c09c9c486949594049
|
https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/CLI/ResultCollectionPresenter.php#L87-L100
|
236,151
|
nirix/radium
|
src/Http/Response.php
|
Response.header
|
public function header($header, $value, $replace = true)
{
$this->headers[] = array($header, $value, $replace);
}
|
php
|
public function header($header, $value, $replace = true)
{
$this->headers[] = array($header, $value, $replace);
}
|
[
"public",
"function",
"header",
"(",
"$",
"header",
",",
"$",
"value",
",",
"$",
"replace",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"]",
"=",
"array",
"(",
"$",
"header",
",",
"$",
"value",
",",
"$",
"replace",
")",
";",
"}"
] |
Sets a response header.
@param string $header
@param string $value
|
[
"Sets",
"a",
"response",
"header",
"."
] |
cc6907bfee296b64a7630b0b188e233d7cdb86fd
|
https://github.com/nirix/radium/blob/cc6907bfee296b64a7630b0b188e233d7cdb86fd/src/Http/Response.php#L89-L92
|
236,152
|
heyday/heystack-ecommerce-core
|
src/Currency/Input/Processor.php
|
Processor.process
|
public function process(\SS_HTTPRequest $request)
{
if ($identifier = $request->param('ID')) {
if ($this->currencyService->setActiveCurrency(new Identifier($identifier))) {
return [
'Success' => true
];
}
}
return [
'Success' => false
];
}
|
php
|
public function process(\SS_HTTPRequest $request)
{
if ($identifier = $request->param('ID')) {
if ($this->currencyService->setActiveCurrency(new Identifier($identifier))) {
return [
'Success' => true
];
}
}
return [
'Success' => false
];
}
|
[
"public",
"function",
"process",
"(",
"\\",
"SS_HTTPRequest",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"identifier",
"=",
"$",
"request",
"->",
"param",
"(",
"'ID'",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currencyService",
"->",
"setActiveCurrency",
"(",
"new",
"Identifier",
"(",
"$",
"identifier",
")",
")",
")",
"{",
"return",
"[",
"'Success'",
"=>",
"true",
"]",
";",
"}",
"}",
"return",
"[",
"'Success'",
"=>",
"false",
"]",
";",
"}"
] |
Method to determine how to handle the request.
Uses the currency service to set the active currency
@param \SS_HTTPRequest $request
@return array
|
[
"Method",
"to",
"determine",
"how",
"to",
"handle",
"the",
"request",
".",
"Uses",
"the",
"currency",
"service",
"to",
"set",
"the",
"active",
"currency"
] |
b56c83839cd3396da6bc881d843fcb4f28b74685
|
https://github.com/heyday/heystack-ecommerce-core/blob/b56c83839cd3396da6bc881d843fcb4f28b74685/src/Currency/Input/Processor.php#L58-L71
|
236,153
|
sellerlabs/nucleus
|
src/SellerLabs/Nucleus/Transformation/TransformPipeline.php
|
TransformPipeline.run
|
public function run(array $input)
{
return Std::foldl(function ($current, TransformInterface $input) {
return $input->run($current);
}, $input, $this->transforms);
}
|
php
|
public function run(array $input)
{
return Std::foldl(function ($current, TransformInterface $input) {
return $input->run($current);
}, $input, $this->transforms);
}
|
[
"public",
"function",
"run",
"(",
"array",
"$",
"input",
")",
"{",
"return",
"Std",
"::",
"foldl",
"(",
"function",
"(",
"$",
"current",
",",
"TransformInterface",
"$",
"input",
")",
"{",
"return",
"$",
"input",
"->",
"run",
"(",
"$",
"current",
")",
";",
"}",
",",
"$",
"input",
",",
"$",
"this",
"->",
"transforms",
")",
";",
"}"
] |
Run the input through the pipeline.
@param array $input
@return array
|
[
"Run",
"the",
"input",
"through",
"the",
"pipeline",
"."
] |
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
|
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Transformation/TransformPipeline.php#L73-L78
|
236,154
|
takatost/php-pubsub-cmq
|
src/CMQPubSubAdapter.php
|
CMQPubSubAdapter.subscribe
|
public function subscribe($topicQueueName, callable $handler)
{
$isSubscriptionLoopActive = true;
while ($isSubscriptionLoopActive) {
$request = new SubscribeMessageRequest([
'queueName' => $topicQueueName,
'pollingWaitSeconds' => 0,
]);
try {
$message = $this->client->send($request);
} catch (RequestException $e) {
throw $e;
} catch (ResponseException $e) {
$message = $e->getBody();
if (!$message->has('code')) {
throw $e;
} else if (!in_array($message->get('code'), ['7000', '6070'])) { // 队列没有消息或队列中有太多不可见或者延时消息
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
if ($message === null || $message->get('msgBody') === null) {
sleep(mt_rand(1, 5));
continue;
}
call_user_func($handler,
Utils::unserializeMessagePayload($message->get('msgBody')),
new MessageHandler($this->client, $topicQueueName, $message)
);
unset($message);
}
}
|
php
|
public function subscribe($topicQueueName, callable $handler)
{
$isSubscriptionLoopActive = true;
while ($isSubscriptionLoopActive) {
$request = new SubscribeMessageRequest([
'queueName' => $topicQueueName,
'pollingWaitSeconds' => 0,
]);
try {
$message = $this->client->send($request);
} catch (RequestException $e) {
throw $e;
} catch (ResponseException $e) {
$message = $e->getBody();
if (!$message->has('code')) {
throw $e;
} else if (!in_array($message->get('code'), ['7000', '6070'])) { // 队列没有消息或队列中有太多不可见或者延时消息
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
if ($message === null || $message->get('msgBody') === null) {
sleep(mt_rand(1, 5));
continue;
}
call_user_func($handler,
Utils::unserializeMessagePayload($message->get('msgBody')),
new MessageHandler($this->client, $topicQueueName, $message)
);
unset($message);
}
}
|
[
"public",
"function",
"subscribe",
"(",
"$",
"topicQueueName",
",",
"callable",
"$",
"handler",
")",
"{",
"$",
"isSubscriptionLoopActive",
"=",
"true",
";",
"while",
"(",
"$",
"isSubscriptionLoopActive",
")",
"{",
"$",
"request",
"=",
"new",
"SubscribeMessageRequest",
"(",
"[",
"'queueName'",
"=>",
"$",
"topicQueueName",
",",
"'pollingWaitSeconds'",
"=>",
"0",
",",
"]",
")",
";",
"try",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"catch",
"(",
"ResponseException",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"$",
"e",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"!",
"$",
"message",
"->",
"has",
"(",
"'code'",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"else",
"if",
"(",
"!",
"in_array",
"(",
"$",
"message",
"->",
"get",
"(",
"'code'",
")",
",",
"[",
"'7000'",
",",
"'6070'",
"]",
")",
")",
"{",
"// 队列没有消息或队列中有太多不可见或者延时消息",
"throw",
"$",
"e",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"$",
"message",
"===",
"null",
"||",
"$",
"message",
"->",
"get",
"(",
"'msgBody'",
")",
"===",
"null",
")",
"{",
"sleep",
"(",
"mt_rand",
"(",
"1",
",",
"5",
")",
")",
";",
"continue",
";",
"}",
"call_user_func",
"(",
"$",
"handler",
",",
"Utils",
"::",
"unserializeMessagePayload",
"(",
"$",
"message",
"->",
"get",
"(",
"'msgBody'",
")",
")",
",",
"new",
"MessageHandler",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"topicQueueName",
",",
"$",
"message",
")",
")",
";",
"unset",
"(",
"$",
"message",
")",
";",
"}",
"}"
] |
Subscribe a handler to a topic queue.
@param string $topicQueueName
@param callable $handler
@throws RequestException
@throws ResponseException
@throws \Exception
|
[
"Subscribe",
"a",
"handler",
"to",
"a",
"topic",
"queue",
"."
] |
74c980b5dd4e98150d01b8e50d3dfb9a02c7d4fd
|
https://github.com/takatost/php-pubsub-cmq/blob/74c980b5dd4e98150d01b8e50d3dfb9a02c7d4fd/src/CMQPubSubAdapter.php#L50-L87
|
236,155
|
titon/model
|
src/Titon/Model/Relation.php
|
Relation.detectForeignKey
|
public function detectForeignKey($config, $class) {
$foreignKey = $this->getConfig($config);
if (!$foreignKey) {
$foreignKey = $this->buildForeignKey($class);
$this->setConfig($config, $foreignKey);
}
return $foreignKey;
}
|
php
|
public function detectForeignKey($config, $class) {
$foreignKey = $this->getConfig($config);
if (!$foreignKey) {
$foreignKey = $this->buildForeignKey($class);
$this->setConfig($config, $foreignKey);
}
return $foreignKey;
}
|
[
"public",
"function",
"detectForeignKey",
"(",
"$",
"config",
",",
"$",
"class",
")",
"{",
"$",
"foreignKey",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"$",
"config",
")",
";",
"if",
"(",
"!",
"$",
"foreignKey",
")",
"{",
"$",
"foreignKey",
"=",
"$",
"this",
"->",
"buildForeignKey",
"(",
"$",
"class",
")",
";",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"config",
",",
"$",
"foreignKey",
")",
";",
"}",
"return",
"$",
"foreignKey",
";",
"}"
] |
Return a foreign key either for the primary or related model.
If no foreign key is defined, automatically inflect one and set it.
@param string $config
@param string $class
@return string
|
[
"Return",
"a",
"foreign",
"key",
"either",
"for",
"the",
"primary",
"or",
"related",
"model",
".",
"If",
"no",
"foreign",
"key",
"is",
"defined",
"automatically",
"inflect",
"one",
"and",
"set",
"it",
"."
] |
274e3810c2cfbb6818a388daaa462ff05de99cbd
|
https://github.com/titon/model/blob/274e3810c2cfbb6818a388daaa462ff05de99cbd/src/Titon/Model/Relation.php#L142-L152
|
236,156
|
titon/model
|
src/Titon/Model/Relation.php
|
Relation.getPrimaryModel
|
public function getPrimaryModel() {
if ($model = $this->_model) {
return $model;
}
$class = $this->getPrimaryClass();
if (!$class) {
return null;
}
$this->setPrimaryModel(new $class());
return $this->_model;
}
|
php
|
public function getPrimaryModel() {
if ($model = $this->_model) {
return $model;
}
$class = $this->getPrimaryClass();
if (!$class) {
return null;
}
$this->setPrimaryModel(new $class());
return $this->_model;
}
|
[
"public",
"function",
"getPrimaryModel",
"(",
")",
"{",
"if",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"_model",
")",
"{",
"return",
"$",
"model",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"getPrimaryClass",
"(",
")",
";",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"setPrimaryModel",
"(",
"new",
"$",
"class",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"_model",
";",
"}"
] |
Return a primary model object.
@return \Titon\Model\Model
|
[
"Return",
"a",
"primary",
"model",
"object",
"."
] |
274e3810c2cfbb6818a388daaa462ff05de99cbd
|
https://github.com/titon/model/blob/274e3810c2cfbb6818a388daaa462ff05de99cbd/src/Titon/Model/Relation.php#L232-L246
|
236,157
|
titon/model
|
src/Titon/Model/Relation.php
|
Relation.getRelatedModel
|
public function getRelatedModel() {
if ($model = $this->_relatedModel) {
return $model;
}
$class = $this->getRelatedClass();
$this->setRelatedModel(new $class());
return $this->_relatedModel;
}
|
php
|
public function getRelatedModel() {
if ($model = $this->_relatedModel) {
return $model;
}
$class = $this->getRelatedClass();
$this->setRelatedModel(new $class());
return $this->_relatedModel;
}
|
[
"public",
"function",
"getRelatedModel",
"(",
")",
"{",
"if",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"_relatedModel",
")",
"{",
"return",
"$",
"model",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"getRelatedClass",
"(",
")",
";",
"$",
"this",
"->",
"setRelatedModel",
"(",
"new",
"$",
"class",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"_relatedModel",
";",
"}"
] |
Return a related model object.
@return \Titon\Model\Model
|
[
"Return",
"a",
"related",
"model",
"object",
"."
] |
274e3810c2cfbb6818a388daaa462ff05de99cbd
|
https://github.com/titon/model/blob/274e3810c2cfbb6818a388daaa462ff05de99cbd/src/Titon/Model/Relation.php#L271-L281
|
236,158
|
titon/model
|
src/Titon/Model/Relation.php
|
Relation.setPrimaryModel
|
public function setPrimaryModel(Model $model) {
$this->_model = $model;
$this->setPrimaryClass(get_class($model));
return $this;
}
|
php
|
public function setPrimaryModel(Model $model) {
$this->_model = $model;
$this->setPrimaryClass(get_class($model));
return $this;
}
|
[
"public",
"function",
"setPrimaryModel",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"_model",
"=",
"$",
"model",
";",
"$",
"this",
"->",
"setPrimaryClass",
"(",
"get_class",
"(",
"$",
"model",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the primary model object.
@param \Titon\Model\Model $model
@return $this
|
[
"Set",
"the",
"primary",
"model",
"object",
"."
] |
274e3810c2cfbb6818a388daaa462ff05de99cbd
|
https://github.com/titon/model/blob/274e3810c2cfbb6818a388daaa462ff05de99cbd/src/Titon/Model/Relation.php#L420-L425
|
236,159
|
titon/model
|
src/Titon/Model/Relation.php
|
Relation.setRelatedModel
|
public function setRelatedModel(Model $model) {
$this->_relatedModel = $model;
$this->setRelatedClass(get_class($model));
return $this;
}
|
php
|
public function setRelatedModel(Model $model) {
$this->_relatedModel = $model;
$this->setRelatedClass(get_class($model));
return $this;
}
|
[
"public",
"function",
"setRelatedModel",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"_relatedModel",
"=",
"$",
"model",
";",
"$",
"this",
"->",
"setRelatedClass",
"(",
"get_class",
"(",
"$",
"model",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the related model object.
@param \Titon\Model\Model $model
@return $this
|
[
"Set",
"the",
"related",
"model",
"object",
"."
] |
274e3810c2cfbb6818a388daaa462ff05de99cbd
|
https://github.com/titon/model/blob/274e3810c2cfbb6818a388daaa462ff05de99cbd/src/Titon/Model/Relation.php#L457-L462
|
236,160
|
remote-office/libx
|
src/External/SimplePay/User.php
|
User.setHash
|
public function setHash($hash)
{
if(!is_string($hash) || strlen(trim($hash)) == 0)
throw new InvalidArgumentException(__METHOD__ . '; Invalid hash, must be a non empty string');
$this->hash = $hash;
}
|
php
|
public function setHash($hash)
{
if(!is_string($hash) || strlen(trim($hash)) == 0)
throw new InvalidArgumentException(__METHOD__ . '; Invalid hash, must be a non empty string');
$this->hash = $hash;
}
|
[
"public",
"function",
"setHash",
"(",
"$",
"hash",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"hash",
")",
"||",
"strlen",
"(",
"trim",
"(",
"$",
"hash",
")",
")",
"==",
"0",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"'; Invalid hash, must be a non empty string'",
")",
";",
"$",
"this",
"->",
"hash",
"=",
"$",
"hash",
";",
"}"
] |
Set hash of this User
@param string $hash
@return void
|
[
"Set",
"hash",
"of",
"this",
"User"
] |
8baeaae99a6110e7c588bc0388df89a0dc0768b5
|
https://github.com/remote-office/libx/blob/8baeaae99a6110e7c588bc0388df89a0dc0768b5/src/External/SimplePay/User.php#L72-L78
|
236,161
|
consigliere/components
|
src/Publishing/Publisher.php
|
Publisher.publish
|
public function publish()
{
if (!$this->console instanceof Command) {
$message = "The 'console' property must instance of \\Illuminate\\Console\\Command.";
throw new \RuntimeException($message);
}
if (!$this->getFilesystem()->isDirectory($sourcePath = $this->getSourcePath())) {
return;
}
if (!$this->getFilesystem()->isDirectory($destinationPath = $this->getDestinationPath())) {
$this->getFilesystem()->makeDirectory($destinationPath, 0775, true);
}
if ($this->getFilesystem()->copyDirectory($sourcePath, $destinationPath)) {
if ($this->showMessage === true) {
$this->console->line("<info>Published</info>: {$this->component->getStudlyName()}");
}
} else {
$this->console->error($this->error);
}
}
|
php
|
public function publish()
{
if (!$this->console instanceof Command) {
$message = "The 'console' property must instance of \\Illuminate\\Console\\Command.";
throw new \RuntimeException($message);
}
if (!$this->getFilesystem()->isDirectory($sourcePath = $this->getSourcePath())) {
return;
}
if (!$this->getFilesystem()->isDirectory($destinationPath = $this->getDestinationPath())) {
$this->getFilesystem()->makeDirectory($destinationPath, 0775, true);
}
if ($this->getFilesystem()->copyDirectory($sourcePath, $destinationPath)) {
if ($this->showMessage === true) {
$this->console->line("<info>Published</info>: {$this->component->getStudlyName()}");
}
} else {
$this->console->error($this->error);
}
}
|
[
"public",
"function",
"publish",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"console",
"instanceof",
"Command",
")",
"{",
"$",
"message",
"=",
"\"The 'console' property must instance of \\\\Illuminate\\\\Console\\\\Command.\"",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getFilesystem",
"(",
")",
"->",
"isDirectory",
"(",
"$",
"sourcePath",
"=",
"$",
"this",
"->",
"getSourcePath",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getFilesystem",
"(",
")",
"->",
"isDirectory",
"(",
"$",
"destinationPath",
"=",
"$",
"this",
"->",
"getDestinationPath",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"getFilesystem",
"(",
")",
"->",
"makeDirectory",
"(",
"$",
"destinationPath",
",",
"0775",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getFilesystem",
"(",
")",
"->",
"copyDirectory",
"(",
"$",
"sourcePath",
",",
"$",
"destinationPath",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"showMessage",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"console",
"->",
"line",
"(",
"\"<info>Published</info>: {$this->component->getStudlyName()}\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"console",
"->",
"error",
"(",
"$",
"this",
"->",
"error",
")",
";",
"}",
"}"
] |
Publish something.
|
[
"Publish",
"something",
"."
] |
9b08bb111f0b55b0a860ed9c3407eda0d9cc1252
|
https://github.com/consigliere/components/blob/9b08bb111f0b55b0a860ed9c3407eda0d9cc1252/src/Publishing/Publisher.php#L173-L196
|
236,162
|
dbtlr/php-env-builder
|
src/EnvWriter.php
|
EnvWriter.save
|
public function save(array $answers)
{
$path = $this->directory . DIRECTORY_SEPARATOR . $this->file;
if (!file_exists($path)) {
if (!is_writable($this->directory)) {
throw new WritableException(
sprintf(
'The env file is not present and the directory `%s` is not writeable!',
$this->directory
)
);
}
touch($path);
}
if (!is_writable($path)) {
throw new WritableException(sprintf('The env file `%s` is not writeable!', $path));
}
$text = '';
foreach ($answers as $key => $value) {
$text .= sprintf("%s=%s\n", $key, $value);
}
file_put_contents($path, $text);
}
|
php
|
public function save(array $answers)
{
$path = $this->directory . DIRECTORY_SEPARATOR . $this->file;
if (!file_exists($path)) {
if (!is_writable($this->directory)) {
throw new WritableException(
sprintf(
'The env file is not present and the directory `%s` is not writeable!',
$this->directory
)
);
}
touch($path);
}
if (!is_writable($path)) {
throw new WritableException(sprintf('The env file `%s` is not writeable!', $path));
}
$text = '';
foreach ($answers as $key => $value) {
$text .= sprintf("%s=%s\n", $key, $value);
}
file_put_contents($path, $text);
}
|
[
"public",
"function",
"save",
"(",
"array",
"$",
"answers",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"file",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"this",
"->",
"directory",
")",
")",
"{",
"throw",
"new",
"WritableException",
"(",
"sprintf",
"(",
"'The env file is not present and the directory `%s` is not writeable!'",
",",
"$",
"this",
"->",
"directory",
")",
")",
";",
"}",
"touch",
"(",
"$",
"path",
")",
";",
"}",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"WritableException",
"(",
"sprintf",
"(",
"'The env file `%s` is not writeable!'",
",",
"$",
"path",
")",
")",
";",
"}",
"$",
"text",
"=",
"''",
";",
"foreach",
"(",
"$",
"answers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"text",
".=",
"sprintf",
"(",
"\"%s=%s\\n\"",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"text",
")",
";",
"}"
] |
Save the given answers to the env file.
@throws WritableException
@param array $answers
|
[
"Save",
"the",
"given",
"answers",
"to",
"the",
"env",
"file",
"."
] |
94b78bcd308d58dc7994164a87e80fe39ed871c7
|
https://github.com/dbtlr/php-env-builder/blob/94b78bcd308d58dc7994164a87e80fe39ed871c7/src/EnvWriter.php#L32-L59
|
236,163
|
oaugustus/direct-silex-provider
|
src/Direct/Router/Request.php
|
Request.getCalls
|
public function getCalls()
{
if (null == $this->calls) {
$this->calls = $this->extractCalls();
}
return $this->calls;
}
|
php
|
public function getCalls()
{
if (null == $this->calls) {
$this->calls = $this->extractCalls();
}
return $this->calls;
}
|
[
"public",
"function",
"getCalls",
"(",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"this",
"->",
"calls",
")",
"{",
"$",
"this",
"->",
"calls",
"=",
"$",
"this",
"->",
"extractCalls",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"calls",
";",
"}"
] |
Get the direct calls object.
@return array
|
[
"Get",
"the",
"direct",
"calls",
"object",
"."
] |
8d92afdf5ede04c3048cde82b9879de7e1d6c153
|
https://github.com/oaugustus/direct-silex-provider/blob/8d92afdf5ede04c3048cde82b9879de7e1d6c153/src/Direct/Router/Request.php#L96-L103
|
236,164
|
oaugustus/direct-silex-provider
|
src/Direct/Router/Request.php
|
Request.extractCalls
|
public function extractCalls()
{
$calls = array();
if ('form' == $this->callType) {
$calls[] = new Call($this->post, 'form');
} else {
$decoded = json_decode($this->rawPost);
$decoded = !is_array($decoded) ? array($decoded) : $decoded;
array_walk_recursive($decoded, array($this, 'parseRawToArray'));
if ($this->requestDecode)
array_walk_recursive($decoded, array($this, 'decode'));
foreach ($decoded as $call) {
$calls[] = new Call((array)$call, 'single');
}
}
return $calls;
}
|
php
|
public function extractCalls()
{
$calls = array();
if ('form' == $this->callType) {
$calls[] = new Call($this->post, 'form');
} else {
$decoded = json_decode($this->rawPost);
$decoded = !is_array($decoded) ? array($decoded) : $decoded;
array_walk_recursive($decoded, array($this, 'parseRawToArray'));
if ($this->requestDecode)
array_walk_recursive($decoded, array($this, 'decode'));
foreach ($decoded as $call) {
$calls[] = new Call((array)$call, 'single');
}
}
return $calls;
}
|
[
"public",
"function",
"extractCalls",
"(",
")",
"{",
"$",
"calls",
"=",
"array",
"(",
")",
";",
"if",
"(",
"'form'",
"==",
"$",
"this",
"->",
"callType",
")",
"{",
"$",
"calls",
"[",
"]",
"=",
"new",
"Call",
"(",
"$",
"this",
"->",
"post",
",",
"'form'",
")",
";",
"}",
"else",
"{",
"$",
"decoded",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"rawPost",
")",
";",
"$",
"decoded",
"=",
"!",
"is_array",
"(",
"$",
"decoded",
")",
"?",
"array",
"(",
"$",
"decoded",
")",
":",
"$",
"decoded",
";",
"array_walk_recursive",
"(",
"$",
"decoded",
",",
"array",
"(",
"$",
"this",
",",
"'parseRawToArray'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"requestDecode",
")",
"array_walk_recursive",
"(",
"$",
"decoded",
",",
"array",
"(",
"$",
"this",
",",
"'decode'",
")",
")",
";",
"foreach",
"(",
"$",
"decoded",
"as",
"$",
"call",
")",
"{",
"$",
"calls",
"[",
"]",
"=",
"new",
"Call",
"(",
"(",
"array",
")",
"$",
"call",
",",
"'single'",
")",
";",
"}",
"}",
"return",
"$",
"calls",
";",
"}"
] |
Extract the ExtDirect calls from request.
@return array
|
[
"Extract",
"the",
"ExtDirect",
"calls",
"from",
"request",
"."
] |
8d92afdf5ede04c3048cde82b9879de7e1d6c153
|
https://github.com/oaugustus/direct-silex-provider/blob/8d92afdf5ede04c3048cde82b9879de7e1d6c153/src/Direct/Router/Request.php#L110-L131
|
236,165
|
oaugustus/direct-silex-provider
|
src/Direct/Router/Request.php
|
Request.parseRawToArray
|
private function parseRawToArray(&$value, &$key)
{
// parse a json string to an array
if (is_string($value)) {
$pos = substr($value,0,1);
if ($pos == '[' || $pos == '(' || $pos == '{') {
$json = json_decode($value);
} else {
$json = $value;
}
$pos = substr($value,0,1);
if ($pos == '[' || $pos == '(' || $pos == '{') {
$json = json_decode($value);
} else {
$json = $value;
}
if ($json) {
$value = $json;
}
}
// if the value is an object, parse it to an array
if (is_object($value)) {
$value = (array)$value;
}
// call the recursive function to all keys of array
if (is_array($value)) {
array_walk_recursive($value, array($this, 'parseRawToArray'));
}
}
|
php
|
private function parseRawToArray(&$value, &$key)
{
// parse a json string to an array
if (is_string($value)) {
$pos = substr($value,0,1);
if ($pos == '[' || $pos == '(' || $pos == '{') {
$json = json_decode($value);
} else {
$json = $value;
}
$pos = substr($value,0,1);
if ($pos == '[' || $pos == '(' || $pos == '{') {
$json = json_decode($value);
} else {
$json = $value;
}
if ($json) {
$value = $json;
}
}
// if the value is an object, parse it to an array
if (is_object($value)) {
$value = (array)$value;
}
// call the recursive function to all keys of array
if (is_array($value)) {
array_walk_recursive($value, array($this, 'parseRawToArray'));
}
}
|
[
"private",
"function",
"parseRawToArray",
"(",
"&",
"$",
"value",
",",
"&",
"$",
"key",
")",
"{",
"// parse a json string to an array",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"pos",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"1",
")",
";",
"if",
"(",
"$",
"pos",
"==",
"'['",
"||",
"$",
"pos",
"==",
"'('",
"||",
"$",
"pos",
"==",
"'{'",
")",
"{",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"json",
"=",
"$",
"value",
";",
"}",
"$",
"pos",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"1",
")",
";",
"if",
"(",
"$",
"pos",
"==",
"'['",
"||",
"$",
"pos",
"==",
"'('",
"||",
"$",
"pos",
"==",
"'{'",
")",
"{",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"json",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"json",
")",
"{",
"$",
"value",
"=",
"$",
"json",
";",
"}",
"}",
"// if the value is an object, parse it to an array",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"value",
";",
"}",
"// call the recursive function to all keys of array",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"array_walk_recursive",
"(",
"$",
"value",
",",
"array",
"(",
"$",
"this",
",",
"'parseRawToArray'",
")",
")",
";",
"}",
"}"
] |
Parse a raw http post to a php array.
@param mixed $value
@param string $key
|
[
"Parse",
"a",
"raw",
"http",
"post",
"to",
"a",
"php",
"array",
"."
] |
8d92afdf5ede04c3048cde82b9879de7e1d6c153
|
https://github.com/oaugustus/direct-silex-provider/blob/8d92afdf5ede04c3048cde82b9879de7e1d6c153/src/Direct/Router/Request.php#L152-L187
|
236,166
|
SagePHP/System
|
src/SagePHP/System/Exec.php
|
Exec.run
|
public function run()
{
$process = $this->getProcessExecutor();
$process->setCommandLine($this->getCommand());
$logger = function ($error, $line) {
call_user_func_array(array($this, 'logLine'), array($error, $line));
};
return $process->run($logger);
}
|
php
|
public function run()
{
$process = $this->getProcessExecutor();
$process->setCommandLine($this->getCommand());
$logger = function ($error, $line) {
call_user_func_array(array($this, 'logLine'), array($error, $line));
};
return $process->run($logger);
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"$",
"process",
"=",
"$",
"this",
"->",
"getProcessExecutor",
"(",
")",
";",
"$",
"process",
"->",
"setCommandLine",
"(",
"$",
"this",
"->",
"getCommand",
"(",
")",
")",
";",
"$",
"logger",
"=",
"function",
"(",
"$",
"error",
",",
"$",
"line",
")",
"{",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"'logLine'",
")",
",",
"array",
"(",
"$",
"error",
",",
"$",
"line",
")",
")",
";",
"}",
";",
"return",
"$",
"process",
"->",
"run",
"(",
"$",
"logger",
")",
";",
"}"
] |
executes the command.
@return integer the return code of the executed command
|
[
"executes",
"the",
"command",
"."
] |
4fbac093c16c65607e75dc31b54be9593b82c56a
|
https://github.com/SagePHP/System/blob/4fbac093c16c65607e75dc31b54be9593b82c56a/src/SagePHP/System/Exec.php#L98-L108
|
236,167
|
SagePHP/System
|
src/SagePHP/System/Exec.php
|
Exec.logLine
|
protected function logLine($messageType, $messageText)
{
switch ($messageType) {
case Process::ERR:
$typeStr = "[Error]";
break;
default:
$typeStr = "";
break;
}
echo sprintf("\n%s %s\n", $typeStr, $messageText);
}
|
php
|
protected function logLine($messageType, $messageText)
{
switch ($messageType) {
case Process::ERR:
$typeStr = "[Error]";
break;
default:
$typeStr = "";
break;
}
echo sprintf("\n%s %s\n", $typeStr, $messageText);
}
|
[
"protected",
"function",
"logLine",
"(",
"$",
"messageType",
",",
"$",
"messageText",
")",
"{",
"switch",
"(",
"$",
"messageType",
")",
"{",
"case",
"Process",
"::",
"ERR",
":",
"$",
"typeStr",
"=",
"\"[Error]\"",
";",
"break",
";",
"default",
":",
"$",
"typeStr",
"=",
"\"\"",
";",
"break",
";",
"}",
"echo",
"sprintf",
"(",
"\"\\n%s %s\\n\"",
",",
"$",
"typeStr",
",",
"$",
"messageText",
")",
";",
"}"
] |
logs a line from the command output
@return [type]
|
[
"logs",
"a",
"line",
"from",
"the",
"command",
"output"
] |
4fbac093c16c65607e75dc31b54be9593b82c56a
|
https://github.com/SagePHP/System/blob/4fbac093c16c65607e75dc31b54be9593b82c56a/src/SagePHP/System/Exec.php#L137-L149
|
236,168
|
kreta-plugins/VCS
|
src/Kreta/Component/VCS/EventSubscriber/DoctrineEventSubscriber.php
|
DoctrineEventSubscriber.postPersist
|
public function postPersist(LifecycleEventArgs $args)
{
if ($args->getObject() instanceof CommitInterface) {
$this->dispatcher->dispatch(NewCommitEvent::NAME, new NewCommitEvent($args->getObject()));
} elseif ($args->getObject() instanceof BranchInterface) {
$this->dispatcher->dispatch(NewBranchEvent::NAME, new NewBranchEvent($args->getObject()));
}
}
|
php
|
public function postPersist(LifecycleEventArgs $args)
{
if ($args->getObject() instanceof CommitInterface) {
$this->dispatcher->dispatch(NewCommitEvent::NAME, new NewCommitEvent($args->getObject()));
} elseif ($args->getObject() instanceof BranchInterface) {
$this->dispatcher->dispatch(NewBranchEvent::NAME, new NewBranchEvent($args->getObject()));
}
}
|
[
"public",
"function",
"postPersist",
"(",
"LifecycleEventArgs",
"$",
"args",
")",
"{",
"if",
"(",
"$",
"args",
"->",
"getObject",
"(",
")",
"instanceof",
"CommitInterface",
")",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"NewCommitEvent",
"::",
"NAME",
",",
"new",
"NewCommitEvent",
"(",
"$",
"args",
"->",
"getObject",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"args",
"->",
"getObject",
"(",
")",
"instanceof",
"BranchInterface",
")",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"NewBranchEvent",
"::",
"NAME",
",",
"new",
"NewBranchEvent",
"(",
"$",
"args",
"->",
"getObject",
"(",
")",
")",
")",
";",
"}",
"}"
] |
Handles postPersist event triggered by doctrine.
@param \Doctrine\ORM\Event\LifecycleEventArgs $args The arguments
|
[
"Handles",
"postPersist",
"event",
"triggered",
"by",
"doctrine",
"."
] |
0b6daae2b8044d9250adc8009d03a6745370cd2e
|
https://github.com/kreta-plugins/VCS/blob/0b6daae2b8044d9250adc8009d03a6745370cd2e/src/Kreta/Component/VCS/EventSubscriber/DoctrineEventSubscriber.php#L62-L69
|
236,169
|
NitroXy/php-forms
|
src/lib/FormUtils.php
|
FormUtils.serializeAttr
|
public static function serializeAttr(array $data, array $order=[]){
$attr = [];
/* convert data to sorted array */
$sorted = static::sortedAttr($data, $order);
foreach ( $sorted as list($key, $value) ){
if ( is_array($value) ){
/* ignore empty arrays */
if ( count($value) === 0 ){
continue;
}
foreach ( static::_serializeAttrArray($key, $value) as $sub ){
$value = htmlspecialchars($sub[1], ENT_QUOTES | ENT_HTML5);
$attr[] = "{$sub[0]}=\"{$value}\"";
}
} else {
if ( $value === true ){
$attr[] = "$key";
} else if ( $value === false ){
/* ignore */
} else {
$value = htmlspecialchars($value, ENT_QUOTES | ENT_HTML5);
$attr[] = "$key=\"$value\"";
}
}
}
return implode(' ', $attr);
}
|
php
|
public static function serializeAttr(array $data, array $order=[]){
$attr = [];
/* convert data to sorted array */
$sorted = static::sortedAttr($data, $order);
foreach ( $sorted as list($key, $value) ){
if ( is_array($value) ){
/* ignore empty arrays */
if ( count($value) === 0 ){
continue;
}
foreach ( static::_serializeAttrArray($key, $value) as $sub ){
$value = htmlspecialchars($sub[1], ENT_QUOTES | ENT_HTML5);
$attr[] = "{$sub[0]}=\"{$value}\"";
}
} else {
if ( $value === true ){
$attr[] = "$key";
} else if ( $value === false ){
/* ignore */
} else {
$value = htmlspecialchars($value, ENT_QUOTES | ENT_HTML5);
$attr[] = "$key=\"$value\"";
}
}
}
return implode(' ', $attr);
}
|
[
"public",
"static",
"function",
"serializeAttr",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"order",
"=",
"[",
"]",
")",
"{",
"$",
"attr",
"=",
"[",
"]",
";",
"/* convert data to sorted array */",
"$",
"sorted",
"=",
"static",
"::",
"sortedAttr",
"(",
"$",
"data",
",",
"$",
"order",
")",
";",
"foreach",
"(",
"$",
"sorted",
"as",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"/* ignore empty arrays */",
"if",
"(",
"count",
"(",
"$",
"value",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"static",
"::",
"_serializeAttrArray",
"(",
"$",
"key",
",",
"$",
"value",
")",
"as",
"$",
"sub",
")",
"{",
"$",
"value",
"=",
"htmlspecialchars",
"(",
"$",
"sub",
"[",
"1",
"]",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
")",
";",
"$",
"attr",
"[",
"]",
"=",
"\"{$sub[0]}=\\\"{$value}\\\"\"",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"===",
"true",
")",
"{",
"$",
"attr",
"[",
"]",
"=",
"\"$key\"",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"/* ignore */",
"}",
"else",
"{",
"$",
"value",
"=",
"htmlspecialchars",
"(",
"$",
"value",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
")",
";",
"$",
"attr",
"[",
"]",
"=",
"\"$key=\\\"$value\\\"\"",
";",
"}",
"}",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"attr",
")",
";",
"}"
] |
Takes key-value array and serializes them to a string as
'key="value" foo="bar"'.
['foo' => 'bar'] becomes foo="bar".
['class' => ['foo', 'bar'] becomes class="foo bar"
['data' => ['foo' => 'bar'] becomes data-foo="bar"
@param $data Data to serializeattr
@param $order Array with predefined order keys should appear
in. Keys not in this array will appear last in any order.
|
[
"Takes",
"key",
"-",
"value",
"array",
"and",
"serializes",
"them",
"to",
"a",
"string",
"as",
"key",
"=",
"value",
"foo",
"=",
"bar",
"."
] |
28970779c3b438372c83f4f651a9897a542c1e54
|
https://github.com/NitroXy/php-forms/blob/28970779c3b438372c83f4f651a9897a542c1e54/src/lib/FormUtils.php#L18-L46
|
236,170
|
zicht/version
|
src/Zicht/Version/Constraint.php
|
Constraint.fromString
|
public static function fromString($constraintExpression)
{
if (!preg_match('/^(==?|\!=?|~|[<>]=?)?((?:\*|[0-9]+)(?:.(?:\*|[0-9]+))*)(?:\@(\w+))?$/', $constraintExpression, $m)) {
throw new \InvalidArgumentException("Constraint expression '$constraintExpression' could not be parsed");
}
return new self(
!empty($m[1]) ? $m[1] : '=',
$m[2],
!empty($m[3]) ? $m[3] : 'stable'
);
}
|
php
|
public static function fromString($constraintExpression)
{
if (!preg_match('/^(==?|\!=?|~|[<>]=?)?((?:\*|[0-9]+)(?:.(?:\*|[0-9]+))*)(?:\@(\w+))?$/', $constraintExpression, $m)) {
throw new \InvalidArgumentException("Constraint expression '$constraintExpression' could not be parsed");
}
return new self(
!empty($m[1]) ? $m[1] : '=',
$m[2],
!empty($m[3]) ? $m[3] : 'stable'
);
}
|
[
"public",
"static",
"function",
"fromString",
"(",
"$",
"constraintExpression",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^(==?|\\!=?|~|[<>]=?)?((?:\\*|[0-9]+)(?:.(?:\\*|[0-9]+))*)(?:\\@(\\w+))?$/'",
",",
"$",
"constraintExpression",
",",
"$",
"m",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Constraint expression '$constraintExpression' could not be parsed\"",
")",
";",
"}",
"return",
"new",
"self",
"(",
"!",
"empty",
"(",
"$",
"m",
"[",
"1",
"]",
")",
"?",
"$",
"m",
"[",
"1",
"]",
":",
"'='",
",",
"$",
"m",
"[",
"2",
"]",
",",
"!",
"empty",
"(",
"$",
"m",
"[",
"3",
"]",
")",
"?",
"$",
"m",
"[",
"3",
"]",
":",
"'stable'",
")",
";",
"}"
] |
Construct a Constraint instance based on the passed string constraint.
@param string $constraintExpression
@return Constraint
@throws \InvalidArgumentException
|
[
"Construct",
"a",
"Constraint",
"instance",
"based",
"on",
"the",
"passed",
"string",
"constraint",
"."
] |
2653209f2620e1d4a8baf17a0b5b74fd339abba3
|
https://github.com/zicht/version/blob/2653209f2620e1d4a8baf17a0b5b74fd339abba3/src/Zicht/Version/Constraint.php#L43-L53
|
236,171
|
zicht/version
|
src/Zicht/Version/Constraint.php
|
Constraint.match
|
public function match(Version $version)
{
$versionStabilityIndex = array_search($version->getStability(), Version::$stabilities);
$constraintStabilityIndex = array_search($this->stability, Version::$stabilities);
if ($this->compare($versionStabilityIndex, $constraintStabilityIndex) !== 0) {
return false;
}
$numericValues = $version->numeric();
$comparisons = array();
foreach ($this->version as $i => $value) {
$comparisons[$i] = $this->compare($numericValues[$i], $value);
}
switch ($this->operator) {
case '=': case '==':
// all parts must be equal:
return array_filter($comparisons) === array();
break;
case '!': case '!=':
// any part must be unequal:
return array_filter($comparisons) !== array();
break;
case '>=':
case '<=':
case '>':
case '<':
// the first mismatch is the tie breaker
$mismatches = array_filter($comparisons);
if (!count($mismatches)) {
// if no mismatches, only ok if equality operator
return in_array($this->operator, array('<=', '>='));
} else {
$first = array_shift($mismatches);
return
($this->operator === '<' && $first < 0)
|| ($this->operator === '<=' && $first < 0)
|| ($this->operator === '>' && $first > 0)
|| ($this->operator === '>=' && $first > 0)
;
}
}
throw new \UnexpectedValueException("An unknown edge case was encountered. Is the constraint valid?");
}
|
php
|
public function match(Version $version)
{
$versionStabilityIndex = array_search($version->getStability(), Version::$stabilities);
$constraintStabilityIndex = array_search($this->stability, Version::$stabilities);
if ($this->compare($versionStabilityIndex, $constraintStabilityIndex) !== 0) {
return false;
}
$numericValues = $version->numeric();
$comparisons = array();
foreach ($this->version as $i => $value) {
$comparisons[$i] = $this->compare($numericValues[$i], $value);
}
switch ($this->operator) {
case '=': case '==':
// all parts must be equal:
return array_filter($comparisons) === array();
break;
case '!': case '!=':
// any part must be unequal:
return array_filter($comparisons) !== array();
break;
case '>=':
case '<=':
case '>':
case '<':
// the first mismatch is the tie breaker
$mismatches = array_filter($comparisons);
if (!count($mismatches)) {
// if no mismatches, only ok if equality operator
return in_array($this->operator, array('<=', '>='));
} else {
$first = array_shift($mismatches);
return
($this->operator === '<' && $first < 0)
|| ($this->operator === '<=' && $first < 0)
|| ($this->operator === '>' && $first > 0)
|| ($this->operator === '>=' && $first > 0)
;
}
}
throw new \UnexpectedValueException("An unknown edge case was encountered. Is the constraint valid?");
}
|
[
"public",
"function",
"match",
"(",
"Version",
"$",
"version",
")",
"{",
"$",
"versionStabilityIndex",
"=",
"array_search",
"(",
"$",
"version",
"->",
"getStability",
"(",
")",
",",
"Version",
"::",
"$",
"stabilities",
")",
";",
"$",
"constraintStabilityIndex",
"=",
"array_search",
"(",
"$",
"this",
"->",
"stability",
",",
"Version",
"::",
"$",
"stabilities",
")",
";",
"if",
"(",
"$",
"this",
"->",
"compare",
"(",
"$",
"versionStabilityIndex",
",",
"$",
"constraintStabilityIndex",
")",
"!==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"numericValues",
"=",
"$",
"version",
"->",
"numeric",
"(",
")",
";",
"$",
"comparisons",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"version",
"as",
"$",
"i",
"=>",
"$",
"value",
")",
"{",
"$",
"comparisons",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"compare",
"(",
"$",
"numericValues",
"[",
"$",
"i",
"]",
",",
"$",
"value",
")",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"operator",
")",
"{",
"case",
"'='",
":",
"case",
"'=='",
":",
"// all parts must be equal:",
"return",
"array_filter",
"(",
"$",
"comparisons",
")",
"===",
"array",
"(",
")",
";",
"break",
";",
"case",
"'!'",
":",
"case",
"'!='",
":",
"// any part must be unequal:",
"return",
"array_filter",
"(",
"$",
"comparisons",
")",
"!==",
"array",
"(",
")",
";",
"break",
";",
"case",
"'>='",
":",
"case",
"'<='",
":",
"case",
"'>'",
":",
"case",
"'<'",
":",
"// the first mismatch is the tie breaker",
"$",
"mismatches",
"=",
"array_filter",
"(",
"$",
"comparisons",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"mismatches",
")",
")",
"{",
"// if no mismatches, only ok if equality operator",
"return",
"in_array",
"(",
"$",
"this",
"->",
"operator",
",",
"array",
"(",
"'<='",
",",
"'>='",
")",
")",
";",
"}",
"else",
"{",
"$",
"first",
"=",
"array_shift",
"(",
"$",
"mismatches",
")",
";",
"return",
"(",
"$",
"this",
"->",
"operator",
"===",
"'<'",
"&&",
"$",
"first",
"<",
"0",
")",
"||",
"(",
"$",
"this",
"->",
"operator",
"===",
"'<='",
"&&",
"$",
"first",
"<",
"0",
")",
"||",
"(",
"$",
"this",
"->",
"operator",
"===",
"'>'",
"&&",
"$",
"first",
">",
"0",
")",
"||",
"(",
"$",
"this",
"->",
"operator",
"===",
"'>='",
"&&",
"$",
"first",
">",
"0",
")",
";",
"}",
"}",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"An unknown edge case was encountered. Is the constraint valid?\"",
")",
";",
"}"
] |
Match the constraint against the passed version.
@param Version $version
@return bool
@throws \UnexpectedValueException
|
[
"Match",
"the",
"constraint",
"against",
"the",
"passed",
"version",
"."
] |
2653209f2620e1d4a8baf17a0b5b74fd339abba3
|
https://github.com/zicht/version/blob/2653209f2620e1d4a8baf17a0b5b74fd339abba3/src/Zicht/Version/Constraint.php#L83-L129
|
236,172
|
Attibee/Bumble-Form
|
src/Element/Element.php
|
Element.setAttribute
|
public function setAttribute( $attr, $value ) {
//data-* attribute or in valid attribute array
if( strpos( $attr, 'data-' ) === 0 || in_array( $attr, $this->validAttributes ) ) {
$this->attrs[$attr] = $value;
} else {
throw new Exception\InvalidAttributeException( $attr );
}
}
|
php
|
public function setAttribute( $attr, $value ) {
//data-* attribute or in valid attribute array
if( strpos( $attr, 'data-' ) === 0 || in_array( $attr, $this->validAttributes ) ) {
$this->attrs[$attr] = $value;
} else {
throw new Exception\InvalidAttributeException( $attr );
}
}
|
[
"public",
"function",
"setAttribute",
"(",
"$",
"attr",
",",
"$",
"value",
")",
"{",
"//data-* attribute or in valid attribute array\r",
"if",
"(",
"strpos",
"(",
"$",
"attr",
",",
"'data-'",
")",
"===",
"0",
"||",
"in_array",
"(",
"$",
"attr",
",",
"$",
"this",
"->",
"validAttributes",
")",
")",
"{",
"$",
"this",
"->",
"attrs",
"[",
"$",
"attr",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidAttributeException",
"(",
"$",
"attr",
")",
";",
"}",
"}"
] |
Sets an attribute given the name and value.
@param $attr the name of the attribute
@param $value the value of the attribute
@throws Exception\InvalidAttributeException if an invalid attribute is provided
|
[
"Sets",
"an",
"attribute",
"given",
"the",
"name",
"and",
"value",
"."
] |
546c4b01806c68d8ffc09766f74dc157d9ab4960
|
https://github.com/Attibee/Bumble-Form/blob/546c4b01806c68d8ffc09766f74dc157d9ab4960/src/Element/Element.php#L57-L64
|
236,173
|
Attibee/Bumble-Form
|
src/Element/Element.php
|
Element.getAttribute
|
public function getAttribute( $name ) {
if( key_exists( $name, $this->attrs ) ) {
return $this->attrs[$name];
} else {
return null;
}
}
|
php
|
public function getAttribute( $name ) {
if( key_exists( $name, $this->attrs ) ) {
return $this->attrs[$name];
} else {
return null;
}
}
|
[
"public",
"function",
"getAttribute",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"attrs",
")",
")",
"{",
"return",
"$",
"this",
"->",
"attrs",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Gets an attribute given the attribute name.
@param $name The name of the attribute.
|
[
"Gets",
"an",
"attribute",
"given",
"the",
"attribute",
"name",
"."
] |
546c4b01806c68d8ffc09766f74dc157d9ab4960
|
https://github.com/Attibee/Bumble-Form/blob/546c4b01806c68d8ffc09766f74dc157d9ab4960/src/Element/Element.php#L83-L89
|
236,174
|
Attibee/Bumble-Form
|
src/Element/Element.php
|
Element.getHTML
|
public function getHTML() {
$tag = "<" . $this->name;
$q = $this->quoteType;
//build attribute strings
foreach( $this->attrs as $name=>$value ) {
//if true, such as CHECKED, we just add the name
if( $value === true ) {
$tag .= " $name";
} else if( is_string( $value ) ) { //if it's a string, we add attr="value"
$tag .= " {$name}={$q}{$value}{$q}";
}
}
//short tag? close it and return
if( $this->isShortTag ) {
$tag .= ' />';
return $tag;
}
//not a short tag, close it
$tag .= '>';
//add the children if they exist
if( $this->hasChildren() ) {
foreach( $this->getChildren() as $child ) {
$tag .= $child->getHTML();
}
}
//closing tag
$tag .= "</{$this->name}>";
return $tag;
}
|
php
|
public function getHTML() {
$tag = "<" . $this->name;
$q = $this->quoteType;
//build attribute strings
foreach( $this->attrs as $name=>$value ) {
//if true, such as CHECKED, we just add the name
if( $value === true ) {
$tag .= " $name";
} else if( is_string( $value ) ) { //if it's a string, we add attr="value"
$tag .= " {$name}={$q}{$value}{$q}";
}
}
//short tag? close it and return
if( $this->isShortTag ) {
$tag .= ' />';
return $tag;
}
//not a short tag, close it
$tag .= '>';
//add the children if they exist
if( $this->hasChildren() ) {
foreach( $this->getChildren() as $child ) {
$tag .= $child->getHTML();
}
}
//closing tag
$tag .= "</{$this->name}>";
return $tag;
}
|
[
"public",
"function",
"getHTML",
"(",
")",
"{",
"$",
"tag",
"=",
"\"<\"",
".",
"$",
"this",
"->",
"name",
";",
"$",
"q",
"=",
"$",
"this",
"->",
"quoteType",
";",
"//build attribute strings\r",
"foreach",
"(",
"$",
"this",
"->",
"attrs",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"//if true, such as CHECKED, we just add the name\r",
"if",
"(",
"$",
"value",
"===",
"true",
")",
"{",
"$",
"tag",
".=",
"\" $name\"",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"//if it's a string, we add attr=\"value\"\r",
"$",
"tag",
".=",
"\" {$name}={$q}{$value}{$q}\"",
";",
"}",
"}",
"//short tag? close it and return\r",
"if",
"(",
"$",
"this",
"->",
"isShortTag",
")",
"{",
"$",
"tag",
".=",
"' />'",
";",
"return",
"$",
"tag",
";",
"}",
"//not a short tag, close it\r",
"$",
"tag",
".=",
"'>'",
";",
"//add the children if they exist\r",
"if",
"(",
"$",
"this",
"->",
"hasChildren",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"tag",
".=",
"$",
"child",
"->",
"getHTML",
"(",
")",
";",
"}",
"}",
"//closing tag\r",
"$",
"tag",
".=",
"\"</{$this->name}>\"",
";",
"return",
"$",
"tag",
";",
"}"
] |
Parses the class data and outputs the HTML.
@return the HTML string of the element
|
[
"Parses",
"the",
"class",
"data",
"and",
"outputs",
"the",
"HTML",
"."
] |
546c4b01806c68d8ffc09766f74dc157d9ab4960
|
https://github.com/Attibee/Bumble-Form/blob/546c4b01806c68d8ffc09766f74dc157d9ab4960/src/Element/Element.php#L96-L131
|
236,175
|
Attibee/Bumble-Form
|
src/Element/Element.php
|
Element.setQuote
|
public function setQuote( $type ) {
$this->quoteType = $quoteType == self::SINGLE_QUOTE ? self::SINGLE_QUOTE : self::DOUBLE_QUOTE;
}
|
php
|
public function setQuote( $type ) {
$this->quoteType = $quoteType == self::SINGLE_QUOTE ? self::SINGLE_QUOTE : self::DOUBLE_QUOTE;
}
|
[
"public",
"function",
"setQuote",
"(",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"quoteType",
"=",
"$",
"quoteType",
"==",
"self",
"::",
"SINGLE_QUOTE",
"?",
"self",
"::",
"SINGLE_QUOTE",
":",
"self",
"::",
"DOUBLE_QUOTE",
";",
"}"
] |
Sets the type of quote to use. Default quote type is double quotes.
@param $type Element::DOUBLE_QUOTE or Element::SINGLE_QUOTE
|
[
"Sets",
"the",
"type",
"of",
"quote",
"to",
"use",
".",
"Default",
"quote",
"type",
"is",
"double",
"quotes",
"."
] |
546c4b01806c68d8ffc09766f74dc157d9ab4960
|
https://github.com/Attibee/Bumble-Form/blob/546c4b01806c68d8ffc09766f74dc157d9ab4960/src/Element/Element.php#L137-L139
|
236,176
|
Attibee/Bumble-Form
|
src/Element/Element.php
|
Element.addValidAttributes
|
protected function addValidAttributes( $attrs ) {
foreach( $attrs as $attr ) {
//add if string
if( is_string( $attr ) ) {
$this->validAttributes[] = $attr;
}
}
}
|
php
|
protected function addValidAttributes( $attrs ) {
foreach( $attrs as $attr ) {
//add if string
if( is_string( $attr ) ) {
$this->validAttributes[] = $attr;
}
}
}
|
[
"protected",
"function",
"addValidAttributes",
"(",
"$",
"attrs",
")",
"{",
"foreach",
"(",
"$",
"attrs",
"as",
"$",
"attr",
")",
"{",
"//add if string\r",
"if",
"(",
"is_string",
"(",
"$",
"attr",
")",
")",
"{",
"$",
"this",
"->",
"validAttributes",
"[",
"]",
"=",
"$",
"attr",
";",
"}",
"}",
"}"
] |
Adds array of attributes to the valid attributes.
@param $attrs an array of attributes
|
[
"Adds",
"array",
"of",
"attributes",
"to",
"the",
"valid",
"attributes",
"."
] |
546c4b01806c68d8ffc09766f74dc157d9ab4960
|
https://github.com/Attibee/Bumble-Form/blob/546c4b01806c68d8ffc09766f74dc157d9ab4960/src/Element/Element.php#L155-L162
|
236,177
|
agalbourdin/agl-core
|
src/Mysql/Query/Select.php
|
Select._formatOrder
|
private function _formatOrder()
{
$orders = array();
if (isset($this->_order[DbInterface::ORDER_RAND])) {
$orders[] = 'RAND()';
} else {
foreach ($this->_order as $field => $order) {
$orders[] = "`$field` $order";
}
}
return ' ORDER BY ' . implode(', ', $orders);
}
|
php
|
private function _formatOrder()
{
$orders = array();
if (isset($this->_order[DbInterface::ORDER_RAND])) {
$orders[] = 'RAND()';
} else {
foreach ($this->_order as $field => $order) {
$orders[] = "`$field` $order";
}
}
return ' ORDER BY ' . implode(', ', $orders);
}
|
[
"private",
"function",
"_formatOrder",
"(",
")",
"{",
"$",
"orders",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_order",
"[",
"DbInterface",
"::",
"ORDER_RAND",
"]",
")",
")",
"{",
"$",
"orders",
"[",
"]",
"=",
"'RAND()'",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_order",
"as",
"$",
"field",
"=>",
"$",
"order",
")",
"{",
"$",
"orders",
"[",
"]",
"=",
"\"`$field` $order\"",
";",
"}",
"}",
"return",
"' ORDER BY '",
".",
"implode",
"(",
"', '",
",",
"$",
"orders",
")",
";",
"}"
] |
Format the order fields to be included into the query.
@return string
|
[
"Format",
"the",
"order",
"fields",
"to",
"be",
"included",
"into",
"the",
"query",
"."
] |
1db556f9a49488aa9fab6887fefb7141a79ad97d
|
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mysql/Query/Select.php#L36-L49
|
236,178
|
agalbourdin/agl-core
|
src/Mysql/Query/Select.php
|
Select._doQuery
|
private function _doQuery($pLimitOne)
{
try {
if (empty($this->_fields)) {
$fields = '*';
} else {
$fields = '`' . implode('`, `', $this->_fields) . '`';
}
$query = "
SELECT
$fields
FROM
`" . $this->getDbPrefix() . $this->_dbContainer . "`";
if ($this->_conditions->count()) {
$query .= "
WHERE
" . $this->_conditions->getPreparedConditions($this->_dbContainer) . "";
}
if (! empty($this->_order)) {
$query .= $this->_formatOrder();
}
if ($pLimitOne) {
$query .= ' LIMIT 0, 1';
} else if ($this->_limit !== NULL or $this->_skip !== NULL) {
$query .= $this->_formatLimit();
}
$this->_stm = Agl::app()->getDb()->getConnection()->prepare($query, array(
PDO::ATTR_CURSOR,
PDO::CURSOR_SCROLL
));
if (! $this->_stm->execute($this->_conditions->getPreparedValues())) {
$error = $this->_stm->errorInfo();
throw new Exception("The select query failed (table '" . $this->getDbPrefix() . $this->_dbContainer . "') with message '" . $error[2] . "'");
}
if (Agl::app()->isDebugMode()) {
Agl::app()->getDb()->incrementCounter();
}
return $this;
} catch (Exception $e) {
throw new Exception($e);
}
}
|
php
|
private function _doQuery($pLimitOne)
{
try {
if (empty($this->_fields)) {
$fields = '*';
} else {
$fields = '`' . implode('`, `', $this->_fields) . '`';
}
$query = "
SELECT
$fields
FROM
`" . $this->getDbPrefix() . $this->_dbContainer . "`";
if ($this->_conditions->count()) {
$query .= "
WHERE
" . $this->_conditions->getPreparedConditions($this->_dbContainer) . "";
}
if (! empty($this->_order)) {
$query .= $this->_formatOrder();
}
if ($pLimitOne) {
$query .= ' LIMIT 0, 1';
} else if ($this->_limit !== NULL or $this->_skip !== NULL) {
$query .= $this->_formatLimit();
}
$this->_stm = Agl::app()->getDb()->getConnection()->prepare($query, array(
PDO::ATTR_CURSOR,
PDO::CURSOR_SCROLL
));
if (! $this->_stm->execute($this->_conditions->getPreparedValues())) {
$error = $this->_stm->errorInfo();
throw new Exception("The select query failed (table '" . $this->getDbPrefix() . $this->_dbContainer . "') with message '" . $error[2] . "'");
}
if (Agl::app()->isDebugMode()) {
Agl::app()->getDb()->incrementCounter();
}
return $this;
} catch (Exception $e) {
throw new Exception($e);
}
}
|
[
"private",
"function",
"_doQuery",
"(",
"$",
"pLimitOne",
")",
"{",
"try",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_fields",
")",
")",
"{",
"$",
"fields",
"=",
"'*'",
";",
"}",
"else",
"{",
"$",
"fields",
"=",
"'`'",
".",
"implode",
"(",
"'`, `'",
",",
"$",
"this",
"->",
"_fields",
")",
".",
"'`'",
";",
"}",
"$",
"query",
"=",
"\"\n SELECT\n $fields\n FROM\n `\"",
".",
"$",
"this",
"->",
"getDbPrefix",
"(",
")",
".",
"$",
"this",
"->",
"_dbContainer",
".",
"\"`\"",
";",
"if",
"(",
"$",
"this",
"->",
"_conditions",
"->",
"count",
"(",
")",
")",
"{",
"$",
"query",
".=",
"\"\n WHERE\n \"",
".",
"$",
"this",
"->",
"_conditions",
"->",
"getPreparedConditions",
"(",
"$",
"this",
"->",
"_dbContainer",
")",
".",
"\"\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_order",
")",
")",
"{",
"$",
"query",
".=",
"$",
"this",
"->",
"_formatOrder",
"(",
")",
";",
"}",
"if",
"(",
"$",
"pLimitOne",
")",
"{",
"$",
"query",
".=",
"' LIMIT 0, 1'",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"_limit",
"!==",
"NULL",
"or",
"$",
"this",
"->",
"_skip",
"!==",
"NULL",
")",
"{",
"$",
"query",
".=",
"$",
"this",
"->",
"_formatLimit",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_stm",
"=",
"Agl",
"::",
"app",
"(",
")",
"->",
"getDb",
"(",
")",
"->",
"getConnection",
"(",
")",
"->",
"prepare",
"(",
"$",
"query",
",",
"array",
"(",
"PDO",
"::",
"ATTR_CURSOR",
",",
"PDO",
"::",
"CURSOR_SCROLL",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_stm",
"->",
"execute",
"(",
"$",
"this",
"->",
"_conditions",
"->",
"getPreparedValues",
"(",
")",
")",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"_stm",
"->",
"errorInfo",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"The select query failed (table '\"",
".",
"$",
"this",
"->",
"getDbPrefix",
"(",
")",
".",
"$",
"this",
"->",
"_dbContainer",
".",
"\"') with message '\"",
".",
"$",
"error",
"[",
"2",
"]",
".",
"\"'\"",
")",
";",
"}",
"if",
"(",
"Agl",
"::",
"app",
"(",
")",
"->",
"isDebugMode",
"(",
")",
")",
"{",
"Agl",
"::",
"app",
"(",
")",
"->",
"getDb",
"(",
")",
"->",
"incrementCounter",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"e",
")",
";",
"}",
"}"
] |
Commit the select query to the database.
@return Select
|
[
"Commit",
"the",
"select",
"query",
"to",
"the",
"database",
"."
] |
1db556f9a49488aa9fab6887fefb7141a79ad97d
|
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mysql/Query/Select.php#L78-L127
|
236,179
|
agalbourdin/agl-core
|
src/Mysql/Query/Select.php
|
Select.fetchAll
|
public function fetchAll($pSingle = false)
{
if ($this->_stm === false) {
return array();
}
if ($pSingle) {
return $this->_stm->fetch(PDO::FETCH_ASSOC);
}
return $this->_stm->fetchAll(PDO::FETCH_ASSOC);
}
|
php
|
public function fetchAll($pSingle = false)
{
if ($this->_stm === false) {
return array();
}
if ($pSingle) {
return $this->_stm->fetch(PDO::FETCH_ASSOC);
}
return $this->_stm->fetchAll(PDO::FETCH_ASSOC);
}
|
[
"public",
"function",
"fetchAll",
"(",
"$",
"pSingle",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_stm",
"===",
"false",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"pSingle",
")",
"{",
"return",
"$",
"this",
"->",
"_stm",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_stm",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] |
Fetch all the results as array.
@param bool $pSingle Return a single row or an array of rows.
@return array
|
[
"Fetch",
"all",
"the",
"results",
"as",
"array",
"."
] |
1db556f9a49488aa9fab6887fefb7141a79ad97d
|
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mysql/Query/Select.php#L169-L180
|
236,180
|
agalbourdin/agl-core
|
src/Mysql/Query/Select.php
|
Select.fetchAllAsItems
|
public function fetchAllAsItems($pSingle = false)
{
$data = array();
if ($this->_stm === false) {
return $data;
}
while ($row = $this->_stm->fetch(PDO::FETCH_ASSOC)) {
if ($pSingle) {
return Agl::getModel($this->_dbContainer, $row);
}
$data[] = Agl::getModel($this->_dbContainer, $row);
}
return $data;
}
|
php
|
public function fetchAllAsItems($pSingle = false)
{
$data = array();
if ($this->_stm === false) {
return $data;
}
while ($row = $this->_stm->fetch(PDO::FETCH_ASSOC)) {
if ($pSingle) {
return Agl::getModel($this->_dbContainer, $row);
}
$data[] = Agl::getModel($this->_dbContainer, $row);
}
return $data;
}
|
[
"public",
"function",
"fetchAllAsItems",
"(",
"$",
"pSingle",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_stm",
"===",
"false",
")",
"{",
"return",
"$",
"data",
";",
"}",
"while",
"(",
"$",
"row",
"=",
"$",
"this",
"->",
"_stm",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"if",
"(",
"$",
"pSingle",
")",
"{",
"return",
"Agl",
"::",
"getModel",
"(",
"$",
"this",
"->",
"_dbContainer",
",",
"$",
"row",
")",
";",
"}",
"$",
"data",
"[",
"]",
"=",
"Agl",
"::",
"getModel",
"(",
"$",
"this",
"->",
"_dbContainer",
",",
"$",
"row",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Fetch all the results as array of items.
@param bool $pSingle Return a single Item or an array of Items.
@return array|Item
|
[
"Fetch",
"all",
"the",
"results",
"as",
"array",
"of",
"items",
"."
] |
1db556f9a49488aa9fab6887fefb7141a79ad97d
|
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mysql/Query/Select.php#L188-L205
|
236,181
|
gios-asu/nectary
|
src/configuration/configuration.php
|
Configuration.add
|
public function add( $key, $value ) {
if ( ! array_key_exists( $key, $this->attributes ) ) {
$this->attributes[ $key ] = $value;
} else {
if ( ! \is_array( $this->attributes[ $key ] ) ) {
$this->attributes[ $key ] = array( $this->attributes[ $key ], $value );
} else {
$this->attributes[ $key ][] = $value;
}
}
}
|
php
|
public function add( $key, $value ) {
if ( ! array_key_exists( $key, $this->attributes ) ) {
$this->attributes[ $key ] = $value;
} else {
if ( ! \is_array( $this->attributes[ $key ] ) ) {
$this->attributes[ $key ] = array( $this->attributes[ $key ], $value );
} else {
$this->attributes[ $key ][] = $value;
}
}
}
|
[
"public",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"attributes",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] |
Add to an new or existing value.
This will promote scalar values into an array to contain multiple values.
@param string $key
@param mixed $value
|
[
"Add",
"to",
"an",
"new",
"or",
"existing",
"value",
".",
"This",
"will",
"promote",
"scalar",
"values",
"into",
"an",
"array",
"to",
"contain",
"multiple",
"values",
"."
] |
f972c737a9036a3090652950a1309a62c07d86c0
|
https://github.com/gios-asu/nectary/blob/f972c737a9036a3090652950a1309a62c07d86c0/src/configuration/configuration.php#L48-L58
|
236,182
|
maestrano/maestrano-php
|
lib/Saml/Response.php
|
Maestrano_Saml_Response.getAttributes
|
public function getAttributes()
{
if ($this->cachedAttributes != null) {
return $this->cachedAttributes;
}
$entries = $this->_queryAssertion('/saml:AttributeStatement/saml:Attribute');
$this->cachedAttributes = array();
/** $entry DOMNode */
foreach ($entries as $entry) {
$attributeName = $entry->attributes->getNamedItem('Name')->nodeValue;
// Keep only one value for each entry type
foreach ($entry->childNodes as $childNode) {
if (is_a($childNode, 'DOMElement') && preg_match('/AttributeValue/',$childNode->tagName)){
$attributeValue = $childNode->nodeValue;
}
}
$this->cachedAttributes[$attributeName] = $attributeValue;
}
return $this->cachedAttributes;
}
|
php
|
public function getAttributes()
{
if ($this->cachedAttributes != null) {
return $this->cachedAttributes;
}
$entries = $this->_queryAssertion('/saml:AttributeStatement/saml:Attribute');
$this->cachedAttributes = array();
/** $entry DOMNode */
foreach ($entries as $entry) {
$attributeName = $entry->attributes->getNamedItem('Name')->nodeValue;
// Keep only one value for each entry type
foreach ($entry->childNodes as $childNode) {
if (is_a($childNode, 'DOMElement') && preg_match('/AttributeValue/',$childNode->tagName)){
$attributeValue = $childNode->nodeValue;
}
}
$this->cachedAttributes[$attributeName] = $attributeValue;
}
return $this->cachedAttributes;
}
|
[
"public",
"function",
"getAttributes",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cachedAttributes",
"!=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"cachedAttributes",
";",
"}",
"$",
"entries",
"=",
"$",
"this",
"->",
"_queryAssertion",
"(",
"'/saml:AttributeStatement/saml:Attribute'",
")",
";",
"$",
"this",
"->",
"cachedAttributes",
"=",
"array",
"(",
")",
";",
"/** $entry DOMNode */",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"entry",
")",
"{",
"$",
"attributeName",
"=",
"$",
"entry",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"'Name'",
")",
"->",
"nodeValue",
";",
"// Keep only one value for each entry type",
"foreach",
"(",
"$",
"entry",
"->",
"childNodes",
"as",
"$",
"childNode",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"childNode",
",",
"'DOMElement'",
")",
"&&",
"preg_match",
"(",
"'/AttributeValue/'",
",",
"$",
"childNode",
"->",
"tagName",
")",
")",
"{",
"$",
"attributeValue",
"=",
"$",
"childNode",
"->",
"nodeValue",
";",
"}",
"}",
"$",
"this",
"->",
"cachedAttributes",
"[",
"$",
"attributeName",
"]",
"=",
"$",
"attributeValue",
";",
"}",
"return",
"$",
"this",
"->",
"cachedAttributes",
";",
"}"
] |
Return the attributes of a SAML response
@return array
|
[
"Return",
"the",
"attributes",
"of",
"a",
"SAML",
"response"
] |
757cbefb0f0bf07cb35ea7442041d9bfdcce1558
|
https://github.com/maestrano/maestrano-php/blob/757cbefb0f0bf07cb35ea7442041d9bfdcce1558/lib/Saml/Response.php#L79-L102
|
236,183
|
rikby/console-helper
|
src/Helper/SimpleQuestionHelper.php
|
SimpleQuestionHelper.getFormattedQuestion
|
public function getFormattedQuestion($question, $default, array $options)
{
if ($this->isList($options)) {
/**
* Options list mode
*/
return $this->getFormattedListQuestion($question, $default, $options);
} else {
/**
* Simple options mode
*/
return $this->getFormattedSimpleQuestion($question, $default, $options);
}
}
|
php
|
public function getFormattedQuestion($question, $default, array $options)
{
if ($this->isList($options)) {
/**
* Options list mode
*/
return $this->getFormattedListQuestion($question, $default, $options);
} else {
/**
* Simple options mode
*/
return $this->getFormattedSimpleQuestion($question, $default, $options);
}
}
|
[
"public",
"function",
"getFormattedQuestion",
"(",
"$",
"question",
",",
"$",
"default",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isList",
"(",
"$",
"options",
")",
")",
"{",
"/**\n * Options list mode\n */",
"return",
"$",
"this",
"->",
"getFormattedListQuestion",
"(",
"$",
"question",
",",
"$",
"default",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"/**\n * Simple options mode\n */",
"return",
"$",
"this",
"->",
"getFormattedSimpleQuestion",
"(",
"$",
"question",
",",
"$",
"default",
",",
"$",
"options",
")",
";",
"}",
"}"
] |
Get formatted question
@param string $question
@param string $default
@param array $options
@return string
|
[
"Get",
"formatted",
"question"
] |
c618daf79e01439ea6cd60a75c9ff5b09de9b75d
|
https://github.com/rikby/console-helper/blob/c618daf79e01439ea6cd60a75c9ff5b09de9b75d/src/Helper/SimpleQuestionHelper.php#L94-L107
|
236,184
|
rikby/console-helper
|
src/Helper/SimpleQuestionHelper.php
|
SimpleQuestionHelper.getFormattedListQuestion
|
protected function getFormattedListQuestion($question, $default, array $options)
{
$list = '';
foreach ($options as $key => $title) {
$list .= " $key - $title".($default == $key ? ' (Default)' : '').PHP_EOL;
}
return $question.":\n".$list;
}
|
php
|
protected function getFormattedListQuestion($question, $default, array $options)
{
$list = '';
foreach ($options as $key => $title) {
$list .= " $key - $title".($default == $key ? ' (Default)' : '').PHP_EOL;
}
return $question.":\n".$list;
}
|
[
"protected",
"function",
"getFormattedListQuestion",
"(",
"$",
"question",
",",
"$",
"default",
",",
"array",
"$",
"options",
")",
"{",
"$",
"list",
"=",
"''",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"title",
")",
"{",
"$",
"list",
".=",
"\" $key - $title\"",
".",
"(",
"$",
"default",
"==",
"$",
"key",
"?",
"' (Default)'",
":",
"''",
")",
".",
"PHP_EOL",
";",
"}",
"return",
"$",
"question",
".",
"\":\\n\"",
".",
"$",
"list",
";",
"}"
] |
Get formatted "list" question
@param array $question
@param string|int $default
@param array $options
@return string
|
[
"Get",
"formatted",
"list",
"question"
] |
c618daf79e01439ea6cd60a75c9ff5b09de9b75d
|
https://github.com/rikby/console-helper/blob/c618daf79e01439ea6cd60a75c9ff5b09de9b75d/src/Helper/SimpleQuestionHelper.php#L128-L136
|
236,185
|
rikby/console-helper
|
src/Helper/SimpleQuestionHelper.php
|
SimpleQuestionHelper.getFormattedSimpleQuestion
|
protected function getFormattedSimpleQuestion($question, $default, array $options)
{
$question .= '%s';
$question = sprintf(
$question,
($options ? ' ('.implode('/', $options).')' : '')
);
return $question;
}
|
php
|
protected function getFormattedSimpleQuestion($question, $default, array $options)
{
$question .= '%s';
$question = sprintf(
$question,
($options ? ' ('.implode('/', $options).')' : '')
);
return $question;
}
|
[
"protected",
"function",
"getFormattedSimpleQuestion",
"(",
"$",
"question",
",",
"$",
"default",
",",
"array",
"$",
"options",
")",
"{",
"$",
"question",
".=",
"'%s'",
";",
"$",
"question",
"=",
"sprintf",
"(",
"$",
"question",
",",
"(",
"$",
"options",
"?",
"' ('",
".",
"implode",
"(",
"'/'",
",",
"$",
"options",
")",
".",
"')'",
":",
"''",
")",
")",
";",
"return",
"$",
"question",
";",
"}"
] |
Get formatted "simple" question
@param string $question
@param string $default
@param array $options
@return string
|
[
"Get",
"formatted",
"simple",
"question"
] |
c618daf79e01439ea6cd60a75c9ff5b09de9b75d
|
https://github.com/rikby/console-helper/blob/c618daf79e01439ea6cd60a75c9ff5b09de9b75d/src/Helper/SimpleQuestionHelper.php#L146-L155
|
236,186
|
rikby/console-helper
|
src/Helper/SimpleQuestionHelper.php
|
SimpleQuestionHelper.getValidator
|
protected function getValidator(array $options, $required, $optionValueIsAnswer)
{
// @codingStandardsIgnoreStart
if ($options) {
$useValue = $this->isList($options) && $optionValueIsAnswer;
return function ($value) use ($options, $useValue) {
if ($useValue && !array_key_exists($value, $options)
|| !$useValue && !in_array($value, $options, true)
) {
throw new LogicException("Incorrect value '$value'.");
}
return $useValue ? $options[$value] : $value;
};
} else {
return function ($value) use ($required) {
if ($required && (null === $value)) {
throw new LogicException('Empty value.');
}
return $value;
};
}
// @codingStandardsIgnoreEnd
}
|
php
|
protected function getValidator(array $options, $required, $optionValueIsAnswer)
{
// @codingStandardsIgnoreStart
if ($options) {
$useValue = $this->isList($options) && $optionValueIsAnswer;
return function ($value) use ($options, $useValue) {
if ($useValue && !array_key_exists($value, $options)
|| !$useValue && !in_array($value, $options, true)
) {
throw new LogicException("Incorrect value '$value'.");
}
return $useValue ? $options[$value] : $value;
};
} else {
return function ($value) use ($required) {
if ($required && (null === $value)) {
throw new LogicException('Empty value.');
}
return $value;
};
}
// @codingStandardsIgnoreEnd
}
|
[
"protected",
"function",
"getValidator",
"(",
"array",
"$",
"options",
",",
"$",
"required",
",",
"$",
"optionValueIsAnswer",
")",
"{",
"// @codingStandardsIgnoreStart",
"if",
"(",
"$",
"options",
")",
"{",
"$",
"useValue",
"=",
"$",
"this",
"->",
"isList",
"(",
"$",
"options",
")",
"&&",
"$",
"optionValueIsAnswer",
";",
"return",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"options",
",",
"$",
"useValue",
")",
"{",
"if",
"(",
"$",
"useValue",
"&&",
"!",
"array_key_exists",
"(",
"$",
"value",
",",
"$",
"options",
")",
"||",
"!",
"$",
"useValue",
"&&",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"options",
",",
"true",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"\"Incorrect value '$value'.\"",
")",
";",
"}",
"return",
"$",
"useValue",
"?",
"$",
"options",
"[",
"$",
"value",
"]",
":",
"$",
"value",
";",
"}",
";",
"}",
"else",
"{",
"return",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"required",
")",
"{",
"if",
"(",
"$",
"required",
"&&",
"(",
"null",
"===",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Empty value.'",
")",
";",
"}",
"return",
"$",
"value",
";",
"}",
";",
"}",
"// @codingStandardsIgnoreEnd",
"}"
] |
Get value validator
@param array $options
@param bool $required
@param bool $optionValueIsAnswer Value from options should be considered as an answer
@return \Closure
@throws LogicException
|
[
"Get",
"value",
"validator"
] |
c618daf79e01439ea6cd60a75c9ff5b09de9b75d
|
https://github.com/rikby/console-helper/blob/c618daf79e01439ea6cd60a75c9ff5b09de9b75d/src/Helper/SimpleQuestionHelper.php#L166-L191
|
236,187
|
chEbba/HttpApiAuth
|
src/Che/HttpApiAuth/CustomRequest.php
|
CustomRequest.copy
|
public static function copy(HttpRequest $request)
{
return new self(
$request->getHost(),
$request->getUri(),
$request->getMethod(),
$request->getHeaders(),
$request->getBody()
);
}
|
php
|
public static function copy(HttpRequest $request)
{
return new self(
$request->getHost(),
$request->getUri(),
$request->getMethod(),
$request->getHeaders(),
$request->getBody()
);
}
|
[
"public",
"static",
"function",
"copy",
"(",
"HttpRequest",
"$",
"request",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"request",
"->",
"getHost",
"(",
")",
",",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"request",
"->",
"getHeaders",
"(",
")",
",",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
";",
"}"
] |
Create copy from request
@param HttpRequest $request
@return CustomRequest
|
[
"Create",
"copy",
"from",
"request"
] |
99d017b2149a4956f5e942241e8b6c6efced7ea8
|
https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/CustomRequest.php#L49-L58
|
236,188
|
chEbba/HttpApiAuth
|
src/Che/HttpApiAuth/CustomRequest.php
|
CustomRequest.jsonSerialize
|
public function jsonSerialize()
{
return [
'host' => $this->host,
'uri' => $this->uri,
'method' => $this->method,
'headers' => $this->headers,
'body' => $this->body
];
}
|
php
|
public function jsonSerialize()
{
return [
'host' => $this->host,
'uri' => $this->uri,
'method' => $this->method,
'headers' => $this->headers,
'body' => $this->body
];
}
|
[
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"return",
"[",
"'host'",
"=>",
"$",
"this",
"->",
"host",
",",
"'uri'",
"=>",
"$",
"this",
"->",
"uri",
",",
"'method'",
"=>",
"$",
"this",
"->",
"method",
",",
"'headers'",
"=>",
"$",
"this",
"->",
"headers",
",",
"'body'",
"=>",
"$",
"this",
"->",
"body",
"]",
";",
"}"
] |
Serialize request properties for JSON as array
@return array
|
[
"Serialize",
"request",
"properties",
"for",
"JSON",
"as",
"array"
] |
99d017b2149a4956f5e942241e8b6c6efced7ea8
|
https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/CustomRequest.php#L105-L114
|
236,189
|
tmquang6805/phalex
|
library/Phalex/Di/Di.php
|
Di.setEventsManager
|
protected function setEventsManager()
{
$ev = new EventsManager();
$ev->enablePriorities(true);
$ev->collectResponses(true);
$this->set('eventsManager', $ev, true);
return $this;
}
|
php
|
protected function setEventsManager()
{
$ev = new EventsManager();
$ev->enablePriorities(true);
$ev->collectResponses(true);
$this->set('eventsManager', $ev, true);
return $this;
}
|
[
"protected",
"function",
"setEventsManager",
"(",
")",
"{",
"$",
"ev",
"=",
"new",
"EventsManager",
"(",
")",
";",
"$",
"ev",
"->",
"enablePriorities",
"(",
"true",
")",
";",
"$",
"ev",
"->",
"collectResponses",
"(",
"true",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'eventsManager'",
",",
"$",
"ev",
",",
"true",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Override events manager default in Phalcon
@return \Phalex\Di\Di
|
[
"Override",
"events",
"manager",
"default",
"in",
"Phalcon"
] |
6452b4e695b456838d9d553d96f2b114e1c110b4
|
https://github.com/tmquang6805/phalex/blob/6452b4e695b456838d9d553d96f2b114e1c110b4/library/Phalex/Di/Di.php#L37-L44
|
236,190
|
Niirrty/Niirrty.Translation
|
src/Sources/AbstractFileSource.php
|
AbstractFileSource.setData
|
public function setData( array $data, bool $doReload = true )
{
$this->logInfo( 'Manual set new data' . ( $doReload ? ' and reload.' : '.' ), __CLASS__ );
$this->_options[ 'data' ] = $data;
if ( $doReload )
{
$this->reload();
}
return $this;
}
|
php
|
public function setData( array $data, bool $doReload = true )
{
$this->logInfo( 'Manual set new data' . ( $doReload ? ' and reload.' : '.' ), __CLASS__ );
$this->_options[ 'data' ] = $data;
if ( $doReload )
{
$this->reload();
}
return $this;
}
|
[
"public",
"function",
"setData",
"(",
"array",
"$",
"data",
",",
"bool",
"$",
"doReload",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"logInfo",
"(",
"'Manual set new data'",
".",
"(",
"$",
"doReload",
"?",
"' and reload.'",
":",
"'.'",
")",
",",
"__CLASS__",
")",
";",
"$",
"this",
"->",
"_options",
"[",
"'data'",
"]",
"=",
"$",
"data",
";",
"if",
"(",
"$",
"doReload",
")",
"{",
"$",
"this",
"->",
"reload",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets a new array with translation data that should be used.
The array keys are the identifiers (string|int) the values must be arrays with items 'text' and optionally
with 'category' or the values is a string that will be converted to [ 'text' => $value ]
@param array $data
@param bool $doReload
@return \Niirrty\Translation\Sources\AbstractFileSource
|
[
"Sets",
"a",
"new",
"array",
"with",
"translation",
"data",
"that",
"should",
"be",
"used",
"."
] |
5b1ad27fb87c14435edd2dc03e9af46dd5062de8
|
https://github.com/Niirrty/Niirrty.Translation/blob/5b1ad27fb87c14435edd2dc03e9af46dd5062de8/src/Sources/AbstractFileSource.php#L152-L166
|
236,191
|
Niirrty/Niirrty.Translation
|
src/Sources/AbstractFileSource.php
|
AbstractFileSource.read
|
public function read( $identifier, $defaultTranslation = false )
{
if ( ! isset( $this->_options[ 'data' ] ) )
{
$this->reload();
}
if ( ! \is_int( $identifier ) && ! \is_string( $identifier ) )
{
// No identifier => RETURN ALL REGISTERED TRANSLATIONS
return $this->_options[ 'data' ];
}
// A known identifier format
if ( ! isset( $this->_options[ 'data' ][ $identifier ] ) )
{
// The translation not exists
return $defaultTranslation;
}
return $this->_options[ 'data' ][ $identifier ];
}
|
php
|
public function read( $identifier, $defaultTranslation = false )
{
if ( ! isset( $this->_options[ 'data' ] ) )
{
$this->reload();
}
if ( ! \is_int( $identifier ) && ! \is_string( $identifier ) )
{
// No identifier => RETURN ALL REGISTERED TRANSLATIONS
return $this->_options[ 'data' ];
}
// A known identifier format
if ( ! isset( $this->_options[ 'data' ][ $identifier ] ) )
{
// The translation not exists
return $defaultTranslation;
}
return $this->_options[ 'data' ][ $identifier ];
}
|
[
"public",
"function",
"read",
"(",
"$",
"identifier",
",",
"$",
"defaultTranslation",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_options",
"[",
"'data'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"reload",
"(",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"is_int",
"(",
"$",
"identifier",
")",
"&&",
"!",
"\\",
"is_string",
"(",
"$",
"identifier",
")",
")",
"{",
"// No identifier => RETURN ALL REGISTERED TRANSLATIONS",
"return",
"$",
"this",
"->",
"_options",
"[",
"'data'",
"]",
";",
"}",
"// A known identifier format",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_options",
"[",
"'data'",
"]",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"// The translation not exists",
"return",
"$",
"defaultTranslation",
";",
"}",
"return",
"$",
"this",
"->",
"_options",
"[",
"'data'",
"]",
"[",
"$",
"identifier",
"]",
";",
"}"
] |
Reads one or more translation values.
@param string|int $identifier
@param mixed $defaultTranslation Is returned if no translation was found for defined identifier.
@return mixed
|
[
"Reads",
"one",
"or",
"more",
"translation",
"values",
"."
] |
5b1ad27fb87c14435edd2dc03e9af46dd5062de8
|
https://github.com/Niirrty/Niirrty.Translation/blob/5b1ad27fb87c14435edd2dc03e9af46dd5062de8/src/Sources/AbstractFileSource.php#L182-L205
|
236,192
|
jannisfink/config
|
src/Configuration.php
|
Configuration.addConfigurationLoader
|
public static function addConfigurationLoader($id, $loader) {
if (array_key_exists($id, self::$configurationLoaders)) {
throw new \Exception("there is already a configuration loader for id $id");
}
$reflection = new \ReflectionClass($loader);
if (!$reflection->implementsInterface(ConfigurationLoader::class)) {
throw new \Exception("given loader must implement the ConfigurationLoader interface");
}
self::$configurationLoaders[$id] = $loader;
ksort(self::$configurationLoaders);
}
|
php
|
public static function addConfigurationLoader($id, $loader) {
if (array_key_exists($id, self::$configurationLoaders)) {
throw new \Exception("there is already a configuration loader for id $id");
}
$reflection = new \ReflectionClass($loader);
if (!$reflection->implementsInterface(ConfigurationLoader::class)) {
throw new \Exception("given loader must implement the ConfigurationLoader interface");
}
self::$configurationLoaders[$id] = $loader;
ksort(self::$configurationLoaders);
}
|
[
"public",
"static",
"function",
"addConfigurationLoader",
"(",
"$",
"id",
",",
"$",
"loader",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"self",
"::",
"$",
"configurationLoaders",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"there is already a configuration loader for id $id\"",
")",
";",
"}",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"loader",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"implementsInterface",
"(",
"ConfigurationLoader",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"given loader must implement the ConfigurationLoader interface\"",
")",
";",
"}",
"self",
"::",
"$",
"configurationLoaders",
"[",
"$",
"id",
"]",
"=",
"$",
"loader",
";",
"ksort",
"(",
"self",
"::",
"$",
"configurationLoaders",
")",
";",
"}"
] |
Add a new configuration loader to the list of supported configuration loaders
@param int $id id of the new loader. Must be unique
@param string $loader class name of the loader to use for this id
@throws \Exception if there is a configuration loader present for the given id or the given class name is no
configuration loader
|
[
"Add",
"a",
"new",
"configuration",
"loader",
"to",
"the",
"list",
"of",
"supported",
"configuration",
"loaders"
] |
54dc18c6125c971c46ded9f9484f6802112aab44
|
https://github.com/jannisfink/config/blob/54dc18c6125c971c46ded9f9484f6802112aab44/src/Configuration.php#L157-L169
|
236,193
|
Chill-project/Report
|
DataFixtures/ORM/LoadCustomFieldsGroup.php
|
LoadCustomFieldsGroup.createReport
|
private function createReport(
ObjectManager $manager,
array $name,
array $options = array())
{
echo $name['fr']." \n";
$cFGroup = (new CustomFieldsGroup())
->setName($name)
->setEntity('Chill\ReportBundle\Entity\Report')
->setOptions($options);
$manager->persist($cFGroup);
return $cFGroup;
}
|
php
|
private function createReport(
ObjectManager $manager,
array $name,
array $options = array())
{
echo $name['fr']." \n";
$cFGroup = (new CustomFieldsGroup())
->setName($name)
->setEntity('Chill\ReportBundle\Entity\Report')
->setOptions($options);
$manager->persist($cFGroup);
return $cFGroup;
}
|
[
"private",
"function",
"createReport",
"(",
"ObjectManager",
"$",
"manager",
",",
"array",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"echo",
"$",
"name",
"[",
"'fr'",
"]",
".",
"\" \\n\"",
";",
"$",
"cFGroup",
"=",
"(",
"new",
"CustomFieldsGroup",
"(",
")",
")",
"->",
"setName",
"(",
"$",
"name",
")",
"->",
"setEntity",
"(",
"'Chill\\ReportBundle\\Entity\\Report'",
")",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"manager",
"->",
"persist",
"(",
"$",
"cFGroup",
")",
";",
"return",
"$",
"cFGroup",
";",
"}"
] |
create a report and persist in the db
@param ObjectManager $manager
@param array $name
@return CustomFieldsGroup
|
[
"create",
"a",
"report",
"and",
"persist",
"in",
"the",
"db"
] |
ef718fe93a34f93a4827b3642e5da17c1566f6ae
|
https://github.com/Chill-project/Report/blob/ef718fe93a34f93a4827b3642e5da17c1566f6ae/DataFixtures/ORM/LoadCustomFieldsGroup.php#L73-L88
|
236,194
|
DevGroup-ru/dotplant-entity-structure
|
src/commands/StructureController.php
|
StructureController.actionRegenerateSlugs
|
public function actionRegenerateSlugs()
{
$this->elements = (new Query())
->select(['id', 'parent_id'])
->from(BaseStructure::tableName())
->orderBy(['parent_id' => SORT_ASC])
->indexBy('id')
->all();
foreach ($this->elements as &$element) {
if ((int)$element['parent_id'] === 0) {
$this->setTreeUrl($element);
}
}
}
|
php
|
public function actionRegenerateSlugs()
{
$this->elements = (new Query())
->select(['id', 'parent_id'])
->from(BaseStructure::tableName())
->orderBy(['parent_id' => SORT_ASC])
->indexBy('id')
->all();
foreach ($this->elements as &$element) {
if ((int)$element['parent_id'] === 0) {
$this->setTreeUrl($element);
}
}
}
|
[
"public",
"function",
"actionRegenerateSlugs",
"(",
")",
"{",
"$",
"this",
"->",
"elements",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'id'",
",",
"'parent_id'",
"]",
")",
"->",
"from",
"(",
"BaseStructure",
"::",
"tableName",
"(",
")",
")",
"->",
"orderBy",
"(",
"[",
"'parent_id'",
"=>",
"SORT_ASC",
"]",
")",
"->",
"indexBy",
"(",
"'id'",
")",
"->",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"&",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"int",
")",
"$",
"element",
"[",
"'parent_id'",
"]",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"setTreeUrl",
"(",
"$",
"element",
")",
";",
"}",
"}",
"}"
] |
Check and regenerate compiled urls
|
[
"Check",
"and",
"regenerate",
"compiled",
"urls"
] |
43e3354b5ebf9171e9afef38d82dccb02357bfed
|
https://github.com/DevGroup-ru/dotplant-entity-structure/blob/43e3354b5ebf9171e9afef38d82dccb02357bfed/src/commands/StructureController.php#L24-L38
|
236,195
|
antarctica/laravel-base-exceptions
|
src/Exception/InvalidArgumentTypeException.php
|
InvalidArgumentTypeException.constructException
|
private function constructException()
{
$this->details['argument_type_error'][$this->argument] = $this->details['argument_type_error']['ARG'];
$this->details['argument_type_error'][$this->argument] = str_replace(['VAR_TYPE', 'ARG_TYPE'], [$this->argumentValueType, $this->argumentType], $this->details['argument_type_error'][$this->argument]);
unset($this->details['argument_type_error']['ARG']);
$this->resolution = str_replace('ARG_TYPE', $this->argumentType, $this->resolution);
}
|
php
|
private function constructException()
{
$this->details['argument_type_error'][$this->argument] = $this->details['argument_type_error']['ARG'];
$this->details['argument_type_error'][$this->argument] = str_replace(['VAR_TYPE', 'ARG_TYPE'], [$this->argumentValueType, $this->argumentType], $this->details['argument_type_error'][$this->argument]);
unset($this->details['argument_type_error']['ARG']);
$this->resolution = str_replace('ARG_TYPE', $this->argumentType, $this->resolution);
}
|
[
"private",
"function",
"constructException",
"(",
")",
"{",
"$",
"this",
"->",
"details",
"[",
"'argument_type_error'",
"]",
"[",
"$",
"this",
"->",
"argument",
"]",
"=",
"$",
"this",
"->",
"details",
"[",
"'argument_type_error'",
"]",
"[",
"'ARG'",
"]",
";",
"$",
"this",
"->",
"details",
"[",
"'argument_type_error'",
"]",
"[",
"$",
"this",
"->",
"argument",
"]",
"=",
"str_replace",
"(",
"[",
"'VAR_TYPE'",
",",
"'ARG_TYPE'",
"]",
",",
"[",
"$",
"this",
"->",
"argumentValueType",
",",
"$",
"this",
"->",
"argumentType",
"]",
",",
"$",
"this",
"->",
"details",
"[",
"'argument_type_error'",
"]",
"[",
"$",
"this",
"->",
"argument",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"details",
"[",
"'argument_type_error'",
"]",
"[",
"'ARG'",
"]",
")",
";",
"$",
"this",
"->",
"resolution",
"=",
"str_replace",
"(",
"'ARG_TYPE'",
",",
"$",
"this",
"->",
"argumentType",
",",
"$",
"this",
"->",
"resolution",
")",
";",
"}"
] |
Fill in 'templates' with given values
|
[
"Fill",
"in",
"templates",
"with",
"given",
"values"
] |
c5747b51dcf31e91ccc038302a0bb9a74d3daefc
|
https://github.com/antarctica/laravel-base-exceptions/blob/c5747b51dcf31e91ccc038302a0bb9a74d3daefc/src/Exception/InvalidArgumentTypeException.php#L59-L66
|
236,196
|
ampersa/safebrowsing
|
src/SafeBrowsing.php
|
SafeBrowsing.listed
|
public function listed(string $url, $returnType = false)
{
if (empty($this->apiKey)) {
throw new Exception('A Google Safebrowsing API key has not been specified');
}
// Retrieve the result from SafeBrowsing
$result = $this->getSafebrowsingResult($url);
// Check for exististance of the supplied URL in any matches
if (is_object($result) and isset($result->matches)) {
foreach ($result->matches as $match) {
if ($match->threat->url == $url) {
// Return the Threat Type if requested,
// otherwise return true
if ($returnType) {
return $match->threatType;
}
return true;
}
}
}
return false;
}
|
php
|
public function listed(string $url, $returnType = false)
{
if (empty($this->apiKey)) {
throw new Exception('A Google Safebrowsing API key has not been specified');
}
// Retrieve the result from SafeBrowsing
$result = $this->getSafebrowsingResult($url);
// Check for exististance of the supplied URL in any matches
if (is_object($result) and isset($result->matches)) {
foreach ($result->matches as $match) {
if ($match->threat->url == $url) {
// Return the Threat Type if requested,
// otherwise return true
if ($returnType) {
return $match->threatType;
}
return true;
}
}
}
return false;
}
|
[
"public",
"function",
"listed",
"(",
"string",
"$",
"url",
",",
"$",
"returnType",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"apiKey",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'A Google Safebrowsing API key has not been specified'",
")",
";",
"}",
"// Retrieve the result from SafeBrowsing",
"$",
"result",
"=",
"$",
"this",
"->",
"getSafebrowsingResult",
"(",
"$",
"url",
")",
";",
"// Check for exististance of the supplied URL in any matches",
"if",
"(",
"is_object",
"(",
"$",
"result",
")",
"and",
"isset",
"(",
"$",
"result",
"->",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"result",
"->",
"matches",
"as",
"$",
"match",
")",
"{",
"if",
"(",
"$",
"match",
"->",
"threat",
"->",
"url",
"==",
"$",
"url",
")",
"{",
"// Return the Threat Type if requested,",
"// otherwise return true",
"if",
"(",
"$",
"returnType",
")",
"{",
"return",
"$",
"match",
"->",
"threatType",
";",
"}",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Return listed status from Google Safebrowsing. Returns true on listed status
@param string $url
@param bool $returnType
@return bool|string
|
[
"Return",
"listed",
"status",
"from",
"Google",
"Safebrowsing",
".",
"Returns",
"true",
"on",
"listed",
"status"
] |
6fb83626ba7441d10f431a701718fe7365def6b3
|
https://github.com/ampersa/safebrowsing/blob/6fb83626ba7441d10f431a701718fe7365def6b3/src/SafeBrowsing.php#L39-L64
|
236,197
|
ampersa/safebrowsing
|
src/SafeBrowsing.php
|
SafeBrowsing.getSafebrowsingResult
|
protected function getSafebrowsingResult(string $url)
{
// Prepare the Safebrowsing API URL and
// populate the API key for the request
$safebrowsingUrl = sprintf('https://safebrowsing.googleapis.com/v4/threatMatches:find?key=%s', $this->apiKey);
// Prepare the payload that will be sent
// to Google Safebrowsing API as JSON
$safebrowsingPayload = [
'client' => [
'clientId' => 'Ampersa/SafeBrowsing',
'clientVersion' => '0.1',
],
'threatInfo' => [
'threatTypes' => [
'MALWARE',
'SOCIAL_ENGINEERING',
'UNWANTED_SOFTWARE',
'POTENTIALLY_HARMFUL_APPLICATION',
],
'platformTypes' => [
'ANY_PLATFORM'
],
'threatEntryTypes' => [
'URL',
],
'threatEntries' => [
[
'url' => $url
],
],
]
];
// Prepare the request and get the response
try {
$response = (new HttpClient)->post($safebrowsingUrl, [
'json' => $safebrowsingPayload
]);
} catch (Exception $e) {
return new StdClass;
}
// Retrieve and decode the result from the response
$result = json_decode((string) $response->getBody());
return $result;
}
|
php
|
protected function getSafebrowsingResult(string $url)
{
// Prepare the Safebrowsing API URL and
// populate the API key for the request
$safebrowsingUrl = sprintf('https://safebrowsing.googleapis.com/v4/threatMatches:find?key=%s', $this->apiKey);
// Prepare the payload that will be sent
// to Google Safebrowsing API as JSON
$safebrowsingPayload = [
'client' => [
'clientId' => 'Ampersa/SafeBrowsing',
'clientVersion' => '0.1',
],
'threatInfo' => [
'threatTypes' => [
'MALWARE',
'SOCIAL_ENGINEERING',
'UNWANTED_SOFTWARE',
'POTENTIALLY_HARMFUL_APPLICATION',
],
'platformTypes' => [
'ANY_PLATFORM'
],
'threatEntryTypes' => [
'URL',
],
'threatEntries' => [
[
'url' => $url
],
],
]
];
// Prepare the request and get the response
try {
$response = (new HttpClient)->post($safebrowsingUrl, [
'json' => $safebrowsingPayload
]);
} catch (Exception $e) {
return new StdClass;
}
// Retrieve and decode the result from the response
$result = json_decode((string) $response->getBody());
return $result;
}
|
[
"protected",
"function",
"getSafebrowsingResult",
"(",
"string",
"$",
"url",
")",
"{",
"// Prepare the Safebrowsing API URL and",
"// populate the API key for the request",
"$",
"safebrowsingUrl",
"=",
"sprintf",
"(",
"'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=%s'",
",",
"$",
"this",
"->",
"apiKey",
")",
";",
"// Prepare the payload that will be sent",
"// to Google Safebrowsing API as JSON",
"$",
"safebrowsingPayload",
"=",
"[",
"'client'",
"=>",
"[",
"'clientId'",
"=>",
"'Ampersa/SafeBrowsing'",
",",
"'clientVersion'",
"=>",
"'0.1'",
",",
"]",
",",
"'threatInfo'",
"=>",
"[",
"'threatTypes'",
"=>",
"[",
"'MALWARE'",
",",
"'SOCIAL_ENGINEERING'",
",",
"'UNWANTED_SOFTWARE'",
",",
"'POTENTIALLY_HARMFUL_APPLICATION'",
",",
"]",
",",
"'platformTypes'",
"=>",
"[",
"'ANY_PLATFORM'",
"]",
",",
"'threatEntryTypes'",
"=>",
"[",
"'URL'",
",",
"]",
",",
"'threatEntries'",
"=>",
"[",
"[",
"'url'",
"=>",
"$",
"url",
"]",
",",
"]",
",",
"]",
"]",
";",
"// Prepare the request and get the response",
"try",
"{",
"$",
"response",
"=",
"(",
"new",
"HttpClient",
")",
"->",
"post",
"(",
"$",
"safebrowsingUrl",
",",
"[",
"'json'",
"=>",
"$",
"safebrowsingPayload",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"new",
"StdClass",
";",
"}",
"// Retrieve and decode the result from the response",
"$",
"result",
"=",
"json_decode",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Prepare the request to Google Safebrowsing, retrieve the result
and decode before returning.
@param string $url
@return object
|
[
"Prepare",
"the",
"request",
"to",
"Google",
"Safebrowsing",
"retrieve",
"the",
"result",
"and",
"decode",
"before",
"returning",
"."
] |
6fb83626ba7441d10f431a701718fe7365def6b3
|
https://github.com/ampersa/safebrowsing/blob/6fb83626ba7441d10f431a701718fe7365def6b3/src/SafeBrowsing.php#L72-L119
|
236,198
|
eix/core
|
src/php/main/Eix/Core/User.php
|
User.checkAuthorisation
|
public function checkAuthorisation($object, $functionName)
{
// Check whether the user has authenticated.
if ($this->isAuthenticated()) {
// The user is authenticated. Proceed.
$class = $object;
if (is_object($class)) {
$class = get_class($class);
}
Logger::get()->debug("Checking authorisation for {$class}:{$functionName}...");
// Check that at least one condition is valid.
if (!(
// User has total authorisation.
in_array('*', $this->permissions)
// User has total class authorisation for this class.
|| @$this->permissions[$class]['*']
// User has authorisation for this function in this class.
|| @$this->permissions[$class][$functionName]
)) {
// User has no authorisation.
throw new NotAuthorisedException("The current user does not have permission for '{$class}.{$functionName}'.");
}
Logger::get()->debug('Authorised.');
} else {
// The user is not authenticated.
throw new NotAuthenticatedException('There is no current authenticated user.');
}
}
|
php
|
public function checkAuthorisation($object, $functionName)
{
// Check whether the user has authenticated.
if ($this->isAuthenticated()) {
// The user is authenticated. Proceed.
$class = $object;
if (is_object($class)) {
$class = get_class($class);
}
Logger::get()->debug("Checking authorisation for {$class}:{$functionName}...");
// Check that at least one condition is valid.
if (!(
// User has total authorisation.
in_array('*', $this->permissions)
// User has total class authorisation for this class.
|| @$this->permissions[$class]['*']
// User has authorisation for this function in this class.
|| @$this->permissions[$class][$functionName]
)) {
// User has no authorisation.
throw new NotAuthorisedException("The current user does not have permission for '{$class}.{$functionName}'.");
}
Logger::get()->debug('Authorised.');
} else {
// The user is not authenticated.
throw new NotAuthenticatedException('There is no current authenticated user.');
}
}
|
[
"public",
"function",
"checkAuthorisation",
"(",
"$",
"object",
",",
"$",
"functionName",
")",
"{",
"// Check whether the user has authenticated.",
"if",
"(",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"// The user is authenticated. Proceed.",
"$",
"class",
"=",
"$",
"object",
";",
"if",
"(",
"is_object",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"class",
")",
";",
"}",
"Logger",
"::",
"get",
"(",
")",
"->",
"debug",
"(",
"\"Checking authorisation for {$class}:{$functionName}...\"",
")",
";",
"// Check that at least one condition is valid.",
"if",
"(",
"!",
"(",
"// User has total authorisation.",
"in_array",
"(",
"'*'",
",",
"$",
"this",
"->",
"permissions",
")",
"// User has total class authorisation for this class.",
"||",
"@",
"$",
"this",
"->",
"permissions",
"[",
"$",
"class",
"]",
"[",
"'*'",
"]",
"// User has authorisation for this function in this class.",
"||",
"@",
"$",
"this",
"->",
"permissions",
"[",
"$",
"class",
"]",
"[",
"$",
"functionName",
"]",
")",
")",
"{",
"// User has no authorisation.",
"throw",
"new",
"NotAuthorisedException",
"(",
"\"The current user does not have permission for '{$class}.{$functionName}'.\"",
")",
";",
"}",
"Logger",
"::",
"get",
"(",
")",
"->",
"debug",
"(",
"'Authorised.'",
")",
";",
"}",
"else",
"{",
"// The user is not authenticated.",
"throw",
"new",
"NotAuthenticatedException",
"(",
"'There is no current authenticated user.'",
")",
";",
"}",
"}"
] |
Checks whether a user is allowed to execute a particular function in a
class.
@param mixed $object the object or class name that contains the function.
@param type $functionName the function name to execute.
@throws NotAuthorisedException
|
[
"Checks",
"whether",
"a",
"user",
"is",
"allowed",
"to",
"execute",
"a",
"particular",
"function",
"in",
"a",
"class",
"."
] |
a5b4c09cc168221e85804fdfeb78e519a0415466
|
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/User.php#L121-L151
|
236,199
|
eix/core
|
src/php/main/Eix/Core/User.php
|
User.destroy
|
public function destroy()
{
parent::destroy();
Logger::get()->debug('Destroying user ' . $this->id);
// If this user is the one stored in the session, destroy that too.
if (!empty($_SESSION) && ($_SESSION['current_user'] == $this)) {
unset($_SESSION['current_user']);
}
}
|
php
|
public function destroy()
{
parent::destroy();
Logger::get()->debug('Destroying user ' . $this->id);
// If this user is the one stored in the session, destroy that too.
if (!empty($_SESSION) && ($_SESSION['current_user'] == $this)) {
unset($_SESSION['current_user']);
}
}
|
[
"public",
"function",
"destroy",
"(",
")",
"{",
"parent",
"::",
"destroy",
"(",
")",
";",
"Logger",
"::",
"get",
"(",
")",
"->",
"debug",
"(",
"'Destroying user '",
".",
"$",
"this",
"->",
"id",
")",
";",
"// If this user is the one stored in the session, destroy that too.",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SESSION",
")",
"&&",
"(",
"$",
"_SESSION",
"[",
"'current_user'",
"]",
"==",
"$",
"this",
")",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"'current_user'",
"]",
")",
";",
"}",
"}"
] |
Flag the user as no longer in existence, so that it does not
automatically get saved in the session.
|
[
"Flag",
"the",
"user",
"as",
"no",
"longer",
"in",
"existence",
"so",
"that",
"it",
"does",
"not",
"automatically",
"get",
"saved",
"in",
"the",
"session",
"."
] |
a5b4c09cc168221e85804fdfeb78e519a0415466
|
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/User.php#L157-L166
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.