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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
nails/module-email | src/Service/Emailer.php | Emailer.trackOpen | public function trackOpen($ref)
{
$oEmail = $this->getByRef($ref);
if ($oEmail) {
// Update the read count and a add a track data point
$oDb = Factory::service('Database');
$oDb->set('read_count', 'read_count+1', false);
$oDb->where('id', $oEmail->id);
$oDb->update($this->sTable);
$oDb->set('created', 'NOW()', false);
$oDb->set('email_id', $oEmail->id);
if (activeUser('id')) {
$oDb->set('user_id', activeUser('id'));
}
$oDb->insert(NAILS_DB_PREFIX . 'email_archive_track_open');
}
} | php | public function trackOpen($ref)
{
$oEmail = $this->getByRef($ref);
if ($oEmail) {
// Update the read count and a add a track data point
$oDb = Factory::service('Database');
$oDb->set('read_count', 'read_count+1', false);
$oDb->where('id', $oEmail->id);
$oDb->update($this->sTable);
$oDb->set('created', 'NOW()', false);
$oDb->set('email_id', $oEmail->id);
if (activeUser('id')) {
$oDb->set('user_id', activeUser('id'));
}
$oDb->insert(NAILS_DB_PREFIX . 'email_archive_track_open');
}
} | [
"public",
"function",
"trackOpen",
"(",
"$",
"ref",
")",
"{",
"$",
"oEmail",
"=",
"$",
"this",
"->",
"getByRef",
"(",
"$",
"ref",
")",
";",
"if",
"(",
"$",
"oEmail",
")",
"{",
"// Update the read count and a add a track data point",
"$",
"oDb",
"=",
"Fact... | Increments an email's open count and adds a tracking note
@param string $ref The email's reference
@return void | [
"Increments",
"an",
"email",
"s",
"open",
"count",
"and",
"adds",
"a",
"tracking",
"note"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L1110-L1130 | train |
nails/module-email | src/Service/Emailer.php | Emailer.trackLink | public function trackLink($sRef, $iLinkId)
{
$oEmail = $this->getByRef($sRef);
if ($oEmail) {
// Get the link which was clicked
$oDb = Factory::service('Database');
$oDb->select('id, url');
$oDb->where('email_id', $oEmail->id);
$oDb->where('id', $iLinkId);
$oLink = $oDb->get(NAILS_DB_PREFIX . 'email_archive_link')->row();
if ($oLink) {
// Update the read count and a add a track data point
$oDb->set('link_click_count', 'link_click_count+1', false);
$oDb->where('id', $oEmail->id);
$oDb->update($this->sTable);
// Add a link trackback
$oDb->set('created', 'NOW()', false);
$oDb->set('email_id', $oEmail->id);
$oDb->set('link_id', $oLink->id);
if (activeUser('id')) {
$oDb->set('user_id', activeUser('id'));
}
$oDb->insert(NAILS_DB_PREFIX . 'email_archive_track_link');
// Return the URL to go to
return $oLink->url;
} else {
return false;
}
}
return false;
} | php | public function trackLink($sRef, $iLinkId)
{
$oEmail = $this->getByRef($sRef);
if ($oEmail) {
// Get the link which was clicked
$oDb = Factory::service('Database');
$oDb->select('id, url');
$oDb->where('email_id', $oEmail->id);
$oDb->where('id', $iLinkId);
$oLink = $oDb->get(NAILS_DB_PREFIX . 'email_archive_link')->row();
if ($oLink) {
// Update the read count and a add a track data point
$oDb->set('link_click_count', 'link_click_count+1', false);
$oDb->where('id', $oEmail->id);
$oDb->update($this->sTable);
// Add a link trackback
$oDb->set('created', 'NOW()', false);
$oDb->set('email_id', $oEmail->id);
$oDb->set('link_id', $oLink->id);
if (activeUser('id')) {
$oDb->set('user_id', activeUser('id'));
}
$oDb->insert(NAILS_DB_PREFIX . 'email_archive_track_link');
// Return the URL to go to
return $oLink->url;
} else {
return false;
}
}
return false;
} | [
"public",
"function",
"trackLink",
"(",
"$",
"sRef",
",",
"$",
"iLinkId",
")",
"{",
"$",
"oEmail",
"=",
"$",
"this",
"->",
"getByRef",
"(",
"$",
"sRef",
")",
";",
"if",
"(",
"$",
"oEmail",
")",
"{",
"// Get the link which was clicked",
"$",
"oDb",
"="... | Increments a link's open count and adds a tracking note
@param string $sRef The email's reference
@param integer $iLinkId The link's ID
@return string
@throws \Nails\Common\Exception\FactoryException | [
"Increments",
"a",
"link",
"s",
"open",
"count",
"and",
"adds",
"a",
"tracking",
"note"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L1143-L1183 | train |
nails/module-email | src/Service/Emailer.php | Emailer.processLinkGenerate | protected function processLinkGenerate($html, $url, $title, $is_html)
{
// Ensure URLs have a domain
if (preg_match('/^\//', $url)) {
$url = $this->getDomain() . $url;
}
/**
* Generate a tracking URL for this link
* Firstly, check this URL hasn't been processed already (for this email)
*/
if (isset($this->aTrackLinkCache[md5($url)])) {
$trackingUrl = $this->aTrackLinkCache[md5($url)];
// Replace the URL and return the new tag
$html = str_replace($url, $trackingUrl, $html);
} else {
/**
* New URL, needs processed. We take the URL and the Title, store it in the
* database and generate the new tracking link (inc. hashes etc). We'll cache
* this link so we don't have to process it again.
*
* If the email we're sending to hasn't been verified yet we should set the
* actual URL as the return_to value of the email verifier, that means that
* every link in this email behaves as a verifying email. Obviously we shouldn't
* do this for the actual email verifier...
*/
if ($this->mGenerateTrackingNeedsVerified) {
// Make sure we're not applying this to an activation URL
if (!preg_match('#email/verify/[0-9]*?/(.*?)#', $url)) {
$_user_id = $this->mGenerateTrackingNeedsVerified['id'];
$_code = $this->mGenerateTrackingNeedsVerified['code'];
$_return = urlencode($url);
$_url = site_url('email/verify/' . $_user_id . '/' . $_code . '?return_to=' . $_return);
} else {
$_url = $url;
}
} else {
$_url = $url;
}
$oDb = Factory::service('Database');
$oDb->set('email_id', $this->iGenerateTrackingEmailId);
$oDb->set('url', $_url);
$oDb->set('title', $title);
$oDb->set('created', 'NOW()', false);
$oDb->set('is_html', $is_html);
$oDb->insert(NAILS_DB_PREFIX . 'email_archive_link');
$_id = $oDb->insert_id();
if ($_id) {
$_time = time();
$trackingUrl = 'email/tracker/link/' . $this->sGenerateTrackingEmailRef . '/' . $_time . '/';
$trackingUrl .= $this->generateHash($this->sGenerateTrackingEmailRef, $_time) . '/' . $_id;
$trackingUrl = site_url($trackingUrl);
$this->aTrackLinkCache[md5($url)] = $trackingUrl;
// --------------------------------------------------------------------------
/**
* Replace the URL and return the new tag. $url in quotes so we only replace
* hyperlinks and not something else, such as an image's URL
*/
$html = str_replace('"' . $url . '"', $trackingUrl, $html);
}
}
return $html;
} | php | protected function processLinkGenerate($html, $url, $title, $is_html)
{
// Ensure URLs have a domain
if (preg_match('/^\//', $url)) {
$url = $this->getDomain() . $url;
}
/**
* Generate a tracking URL for this link
* Firstly, check this URL hasn't been processed already (for this email)
*/
if (isset($this->aTrackLinkCache[md5($url)])) {
$trackingUrl = $this->aTrackLinkCache[md5($url)];
// Replace the URL and return the new tag
$html = str_replace($url, $trackingUrl, $html);
} else {
/**
* New URL, needs processed. We take the URL and the Title, store it in the
* database and generate the new tracking link (inc. hashes etc). We'll cache
* this link so we don't have to process it again.
*
* If the email we're sending to hasn't been verified yet we should set the
* actual URL as the return_to value of the email verifier, that means that
* every link in this email behaves as a verifying email. Obviously we shouldn't
* do this for the actual email verifier...
*/
if ($this->mGenerateTrackingNeedsVerified) {
// Make sure we're not applying this to an activation URL
if (!preg_match('#email/verify/[0-9]*?/(.*?)#', $url)) {
$_user_id = $this->mGenerateTrackingNeedsVerified['id'];
$_code = $this->mGenerateTrackingNeedsVerified['code'];
$_return = urlencode($url);
$_url = site_url('email/verify/' . $_user_id . '/' . $_code . '?return_to=' . $_return);
} else {
$_url = $url;
}
} else {
$_url = $url;
}
$oDb = Factory::service('Database');
$oDb->set('email_id', $this->iGenerateTrackingEmailId);
$oDb->set('url', $_url);
$oDb->set('title', $title);
$oDb->set('created', 'NOW()', false);
$oDb->set('is_html', $is_html);
$oDb->insert(NAILS_DB_PREFIX . 'email_archive_link');
$_id = $oDb->insert_id();
if ($_id) {
$_time = time();
$trackingUrl = 'email/tracker/link/' . $this->sGenerateTrackingEmailRef . '/' . $_time . '/';
$trackingUrl .= $this->generateHash($this->sGenerateTrackingEmailRef, $_time) . '/' . $_id;
$trackingUrl = site_url($trackingUrl);
$this->aTrackLinkCache[md5($url)] = $trackingUrl;
// --------------------------------------------------------------------------
/**
* Replace the URL and return the new tag. $url in quotes so we only replace
* hyperlinks and not something else, such as an image's URL
*/
$html = str_replace('"' . $url . '"', $trackingUrl, $html);
}
}
return $html;
} | [
"protected",
"function",
"processLinkGenerate",
"(",
"$",
"html",
",",
"$",
"url",
",",
"$",
"title",
",",
"$",
"is_html",
")",
"{",
"// Ensure URLs have a domain",
"if",
"(",
"preg_match",
"(",
"'/^\\//'",
",",
"$",
"url",
")",
")",
"{",
"$",
"url",
"=... | Generate a tracking URL
@param string $html The Link HTML
@param string $url The Link's URL
@param string $title The Link's Title
@param boolean $is_html Whether this is HTML or not
@return string
@throws HostNotKnownException
@throws \Nails\Common\Exception\FactoryException | [
"Generate",
"a",
"tracking",
"URL"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L1298-L1380 | train |
nails/module-email | src/Service/Emailer.php | Emailer.getDomain | protected function getDomain()
{
if (!empty($this->sDomain)) {
return $this->sDomain;
} elseif (site_url() === '/') {
$oInput = Factory::service('Input');
$sHost = $oInput->server('SERVER_NAME');
$sProtocol = $oInput->server('REQUEST_SCHEME') ?: 'http';
if (empty($sHost)) {
throw new HostNotKnownException('Failed to resolve host; email links will be incomplete.');
} else {
$this->sDomain = $sProtocol . '://' . $sHost . '/';
}
} else {
$this->sDomain = site_url();
}
$this->sDomain = rtrim($this->sDomain, '/');
return $this->sDomain;
} | php | protected function getDomain()
{
if (!empty($this->sDomain)) {
return $this->sDomain;
} elseif (site_url() === '/') {
$oInput = Factory::service('Input');
$sHost = $oInput->server('SERVER_NAME');
$sProtocol = $oInput->server('REQUEST_SCHEME') ?: 'http';
if (empty($sHost)) {
throw new HostNotKnownException('Failed to resolve host; email links will be incomplete.');
} else {
$this->sDomain = $sProtocol . '://' . $sHost . '/';
}
} else {
$this->sDomain = site_url();
}
$this->sDomain = rtrim($this->sDomain, '/');
return $this->sDomain;
} | [
"protected",
"function",
"getDomain",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"sDomain",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sDomain",
";",
"}",
"elseif",
"(",
"site_url",
"(",
")",
"===",
"'/'",
")",
"{",
"$",
"o... | Returns the domain to use for the email
@return string
@throws HostNotKnownException
@throws \Nails\Common\Exception\FactoryException | [
"Returns",
"the",
"domain",
"to",
"use",
"for",
"the",
"email"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L1391-L1410 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.createXmlDocument | public static function createXmlDocument($docOptions = 0)
{
$xmldoc = new DOMDocument(self::XML_VERSION, self::XML_ENCODING);
$xmldoc->preserveWhiteSpace =
($docOptions & XMLUTIL_OPT_DONT_PRESERVE_WHITESPACE) != XMLUTIL_OPT_DONT_PRESERVE_WHITESPACE
;
$xmldoc->formatOutput = false;
if (($docOptions & XMLUTIL_OPT_FORMAT_OUTPUT) == XMLUTIL_OPT_FORMAT_OUTPUT) {
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;
}
XmlUtil::$xmlNsPrefix[spl_object_hash($xmldoc)] = array();
return $xmldoc;
} | php | public static function createXmlDocument($docOptions = 0)
{
$xmldoc = new DOMDocument(self::XML_VERSION, self::XML_ENCODING);
$xmldoc->preserveWhiteSpace =
($docOptions & XMLUTIL_OPT_DONT_PRESERVE_WHITESPACE) != XMLUTIL_OPT_DONT_PRESERVE_WHITESPACE
;
$xmldoc->formatOutput = false;
if (($docOptions & XMLUTIL_OPT_FORMAT_OUTPUT) == XMLUTIL_OPT_FORMAT_OUTPUT) {
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;
}
XmlUtil::$xmlNsPrefix[spl_object_hash($xmldoc)] = array();
return $xmldoc;
} | [
"public",
"static",
"function",
"createXmlDocument",
"(",
"$",
"docOptions",
"=",
"0",
")",
"{",
"$",
"xmldoc",
"=",
"new",
"DOMDocument",
"(",
"self",
"::",
"XML_VERSION",
",",
"self",
"::",
"XML_ENCODING",
")",
";",
"$",
"xmldoc",
"->",
"preserveWhiteSpace... | Create an empty XmlDocument object with some default parameters
@param int $docOptions
@return DOMDocument object | [
"Create",
"an",
"empty",
"XmlDocument",
"object",
"with",
"some",
"default",
"parameters"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L43-L56 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.createXmlDocumentFromFile | public static function createXmlDocumentFromFile($filename, $docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND)
{
if (!file_exists($filename)) {
throw new XmlUtilException("Xml document $filename not found.", 250);
}
$xml = file_get_contents($filename);
$xmldoc = self::createXmlDocumentFromStr($xml, $docOptions);
return $xmldoc;
} | php | public static function createXmlDocumentFromFile($filename, $docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND)
{
if (!file_exists($filename)) {
throw new XmlUtilException("Xml document $filename not found.", 250);
}
$xml = file_get_contents($filename);
$xmldoc = self::createXmlDocumentFromStr($xml, $docOptions);
return $xmldoc;
} | [
"public",
"static",
"function",
"createXmlDocumentFromFile",
"(",
"$",
"filename",
",",
"$",
"docOptions",
"=",
"XMLUTIL_OPT_DONT_FIX_AMPERSAND",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"XmlUtilException",
"(... | Create a XmlDocument object from a file saved on disk.
@param string $filename
@param int $docOptions
@return DOMDocument
@throws \ByJG\Util\Exception\XmlUtilException | [
"Create",
"a",
"XmlDocument",
"object",
"from",
"a",
"file",
"saved",
"on",
"disk",
"."
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L66-L74 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.createXmlDocumentFromStr | public static function createXmlDocumentFromStr($xml, $docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND)
{
set_error_handler(function ($number, $error) {
$matches = [];
if (preg_match('/^DOMDocument::loadXML\(\): (.+)$/', $error, $matches) === 1) {
throw new \InvalidArgumentException("[Err #$number] ".$matches[1]);
}
});
$xmldoc = self::createXmlDocument($docOptions);
$xmlFixed = XmlUtil::fixXmlHeader($xml);
if (($docOptions & XMLUTIL_OPT_DONT_FIX_AMPERSAND) != XMLUTIL_OPT_DONT_FIX_AMPERSAND) {
$xmlFixed = str_replace("&", "&", $xmlFixed);
}
$xmldoc->loadXML($xmlFixed);
XmlUtil::extractNamespaces($xmldoc);
restore_error_handler();
return $xmldoc;
} | php | public static function createXmlDocumentFromStr($xml, $docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND)
{
set_error_handler(function ($number, $error) {
$matches = [];
if (preg_match('/^DOMDocument::loadXML\(\): (.+)$/', $error, $matches) === 1) {
throw new \InvalidArgumentException("[Err #$number] ".$matches[1]);
}
});
$xmldoc = self::createXmlDocument($docOptions);
$xmlFixed = XmlUtil::fixXmlHeader($xml);
if (($docOptions & XMLUTIL_OPT_DONT_FIX_AMPERSAND) != XMLUTIL_OPT_DONT_FIX_AMPERSAND) {
$xmlFixed = str_replace("&", "&", $xmlFixed);
}
$xmldoc->loadXML($xmlFixed);
XmlUtil::extractNamespaces($xmldoc);
restore_error_handler();
return $xmldoc;
} | [
"public",
"static",
"function",
"createXmlDocumentFromStr",
"(",
"$",
"xml",
",",
"$",
"docOptions",
"=",
"XMLUTIL_OPT_DONT_FIX_AMPERSAND",
")",
"{",
"set_error_handler",
"(",
"function",
"(",
"$",
"number",
",",
"$",
"error",
")",
"{",
"$",
"matches",
"=",
"[... | Create XML \DOMDocument from a string
@param string $xml - XML string document
@param int $docOptions
@return DOMDocument
@throws \ByJG\Util\Exception\XmlUtilException | [
"Create",
"XML",
"\\",
"DOMDocument",
"from",
"a",
"string"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L84-L107 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.createDocumentFromNode | public static function createDocumentFromNode(\DOMNode $node, $docOptions = 0)
{
$xmldoc = self::createXmlDocument($docOptions);
XmlUtil::$xmlNsPrefix[spl_object_hash($xmldoc)] = array();
$root = $xmldoc->importNode($node, true);
$xmldoc->appendChild($root);
return $xmldoc;
} | php | public static function createDocumentFromNode(\DOMNode $node, $docOptions = 0)
{
$xmldoc = self::createXmlDocument($docOptions);
XmlUtil::$xmlNsPrefix[spl_object_hash($xmldoc)] = array();
$root = $xmldoc->importNode($node, true);
$xmldoc->appendChild($root);
return $xmldoc;
} | [
"public",
"static",
"function",
"createDocumentFromNode",
"(",
"\\",
"DOMNode",
"$",
"node",
",",
"$",
"docOptions",
"=",
"0",
")",
"{",
"$",
"xmldoc",
"=",
"self",
"::",
"createXmlDocument",
"(",
"$",
"docOptions",
")",
";",
"XmlUtil",
"::",
"$",
"xmlNsPr... | Create a \DOMDocumentFragment from a node
@param DOMNode $node
@param int $docOptions
@return DOMDocument | [
"Create",
"a",
"\\",
"DOMDocumentFragment",
"from",
"a",
"node"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L116-L123 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.fixXmlHeader | public static function fixXmlHeader($string)
{
$string = XmlUtil::removeBom($string);
if (strpos($string, "<?xml") !== false) {
$xmltagend = strpos($string, "?>");
if ($xmltagend !== false) {
$xmltagend += 2;
$xmlheader = substr($string, 0, $xmltagend);
if ($xmlheader == "<?xml?>") {
$xmlheader = "<?xml ?>";
}
} else {
throw new XmlUtilException("XML header bad formatted.", 251);
}
// Complete header elements
$count = 0;
$xmlheader = preg_replace(
"/version=([\"'][\w\d\-\.]+[\"'])/",
"version=\"".self::XML_VERSION."\"",
$xmlheader,
1,
$count
);
if ($count == 0) {
$xmlheader = substr($xmlheader, 0, 6)."version=\"".self::XML_VERSION."\" ".substr($xmlheader, 6);
}
$count = 0;
$xmlheader = preg_replace(
"/encoding=([\"'][\w\d\-\.]+[\"'])/",
"encoding=\"".self::XML_ENCODING."\"",
$xmlheader,
1,
$count
);
if ($count == 0) {
$xmlheader = substr($xmlheader, 0, 6)."encoding=\"".self::XML_ENCODING."\" ".substr($xmlheader, 6);
}
// Fix header position (first version, after encoding)
$xmlheader = preg_replace(
"/<\?([\w\W]*)\s+(encoding=([\"'][\w\d\-\.]+[\"']))\s+(version=([\"'][\w\d\-\.]+[\"']))\s*\?>/",
"<?\\1 \\4 \\2?>",
$xmlheader,
1,
$count
);
return $xmlheader.substr($string, $xmltagend);
} else {
$xmlheader = '<?xml version="'.self::XML_VERSION.'" encoding="'.self::XML_ENCODING.'"?>';
return $xmlheader.$string;
}
} | php | public static function fixXmlHeader($string)
{
$string = XmlUtil::removeBom($string);
if (strpos($string, "<?xml") !== false) {
$xmltagend = strpos($string, "?>");
if ($xmltagend !== false) {
$xmltagend += 2;
$xmlheader = substr($string, 0, $xmltagend);
if ($xmlheader == "<?xml?>") {
$xmlheader = "<?xml ?>";
}
} else {
throw new XmlUtilException("XML header bad formatted.", 251);
}
// Complete header elements
$count = 0;
$xmlheader = preg_replace(
"/version=([\"'][\w\d\-\.]+[\"'])/",
"version=\"".self::XML_VERSION."\"",
$xmlheader,
1,
$count
);
if ($count == 0) {
$xmlheader = substr($xmlheader, 0, 6)."version=\"".self::XML_VERSION."\" ".substr($xmlheader, 6);
}
$count = 0;
$xmlheader = preg_replace(
"/encoding=([\"'][\w\d\-\.]+[\"'])/",
"encoding=\"".self::XML_ENCODING."\"",
$xmlheader,
1,
$count
);
if ($count == 0) {
$xmlheader = substr($xmlheader, 0, 6)."encoding=\"".self::XML_ENCODING."\" ".substr($xmlheader, 6);
}
// Fix header position (first version, after encoding)
$xmlheader = preg_replace(
"/<\?([\w\W]*)\s+(encoding=([\"'][\w\d\-\.]+[\"']))\s+(version=([\"'][\w\d\-\.]+[\"']))\s*\?>/",
"<?\\1 \\4 \\2?>",
$xmlheader,
1,
$count
);
return $xmlheader.substr($string, $xmltagend);
} else {
$xmlheader = '<?xml version="'.self::XML_VERSION.'" encoding="'.self::XML_ENCODING.'"?>';
return $xmlheader.$string;
}
} | [
"public",
"static",
"function",
"fixXmlHeader",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"XmlUtil",
"::",
"removeBom",
"(",
"$",
"string",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"string",
",",
"\"<?xml\"",
")",
"!==",
"false",
")",
"{",
"$... | Adjust xml string to the proper format
@param string $string - XML string document
@return string - Return the string converted
@throws \ByJG\Util\Exception\XmlUtilException | [
"Adjust",
"xml",
"string",
"to",
"the",
"proper",
"format"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L150-L205 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.getFormattedDocument | public static function getFormattedDocument($xml)
{
$oldValue = $xml->preserveWhiteSpace;
$oldFormatOutput = $xml->formatOutput;
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$document = $xml->saveXML();
$xml->preserveWhiteSpace = $oldValue;
$xml->formatOutput = $oldFormatOutput;
return $document;
} | php | public static function getFormattedDocument($xml)
{
$oldValue = $xml->preserveWhiteSpace;
$oldFormatOutput = $xml->formatOutput;
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$document = $xml->saveXML();
$xml->preserveWhiteSpace = $oldValue;
$xml->formatOutput = $oldFormatOutput;
return $document;
} | [
"public",
"static",
"function",
"getFormattedDocument",
"(",
"$",
"xml",
")",
"{",
"$",
"oldValue",
"=",
"$",
"xml",
"->",
"preserveWhiteSpace",
";",
"$",
"oldFormatOutput",
"=",
"$",
"xml",
"->",
"formatOutput",
";",
"$",
"xml",
"->",
"preserveWhiteSpace",
... | Get document without xml parameters
@param DOMDocument $xml
@return string | [
"Get",
"document",
"without",
"xml",
"parameters"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L231-L244 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.addNodeFromFile | public static function addNodeFromFile(\DOMNode $rootNode, $filename, $nodetoadd)
{
if ($rootNode === null) {
return;
}
if (!file_exists($filename)) {
return;
}
$source = XmlUtil::createXmlDocumentFromFile($filename);
$nodes = $source->getElementsByTagName($nodetoadd)->item(0)->childNodes;
foreach ($nodes as $node) {
$newNode = $rootNode->ownerDocument->importNode($node, true);
$rootNode->appendChild($newNode);
}
} | php | public static function addNodeFromFile(\DOMNode $rootNode, $filename, $nodetoadd)
{
if ($rootNode === null) {
return;
}
if (!file_exists($filename)) {
return;
}
$source = XmlUtil::createXmlDocumentFromFile($filename);
$nodes = $source->getElementsByTagName($nodetoadd)->item(0)->childNodes;
foreach ($nodes as $node) {
$newNode = $rootNode->ownerDocument->importNode($node, true);
$rootNode->appendChild($newNode);
}
} | [
"public",
"static",
"function",
"addNodeFromFile",
"(",
"\\",
"DOMNode",
"$",
"rootNode",
",",
"$",
"filename",
",",
"$",
"nodetoadd",
")",
"{",
"if",
"(",
"$",
"rootNode",
"===",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"file_exists",
"("... | Add node to specific XmlNode from file existing on disk
@param \DOMNode $rootNode XmlNode receives node
@param string $filename File to import node
@param string $nodetoadd Node to be added
@throws \ByJG\Util\Exception\XmlUtilException | [
"Add",
"node",
"to",
"specific",
"XmlNode",
"from",
"file",
"existing",
"on",
"disk"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L279-L296 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.createChild | public static function createChild(\DOMNode $rootNode, $nodeName, $nodeText = "", $uri = "")
{
if (empty($nodeName)) {
throw new XmlUtilException("Node name must be a string.");
}
$nodeworking = XmlUtil::createChildNode($rootNode, $nodeName, $uri);
self::addTextNode($nodeworking, $nodeText);
$rootNode->appendChild($nodeworking);
return $nodeworking;
} | php | public static function createChild(\DOMNode $rootNode, $nodeName, $nodeText = "", $uri = "")
{
if (empty($nodeName)) {
throw new XmlUtilException("Node name must be a string.");
}
$nodeworking = XmlUtil::createChildNode($rootNode, $nodeName, $uri);
self::addTextNode($nodeworking, $nodeText);
$rootNode->appendChild($nodeworking);
return $nodeworking;
} | [
"public",
"static",
"function",
"createChild",
"(",
"\\",
"DOMNode",
"$",
"rootNode",
",",
"$",
"nodeName",
",",
"$",
"nodeText",
"=",
"\"\"",
",",
"$",
"uri",
"=",
"\"\"",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"nodeName",
")",
")",
"{",
"throw",
... | Append child node from specific node and add text
@param \DOMNode $rootNode Parent node
@param string $nodeName Node to add string
@param string $nodeText Text to add string
@param string $uri
@return DOMNode
@throws \ByJG\Util\Exception\XmlUtilException | [
"Append",
"child",
"node",
"from",
"specific",
"node",
"and",
"add",
"text"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L328-L338 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.createChildBefore | public static function createChildBefore(\DOMNode $rootNode, $nodeName, $nodeText, $position = 0)
{
return self::createChildBeforeNode($nodeName, $nodeText, $rootNode->childNodes->item($position));
} | php | public static function createChildBefore(\DOMNode $rootNode, $nodeName, $nodeText, $position = 0)
{
return self::createChildBeforeNode($nodeName, $nodeText, $rootNode->childNodes->item($position));
} | [
"public",
"static",
"function",
"createChildBefore",
"(",
"\\",
"DOMNode",
"$",
"rootNode",
",",
"$",
"nodeName",
",",
"$",
"nodeText",
",",
"$",
"position",
"=",
"0",
")",
"{",
"return",
"self",
"::",
"createChildBeforeNode",
"(",
"$",
"nodeName",
",",
"$... | Create child node on the top from specific node and add text
@param \DOMNode $rootNode Parent node
@param string $nodeName Node to add string
@param string $nodeText Text to add string
@param int $position
@return DOMNode
@throws \ByJG\Util\Exception\XmlUtilException | [
"Create",
"child",
"node",
"on",
"the",
"top",
"from",
"specific",
"node",
"and",
"add",
"text"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L350-L353 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.addTextNode | public static function addTextNode(\DOMNode $rootNode, $text, $escapeChars = false)
{
if (!empty($text) || is_numeric($text)) {
$owner = XmlUtil::getOwnerDocument($rootNode);
if ($escapeChars) {
$nodeworkingText = $owner->createCDATASection($text);
} else {
$nodeworkingText = $owner->createTextNode($text);
}
$rootNode->appendChild($nodeworkingText);
}
} | php | public static function addTextNode(\DOMNode $rootNode, $text, $escapeChars = false)
{
if (!empty($text) || is_numeric($text)) {
$owner = XmlUtil::getOwnerDocument($rootNode);
if ($escapeChars) {
$nodeworkingText = $owner->createCDATASection($text);
} else {
$nodeworkingText = $owner->createTextNode($text);
}
$rootNode->appendChild($nodeworkingText);
}
} | [
"public",
"static",
"function",
"addTextNode",
"(",
"\\",
"DOMNode",
"$",
"rootNode",
",",
"$",
"text",
",",
"$",
"escapeChars",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"text",
")",
"||",
"is_numeric",
"(",
"$",
"text",
")",
")",
... | Add text to node
@param \DOMNode $rootNode Parent node
@param string $text Text to add String
@param bool $escapeChars (True create CData instead Text node)
@throws \ByJG\Util\Exception\XmlUtilException | [
"Add",
"text",
"to",
"node"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L379-L390 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.addAttribute | public static function addAttribute(\DOMNode $rootNode, $name, $value)
{
XmlUtil::checkIfPrefixWasDefined($rootNode, $name);
$owner = XmlUtil::getOwnerDocument($rootNode);
$attrNode = $owner->createAttribute($name);
$attrNode->value = $value;
$rootNode->setAttributeNode($attrNode);
return $rootNode;
} | php | public static function addAttribute(\DOMNode $rootNode, $name, $value)
{
XmlUtil::checkIfPrefixWasDefined($rootNode, $name);
$owner = XmlUtil::getOwnerDocument($rootNode);
$attrNode = $owner->createAttribute($name);
$attrNode->value = $value;
$rootNode->setAttributeNode($attrNode);
return $rootNode;
} | [
"public",
"static",
"function",
"addAttribute",
"(",
"\\",
"DOMNode",
"$",
"rootNode",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"XmlUtil",
"::",
"checkIfPrefixWasDefined",
"(",
"$",
"rootNode",
",",
"$",
"name",
")",
";",
"$",
"owner",
"=",
"XmlUti... | Add a attribute to specific node
@param \DOMNode $rootNode Node to receive attribute
@param string $name Attribute name string
@param string $value Attribute value string
@return DOMNode
@throws \ByJG\Util\Exception\XmlUtilException | [
"Add",
"a",
"attribute",
"to",
"specific",
"node"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L401-L410 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.selectNodes | public static function selectNodes(\DOMNode $pNode, $xPath, $arNamespace = null) // <- Retorna N�!
{
if (preg_match('~^/[^/]~', $xPath)) {
$xPath = substr($xPath, 1);
}
$owner = XmlUtil::getOwnerDocument($pNode);
$xpath = new DOMXPath($owner);
XmlUtil::registerNamespaceForFilter($xpath, $arNamespace);
$rNodeList = $xpath->query($xPath, $pNode);
return $rNodeList;
} | php | public static function selectNodes(\DOMNode $pNode, $xPath, $arNamespace = null) // <- Retorna N�!
{
if (preg_match('~^/[^/]~', $xPath)) {
$xPath = substr($xPath, 1);
}
$owner = XmlUtil::getOwnerDocument($pNode);
$xpath = new DOMXPath($owner);
XmlUtil::registerNamespaceForFilter($xpath, $arNamespace);
$rNodeList = $xpath->query($xPath, $pNode);
return $rNodeList;
} | [
"public",
"static",
"function",
"selectNodes",
"(",
"\\",
"DOMNode",
"$",
"pNode",
",",
"$",
"xPath",
",",
"$",
"arNamespace",
"=",
"null",
")",
"// <- Retorna N�!",
"{",
"if",
"(",
"preg_match",
"(",
"'~^/[^/]~'",
",",
"$",
"xPath",
")",
")",
"{",
... | Returns a \DOMNodeList from a relative xPath from other \DOMNode
@param \DOMNode $pNode
@param string $xPath
@param array $arNamespace
@return DOMNodeList
@throws \ByJG\Util\Exception\XmlUtilException | [
"Returns",
"a",
"\\",
"DOMNodeList",
"from",
"a",
"relative",
"xPath",
"from",
"other",
"\\",
"DOMNode"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L421-L433 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.selectSingleNode | public static function selectSingleNode(\DOMNode $pNode, $xPath, $arNamespace = null) // <- Retorna
{
$rNodeList = self::selectNodes($pNode, $xPath, $arNamespace);
return $rNodeList->item(0);
} | php | public static function selectSingleNode(\DOMNode $pNode, $xPath, $arNamespace = null) // <- Retorna
{
$rNodeList = self::selectNodes($pNode, $xPath, $arNamespace);
return $rNodeList->item(0);
} | [
"public",
"static",
"function",
"selectSingleNode",
"(",
"\\",
"DOMNode",
"$",
"pNode",
",",
"$",
"xPath",
",",
"$",
"arNamespace",
"=",
"null",
")",
"// <- Retorna",
"{",
"$",
"rNodeList",
"=",
"self",
"::",
"selectNodes",
"(",
"$",
"pNode",
",",
"$",
"... | Returns a \DOMElement from a relative xPath from other \DOMNode
@param \DOMNode $pNode
@param string $xPath xPath string format
@param array $arNamespace
@return DOMElement
@throws \ByJG\Util\Exception\XmlUtilException | [
"Returns",
"a",
"\\",
"DOMElement",
"from",
"a",
"relative",
"xPath",
"from",
"other",
"\\",
"DOMNode"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L444-L449 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.innerXML | public static function innerXML(\DOMNode $node, $xmlstring)
{
$xmlstring = str_replace("<br>", "<br/>", $xmlstring);
$len = strlen($xmlstring);
$endText = "";
$close = strrpos($xmlstring, '>');
if ($close !== false && $close < $len - 1) {
$endText = substr($xmlstring, $close + 1);
$xmlstring = substr($xmlstring, 0, $close + 1);
}
$open = strpos($xmlstring, '<');
if ($open === false) {
$node->nodeValue .= $xmlstring;
} else {
if ($open > 0) {
$text = substr($xmlstring, 0, $open);
$xmlstring = substr($xmlstring, $open);
$node->nodeValue .= $text;
}
$dom = XmlUtil::getOwnerDocument($node);
$xmlstring = "<rootxml>$xmlstring</rootxml>";
$sxe = @simplexml_load_string($xmlstring);
if ($sxe === false) {
throw new XmlUtilException("Cannot load XML string.", 252);
}
$domSimpleXml = dom_import_simplexml($sxe);
if (!$domSimpleXml) {
throw new XmlUtilException("XML Parsing error.", 253);
}
$domSimpleXml = $dom->importNode($domSimpleXml, true);
$childs = $domSimpleXml->childNodes->length;
for ($i = 0; $i < $childs; $i++) {
$node->appendChild($domSimpleXml->childNodes->item($i)->cloneNode(true));
}
}
if (!empty($endText) && $endText != "") {
$textNode = $dom->createTextNode($endText);
$node->appendChild($textNode);
}
return $node->firstChild;
} | php | public static function innerXML(\DOMNode $node, $xmlstring)
{
$xmlstring = str_replace("<br>", "<br/>", $xmlstring);
$len = strlen($xmlstring);
$endText = "";
$close = strrpos($xmlstring, '>');
if ($close !== false && $close < $len - 1) {
$endText = substr($xmlstring, $close + 1);
$xmlstring = substr($xmlstring, 0, $close + 1);
}
$open = strpos($xmlstring, '<');
if ($open === false) {
$node->nodeValue .= $xmlstring;
} else {
if ($open > 0) {
$text = substr($xmlstring, 0, $open);
$xmlstring = substr($xmlstring, $open);
$node->nodeValue .= $text;
}
$dom = XmlUtil::getOwnerDocument($node);
$xmlstring = "<rootxml>$xmlstring</rootxml>";
$sxe = @simplexml_load_string($xmlstring);
if ($sxe === false) {
throw new XmlUtilException("Cannot load XML string.", 252);
}
$domSimpleXml = dom_import_simplexml($sxe);
if (!$domSimpleXml) {
throw new XmlUtilException("XML Parsing error.", 253);
}
$domSimpleXml = $dom->importNode($domSimpleXml, true);
$childs = $domSimpleXml->childNodes->length;
for ($i = 0; $i < $childs; $i++) {
$node->appendChild($domSimpleXml->childNodes->item($i)->cloneNode(true));
}
}
if (!empty($endText) && $endText != "") {
$textNode = $dom->createTextNode($endText);
$node->appendChild($textNode);
}
return $node->firstChild;
} | [
"public",
"static",
"function",
"innerXML",
"(",
"\\",
"DOMNode",
"$",
"node",
",",
"$",
"xmlstring",
")",
"{",
"$",
"xmlstring",
"=",
"str_replace",
"(",
"\"<br>\"",
",",
"\"<br/>\"",
",",
"$",
"xmlstring",
")",
";",
"$",
"len",
"=",
"strlen",
"(",
"$... | Concat a xml string in the node
@param \DOMNode $node
@param string $xmlstring
@return \DOMNode
@throws \ByJG\Util\Exception\XmlUtilException | [
"Concat",
"a",
"xml",
"string",
"in",
"the",
"node"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L473-L513 | train |
byjg/xmlutil | src/XmlUtil.php | XmlUtil.saveXmlNodeToString | public static function saveXmlNodeToString(\DOMNode $node)
{
$doc = XmlUtil::getOwnerDocument($node);
$string = $doc->saveXML($node);
return $string;
} | php | public static function saveXmlNodeToString(\DOMNode $node)
{
$doc = XmlUtil::getOwnerDocument($node);
$string = $doc->saveXML($node);
return $string;
} | [
"public",
"static",
"function",
"saveXmlNodeToString",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
"{",
"$",
"doc",
"=",
"XmlUtil",
"::",
"getOwnerDocument",
"(",
"$",
"node",
")",
";",
"$",
"string",
"=",
"$",
"doc",
"->",
"saveXML",
"(",
"$",
"node",
")"... | Return the part node in xml document
@param \DOMNode $node
@return string
@throws \ByJG\Util\Exception\XmlUtilException | [
"Return",
"the",
"part",
"node",
"in",
"xml",
"document"
] | adeded5814b3f66bb995c259fc4e081603faff8f | https://github.com/byjg/xmlutil/blob/adeded5814b3f66bb995c259fc4e081603faff8f/src/XmlUtil.php#L561-L566 | train |
fxpio/fxp-cache | Adapter/ApcuAdapter.php | ApcuAdapter.doClearItem | protected function doClearItem(array $item, $prefix)
{
$id = $item['info'];
$key = substr($id, strrpos($id, ':') + 1);
$res = true;
if ('' === $prefix || 0 === strpos($id, $prefix)) {
$res = $this->deleteItem($key);
}
return $res;
} | php | protected function doClearItem(array $item, $prefix)
{
$id = $item['info'];
$key = substr($id, strrpos($id, ':') + 1);
$res = true;
if ('' === $prefix || 0 === strpos($id, $prefix)) {
$res = $this->deleteItem($key);
}
return $res;
} | [
"protected",
"function",
"doClearItem",
"(",
"array",
"$",
"item",
",",
"$",
"prefix",
")",
"{",
"$",
"id",
"=",
"$",
"item",
"[",
"'info'",
"]",
";",
"$",
"key",
"=",
"substr",
"(",
"$",
"id",
",",
"strrpos",
"(",
"$",
"id",
",",
"':'",
")",
"... | Delete the key that starting by the prefix.
@param array $item The cache item
@param string $prefix The full prefix
@return bool | [
"Delete",
"the",
"key",
"that",
"starting",
"by",
"the",
"prefix",
"."
] | 55abf44a954890080fa2bfb080914ce7228ea769 | https://github.com/fxpio/fxp-cache/blob/55abf44a954890080fa2bfb080914ce7228ea769/Adapter/ApcuAdapter.php#L47-L58 | train |
cmsgears/module-core | common/models/entities/Permission.php | Permission.getRolesIdList | public function getRolesIdList() {
$roles = $this->roleMappingList;
$rolesList = array();
foreach ( $roles as $role ) {
array_push( $rolesList, $role->roleId );
}
return $rolesList;
} | php | public function getRolesIdList() {
$roles = $this->roleMappingList;
$rolesList = array();
foreach ( $roles as $role ) {
array_push( $rolesList, $role->roleId );
}
return $rolesList;
} | [
"public",
"function",
"getRolesIdList",
"(",
")",
"{",
"$",
"roles",
"=",
"$",
"this",
"->",
"roleMappingList",
";",
"$",
"rolesList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"array_push",
"(",
"$",
"ro... | Generate and return the array having id of mapped roles.
@return array | [
"Generate",
"and",
"return",
"the",
"array",
"having",
"id",
"of",
"mapped",
"roles",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/entities/Permission.php#L216-L227 | train |
cmsgears/module-core | common/models/entities/Permission.php | Permission.findGroupPermissions | public static function findGroupPermissions( $ids = [], $config = [] ) {
$permissionTable = CoreTables::getTableName( CoreTables::TABLE_PERMISSION );
$hierarchyTable = CoreTables::getTableName( CoreTables::TABLE_MODEL_HIERARCHY );
$idStr = join( ",", $ids );
return Permission::find()->leftJoin( $hierarchyTable, "`$permissionTable`.`id` = `$hierarchyTable`.`childId`" )
->where( "`$hierarchyTable`.`parentType` = 'permission' AND `$hierarchyTable`.`parentId` IN ($idStr)" )->all();
} | php | public static function findGroupPermissions( $ids = [], $config = [] ) {
$permissionTable = CoreTables::getTableName( CoreTables::TABLE_PERMISSION );
$hierarchyTable = CoreTables::getTableName( CoreTables::TABLE_MODEL_HIERARCHY );
$idStr = join( ",", $ids );
return Permission::find()->leftJoin( $hierarchyTable, "`$permissionTable`.`id` = `$hierarchyTable`.`childId`" )
->where( "`$hierarchyTable`.`parentType` = 'permission' AND `$hierarchyTable`.`parentId` IN ($idStr)" )->all();
} | [
"public",
"static",
"function",
"findGroupPermissions",
"(",
"$",
"ids",
"=",
"[",
"]",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"permissionTable",
"=",
"CoreTables",
"::",
"getTableName",
"(",
"CoreTables",
"::",
"TABLE_PERMISSION",
")",
";",
"$"... | Find and return the children of given permissions id.
@param array $ids L0 id list
@param array $config
@return Permission[] | [
"Find",
"and",
"return",
"the",
"children",
"of",
"given",
"permissions",
"id",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/entities/Permission.php#L292-L300 | train |
phPoirot/Std | src/CriteriaLexer/ParsedCriteria.php | ParsedCriteria._buildStringFromParsed | protected function _buildStringFromParsed(array $parts, $params = [])
{
if ($params instanceof \Traversable)
$params = StdTravers::of($params)->toArray();
if (! is_array($params) )
throw new \InvalidArgumentException(sprintf(
'Parameters must be an array or Traversable; given: (%s).'
, \Poirot\Std\flatten($params)
));
// regard to recursive function call
$isOptional = false;
$args = func_get_args();
if ($args && isset($args[2]))
$isOptional = $args[2];
# Check For Presented Values in Optional Segment
// consider this "/[@:username{{\w+}}][-:userid{{\w+}}]"
// if username not presented as params injected then first part include @ as literal
// not rendered.
// optional part only render when all parameter is present
if ($isOptional) {
foreach ($parts as $parsed) {
if (! isset($parsed['_parameter_']) )
continue;
## need parameter
$neededParameterName = $parsed['_parameter_'];
if (! (isset($params[$neededParameterName]) && $params[$neededParameterName] !== '') )
return '';
}
}
$return = '';
// [0 => ['_literal_' => 'localhost'], 1=>['_optional' => ..] ..]
foreach ($parts as $parsed) {
$definition_name = key($parsed);
$definition_value = $parsed[$definition_name];
// $parsed can also have extra parsed data options
// _parameter_ String(3) => tld \
// tld String(4) => .com
switch ($definition_name)
{
case '_literal_':
$return .= $definition_value;
break;
case '_parameter_':
if (! isset($params[$definition_value]) ) {
if ($isOptional) return '';
throw new \InvalidArgumentException(sprintf(
'Missing parameter (%s).'
, $definition_value
));
}
if (! \Poirot\Std\isStringify($params[$definition_value]) )
throw new \Exception(sprintf(
'Parameter %s is not stringify; given: (%s).'
, $definition_value
, \Poirot\Std\flatten($params[$definition_value])
));
$return .= $params[$definition_value];
break;
case '_optional_':
$optionalPart = $this->_buildStringFromParsed($definition_value, $params, true);
if ($optionalPart !== '')
$return .= $optionalPart;
break;
}
}
return $return;
} | php | protected function _buildStringFromParsed(array $parts, $params = [])
{
if ($params instanceof \Traversable)
$params = StdTravers::of($params)->toArray();
if (! is_array($params) )
throw new \InvalidArgumentException(sprintf(
'Parameters must be an array or Traversable; given: (%s).'
, \Poirot\Std\flatten($params)
));
// regard to recursive function call
$isOptional = false;
$args = func_get_args();
if ($args && isset($args[2]))
$isOptional = $args[2];
# Check For Presented Values in Optional Segment
// consider this "/[@:username{{\w+}}][-:userid{{\w+}}]"
// if username not presented as params injected then first part include @ as literal
// not rendered.
// optional part only render when all parameter is present
if ($isOptional) {
foreach ($parts as $parsed) {
if (! isset($parsed['_parameter_']) )
continue;
## need parameter
$neededParameterName = $parsed['_parameter_'];
if (! (isset($params[$neededParameterName]) && $params[$neededParameterName] !== '') )
return '';
}
}
$return = '';
// [0 => ['_literal_' => 'localhost'], 1=>['_optional' => ..] ..]
foreach ($parts as $parsed) {
$definition_name = key($parsed);
$definition_value = $parsed[$definition_name];
// $parsed can also have extra parsed data options
// _parameter_ String(3) => tld \
// tld String(4) => .com
switch ($definition_name)
{
case '_literal_':
$return .= $definition_value;
break;
case '_parameter_':
if (! isset($params[$definition_value]) ) {
if ($isOptional) return '';
throw new \InvalidArgumentException(sprintf(
'Missing parameter (%s).'
, $definition_value
));
}
if (! \Poirot\Std\isStringify($params[$definition_value]) )
throw new \Exception(sprintf(
'Parameter %s is not stringify; given: (%s).'
, $definition_value
, \Poirot\Std\flatten($params[$definition_value])
));
$return .= $params[$definition_value];
break;
case '_optional_':
$optionalPart = $this->_buildStringFromParsed($definition_value, $params, true);
if ($optionalPart !== '')
$return .= $optionalPart;
break;
}
}
return $return;
} | [
"protected",
"function",
"_buildStringFromParsed",
"(",
"array",
"$",
"parts",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"params",
"instanceof",
"\\",
"Traversable",
")",
"$",
"params",
"=",
"StdTravers",
"::",
"of",
"(",
"$",
"params"... | Build String Representation From Given Parts and Params
@param array $parts
@param array|\Traversable $params
@return string | [
"Build",
"String",
"Representation",
"From",
"Given",
"Parts",
"and",
"Params"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/CriteriaLexer/ParsedCriteria.php#L169-L249 | train |
cmsgears/module-core | common/models/traits/mappers/ModelFollowerTrait.php | ModelFollowerTrait.generateFollowCounts | protected function generateFollowCounts() {
$returnArr = [
IFollower::TYPE_LIKE => [ 0 => 0, 1 => 0 ],
IFollower::TYPE_DISLIKE => [ 0 => 0, 1 => 0 ],
IFollower::TYPE_FOLLOW => [ 0 => 0, 1 => 0 ],
IFollower::TYPE_WISHLIST => [ 0 => 0, 1 => 0 ]
];
$followerTable = ModelFollower::tableName();
$query = new Query();
$query->select( [ 'type', 'active', 'count(id) as total' ] )
->from( $followerTable )
->where( [ 'parentId' => $this->id, 'parentType' => $this->modelType, 'active' => true ] )
->groupBy( [ 'type', 'active' ] );
$counts = $query->all();
foreach( $counts as $count ) {
$returnArr[ $count[ 'type' ] ][ $count[ 'active' ] ] = $count[ 'total' ];
}
return $returnArr;
} | php | protected function generateFollowCounts() {
$returnArr = [
IFollower::TYPE_LIKE => [ 0 => 0, 1 => 0 ],
IFollower::TYPE_DISLIKE => [ 0 => 0, 1 => 0 ],
IFollower::TYPE_FOLLOW => [ 0 => 0, 1 => 0 ],
IFollower::TYPE_WISHLIST => [ 0 => 0, 1 => 0 ]
];
$followerTable = ModelFollower::tableName();
$query = new Query();
$query->select( [ 'type', 'active', 'count(id) as total' ] )
->from( $followerTable )
->where( [ 'parentId' => $this->id, 'parentType' => $this->modelType, 'active' => true ] )
->groupBy( [ 'type', 'active' ] );
$counts = $query->all();
foreach( $counts as $count ) {
$returnArr[ $count[ 'type' ] ][ $count[ 'active' ] ] = $count[ 'total' ];
}
return $returnArr;
} | [
"protected",
"function",
"generateFollowCounts",
"(",
")",
"{",
"$",
"returnArr",
"=",
"[",
"IFollower",
"::",
"TYPE_LIKE",
"=>",
"[",
"0",
"=>",
"0",
",",
"1",
"=>",
"0",
"]",
",",
"IFollower",
"::",
"TYPE_DISLIKE",
"=>",
"[",
"0",
"=>",
"0",
",",
"... | Generate and return the follow counts.
@return array | [
"Generate",
"and",
"return",
"the",
"follow",
"counts",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/traits/mappers/ModelFollowerTrait.php#L141-L166 | train |
cmsgears/module-core | common/models/traits/mappers/ModelFollowerTrait.php | ModelFollowerTrait.generateUserFollows | protected function generateUserFollows() {
$user = Yii::$app->user->identity;
$returnArr = [ IFollower::TYPE_LIKE => false, IFollower::TYPE_DISLIKE => false, IFollower::TYPE_FOLLOW => false, IFollower::TYPE_WISHLIST => false ];
if( isset( $user ) ) {
$followerTable = ModelFollower::tableName();
$query = new Query();
$query->select( [ 'type', 'active' ] )
->from( $followerTable )
->where( [ 'parentId' => $this->id, 'parentType' => $this->modelType, 'modelId' => $user->id ] );
$follows = $query->all();
foreach ( $follows as $follow ) {
$returnArr[ $follow[ 'type' ] ] = $follow[ 'active' ];
}
}
return $returnArr;
} | php | protected function generateUserFollows() {
$user = Yii::$app->user->identity;
$returnArr = [ IFollower::TYPE_LIKE => false, IFollower::TYPE_DISLIKE => false, IFollower::TYPE_FOLLOW => false, IFollower::TYPE_WISHLIST => false ];
if( isset( $user ) ) {
$followerTable = ModelFollower::tableName();
$query = new Query();
$query->select( [ 'type', 'active' ] )
->from( $followerTable )
->where( [ 'parentId' => $this->id, 'parentType' => $this->modelType, 'modelId' => $user->id ] );
$follows = $query->all();
foreach ( $follows as $follow ) {
$returnArr[ $follow[ 'type' ] ] = $follow[ 'active' ];
}
}
return $returnArr;
} | [
"protected",
"function",
"generateUserFollows",
"(",
")",
"{",
"$",
"user",
"=",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"identity",
";",
"$",
"returnArr",
"=",
"[",
"IFollower",
"::",
"TYPE_LIKE",
"=>",
"false",
",",
"IFollower",
"::",
"TYPE_DISLIKE"... | Generate and return the user follows.
@return array | [
"Generate",
"and",
"return",
"the",
"user",
"follows",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/traits/mappers/ModelFollowerTrait.php#L227-L250 | train |
willwashburn/stream | src/Stream/Stream.php | Stream.peek | public function peek($characters)
{
if ( strlen($this->stream_string) < $this->strpos + $characters ) {
throw new StreamBufferTooSmallException('Not enough of the stream available.');
}
return substr($this->stream_string, $this->strpos, $characters);
} | php | public function peek($characters)
{
if ( strlen($this->stream_string) < $this->strpos + $characters ) {
throw new StreamBufferTooSmallException('Not enough of the stream available.');
}
return substr($this->stream_string, $this->strpos, $characters);
} | [
"public",
"function",
"peek",
"(",
"$",
"characters",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"stream_string",
")",
"<",
"$",
"this",
"->",
"strpos",
"+",
"$",
"characters",
")",
"{",
"throw",
"new",
"StreamBufferTooSmallException",
"(",
"... | Get characters from the string but don't move the pointer
@param $characters
@return string
@throws StreamBufferTooSmallException | [
"Get",
"characters",
"from",
"the",
"string",
"but",
"don",
"t",
"move",
"the",
"pointer"
] | 17b32f35401640a63d624add1d5d8a04876422c2 | https://github.com/willwashburn/stream/blob/17b32f35401640a63d624add1d5d8a04876422c2/src/Stream/Stream.php#L33-L40 | train |
willwashburn/stream | src/Stream/Stream.php | Stream.read | public function read($characters)
{
$result = $this->peek($characters);
$this->strpos += $characters;
return $result;
} | php | public function read($characters)
{
$result = $this->peek($characters);
$this->strpos += $characters;
return $result;
} | [
"public",
"function",
"read",
"(",
"$",
"characters",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"peek",
"(",
"$",
"characters",
")",
";",
"$",
"this",
"->",
"strpos",
"+=",
"$",
"characters",
";",
"return",
"$",
"result",
";",
"}"
] | Get Characters from the string
@param $characters
@return string
@throws StreamBufferTooSmallException | [
"Get",
"Characters",
"from",
"the",
"string"
] | 17b32f35401640a63d624add1d5d8a04876422c2 | https://github.com/willwashburn/stream/blob/17b32f35401640a63d624add1d5d8a04876422c2/src/Stream/Stream.php#L50-L57 | train |
mcaskill/charcoal-support | src/Cms/AbstractWebTemplate.php | AbstractWebTemplate.currentUrl | public function currentUrl()
{
$context = $this->contextObject();
if ($context && isset($context['url'])) {
return $this->createAbsoluteUrl($context['url']);
}
return null;
} | php | public function currentUrl()
{
$context = $this->contextObject();
if ($context && isset($context['url'])) {
return $this->createAbsoluteUrl($context['url']);
}
return null;
} | [
"public",
"function",
"currentUrl",
"(",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"contextObject",
"(",
")",
";",
"if",
"(",
"$",
"context",
"&&",
"isset",
"(",
"$",
"context",
"[",
"'url'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",... | Retrieve the current URI of the context.
@return \Psr\Http\Message\UriInterface|null | [
"Retrieve",
"the",
"current",
"URI",
"of",
"the",
"context",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/AbstractWebTemplate.php#L102-L111 | train |
mcaskill/charcoal-support | src/Cms/AbstractWebTemplate.php | AbstractWebTemplate.currentLocale | public function currentLocale()
{
$langCode = $this->translator()->getLocale();
$locales = $this->translator()->locales();
if (isset($locales[$langCode])) {
$locale = $locales[$langCode];
if (isset($locale['locale'])) {
return $locale['locale'];
} else {
return $langCode;
}
}
return null;
} | php | public function currentLocale()
{
$langCode = $this->translator()->getLocale();
$locales = $this->translator()->locales();
if (isset($locales[$langCode])) {
$locale = $locales[$langCode];
if (isset($locale['locale'])) {
return $locale['locale'];
} else {
return $langCode;
}
}
return null;
} | [
"public",
"function",
"currentLocale",
"(",
")",
"{",
"$",
"langCode",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"$",
"locales",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"locales",
"(",
")",
";",
... | Retrieve the current locale.
@return string|null | [
"Retrieve",
"the",
"current",
"locale",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/AbstractWebTemplate.php#L118-L132 | train |
mcaskill/charcoal-support | src/Cms/AbstractWebTemplate.php | AbstractWebTemplate.metaTitle | public function metaTitle()
{
$context = $this->contextObject();
$title = null;
if ($context instanceof HasMetatagInterface) {
$title = (string)$context['meta_title'];
}
if (!$title) {
$title = (string)$this->fallbackMetaTitle();
}
return $title;
} | php | public function metaTitle()
{
$context = $this->contextObject();
$title = null;
if ($context instanceof HasMetatagInterface) {
$title = (string)$context['meta_title'];
}
if (!$title) {
$title = (string)$this->fallbackMetaTitle();
}
return $title;
} | [
"public",
"function",
"metaTitle",
"(",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"contextObject",
"(",
")",
";",
"$",
"title",
"=",
"null",
";",
"if",
"(",
"$",
"context",
"instanceof",
"HasMetatagInterface",
")",
"{",
"$",
"title",
"=",
"(",
... | Retrieve the name or title of the object.
@return string|null | [
"Retrieve",
"the",
"name",
"or",
"title",
"of",
"the",
"object",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/AbstractWebTemplate.php#L177-L191 | train |
mcaskill/charcoal-support | src/Cms/AbstractWebTemplate.php | AbstractWebTemplate.metaDescription | public function metaDescription()
{
$context = $this->contextObject();
$desc = null;
if ($context instanceof HasMetatagInterface) {
$desc = (string)$context['meta_description'];
}
if (!$desc) {
$desc = (string)$this->fallbackMetaDescription();
}
return $desc;
} | php | public function metaDescription()
{
$context = $this->contextObject();
$desc = null;
if ($context instanceof HasMetatagInterface) {
$desc = (string)$context['meta_description'];
}
if (!$desc) {
$desc = (string)$this->fallbackMetaDescription();
}
return $desc;
} | [
"public",
"function",
"metaDescription",
"(",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"contextObject",
"(",
")",
";",
"$",
"desc",
"=",
"null",
";",
"if",
"(",
"$",
"context",
"instanceof",
"HasMetatagInterface",
")",
"{",
"$",
"desc",
"=",
"... | Retrieve the description of the object.
@return string|null | [
"Retrieve",
"the",
"description",
"of",
"the",
"object",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/AbstractWebTemplate.php#L210-L224 | train |
mcaskill/charcoal-support | src/Cms/AbstractWebTemplate.php | AbstractWebTemplate.hasSeoMetadata | public function hasSeoMetadata()
{
if ($this->seoMetadata instanceof ArrayIterator) {
return (count($this->seoMetadata) > 0);
}
return !empty($this->seoMetadata);
} | php | public function hasSeoMetadata()
{
if ($this->seoMetadata instanceof ArrayIterator) {
return (count($this->seoMetadata) > 0);
}
return !empty($this->seoMetadata);
} | [
"public",
"function",
"hasSeoMetadata",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"seoMetadata",
"instanceof",
"ArrayIterator",
")",
"{",
"return",
"(",
"count",
"(",
"$",
"this",
"->",
"seoMetadata",
")",
">",
"0",
")",
";",
"}",
"return",
"!",
"em... | Determine if we have additional SEO metadata.
@return boolean | [
"Determine",
"if",
"we",
"have",
"additional",
"SEO",
"metadata",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/AbstractWebTemplate.php#L431-L438 | train |
mcaskill/charcoal-support | src/Cms/AbstractWebTemplate.php | AbstractWebTemplate.setSeoMetadata | protected function setSeoMetadata(array $metadata)
{
if (is_array($this->seoMetadata)) {
$this->seoMetadata = new ArrayIterator($this->seoMetadata);
}
foreach ($metadata as $key => $value) {
if (is_array($value)) {
$value = implode(',', $value);
}
$this->seoMetadata[] = [
'name' => $key,
'content' => (string)$value
];
}
return $this;
} | php | protected function setSeoMetadata(array $metadata)
{
if (is_array($this->seoMetadata)) {
$this->seoMetadata = new ArrayIterator($this->seoMetadata);
}
foreach ($metadata as $key => $value) {
if (is_array($value)) {
$value = implode(',', $value);
}
$this->seoMetadata[] = [
'name' => $key,
'content' => (string)$value
];
}
return $this;
} | [
"protected",
"function",
"setSeoMetadata",
"(",
"array",
"$",
"metadata",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"seoMetadata",
")",
")",
"{",
"$",
"this",
"->",
"seoMetadata",
"=",
"new",
"ArrayIterator",
"(",
"$",
"this",
"->",
"seoMe... | Set additional SEO metadata.
@param array $metadata Map of metadata keys and values.
@return self | [
"Set",
"additional",
"SEO",
"metadata",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/AbstractWebTemplate.php#L446-L464 | train |
cmsgears/module-core | common/models/entities/Site.php | Site.getMembers | public function getMembers() {
$siteMemberTable = CoreTables::getTableName( CoreTables::TABLE_SITE_MEMBER );
return $this->hasMany( User::class, [ 'id' => 'userId' ] )
->viaTable( $siteMemberTable, [ 'siteId' => 'id' ] );
} | php | public function getMembers() {
$siteMemberTable = CoreTables::getTableName( CoreTables::TABLE_SITE_MEMBER );
return $this->hasMany( User::class, [ 'id' => 'userId' ] )
->viaTable( $siteMemberTable, [ 'siteId' => 'id' ] );
} | [
"public",
"function",
"getMembers",
"(",
")",
"{",
"$",
"siteMemberTable",
"=",
"CoreTables",
"::",
"getTableName",
"(",
"CoreTables",
"::",
"TABLE_SITE_MEMBER",
")",
";",
"return",
"$",
"this",
"->",
"hasMany",
"(",
"User",
"::",
"class",
",",
"[",
"'id'",
... | Return members of the site.
@return User[] | [
"Return",
"members",
"of",
"the",
"site",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/entities/Site.php#L255-L261 | train |
spiral/exceptions | src/HtmlHandler.php | HtmlHandler.render | private function render(string $view, array $options = []): string
{
extract($options, EXTR_OVERWRITE);
ob_start();
require $this->getFilename($view);
return ob_get_clean();
} | php | private function render(string $view, array $options = []): string
{
extract($options, EXTR_OVERWRITE);
ob_start();
require $this->getFilename($view);
return ob_get_clean();
} | [
"private",
"function",
"render",
"(",
"string",
"$",
"view",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"string",
"{",
"extract",
"(",
"$",
"options",
",",
"EXTR_OVERWRITE",
")",
";",
"ob_start",
"(",
")",
";",
"require",
"$",
"this",
"->... | Render PHP template.
@param string $view
@param array $options
@return string | [
"Render",
"PHP",
"template",
"."
] | 9735a00b189ce61317cd49a9d6ec630f68cee381 | https://github.com/spiral/exceptions/blob/9735a00b189ce61317cd49a9d6ec630f68cee381/src/HtmlHandler.php#L111-L119 | train |
cmsgears/module-core | common/models/entities/Role.php | Role.getPermissionsIdList | public function getPermissionsIdList() {
$permissions = $this->permissionMappingList;
$permissionsList = [];
foreach ( $permissions as $permission ) {
array_push( $permissionsList, $permission->permissionId );
}
return $permissionsList;
} | php | public function getPermissionsIdList() {
$permissions = $this->permissionMappingList;
$permissionsList = [];
foreach ( $permissions as $permission ) {
array_push( $permissionsList, $permission->permissionId );
}
return $permissionsList;
} | [
"public",
"function",
"getPermissionsIdList",
"(",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"permissionMappingList",
";",
"$",
"permissionsList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"array_p... | Generate and return the array having id of mapped permissions.
@return array | [
"Generate",
"and",
"return",
"the",
"array",
"having",
"id",
"of",
"mapped",
"permissions",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/entities/Role.php#L220-L231 | train |
cmsgears/module-core | common/models/entities/Role.php | Role.getPermissionsSlugList | public function getPermissionsSlugList() {
$slugList = [];
$idList = [];
// TODO: Use roles hierarchy recursively to get child roles
if( !empty( $this->gridCache ) ) {
return $this->getGridCacheAttribute( 'permissionsSlugList' );
}
else {
// Generate L0 Slugs and Ids List
$permissions = $this->permissions;
foreach( $permissions as $permission ) {
if( !in_array( $permission->slug, $slugList ) ) {
array_push( $slugList, $permission->slug );
if( $permission->group ) {
array_push( $idList, $permission->id );
}
}
}
// Add child permission slugs recursively till all leaf nodes get exhausted.
while( count( $idList ) > 0 ) {
$permissions = Permission::findGroupPermissions( $idList );
$idList = [];
foreach( $permissions as $permission ) {
if( !in_array( $permission->slug, $slugList ) ) {
array_push( $slugList, $permission->slug );
if( $permission->group ) {
array_push( $idList, $permission->id );
}
}
}
if( count( $idList ) == 0 ) {
break;
}
};
}
return $slugList;
} | php | public function getPermissionsSlugList() {
$slugList = [];
$idList = [];
// TODO: Use roles hierarchy recursively to get child roles
if( !empty( $this->gridCache ) ) {
return $this->getGridCacheAttribute( 'permissionsSlugList' );
}
else {
// Generate L0 Slugs and Ids List
$permissions = $this->permissions;
foreach( $permissions as $permission ) {
if( !in_array( $permission->slug, $slugList ) ) {
array_push( $slugList, $permission->slug );
if( $permission->group ) {
array_push( $idList, $permission->id );
}
}
}
// Add child permission slugs recursively till all leaf nodes get exhausted.
while( count( $idList ) > 0 ) {
$permissions = Permission::findGroupPermissions( $idList );
$idList = [];
foreach( $permissions as $permission ) {
if( !in_array( $permission->slug, $slugList ) ) {
array_push( $slugList, $permission->slug );
if( $permission->group ) {
array_push( $idList, $permission->id );
}
}
}
if( count( $idList ) == 0 ) {
break;
}
};
}
return $slugList;
} | [
"public",
"function",
"getPermissionsSlugList",
"(",
")",
"{",
"$",
"slugList",
"=",
"[",
"]",
";",
"$",
"idList",
"=",
"[",
"]",
";",
"// TODO: Use roles hierarchy recursively to get child roles",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"gridCache",
... | Generate and return the array having slug of mapped permissions.
@return array | [
"Generate",
"and",
"return",
"the",
"array",
"having",
"slug",
"of",
"mapped",
"permissions",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/entities/Role.php#L238-L295 | train |
cmsgears/module-core | common/models/traits/base/ApprovalTrait.php | ApprovalTrait.isEditable | public function isEditable() {
$editable = [ IApproval::STATUS_SUBMITTED, IApproval::STATUS_RE_SUBMIT, IApproval::STATUS_UPLIFT_FREEZE, IApproval::STATUS_UPLIFT_BLOCK ];
return !in_array( $this->status, $editable );
} | php | public function isEditable() {
$editable = [ IApproval::STATUS_SUBMITTED, IApproval::STATUS_RE_SUBMIT, IApproval::STATUS_UPLIFT_FREEZE, IApproval::STATUS_UPLIFT_BLOCK ];
return !in_array( $this->status, $editable );
} | [
"public",
"function",
"isEditable",
"(",
")",
"{",
"$",
"editable",
"=",
"[",
"IApproval",
"::",
"STATUS_SUBMITTED",
",",
"IApproval",
"::",
"STATUS_RE_SUBMIT",
",",
"IApproval",
"::",
"STATUS_UPLIFT_FREEZE",
",",
"IApproval",
"::",
"STATUS_UPLIFT_BLOCK",
"]",
";"... | The model owner cannot update it in the states defined within this method.
@return boolean | [
"The",
"model",
"owner",
"cannot",
"update",
"it",
"in",
"the",
"states",
"defined",
"within",
"this",
"method",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/traits/base/ApprovalTrait.php#L353-L358 | train |
cmsgears/module-core | common/models/traits/base/ApprovalTrait.php | ApprovalTrait.isSubmittable | public function isSubmittable() {
return $this->isRegistration() || $this->status == IApproval::STATUS_REJECTED ||
$this->status == IApproval::STATUS_FROJEN || $this->status == IApproval::STATUS_BLOCKED;
} | php | public function isSubmittable() {
return $this->isRegistration() || $this->status == IApproval::STATUS_REJECTED ||
$this->status == IApproval::STATUS_FROJEN || $this->status == IApproval::STATUS_BLOCKED;
} | [
"public",
"function",
"isSubmittable",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"isRegistration",
"(",
")",
"||",
"$",
"this",
"->",
"status",
"==",
"IApproval",
"::",
"STATUS_REJECTED",
"||",
"$",
"this",
"->",
"status",
"==",
"IApproval",
"::",
"STATU... | The model owner can submit the model for limit removal in selected states i.e. new,
rejected, frozen or blocked. defined within this method.
@return boolean | [
"The",
"model",
"owner",
"can",
"submit",
"the",
"model",
"for",
"limit",
"removal",
"in",
"selected",
"states",
"i",
".",
"e",
".",
"new",
"rejected",
"frozen",
"or",
"blocked",
".",
"defined",
"within",
"this",
"method",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/traits/base/ApprovalTrait.php#L366-L370 | train |
cmsgears/module-core | common/models/traits/base/ApprovalTrait.php | ApprovalTrait.isApprovable | public function isApprovable() {
return $this->status == IApproval::STATUS_SUBMITTED || $this->status == IApproval::STATUS_FROJEN ||
$this->status == IApproval::STATUS_UPLIFT_FREEZE || $this->status == IApproval::STATUS_BLOCKED ||
$this->status == IApproval::STATUS_UPLIFT_BLOCK;
} | php | public function isApprovable() {
return $this->status == IApproval::STATUS_SUBMITTED || $this->status == IApproval::STATUS_FROJEN ||
$this->status == IApproval::STATUS_UPLIFT_FREEZE || $this->status == IApproval::STATUS_BLOCKED ||
$this->status == IApproval::STATUS_UPLIFT_BLOCK;
} | [
"public",
"function",
"isApprovable",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"status",
"==",
"IApproval",
"::",
"STATUS_SUBMITTED",
"||",
"$",
"this",
"->",
"status",
"==",
"IApproval",
"::",
"STATUS_FROJEN",
"||",
"$",
"this",
"->",
"status",
"==",
"... | Admin can check whether the model is ready for approval in selected states i.e. frozen,
uplift-freeze, blocked or uplift-block defined within this method. A model can be activated only
in the states specified within this method.
@return boolean | [
"Admin",
"can",
"check",
"whether",
"the",
"model",
"is",
"ready",
"for",
"approval",
"in",
"selected",
"states",
"i",
".",
"e",
".",
"frozen",
"uplift",
"-",
"freeze",
"blocked",
"or",
"uplift",
"-",
"block",
"defined",
"within",
"this",
"method",
".",
... | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/traits/base/ApprovalTrait.php#L379-L384 | train |
paulbunyannet/bandolier | src/Bandolier/Validate/WritableLocation.php | WritableLocation.isWritable | protected function isWritable()
{
if (!is_writable($this->path)) {
throw new LocationIsWritable(
$this->getPath() . ' is not writable!',
self::WRITABLE_IS_NOT_WRITABLE_ERROR
);
}
return true;
} | php | protected function isWritable()
{
if (!is_writable($this->path)) {
throw new LocationIsWritable(
$this->getPath() . ' is not writable!',
self::WRITABLE_IS_NOT_WRITABLE_ERROR
);
}
return true;
} | [
"protected",
"function",
"isWritable",
"(",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"this",
"->",
"path",
")",
")",
"{",
"throw",
"new",
"LocationIsWritable",
"(",
"$",
"this",
"->",
"getPath",
"(",
")",
".",
"' is not writable!'",
",",
"self"... | Check if path is writable
@return bool
@throws LocationIsWritable | [
"Check",
"if",
"path",
"is",
"writable"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Validate/WritableLocation.php#L87-L96 | train |
paulbunyannet/bandolier | src/Bandolier/Validate/WritableLocation.php | WritableLocation.isADirectory | protected function isADirectory()
{
if (file_exists($this->path) && !is_dir($this->path)) {
throw new LocationIsADirectory(
$this->getPath() .' already exists but is not a directory!',
self::WRITABLE_IS_NOT_A_DIR_ERROR
);
}
return true;
} | php | protected function isADirectory()
{
if (file_exists($this->path) && !is_dir($this->path)) {
throw new LocationIsADirectory(
$this->getPath() .' already exists but is not a directory!',
self::WRITABLE_IS_NOT_A_DIR_ERROR
);
}
return true;
} | [
"protected",
"function",
"isADirectory",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"path",
")",
"&&",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"path",
")",
")",
"{",
"throw",
"new",
"LocationIsADirectory",
"(",
"$",
"this",
"->",
... | Check if path is a directory
@return bool
@throws LocationIsADirectory | [
"Check",
"if",
"path",
"is",
"a",
"directory"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Validate/WritableLocation.php#L121-L130 | train |
fxpio/fxp-cache | Adapter/FilesystemAdapter.php | FilesystemAdapter.doClearFile | private function doClearFile(&$ok, \SplFileInfo $file, $prefix): void
{
$keys = [];
if ($file->isFile()) {
$key = $this->getFileKey($file);
if (null !== $key && ('' === $prefix || 0 === strpos($key, $prefix))) {
$keys[] = $key;
}
}
$ok = ($file->isDir() || $this->deleteItems($keys) || !file_exists($file)) && $ok;
} | php | private function doClearFile(&$ok, \SplFileInfo $file, $prefix): void
{
$keys = [];
if ($file->isFile()) {
$key = $this->getFileKey($file);
if (null !== $key && ('' === $prefix || 0 === strpos($key, $prefix))) {
$keys[] = $key;
}
}
$ok = ($file->isDir() || $this->deleteItems($keys) || !file_exists($file)) && $ok;
} | [
"private",
"function",
"doClearFile",
"(",
"&",
"$",
"ok",
",",
"\\",
"SplFileInfo",
"$",
"file",
",",
"$",
"prefix",
")",
":",
"void",
"{",
"$",
"keys",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"file",
"->",
"isFile",
"(",
")",
")",
"{",
"$",
"key"... | Action to clear all items in file starting with the prefix.
@param bool $ok The delete status
@param \SplFileInfo $file The spl file info
@param string $prefix The prefix | [
"Action",
"to",
"clear",
"all",
"items",
"in",
"file",
"starting",
"with",
"the",
"prefix",
"."
] | 55abf44a954890080fa2bfb080914ce7228ea769 | https://github.com/fxpio/fxp-cache/blob/55abf44a954890080fa2bfb080914ce7228ea769/Adapter/FilesystemAdapter.php#L51-L64 | train |
fxpio/fxp-cache | Adapter/FilesystemAdapter.php | FilesystemAdapter.getFileKey | private function getFileKey(\SplFileInfo $file)
{
$key = null;
if ($h = @fopen($file, 'r')) {
rawurldecode(rtrim(fgets($h)));
$value = stream_get_contents($h);
fclose($h);
$key = substr($value, 0, strpos($value, "\n"));
}
return $key;
} | php | private function getFileKey(\SplFileInfo $file)
{
$key = null;
if ($h = @fopen($file, 'r')) {
rawurldecode(rtrim(fgets($h)));
$value = stream_get_contents($h);
fclose($h);
$key = substr($value, 0, strpos($value, "\n"));
}
return $key;
} | [
"private",
"function",
"getFileKey",
"(",
"\\",
"SplFileInfo",
"$",
"file",
")",
"{",
"$",
"key",
"=",
"null",
";",
"if",
"(",
"$",
"h",
"=",
"@",
"fopen",
"(",
"$",
"file",
",",
"'r'",
")",
")",
"{",
"rawurldecode",
"(",
"rtrim",
"(",
"fgets",
"... | Get the key of file.
@param \SplFileInfo $file The spl file info
@return null|string | [
"Get",
"the",
"key",
"of",
"file",
"."
] | 55abf44a954890080fa2bfb080914ce7228ea769 | https://github.com/fxpio/fxp-cache/blob/55abf44a954890080fa2bfb080914ce7228ea769/Adapter/FilesystemAdapter.php#L73-L85 | train |
mcaskill/charcoal-support | src/App/Routing/SluggableTrait.php | SluggableTrait.url | public function url($lang = null)
{
if ($this->url === null) {
if (!$this->id()) {
return null;
}
$this->url = $this->generateUri();
}
if ($lang && $this->url instanceof Translation) {
return $this->url[$lang];
}
return strval($this->url);
} | php | public function url($lang = null)
{
if ($this->url === null) {
if (!$this->id()) {
return null;
}
$this->url = $this->generateUri();
}
if ($lang && $this->url instanceof Translation) {
return $this->url[$lang];
}
return strval($this->url);
} | [
"public",
"function",
"url",
"(",
"$",
"lang",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"url",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"id",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
... | Retrieve the object's URI.
@param string|null $lang If object is multilingual, return the object route for the specified locale.
@return Translation|string|null | [
"Retrieve",
"the",
"object",
"s",
"URI",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/App/Routing/SluggableTrait.php#L36-L51 | train |
mcaskill/charcoal-support | src/App/Routing/SluggableTrait.php | SluggableTrait.generateSlug | public function generateSlug()
{
$translator = $this->translator();
$languages = $translator->availableLocales();
$patterns = $this->slugPattern();
$curSlug = $this->slug();
$newSlug = [];
$origLang = $translator->getLocale();
foreach ($languages as $lang) {
$pattern = $patterns[$lang];
$translator->setLocale($lang);
if ($this->isSlugEditable() && isset($curSlug[$lang]) && strlen($curSlug[$lang])) {
$newSlug[$lang] = $curSlug[$lang];
} else {
$newSlug[$lang] = $this->generateRoutePattern($pattern);
if (!strlen($newSlug[$lang])) {
throw new UnexpectedValueException(sprintf(
'The slug is empty; the pattern is "%s"',
$pattern
));
}
}
}
$translator->setLocale($origLang);
return $translator->translation($newSlug);
} | php | public function generateSlug()
{
$translator = $this->translator();
$languages = $translator->availableLocales();
$patterns = $this->slugPattern();
$curSlug = $this->slug();
$newSlug = [];
$origLang = $translator->getLocale();
foreach ($languages as $lang) {
$pattern = $patterns[$lang];
$translator->setLocale($lang);
if ($this->isSlugEditable() && isset($curSlug[$lang]) && strlen($curSlug[$lang])) {
$newSlug[$lang] = $curSlug[$lang];
} else {
$newSlug[$lang] = $this->generateRoutePattern($pattern);
if (!strlen($newSlug[$lang])) {
throw new UnexpectedValueException(sprintf(
'The slug is empty; the pattern is "%s"',
$pattern
));
}
}
}
$translator->setLocale($origLang);
return $translator->translation($newSlug);
} | [
"public",
"function",
"generateSlug",
"(",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
";",
"$",
"languages",
"=",
"$",
"translator",
"->",
"availableLocales",
"(",
")",
";",
"$",
"patterns",
"=",
"$",
"this",
"->",
"sl... | Generate a URI slug from the object's URL slug pattern.
Note: This method bypasses routable affixes and {@see \Charcoal\Object\ObjectRoute}.
@see RoutableTrait::generateSlug()
@throws UnexpectedValueException If the slug is empty.
@return Translation|string|null | [
"Generate",
"a",
"URI",
"slug",
"from",
"the",
"object",
"s",
"URL",
"slug",
"pattern",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/App/Routing/SluggableTrait.php#L62-L90 | train |
fxpio/fxp-cache | Adapter/PhpArrayAdapter.php | PhpArrayAdapter.clearItems | private function clearItems(AdapterInterface $fallbackPool, array $prefixes)
{
$cleared = $fallbackPool->clearByPrefixes($prefixes);
$keys = AdapterUtil::getPropertyValue($this, 'keys') ?: [];
$values = AdapterUtil::getPropertyValue($this, 'values') ?: [];
$warmValues = [];
foreach ($keys as $key => $valuePrefix) {
foreach ($prefixes as $prefix) {
if ('' === $prefix || 0 !== strpos($key, $prefix)) {
$warmValues[$key] = $values[$valuePrefix];
}
}
}
if (\count($values) !== \count($warmValues)) {
$this->warmUp($warmValues);
}
return $cleared;
} | php | private function clearItems(AdapterInterface $fallbackPool, array $prefixes)
{
$cleared = $fallbackPool->clearByPrefixes($prefixes);
$keys = AdapterUtil::getPropertyValue($this, 'keys') ?: [];
$values = AdapterUtil::getPropertyValue($this, 'values') ?: [];
$warmValues = [];
foreach ($keys as $key => $valuePrefix) {
foreach ($prefixes as $prefix) {
if ('' === $prefix || 0 !== strpos($key, $prefix)) {
$warmValues[$key] = $values[$valuePrefix];
}
}
}
if (\count($values) !== \count($warmValues)) {
$this->warmUp($warmValues);
}
return $cleared;
} | [
"private",
"function",
"clearItems",
"(",
"AdapterInterface",
"$",
"fallbackPool",
",",
"array",
"$",
"prefixes",
")",
"{",
"$",
"cleared",
"=",
"$",
"fallbackPool",
"->",
"clearByPrefixes",
"(",
"$",
"prefixes",
")",
";",
"$",
"keys",
"=",
"AdapterUtil",
":... | Clear the items.
@param AdapterInterface $fallbackPool The fallback pool
@param string[] $prefixes The prefixes
@return bool | [
"Clear",
"the",
"items",
"."
] | 55abf44a954890080fa2bfb080914ce7228ea769 | https://github.com/fxpio/fxp-cache/blob/55abf44a954890080fa2bfb080914ce7228ea769/Adapter/PhpArrayAdapter.php#L66-L86 | train |
World-Architects/cakephp-fixture-check | src/Shell/FixtureCheckShell.php | FixtureCheckShell._compareFields | public function _compareFields($fixtureFields, $liveFields) {
// Warn only about relevant fields
$list = [
'autoIncrement',
'default',
'length',
'null',
'precision',
'type',
'unsigned',
];
$errors = [];
foreach ($fixtureFields as $fieldName => $fixtureField) {
if (!isset($liveFields[$fieldName])) {
$this->out('Field ' . $fieldName . ' is missing from the live DB!');
continue;
}
$liveField = $liveFields[$fieldName];
foreach ($fixtureField as $key => $value) {
if (!in_array($key, $list)) {
continue;
}
if (!isset($liveField[$key]) && $value !== null) {
$errors[] = ' * ' . sprintf('Field attribute `%s` is missing from the live DB!', $fieldName . ':' . $key);
continue;
}
if ($liveField[$key] !== $value) {
$errors[] = ' * ' . sprintf(
'Field attribute `%s` differs from live DB! (`%s` vs `%s` live)',
$fieldName . ':' . $key,
Debugger::exportVar($value, true),
Debugger::exportVar($liveField[$key], true)
);
}
}
}
if (!$errors) {
return;
}
$this->warn('The following field attributes mismatch:');
$this->out($errors);
$this->_issuesFound = true;
$this->out($this->nl(0));
} | php | public function _compareFields($fixtureFields, $liveFields) {
// Warn only about relevant fields
$list = [
'autoIncrement',
'default',
'length',
'null',
'precision',
'type',
'unsigned',
];
$errors = [];
foreach ($fixtureFields as $fieldName => $fixtureField) {
if (!isset($liveFields[$fieldName])) {
$this->out('Field ' . $fieldName . ' is missing from the live DB!');
continue;
}
$liveField = $liveFields[$fieldName];
foreach ($fixtureField as $key => $value) {
if (!in_array($key, $list)) {
continue;
}
if (!isset($liveField[$key]) && $value !== null) {
$errors[] = ' * ' . sprintf('Field attribute `%s` is missing from the live DB!', $fieldName . ':' . $key);
continue;
}
if ($liveField[$key] !== $value) {
$errors[] = ' * ' . sprintf(
'Field attribute `%s` differs from live DB! (`%s` vs `%s` live)',
$fieldName . ':' . $key,
Debugger::exportVar($value, true),
Debugger::exportVar($liveField[$key], true)
);
}
}
}
if (!$errors) {
return;
}
$this->warn('The following field attributes mismatch:');
$this->out($errors);
$this->_issuesFound = true;
$this->out($this->nl(0));
} | [
"public",
"function",
"_compareFields",
"(",
"$",
"fixtureFields",
",",
"$",
"liveFields",
")",
"{",
"// Warn only about relevant fields",
"$",
"list",
"=",
"[",
"'autoIncrement'",
",",
"'default'",
",",
"'length'",
",",
"'null'",
",",
"'precision'",
",",
"'type'"... | Compare the fields present.
@param array $fixtureFields The fixtures fields array.
@param array $liveFields The live DB fields
@return void | [
"Compare",
"the",
"fields",
"present",
"."
] | 3a2add52036309c60d4d7c4dee6edd5c72bec467 | https://github.com/World-Architects/cakephp-fixture-check/blob/3a2add52036309c60d4d7c4dee6edd5c72bec467/src/Shell/FixtureCheckShell.php#L140-L190 | train |
cmsgears/module-core | common/services/entities/ThemeService.php | ThemeService.makeDefault | public function makeDefault( Theme $model, $config = [] ) {
$modelClass = static::$modelClass;
$type = CoreGlobal::TYPE_SITE;
if( $model->type !== $type ) {
return false;
}
// Disable All
$modelClass::updateAll( [ 'default' => false ], "`default`=1 AND `type`='$type'" );
// Make Default
$model->default = true;
// Update
return parent::update( $model, [
'attributes' => [ 'default' ]
]);
} | php | public function makeDefault( Theme $model, $config = [] ) {
$modelClass = static::$modelClass;
$type = CoreGlobal::TYPE_SITE;
if( $model->type !== $type ) {
return false;
}
// Disable All
$modelClass::updateAll( [ 'default' => false ], "`default`=1 AND `type`='$type'" );
// Make Default
$model->default = true;
// Update
return parent::update( $model, [
'attributes' => [ 'default' ]
]);
} | [
"public",
"function",
"makeDefault",
"(",
"Theme",
"$",
"model",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"modelClass",
"=",
"static",
"::",
"$",
"modelClass",
";",
"$",
"type",
"=",
"CoreGlobal",
"::",
"TYPE_SITE",
";",
"if",
"(",
"$",
"mod... | Make the default theme available for all sites in case no theme is selected.
@param type $model
@param type $config
@return type | [
"Make",
"the",
"default",
"theme",
"available",
"for",
"all",
"sites",
"in",
"case",
"no",
"theme",
"is",
"selected",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/services/entities/ThemeService.php#L289-L310 | train |
rodrigoiii/skeleton-core | src/classes/AppPhinx.php | AppPhinx.loadEnvironment | private function loadEnvironment()
{
/**
* Application Environment
*/
$required_env = [
# application configuration
'APP_NAME', 'APP_ENV', 'APP_KEY',
# database configuration
'DB_HOSTNAME', 'DB_PORT', 'DB_USERNAME', 'DB_PASSWORD', 'DB_NAME',
# application mode
'APP_MODE'
];
$root = $_SERVER['PWD'];
$dotenv = new Dotenv($root);
$dotenv->overload();
$dotenv->required($required_env);
} | php | private function loadEnvironment()
{
/**
* Application Environment
*/
$required_env = [
# application configuration
'APP_NAME', 'APP_ENV', 'APP_KEY',
# database configuration
'DB_HOSTNAME', 'DB_PORT', 'DB_USERNAME', 'DB_PASSWORD', 'DB_NAME',
# application mode
'APP_MODE'
];
$root = $_SERVER['PWD'];
$dotenv = new Dotenv($root);
$dotenv->overload();
$dotenv->required($required_env);
} | [
"private",
"function",
"loadEnvironment",
"(",
")",
"{",
"/**\n * Application Environment\n */",
"$",
"required_env",
"=",
"[",
"# application configuration",
"'APP_NAME'",
",",
"'APP_ENV'",
",",
"'APP_KEY'",
",",
"# database configuration",
"'DB_HOSTNAME'",
"... | Load the environment of the Application Phinx.
@return void | [
"Load",
"the",
"environment",
"of",
"the",
"Application",
"Phinx",
"."
] | 5dab0637b9cd0f55a64b1f5926d7ba6bb3f93df0 | https://github.com/rodrigoiii/skeleton-core/blob/5dab0637b9cd0f55a64b1f5926d7ba6bb3f93df0/src/classes/AppPhinx.php#L51-L72 | train |
apioo/psx-http | src/Parser/ParserAbstract.php | ParserAbstract.splitMessage | protected function splitMessage($message)
{
if ($this->mode == self::MODE_STRICT) {
$pos = strpos($message, Http::NEW_LINE . Http::NEW_LINE);
$header = substr($message, 0, $pos);
$body = trim(substr($message, $pos + 1));
} elseif ($this->mode == self::MODE_LOOSE) {
$lines = explode("\n", $message);
$header = '';
$body = '';
$found = false;
$count = count($lines);
foreach ($lines as $i => $line) {
$line = trim($line);
if (!$found && empty($line)) {
$found = true;
continue;
}
if (!$found) {
$header.= $line . Http::NEW_LINE;
} else {
$body.= $line . ($i < $count - 1 ? "\n" : '');
}
}
}
return array($header, $body);
} | php | protected function splitMessage($message)
{
if ($this->mode == self::MODE_STRICT) {
$pos = strpos($message, Http::NEW_LINE . Http::NEW_LINE);
$header = substr($message, 0, $pos);
$body = trim(substr($message, $pos + 1));
} elseif ($this->mode == self::MODE_LOOSE) {
$lines = explode("\n", $message);
$header = '';
$body = '';
$found = false;
$count = count($lines);
foreach ($lines as $i => $line) {
$line = trim($line);
if (!$found && empty($line)) {
$found = true;
continue;
}
if (!$found) {
$header.= $line . Http::NEW_LINE;
} else {
$body.= $line . ($i < $count - 1 ? "\n" : '');
}
}
}
return array($header, $body);
} | [
"protected",
"function",
"splitMessage",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"mode",
"==",
"self",
"::",
"MODE_STRICT",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"message",
",",
"Http",
"::",
"NEW_LINE",
".",
"Http",
"::... | Splits an given http message into the header and body part
@param string $message
@return array | [
"Splits",
"an",
"given",
"http",
"message",
"into",
"the",
"header",
"and",
"body",
"part"
] | c54d7212cfb513df84f810429aa34c6ac9942c01 | https://github.com/apioo/psx-http/blob/c54d7212cfb513df84f810429aa34c6ac9942c01/src/Parser/ParserAbstract.php#L72-L102 | train |
apioo/psx-http | src/Parser/ParserAbstract.php | ParserAbstract.headerToArray | protected function headerToArray(MessageInterface $message, $header)
{
$lines = explode(Http::NEW_LINE, $header);
foreach ($lines as $line) {
$parts = explode(':', $line, 2);
if (isset($parts[0]) && isset($parts[1])) {
$key = $parts[0];
$value = substr($parts[1], 1);
$message->addHeader($key, $value);
}
}
} | php | protected function headerToArray(MessageInterface $message, $header)
{
$lines = explode(Http::NEW_LINE, $header);
foreach ($lines as $line) {
$parts = explode(':', $line, 2);
if (isset($parts[0]) && isset($parts[1])) {
$key = $parts[0];
$value = substr($parts[1], 1);
$message->addHeader($key, $value);
}
}
} | [
"protected",
"function",
"headerToArray",
"(",
"MessageInterface",
"$",
"message",
",",
"$",
"header",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"Http",
"::",
"NEW_LINE",
",",
"$",
"header",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
... | Parses an raw http header string into an Message object
@param \PSX\Http\MessageInterface $message
@param string $header | [
"Parses",
"an",
"raw",
"http",
"header",
"string",
"into",
"an",
"Message",
"object"
] | c54d7212cfb513df84f810429aa34c6ac9942c01 | https://github.com/apioo/psx-http/blob/c54d7212cfb513df84f810429aa34c6ac9942c01/src/Parser/ParserAbstract.php#L127-L141 | train |
cmsgears/module-core | common/services/traits/mappers/CategoryTrait.php | CategoryTrait.getPinnedByCategoryId | public function getPinnedByCategoryId( $categoryId, $config = [] ) {
$modelClass = static::$modelClass;
$modelTable = $this->getModelTable();
$config[ 'page' ] = isset( $config[ 'page' ] ) ? $config[ 'page' ] : false;
$config[ 'query' ] = isset( $config[ 'query' ] ) ? $config[ 'query' ] : $modelClass::find();
$config[ 'limit' ] = isset( $config[ 'limit' ] ) ? $config[ 'limit' ] : 10;
$config[ 'active' ] = isset( $config[ 'active' ] ) ? $config[ 'active' ] : true;
if( $config[ 'active' ] ) {
$config[ 'query' ]->joinWith( 'activeCategories' )->andWhere( [ 'modelId' => $categoryId, "$modelTable.pinned" => true ] );
}
else {
$config[ 'query' ]->joinWith( 'categories' )->andWhere( [ 'modelId' => $categoryId, "$modelTable.pinned" => true ] );
}
if( $config[ 'page' ] ) {
$page = $this->getPublicPage( $config );
return $page->getModels();
}
return $config[ 'query' ]->limit( $config[ 'limit' ] )->all();
} | php | public function getPinnedByCategoryId( $categoryId, $config = [] ) {
$modelClass = static::$modelClass;
$modelTable = $this->getModelTable();
$config[ 'page' ] = isset( $config[ 'page' ] ) ? $config[ 'page' ] : false;
$config[ 'query' ] = isset( $config[ 'query' ] ) ? $config[ 'query' ] : $modelClass::find();
$config[ 'limit' ] = isset( $config[ 'limit' ] ) ? $config[ 'limit' ] : 10;
$config[ 'active' ] = isset( $config[ 'active' ] ) ? $config[ 'active' ] : true;
if( $config[ 'active' ] ) {
$config[ 'query' ]->joinWith( 'activeCategories' )->andWhere( [ 'modelId' => $categoryId, "$modelTable.pinned" => true ] );
}
else {
$config[ 'query' ]->joinWith( 'categories' )->andWhere( [ 'modelId' => $categoryId, "$modelTable.pinned" => true ] );
}
if( $config[ 'page' ] ) {
$page = $this->getPublicPage( $config );
return $page->getModels();
}
return $config[ 'query' ]->limit( $config[ 'limit' ] )->all();
} | [
"public",
"function",
"getPinnedByCategoryId",
"(",
"$",
"categoryId",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"modelClass",
"=",
"static",
"::",
"$",
"modelClass",
";",
"$",
"modelTable",
"=",
"$",
"this",
"->",
"getModelTable",
"(",
")",
";",... | Works only with models having pinned column | [
"Works",
"only",
"with",
"models",
"having",
"pinned",
"column"
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/services/traits/mappers/CategoryTrait.php#L104-L131 | train |
cmsgears/module-core | common/components/FormDesigner.php | FormDesigner.getFieldHtml | public function getFieldHtml( $form, $model, $config, $key, $field ) {
switch( $field->type ) {
case FormField::TYPE_TEXT: {
return $this->getTextHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_HIDDEN: {
return $this->getHiddenHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_PASSWORD: {
return $this->getPasswordHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_TEXTAREA: {
return $this->getTextareaHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_CHECKBOX: {
return $form->field( $model, $key )->checkbox( $field->htmlOptions );
}
case FormField::TYPE_TOGGLE: {
return $form->field( $model, $key, [ 'class' => 'switch' ] )->checkbox( $field->htmlOptions );
}
case FormField::TYPE_CHECKBOX_GROUP: {
return $this->getCheckboxGroupHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_RADIO: {
return $form->field( $model, $key )->radio( $field->htmlOptions );
}
case FormField::TYPE_RADIO_GROUP: {
return $this->getRadioGroupHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_SELECT: {
return $this->getSelectHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_RATING : {
return $this->getRatingHtml( $form, $model, $config, $key, $field );
}
}
} | php | public function getFieldHtml( $form, $model, $config, $key, $field ) {
switch( $field->type ) {
case FormField::TYPE_TEXT: {
return $this->getTextHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_HIDDEN: {
return $this->getHiddenHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_PASSWORD: {
return $this->getPasswordHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_TEXTAREA: {
return $this->getTextareaHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_CHECKBOX: {
return $form->field( $model, $key )->checkbox( $field->htmlOptions );
}
case FormField::TYPE_TOGGLE: {
return $form->field( $model, $key, [ 'class' => 'switch' ] )->checkbox( $field->htmlOptions );
}
case FormField::TYPE_CHECKBOX_GROUP: {
return $this->getCheckboxGroupHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_RADIO: {
return $form->field( $model, $key )->radio( $field->htmlOptions );
}
case FormField::TYPE_RADIO_GROUP: {
return $this->getRadioGroupHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_SELECT: {
return $this->getSelectHtml( $form, $model, $config, $key, $field );
}
case FormField::TYPE_RATING : {
return $this->getRatingHtml( $form, $model, $config, $key, $field );
}
}
} | [
"public",
"function",
"getFieldHtml",
"(",
"$",
"form",
",",
"$",
"model",
",",
"$",
"config",
",",
"$",
"key",
",",
"$",
"field",
")",
"{",
"switch",
"(",
"$",
"field",
"->",
"type",
")",
"{",
"case",
"FormField",
"::",
"TYPE_TEXT",
":",
"{",
"ret... | Generate field html using Yii Form Widget.
@param FormField $field | [
"Generate",
"field",
"html",
"using",
"Yii",
"Form",
"Widget",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/components/FormDesigner.php#L63-L112 | train |
cmsgears/module-core | common/components/FormDesigner.php | FormDesigner.getApixFieldHtml | public function getApixFieldHtml( $config, $field, $value = null ) {
switch( $field->type ) {
case FormField::TYPE_TEXT: {
return $this->getApixTextHtml( $config, $field, $value );
}
case FormField::TYPE_HIDDEN: {
return $this->getApixHiddenHtml( $config, $field, $value );
}
case FormField::TYPE_PASSWORD: {
return $this->getApixPasswordHtml( $config, $field );
}
case FormField::TYPE_TEXTAREA: {
return $this->getApixTextareaHtml( $config, $field, $value );
}
case FormField::TYPE_CHECKBOX: {
return $this->getApixCheckboxHtml( $config, $field, $value );
}
case FormField::TYPE_TOGGLE: {
return $this->getApixToggleHtml( $config, $field, $value );
}
case FormField::TYPE_CHECKBOX_GROUP: {
return $this->getApixCheckboxGroupHtml( $config, $field, $value );
}
case FormField::TYPE_RADIO: {
return $this->getApixRadioHtml( $config, $field, $value );
}
case FormField::TYPE_RADIO_GROUP: {
return $this->getApixRadioGroupHtml( $config, $field, $value );
}
case FormField::TYPE_SELECT: {
return $this->getApixSelectHtml( $config, $field, $value );
}
case FormField::TYPE_RATING: {
return $this->getApixRatingHtml( $config, $field, $value );
}
case FormField::TYPE_DATE: {
return $this->getApixDateHtml( $config, $field, $value );
}
}
} | php | public function getApixFieldHtml( $config, $field, $value = null ) {
switch( $field->type ) {
case FormField::TYPE_TEXT: {
return $this->getApixTextHtml( $config, $field, $value );
}
case FormField::TYPE_HIDDEN: {
return $this->getApixHiddenHtml( $config, $field, $value );
}
case FormField::TYPE_PASSWORD: {
return $this->getApixPasswordHtml( $config, $field );
}
case FormField::TYPE_TEXTAREA: {
return $this->getApixTextareaHtml( $config, $field, $value );
}
case FormField::TYPE_CHECKBOX: {
return $this->getApixCheckboxHtml( $config, $field, $value );
}
case FormField::TYPE_TOGGLE: {
return $this->getApixToggleHtml( $config, $field, $value );
}
case FormField::TYPE_CHECKBOX_GROUP: {
return $this->getApixCheckboxGroupHtml( $config, $field, $value );
}
case FormField::TYPE_RADIO: {
return $this->getApixRadioHtml( $config, $field, $value );
}
case FormField::TYPE_RADIO_GROUP: {
return $this->getApixRadioGroupHtml( $config, $field, $value );
}
case FormField::TYPE_SELECT: {
return $this->getApixSelectHtml( $config, $field, $value );
}
case FormField::TYPE_RATING: {
return $this->getApixRatingHtml( $config, $field, $value );
}
case FormField::TYPE_DATE: {
return $this->getApixDateHtml( $config, $field, $value );
}
}
} | [
"public",
"function",
"getApixFieldHtml",
"(",
"$",
"config",
",",
"$",
"field",
",",
"$",
"value",
"=",
"null",
")",
"{",
"switch",
"(",
"$",
"field",
"->",
"type",
")",
"{",
"case",
"FormField",
"::",
"TYPE_TEXT",
":",
"{",
"return",
"$",
"this",
"... | Generate field html for CMGTools JS Library.
@param FormField $field | [
"Generate",
"field",
"html",
"for",
"CMGTools",
"JS",
"Library",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/components/FormDesigner.php#L347-L400 | train |
cmsgears/module-core | common/components/FormDesigner.php | FormDesigner.getRatingStars | public function getRatingStars( $config = [] ) {
$class = isset( $config[ 'class' ] ) && !empty( $config[ 'class' ] ) ? $config[ 'class' ] : 'cmt-rating';
$stars = isset( $config[ 'stars' ] ) ? $config[ 'stars' ] : 5;
$selected = isset( $config[ 'selected' ] ) ? $config[ 'selected' ] : 0;
$disabled = isset( $config[ 'disabled' ] ) ? $config[ 'disabled' ] : false;
$readonly = isset( $config[ 'readonly' ] ) ? $config[ 'readonly' ] : false;
if( $disabled ) {
$class = "$class disabled";
}
if( $readonly ) {
$class = "$class read-only";
}
$ratingHtml = "<div class=\"$class\"><div class=\"wrap-stars\">";
for( $i = 1; $i <= $stars; $i++ ) {
if( $selected > 0 && $selected == $i ) {
$icon = "<span star=\"$i\" class=\"star selected\"></span>";
}
else {
$icon = "<span star=\"$i\" class=\"star\"></span>";
}
$ratingHtml .= $icon;
}
$ratingHtml .= "</div></div>";
return $ratingHtml;
} | php | public function getRatingStars( $config = [] ) {
$class = isset( $config[ 'class' ] ) && !empty( $config[ 'class' ] ) ? $config[ 'class' ] : 'cmt-rating';
$stars = isset( $config[ 'stars' ] ) ? $config[ 'stars' ] : 5;
$selected = isset( $config[ 'selected' ] ) ? $config[ 'selected' ] : 0;
$disabled = isset( $config[ 'disabled' ] ) ? $config[ 'disabled' ] : false;
$readonly = isset( $config[ 'readonly' ] ) ? $config[ 'readonly' ] : false;
if( $disabled ) {
$class = "$class disabled";
}
if( $readonly ) {
$class = "$class read-only";
}
$ratingHtml = "<div class=\"$class\"><div class=\"wrap-stars\">";
for( $i = 1; $i <= $stars; $i++ ) {
if( $selected > 0 && $selected == $i ) {
$icon = "<span star=\"$i\" class=\"star selected\"></span>";
}
else {
$icon = "<span star=\"$i\" class=\"star\"></span>";
}
$ratingHtml .= $icon;
}
$ratingHtml .= "</div></div>";
return $ratingHtml;
} | [
"public",
"function",
"getRatingStars",
"(",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"class",
"=",
"isset",
"(",
"$",
"config",
"[",
"'class'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"config",
"[",
"'class'",
"]",
")",
"?",
"$",
"config",
"... | Generate and return stars html without field. Field must be added within same parent
in case selected value has to be preserved.
@param type $config
@return string | [
"Generate",
"and",
"return",
"stars",
"html",
"without",
"field",
".",
"Field",
"must",
"be",
"added",
"within",
"same",
"parent",
"in",
"case",
"selected",
"value",
"has",
"to",
"be",
"preserved",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/components/FormDesigner.php#L1130-L1167 | train |
cmsgears/module-core | common/components/FormDesigner.php | FormDesigner.getRatingField | public function getRatingField( $config = [] ) {
$class = isset( $config[ 'class' ] ) && !empty( $config[ 'class' ] ) ? $config[ 'class' ] : 'cmt-rating';
$stars = isset( $config[ 'stars' ] ) ? $config[ 'stars' ] : 5;
$label = isset( $config[ 'label' ] ) ? $config[ 'label' ] : null;
$readOnly = isset( $config[ 'readOnly' ] ) ? $config[ 'readOnly' ] : false;
$selected = isset( $config[ 'selected' ] ) ? $config[ 'selected' ] : 0;
$disabled = isset( $config[ 'disabled' ] ) ? $config[ 'disabled' ] : false;
// By default message provided for 5 stars
$starMessage = isset( $config[ 'message' ] ) ? $config[ 'message' ] : [ "Poor", "Good", "Very Good", "Perfect", "Excellent" ];
$modelName = $config[ 'modelName' ];
$fieldName = isset( $config[ 'fieldName' ] ) ? $config[ 'fieldName' ] : 'rating';
$fieldName = $modelName . "[$fieldName]";
if( $readOnly ) {
$class = "$class read-only";
}
if( $disabled ) {
$class = "$class disabled";
}
if( isset( $label ) ) {
// element-60 will work if form is configured for 40-60 split, else it will behave as normal field
$ratingHtml = "<label>$label</label><div class=\"element-60 $class\">";
}
else {
$ratingHtml = "<div class=\"$class\">";
}
$ratingHtml .= '<span class="wrap-stars">';
for( $i = 1; $i <= $stars; $i++ ) {
if( $selected == $i ) {
$icon = "<span star=\"$i\" class=\"star selected\"></span>";
}
else {
$icon = "<span star=\"$i\" class=\"star\"></span>";
}
$ratingHtml .= $icon;
}
$ratingHtml .= '</span>';
$ratingHtml .= '<span class="wrap-messages">';
for( $i = 1; $i <= $stars; $i++ ) {
$message = $starMessage[ $i - 1 ];
if( $selected == $i ) {
$icon = "<span star-message=\"$i\" class=\"star-message selected\">$message</span>";
}
else {
$icon = "<span star-message=\"$i\" class=\"star-message\">$message</span>";
}
$ratingHtml .= $icon;
}
$ratingHtml .= '</span>';
$ratingHtml .= '<input class="star-selected" type="hidden" name="' . $fieldName . '" value="' . $selected . '">';
$ratingHtml .= "</div>";
return $ratingHtml;
} | php | public function getRatingField( $config = [] ) {
$class = isset( $config[ 'class' ] ) && !empty( $config[ 'class' ] ) ? $config[ 'class' ] : 'cmt-rating';
$stars = isset( $config[ 'stars' ] ) ? $config[ 'stars' ] : 5;
$label = isset( $config[ 'label' ] ) ? $config[ 'label' ] : null;
$readOnly = isset( $config[ 'readOnly' ] ) ? $config[ 'readOnly' ] : false;
$selected = isset( $config[ 'selected' ] ) ? $config[ 'selected' ] : 0;
$disabled = isset( $config[ 'disabled' ] ) ? $config[ 'disabled' ] : false;
// By default message provided for 5 stars
$starMessage = isset( $config[ 'message' ] ) ? $config[ 'message' ] : [ "Poor", "Good", "Very Good", "Perfect", "Excellent" ];
$modelName = $config[ 'modelName' ];
$fieldName = isset( $config[ 'fieldName' ] ) ? $config[ 'fieldName' ] : 'rating';
$fieldName = $modelName . "[$fieldName]";
if( $readOnly ) {
$class = "$class read-only";
}
if( $disabled ) {
$class = "$class disabled";
}
if( isset( $label ) ) {
// element-60 will work if form is configured for 40-60 split, else it will behave as normal field
$ratingHtml = "<label>$label</label><div class=\"element-60 $class\">";
}
else {
$ratingHtml = "<div class=\"$class\">";
}
$ratingHtml .= '<span class="wrap-stars">';
for( $i = 1; $i <= $stars; $i++ ) {
if( $selected == $i ) {
$icon = "<span star=\"$i\" class=\"star selected\"></span>";
}
else {
$icon = "<span star=\"$i\" class=\"star\"></span>";
}
$ratingHtml .= $icon;
}
$ratingHtml .= '</span>';
$ratingHtml .= '<span class="wrap-messages">';
for( $i = 1; $i <= $stars; $i++ ) {
$message = $starMessage[ $i - 1 ];
if( $selected == $i ) {
$icon = "<span star-message=\"$i\" class=\"star-message selected\">$message</span>";
}
else {
$icon = "<span star-message=\"$i\" class=\"star-message\">$message</span>";
}
$ratingHtml .= $icon;
}
$ratingHtml .= '</span>';
$ratingHtml .= '<input class="star-selected" type="hidden" name="' . $fieldName . '" value="' . $selected . '">';
$ratingHtml .= "</div>";
return $ratingHtml;
} | [
"public",
"function",
"getRatingField",
"(",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"class",
"=",
"isset",
"(",
"$",
"config",
"[",
"'class'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"config",
"[",
"'class'",
"]",
")",
"?",
"$",
"config",
"... | Generate and return stars html with hidden field.
@param type $config
@return string | [
"Generate",
"and",
"return",
"stars",
"html",
"with",
"hidden",
"field",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/components/FormDesigner.php#L1175-L1254 | train |
Innmind/AMQP | src/Model/Exchange/Declaration.php | Declaration.passive | public static function passive(string $name, Type $type): self
{
$self = new self($name, $type);
$self->passive = true;
return $self;
} | php | public static function passive(string $name, Type $type): self
{
$self = new self($name, $type);
$self->passive = true;
return $self;
} | [
"public",
"static",
"function",
"passive",
"(",
"string",
"$",
"name",
",",
"Type",
"$",
"type",
")",
":",
"self",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
"$",
"name",
",",
"$",
"type",
")",
";",
"$",
"self",
"->",
"passive",
"=",
"true",
";",... | Check if the exchange with the given name exists on the server | [
"Check",
"if",
"the",
"exchange",
"with",
"the",
"given",
"name",
"exists",
"on",
"the",
"server"
] | c22b3a8f56162f7845a13c149cb3118e5fe7cffd | https://github.com/Innmind/AMQP/blob/c22b3a8f56162f7845a13c149cb3118e5fe7cffd/src/Model/Exchange/Declaration.php#L32-L38 | train |
Innmind/AMQP | src/Model/Exchange/Declaration.php | Declaration.durable | public static function durable(string $name, Type $type): self
{
$self = new self($name, $type);
$self->durable = true;
return $self;
} | php | public static function durable(string $name, Type $type): self
{
$self = new self($name, $type);
$self->durable = true;
return $self;
} | [
"public",
"static",
"function",
"durable",
"(",
"string",
"$",
"name",
",",
"Type",
"$",
"type",
")",
":",
"self",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
"$",
"name",
",",
"$",
"type",
")",
";",
"$",
"self",
"->",
"durable",
"=",
"true",
";",... | The exchange will survive after a server restart | [
"The",
"exchange",
"will",
"survive",
"after",
"a",
"server",
"restart"
] | c22b3a8f56162f7845a13c149cb3118e5fe7cffd | https://github.com/Innmind/AMQP/blob/c22b3a8f56162f7845a13c149cb3118e5fe7cffd/src/Model/Exchange/Declaration.php#L43-L49 | train |
Innmind/AMQP | src/Model/Exchange/Declaration.php | Declaration.autoDelete | public static function autoDelete(string $name, Type $type): self
{
$self = new self($name, $type);
$self->autoDelete = true;
$self->durable = false;
return $self;
} | php | public static function autoDelete(string $name, Type $type): self
{
$self = new self($name, $type);
$self->autoDelete = true;
$self->durable = false;
return $self;
} | [
"public",
"static",
"function",
"autoDelete",
"(",
"string",
"$",
"name",
",",
"Type",
"$",
"type",
")",
":",
"self",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
"$",
"name",
",",
"$",
"type",
")",
";",
"$",
"self",
"->",
"autoDelete",
"=",
"true",
... | The exchange will disappear once it's no longer used | [
"The",
"exchange",
"will",
"disappear",
"once",
"it",
"s",
"no",
"longer",
"used"
] | c22b3a8f56162f7845a13c149cb3118e5fe7cffd | https://github.com/Innmind/AMQP/blob/c22b3a8f56162f7845a13c149cb3118e5fe7cffd/src/Model/Exchange/Declaration.php#L62-L69 | train |
mcaskill/charcoal-support | src/Cms/ContextualTemplateTrait.php | ContextualTemplateTrait.contextObject | public function contextObject()
{
if ($this->contextObject === null) {
$this->contextObject = $this->createGenericContext();
}
return $this->contextObject;
} | php | public function contextObject()
{
if ($this->contextObject === null) {
$this->contextObject = $this->createGenericContext();
}
return $this->contextObject;
} | [
"public",
"function",
"contextObject",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"contextObject",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"contextObject",
"=",
"$",
"this",
"->",
"createGenericContext",
"(",
")",
";",
"}",
"return",
"$",
"this",
... | Retrieve the current object relative to the context.
This method is meant to be reimplemented in a child template controller
to return the resolved object that the module considers "the context".
@return ModelInterface|null | [
"Retrieve",
"the",
"current",
"object",
"relative",
"to",
"the",
"context",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/ContextualTemplateTrait.php#L107-L114 | train |
mcaskill/charcoal-support | src/Cms/ContextualTemplateTrait.php | ContextualTemplateTrait.createGenericContext | protected function createGenericContext()
{
if ($this->isCreatingContext) {
return null;
}
$this->isCreatingContext = true;
$obj = $this->modelFactory()->create($this->genericContextClass());
$baseUrl = $this->baseUrl();
if ($this->routeEndpoint) {
$endpoint = $this->translator()->translation($this->routeEndpoint);
foreach ($this->translator()->availableLocales() as $lang) {
$uri = $baseUrl->withPath($endpoint[$lang]);
if ($this->routeGroup) {
$uri = $uri->withBasePath($this->routeGroup[$lang]);
}
$base = $uri->getBasePath();
$path = $uri->getPath();
$path = $base . '/' . ltrim($path, '/');
$endpoint[$lang] = $path;
}
} else {
$endpoint = null;
}
$obj['url'] = $endpoint;
$obj['title'] = $this->title();
$this->isCreatingContext = false;
return $obj;
} | php | protected function createGenericContext()
{
if ($this->isCreatingContext) {
return null;
}
$this->isCreatingContext = true;
$obj = $this->modelFactory()->create($this->genericContextClass());
$baseUrl = $this->baseUrl();
if ($this->routeEndpoint) {
$endpoint = $this->translator()->translation($this->routeEndpoint);
foreach ($this->translator()->availableLocales() as $lang) {
$uri = $baseUrl->withPath($endpoint[$lang]);
if ($this->routeGroup) {
$uri = $uri->withBasePath($this->routeGroup[$lang]);
}
$base = $uri->getBasePath();
$path = $uri->getPath();
$path = $base . '/' . ltrim($path, '/');
$endpoint[$lang] = $path;
}
} else {
$endpoint = null;
}
$obj['url'] = $endpoint;
$obj['title'] = $this->title();
$this->isCreatingContext = false;
return $obj;
} | [
"protected",
"function",
"createGenericContext",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCreatingContext",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"isCreatingContext",
"=",
"true",
";",
"$",
"obj",
"=",
"$",
"this",
"->",
"modelF... | Create a generic object relative to the context.
@return ModelInterface|null | [
"Create",
"a",
"generic",
"object",
"relative",
"to",
"the",
"context",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/ContextualTemplateTrait.php#L121-L157 | train |
mcaskill/charcoal-support | src/Cms/ContextualTemplateTrait.php | ContextualTemplateTrait.setRouteGroup | public function setRouteGroup($path)
{
$group = $this->translator()->translation($path);
foreach ($this->translator()->availableLocales() as $lang) {
$group[$lang] = trim($group[$lang], '/');
}
$this->routeGroup = $group;
return $this;
} | php | public function setRouteGroup($path)
{
$group = $this->translator()->translation($path);
foreach ($this->translator()->availableLocales() as $lang) {
$group[$lang] = trim($group[$lang], '/');
}
$this->routeGroup = $group;
return $this;
} | [
"public",
"function",
"setRouteGroup",
"(",
"$",
"path",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translation",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"availa... | Append a path to the base URI.
@param string $path The base path.
@return self | [
"Append",
"a",
"path",
"to",
"the",
"base",
"URI",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/ContextualTemplateTrait.php#L181-L192 | train |
mcaskill/charcoal-support | src/Cms/ContextualTemplateTrait.php | ContextualTemplateTrait.setRouteEndpoint | public function setRouteEndpoint($path)
{
$endpoint = $this->translator()->translation($path);
foreach ($this->translator()->availableLocales() as $lang) {
$endpoint[$lang] = trim($endpoint[$lang], '/');
}
$this->routeEndpoint = $endpoint;
return $this;
} | php | public function setRouteEndpoint($path)
{
$endpoint = $this->translator()->translation($path);
foreach ($this->translator()->availableLocales() as $lang) {
$endpoint[$lang] = trim($endpoint[$lang], '/');
}
$this->routeEndpoint = $endpoint;
return $this;
} | [
"public",
"function",
"setRouteEndpoint",
"(",
"$",
"path",
")",
"{",
"$",
"endpoint",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translation",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"... | Append a path to the URI.
@param string $path The main path.
@return self | [
"Append",
"a",
"path",
"to",
"the",
"URI",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/ContextualTemplateTrait.php#L200-L211 | train |
mcaskill/charcoal-support | src/Model/Collection.php | Collection.only | public function only($keys)
{
if ($keys === null) {
return new static($this->objects);
}
$keys = is_array($keys) ? $keys : func_get_args();
return new static(array_intersect_key($this->objects, array_flip($keys)));
} | php | public function only($keys)
{
if ($keys === null) {
return new static($this->objects);
}
$keys = is_array($keys) ? $keys : func_get_args();
return new static(array_intersect_key($this->objects, array_flip($keys)));
} | [
"public",
"function",
"only",
"(",
"$",
"keys",
")",
"{",
"if",
"(",
"$",
"keys",
"===",
"null",
")",
"{",
"return",
"new",
"static",
"(",
"$",
"this",
"->",
"objects",
")",
";",
"}",
"$",
"keys",
"=",
"is_array",
"(",
"$",
"keys",
")",
"?",
"$... | Extract the objects with the specified keys.
@param mixed $keys One or more object primary keys.
@return static | [
"Extract",
"the",
"objects",
"with",
"the",
"specified",
"keys",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Model/Collection.php#L170-L179 | train |
mcaskill/charcoal-support | src/Model/Collection.php | Collection.slice | public function slice($offset, $length = null)
{
return new static(array_slice($this->objects, $offset, $length, true));
} | php | public function slice($offset, $length = null)
{
return new static(array_slice($this->objects, $offset, $length, true));
} | [
"public",
"function",
"slice",
"(",
"$",
"offset",
",",
"$",
"length",
"=",
"null",
")",
"{",
"return",
"new",
"static",
"(",
"array_slice",
"(",
"$",
"this",
"->",
"objects",
",",
"$",
"offset",
",",
"$",
"length",
",",
"true",
")",
")",
";",
"}"
... | Extract a slice of the collection.
@param integer $offset See {@see array_slice()} for a description of $offset.
@param integer $length See {@see array_slice()} for a description of $length.
@return static | [
"Extract",
"a",
"slice",
"of",
"the",
"collection",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Model/Collection.php#L188-L191 | train |
mcaskill/charcoal-support | src/Model/Collection.php | Collection.sortBy | public function sortBy($sortBy, $options = SORT_REGULAR, $descending = false)
{
$results = [];
if (is_string($sortBy)) {
$callback = function ($obj) use ($sortBy) {
return $obj[$sortBy];
};
} elseif (is_callable($sortBy)) {
$callback = $sortBy;
} else {
throw new InvalidArgumentException(sprintf(
'The comparator must be a property key or a function, received %s',
(is_object($sortBy) ? get_class($sortBy) : gettype($sortBy))
));
}
// First we will loop through the items and get the comparator from a callback
// function which we were given. Then, we will sort the returned values and
// and grab the corresponding values for the sorted keys from this array.
foreach ($this->objects as $key => $obj) {
$results[$key] = $callback($obj, $key);
}
if ($descending) {
arsort($results, $options);
} else {
asort($results, $options);
}
// Once we have sorted all of the keys in the array, we will loop through them
// and grab the corresponding model so we can set the underlying items list
// to the sorted version. Then we'll just return the collection instance.
foreach (array_keys($results) as $key) {
$results[$key] = $this->objects[$key];
}
$this->objects = $results;
return $this;
} | php | public function sortBy($sortBy, $options = SORT_REGULAR, $descending = false)
{
$results = [];
if (is_string($sortBy)) {
$callback = function ($obj) use ($sortBy) {
return $obj[$sortBy];
};
} elseif (is_callable($sortBy)) {
$callback = $sortBy;
} else {
throw new InvalidArgumentException(sprintf(
'The comparator must be a property key or a function, received %s',
(is_object($sortBy) ? get_class($sortBy) : gettype($sortBy))
));
}
// First we will loop through the items and get the comparator from a callback
// function which we were given. Then, we will sort the returned values and
// and grab the corresponding values for the sorted keys from this array.
foreach ($this->objects as $key => $obj) {
$results[$key] = $callback($obj, $key);
}
if ($descending) {
arsort($results, $options);
} else {
asort($results, $options);
}
// Once we have sorted all of the keys in the array, we will loop through them
// and grab the corresponding model so we can set the underlying items list
// to the sorted version. Then we'll just return the collection instance.
foreach (array_keys($results) as $key) {
$results[$key] = $this->objects[$key];
}
$this->objects = $results;
return $this;
} | [
"public",
"function",
"sortBy",
"(",
"$",
"sortBy",
",",
"$",
"options",
"=",
"SORT_REGULAR",
",",
"$",
"descending",
"=",
"false",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"sortBy",
")",
")",
"{",
"$",
"callb... | Sort the collection by the given callback or object property.
If a {@see \Closure} is passed, it accepts two parameters.
The collection's object first, and its primary key second.
```
mixed callback ( ModelInterface $obj, integer|string $key )
```
@param callable|string $sortBy Sort by a property or a callback.
@param integer $options See {@see sort()} for a description of $sort_flags.
@param boolean $descending If TRUE, the collection is sorted in reverse order.
@throws InvalidArgumentException If the comparator is not a string or callback.
@return self | [
"Sort",
"the",
"collection",
"by",
"the",
"given",
"callback",
"or",
"object",
"property",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Model/Collection.php#L236-L276 | train |
paulbunyannet/bandolier | src/Bandolier/Type/Arrays.php | Arrays.doDefaultAttributes | public function doDefaultAttributes()
{
foreach ((array)$this->attribute as $name => $value) {
if (array_key_exists($name, $this->data)) {
$this->data[$name] = $value;
}
}
return ($this->data) ? $this->data : false;
} | php | public function doDefaultAttributes()
{
foreach ((array)$this->attribute as $name => $value) {
if (array_key_exists($name, $this->data)) {
$this->data[$name] = $value;
}
}
return ($this->data) ? $this->data : false;
} | [
"public",
"function",
"doDefaultAttributes",
"(",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"attribute",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"... | From default attribute list, overwrite if key is found
@return array|boolean | [
"From",
"default",
"attribute",
"list",
"overwrite",
"if",
"key",
"is",
"found"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Type/Arrays.php#L57-L65 | train |
paulbunyannet/bandolier | src/Bandolier/Type/Arrays.php | Arrays.doGetAttribute | public function doGetAttribute()
{
return array_key_exists($this->attribute, $this->data) ? $this->data[$this->attribute] : $this->default;
} | php | public function doGetAttribute()
{
return array_key_exists($this->attribute, $this->data) ? $this->data[$this->attribute] : $this->default;
} | [
"public",
"function",
"doGetAttribute",
"(",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"this",
"->",
"attribute",
",",
"$",
"this",
"->",
"data",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"$",
"this",
"->",
"attribute",
"]",
":",
"$",
"this",
... | Check for key in array, return default is not found
@return mixed | [
"Check",
"for",
"key",
"in",
"array",
"return",
"default",
"is",
"not",
"found"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Type/Arrays.php#L82-L85 | train |
gregorybesson/PlaygroundReward | src/Controller/Frontend/IndexController.php | IndexController.getObjectService | public function getObjectService()
{
if (!$this->objectService) {
$this->objectService = $this->getServiceLocator()->get('playgroundflow_object_service');
}
return $this->objectService;
} | php | public function getObjectService()
{
if (!$this->objectService) {
$this->objectService = $this->getServiceLocator()->get('playgroundflow_object_service');
}
return $this->objectService;
} | [
"public",
"function",
"getObjectService",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"objectService",
")",
"{",
"$",
"this",
"->",
"objectService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'playgroundflow_object_servic... | retrieve object service
@return Service/Object $objectService | [
"retrieve",
"object",
"service"
] | 313ba96f530f27066ebaec6613f78c9bfe257862 | https://github.com/gregorybesson/PlaygroundReward/blob/313ba96f530f27066ebaec6613f78c9bfe257862/src/Controller/Frontend/IndexController.php#L249-L255 | train |
gregorybesson/PlaygroundReward | src/Controller/Frontend/IndexController.php | IndexController.getLeaderboardService | public function getLeaderboardService()
{
if (!$this->leaderboardService) {
$this->leaderboardService = $this->getServiceLocator()->get(\PlaygroundReward\Service\LeaderBoard::class);
}
return $this->leaderboardService;
} | php | public function getLeaderboardService()
{
if (!$this->leaderboardService) {
$this->leaderboardService = $this->getServiceLocator()->get(\PlaygroundReward\Service\LeaderBoard::class);
}
return $this->leaderboardService;
} | [
"public",
"function",
"getLeaderboardService",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"leaderboardService",
")",
"{",
"$",
"this",
"->",
"leaderboardService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"\\",
"Playgr... | retrieve leaderboard service
@return Service/leaderboard $leaderboardService | [
"retrieve",
"leaderboard",
"service"
] | 313ba96f530f27066ebaec6613f78c9bfe257862 | https://github.com/gregorybesson/PlaygroundReward/blob/313ba96f530f27066ebaec6613f78c9bfe257862/src/Controller/Frontend/IndexController.php#L262-L269 | train |
gregorybesson/PlaygroundReward | src/Controller/Frontend/IndexController.php | IndexController.getStoryTellingService | public function getStoryTellingService()
{
if (!$this->storyTellingService) {
$this->storyTellingService = $this->getServiceLocator()->get('playgroundflow_storytelling_service');
}
return $this->storyTellingService;
} | php | public function getStoryTellingService()
{
if (!$this->storyTellingService) {
$this->storyTellingService = $this->getServiceLocator()->get('playgroundflow_storytelling_service');
}
return $this->storyTellingService;
} | [
"public",
"function",
"getStoryTellingService",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"storyTellingService",
")",
"{",
"$",
"this",
"->",
"storyTellingService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'playground... | retrieve storyTelling service
@return Service/storyTelling $storyTellingService | [
"retrieve",
"storyTelling",
"service"
] | 313ba96f530f27066ebaec6613f78c9bfe257862 | https://github.com/gregorybesson/PlaygroundReward/blob/313ba96f530f27066ebaec6613f78c9bfe257862/src/Controller/Frontend/IndexController.php#L316-L323 | train |
mcaskill/charcoal-support | src/Cms/HasTemplateOptionsTrait.php | HasTemplateOptionsTrait.getTemplateOptions | protected function getTemplateOptions($key = null, $default = null)
{
if ($this->templateOptions === null) {
$this->templateOptions = $this->buildTemplateOptions();
}
if ($key) {
if (isset($this->templateOptions[$key])) {
return $this->templateOptions[$key];
} else {
if (!is_string($default) && is_callable($default)) {
return $default();
} else {
return $default;
}
}
}
return $this->templateOptions;
} | php | protected function getTemplateOptions($key = null, $default = null)
{
if ($this->templateOptions === null) {
$this->templateOptions = $this->buildTemplateOptions();
}
if ($key) {
if (isset($this->templateOptions[$key])) {
return $this->templateOptions[$key];
} else {
if (!is_string($default) && is_callable($default)) {
return $default();
} else {
return $default;
}
}
}
return $this->templateOptions;
} | [
"protected",
"function",
"getTemplateOptions",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"templateOptions",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"templateOptions",
"=",
"$",
"this",
"... | Retrieve the template options from the current context.
@param string|null $key Optional data key to retrieve from the configset.
@param mixed|null $default The default value to return if data key does not exist.
@return mixed|array | [
"Retrieve",
"the",
"template",
"options",
"from",
"the",
"current",
"context",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/HasTemplateOptionsTrait.php#L27-L46 | train |
mcaskill/charcoal-support | src/Cms/HasTemplateOptionsTrait.php | HasTemplateOptionsTrait.hasTemplateOption | protected function hasTemplateOption($key)
{
if ($this->templateOptions === null) {
$this->templateOptions = $this->buildTemplateOptions();
}
return isset($this->templateOptions[$key]);
} | php | protected function hasTemplateOption($key)
{
if ($this->templateOptions === null) {
$this->templateOptions = $this->buildTemplateOptions();
}
return isset($this->templateOptions[$key]);
} | [
"protected",
"function",
"hasTemplateOption",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"templateOptions",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"templateOptions",
"=",
"$",
"this",
"->",
"buildTemplateOptions",
"(",
")",
";",
"}",
"... | Determine if the template option exists.
@param string $key Data key to check.
@return boolean | [
"Determine",
"if",
"the",
"template",
"option",
"exists",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/HasTemplateOptionsTrait.php#L54-L61 | train |
cmsgears/module-core | common/models/base/Follower.php | Follower.findByFollower | public static function findByFollower( $modelId, $parentId, $type = self::TYPE_FOLLOW ) {
return self::find()->where( 'modelId=:mid AND parentId=:pid AND type =:type', [ ':mid' => $modelId, ':pid' => $parentId, ':type' => $type ] )->one();
} | php | public static function findByFollower( $modelId, $parentId, $type = self::TYPE_FOLLOW ) {
return self::find()->where( 'modelId=:mid AND parentId=:pid AND type =:type', [ ':mid' => $modelId, ':pid' => $parentId, ':type' => $type ] )->one();
} | [
"public",
"static",
"function",
"findByFollower",
"(",
"$",
"modelId",
",",
"$",
"parentId",
",",
"$",
"type",
"=",
"self",
"::",
"TYPE_FOLLOW",
")",
"{",
"return",
"self",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"'modelId=:mid AND parentId=:pid AND type =... | Find and return the follower using given follower id, parent id and type.
@param integer $modelId
@param integer $followerId
@param integer $type
@return Follower | [
"Find",
"and",
"return",
"the",
"follower",
"using",
"given",
"follower",
"id",
"parent",
"id",
"and",
"type",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/base/Follower.php#L291-L294 | train |
cmsgears/module-core | common/models/base/Follower.php | Follower.isExistByFollower | public static function isExistByFollower( $modelId, $parentId, $type = self::TYPE_FOLLOW ) {
$follower = self::findByFollower( $modelId, $parentId, $type );
return isset( $follower );
} | php | public static function isExistByFollower( $modelId, $parentId, $type = self::TYPE_FOLLOW ) {
$follower = self::findByFollower( $modelId, $parentId, $type );
return isset( $follower );
} | [
"public",
"static",
"function",
"isExistByFollower",
"(",
"$",
"modelId",
",",
"$",
"parentId",
",",
"$",
"type",
"=",
"self",
"::",
"TYPE_FOLLOW",
")",
"{",
"$",
"follower",
"=",
"self",
"::",
"findByFollower",
"(",
"$",
"modelId",
",",
"$",
"parentId",
... | Check whether follower exist using given follower id, parent id and type.
@param integer $modelId
@param integer $parentId
@param integer $type
@return boolean | [
"Check",
"whether",
"follower",
"exist",
"using",
"given",
"follower",
"id",
"parent",
"id",
"and",
"type",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/base/Follower.php#L304-L309 | train |
cmsgears/module-core | common/base/PageWidget.php | PageWidget.initPaging | public function initPaging( $config = [] ) {
// Init Pagination
if( $this->pagination && $this->paging && isset( $this->dataProvider ) ) {
$pagination = $this->dataProvider->getPagination();
$this->pageInfo = CodeGenUtil::getPaginationDetail( $this->dataProvider );
if( isset( $this->route ) ) {
$pagination->route = $this->route;
}
if( count( $this->excludeParams ) > 0 ) {
$pagination->excludeParams = $this->excludeParams;
}
$this->pageLinks = LinkPager::widget([
'pagination' => $pagination, 'disabledPageCssClass' => 'link-disabled',
'nextPageLabel' => $this->nextLabel, 'prevPageLabel' => $this->prevLabel
]);
}
} | php | public function initPaging( $config = [] ) {
// Init Pagination
if( $this->pagination && $this->paging && isset( $this->dataProvider ) ) {
$pagination = $this->dataProvider->getPagination();
$this->pageInfo = CodeGenUtil::getPaginationDetail( $this->dataProvider );
if( isset( $this->route ) ) {
$pagination->route = $this->route;
}
if( count( $this->excludeParams ) > 0 ) {
$pagination->excludeParams = $this->excludeParams;
}
$this->pageLinks = LinkPager::widget([
'pagination' => $pagination, 'disabledPageCssClass' => 'link-disabled',
'nextPageLabel' => $this->nextLabel, 'prevPageLabel' => $this->prevLabel
]);
}
} | [
"public",
"function",
"initPaging",
"(",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"// Init Pagination",
"if",
"(",
"$",
"this",
"->",
"pagination",
"&&",
"$",
"this",
"->",
"paging",
"&&",
"isset",
"(",
"$",
"this",
"->",
"dataProvider",
")",
")",
"{",
... | Initialise paging if applicable. | [
"Initialise",
"paging",
"if",
"applicable",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/base/PageWidget.php#L193-L217 | train |
cmsgears/module-core | common/services/resources/ModelCommentService.php | ModelCommentService.getPageForApproved | public function getPageForApproved( $config = [] ) {
$modelTable = $this->getModelTable();
$topLevel = isset( $config[ 'topLevel' ] ) ? $config[ 'topLevel' ] : true;
if( $topLevel ) {
$config[ 'conditions' ][ 'baseId' ] = null;
}
$config[ 'conditions' ][ "$modelTable.status" ] = ModelComment::STATUS_APPROVED;
return $this->getPage( $config );
} | php | public function getPageForApproved( $config = [] ) {
$modelTable = $this->getModelTable();
$topLevel = isset( $config[ 'topLevel' ] ) ? $config[ 'topLevel' ] : true;
if( $topLevel ) {
$config[ 'conditions' ][ 'baseId' ] = null;
}
$config[ 'conditions' ][ "$modelTable.status" ] = ModelComment::STATUS_APPROVED;
return $this->getPage( $config );
} | [
"public",
"function",
"getPageForApproved",
"(",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"modelTable",
"=",
"$",
"this",
"->",
"getModelTable",
"(",
")",
";",
"$",
"topLevel",
"=",
"isset",
"(",
"$",
"config",
"[",
"'topLevel'",
"]",
")",
"?",
"... | We can pass parentType as condition to utilize the classification. | [
"We",
"can",
"pass",
"parentType",
"as",
"condition",
"to",
"utilize",
"the",
"classification",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/services/resources/ModelCommentService.php#L313-L326 | train |
cmsgears/module-core | common/services/resources/ModelCommentService.php | ModelCommentService.getByBaseId | public function getByBaseId( $baseId, $config = [] ) {
$modelClass = self::$modelClass;
return $modelClass::queryByBaseId( $baseId, $config )->all();
} | php | public function getByBaseId( $baseId, $config = [] ) {
$modelClass = self::$modelClass;
return $modelClass::queryByBaseId( $baseId, $config )->all();
} | [
"public",
"function",
"getByBaseId",
"(",
"$",
"baseId",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"modelClass",
"=",
"self",
"::",
"$",
"modelClass",
";",
"return",
"$",
"modelClass",
"::",
"queryByBaseId",
"(",
"$",
"baseId",
",",
"$",
"confi... | It returns immediate child comments for given base id. | [
"It",
"returns",
"immediate",
"child",
"comments",
"for",
"given",
"base",
"id",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/services/resources/ModelCommentService.php#L335-L340 | train |
cmsgears/module-core | common/models/base/ModelResource.php | ModelResource.queryByParent | public static function queryByParent( $parentId, $parentType, $config = [] ) {
$ignoreSite = isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;
if( static::isMultiSite() && !$ignoreSite ) {
$siteId = isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;
return static::find()->where( 'parentId=:pid AND parentType=:ptype AND siteId=:siteId', [ ':pid' => $parentId, ':ptype' => $parentType, ':siteId' => $siteId ] );
}
else {
return static::find()->where( 'parentId=:pid AND parentType=:ptype', [ ':pid' => $parentId, ':ptype' => $parentType ] );
}
} | php | public static function queryByParent( $parentId, $parentType, $config = [] ) {
$ignoreSite = isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;
if( static::isMultiSite() && !$ignoreSite ) {
$siteId = isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;
return static::find()->where( 'parentId=:pid AND parentType=:ptype AND siteId=:siteId', [ ':pid' => $parentId, ':ptype' => $parentType, ':siteId' => $siteId ] );
}
else {
return static::find()->where( 'parentId=:pid AND parentType=:ptype', [ ':pid' => $parentId, ':ptype' => $parentType ] );
}
} | [
"public",
"static",
"function",
"queryByParent",
"(",
"$",
"parentId",
",",
"$",
"parentType",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"ignoreSite",
"=",
"isset",
"(",
"$",
"config",
"[",
"'ignoreSite'",
"]",
")",
"?",
"$",
"config",
"[",
"... | Return query to find the models by given parent id and parent type.
@param integer $parentId
@param string $parentType
@param array $config
@return \yii\db\ActiveQuery to query by parent id and parent type. | [
"Return",
"query",
"to",
"find",
"the",
"models",
"by",
"given",
"parent",
"id",
"and",
"parent",
"type",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/base/ModelResource.php#L104-L118 | train |
cmsgears/module-core | common/models/base/ModelResource.php | ModelResource.findByParent | public static function findByParent( $parentId, $parentType, $config = [] ) {
return self::queryByParent( $parentId, $parentType, $config )->all();
} | php | public static function findByParent( $parentId, $parentType, $config = [] ) {
return self::queryByParent( $parentId, $parentType, $config )->all();
} | [
"public",
"static",
"function",
"findByParent",
"(",
"$",
"parentId",
",",
"$",
"parentType",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"return",
"self",
"::",
"queryByParent",
"(",
"$",
"parentId",
",",
"$",
"parentType",
",",
"$",
"config",
")",
"... | Find and return models using given parent id and parent type.
@param string $parentId
@param string $parentType
@param array $config
@return \cmsgears\core\common\models\base\ActiveRecord[] | [
"Find",
"and",
"return",
"models",
"using",
"given",
"parent",
"id",
"and",
"parent",
"type",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/base/ModelResource.php#L130-L133 | train |
cmsgears/module-core | common/models/base/ModelResource.php | ModelResource.findFirstByParent | public static function findFirstByParent( $parentId, $parentType, $config = [] ) {
return self::queryByParent( $parentId, $parentType, $config )->one();
} | php | public static function findFirstByParent( $parentId, $parentType, $config = [] ) {
return self::queryByParent( $parentId, $parentType, $config )->one();
} | [
"public",
"static",
"function",
"findFirstByParent",
"(",
"$",
"parentId",
",",
"$",
"parentType",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"return",
"self",
"::",
"queryByParent",
"(",
"$",
"parentId",
",",
"$",
"parentType",
",",
"$",
"config",
")"... | Find and return first model using given parent id and parent type.
@param string $parentId
@param string $parentType
@param array $config
@return \cmsgears\core\common\models\base\ActiveRecord | [
"Find",
"and",
"return",
"first",
"model",
"using",
"given",
"parent",
"id",
"and",
"parent",
"type",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/base/ModelResource.php#L143-L146 | train |
cmsgears/module-core | common/models/base/ModelResource.php | ModelResource.findByParentId | public static function findByParentId( $parentId, $config = [] ) {
$ignoreSite = isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;
if( static::isMultiSite() && !$ignoreSite ) {
$siteId = isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;
return static::find()->where( 'parentId=:pid AND siteId=:siteId', [ ':pid' => $parentId, ':siteId' => $siteId ] )->all();
}
else {
return static::find()->where( 'parentId=:pid', [ ':pid' => $parentId ] )->all();
}
} | php | public static function findByParentId( $parentId, $config = [] ) {
$ignoreSite = isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;
if( static::isMultiSite() && !$ignoreSite ) {
$siteId = isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;
return static::find()->where( 'parentId=:pid AND siteId=:siteId', [ ':pid' => $parentId, ':siteId' => $siteId ] )->all();
}
else {
return static::find()->where( 'parentId=:pid', [ ':pid' => $parentId ] )->all();
}
} | [
"public",
"static",
"function",
"findByParentId",
"(",
"$",
"parentId",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"ignoreSite",
"=",
"isset",
"(",
"$",
"config",
"[",
"'ignoreSite'",
"]",
")",
"?",
"$",
"config",
"[",
"'ignoreSite'",
"]",
":",
... | Find and return models using given parent id. It's useful in cases where only
single parent type is allowed.
@param string $parentId
@param array $config
@return \cmsgears\core\common\models\base\ActiveRecord[] | [
"Find",
"and",
"return",
"models",
"using",
"given",
"parent",
"id",
".",
"It",
"s",
"useful",
"in",
"cases",
"where",
"only",
"single",
"parent",
"type",
"is",
"allowed",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/base/ModelResource.php#L156-L170 | train |
cmsgears/module-core | common/models/base/ModelResource.php | ModelResource.findByParentType | public static function findByParentType( $parentType, $config = [] ) {
$ignoreSite = isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;
if( static::isMultiSite() && !$ignoreSite ) {
$siteId = isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;
return static::find()->where( 'parentType=:ptype AND siteId=:siteId', [ ':ptype' => $parentType, ':siteId' => $siteId ] )->all();
}
else {
return static::find()->where( 'parentType=:ptype', [ ':ptype' => $parentType ] )->all();
}
} | php | public static function findByParentType( $parentType, $config = [] ) {
$ignoreSite = isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;
if( static::isMultiSite() && !$ignoreSite ) {
$siteId = isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;
return static::find()->where( 'parentType=:ptype AND siteId=:siteId', [ ':ptype' => $parentType, ':siteId' => $siteId ] )->all();
}
else {
return static::find()->where( 'parentType=:ptype', [ ':ptype' => $parentType ] )->all();
}
} | [
"public",
"static",
"function",
"findByParentType",
"(",
"$",
"parentType",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"ignoreSite",
"=",
"isset",
"(",
"$",
"config",
"[",
"'ignoreSite'",
"]",
")",
"?",
"$",
"config",
"[",
"'ignoreSite'",
"]",
"... | Find and return models using given parent type.
@param string $parentType
@param array $config
@return \cmsgears\core\common\models\base\ActiveRecord[] | [
"Find",
"and",
"return",
"models",
"using",
"given",
"parent",
"type",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/base/ModelResource.php#L179-L193 | train |
cmsgears/module-core | common/models/forms/Binder.php | Binder.mergeWithBinded | public function mergeWithBinded( $data, $csv = false ) {
$merge = [];
if( $csv && strlen( $merge ) > 1 ) {
$merge = preg_split( '/,/', $data );
}
$this->binded = ArrayHelper::merge( $this->binded, $merge );
} | php | public function mergeWithBinded( $data, $csv = false ) {
$merge = [];
if( $csv && strlen( $merge ) > 1 ) {
$merge = preg_split( '/,/', $data );
}
$this->binded = ArrayHelper::merge( $this->binded, $merge );
} | [
"public",
"function",
"mergeWithBinded",
"(",
"$",
"data",
",",
"$",
"csv",
"=",
"false",
")",
"{",
"$",
"merge",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"csv",
"&&",
"strlen",
"(",
"$",
"merge",
")",
">",
"1",
")",
"{",
"$",
"merge",
"=",
"preg_sp... | Merge the given data either in csv format or as array.
@param array|string $merge
@param boolean $csv | [
"Merge",
"the",
"given",
"data",
"either",
"in",
"csv",
"format",
"or",
"as",
"array",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/forms/Binder.php#L101-L111 | train |
cmsgears/module-core | common/models/forms/Binder.php | Binder.getValueMap | public function getValueMap() {
$count = count( $this->binded );
$map = [];
for( $i = 0; $i < $count; $i++ ) {
$map[ $this->binded[ $i ] ] = $this->value[ $i ];
}
return $map;
} | php | public function getValueMap() {
$count = count( $this->binded );
$map = [];
for( $i = 0; $i < $count; $i++ ) {
$map[ $this->binded[ $i ] ] = $this->value[ $i ];
}
return $map;
} | [
"public",
"function",
"getValueMap",
"(",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"this",
"->",
"binded",
")",
";",
"$",
"map",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++... | Generate and return an array having id as key and value.
@return array | [
"Generate",
"and",
"return",
"an",
"array",
"having",
"id",
"as",
"key",
"and",
"value",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/forms/Binder.php#L118-L129 | train |
cmsgears/module-core | common/models/forms/Binder.php | Binder.mergeMapWithBinded | public function mergeMapWithBinded( $map ) {
foreach( $map as $key => $value ) {
if( !in_array( $key, $this->binded ) ) {
$this->binded[] = $key;
$this->value[] = $value;
}
}
} | php | public function mergeMapWithBinded( $map ) {
foreach( $map as $key => $value ) {
if( !in_array( $key, $this->binded ) ) {
$this->binded[] = $key;
$this->value[] = $value;
}
}
} | [
"public",
"function",
"mergeMapWithBinded",
"(",
"$",
"map",
")",
"{",
"foreach",
"(",
"$",
"map",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"binded",
")",
")",
"{",
"$",
... | Analyze and merge the key and value from given map with the binder.
@param array $map | [
"Analyze",
"and",
"merge",
"the",
"key",
"and",
"value",
"from",
"given",
"map",
"with",
"the",
"binder",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/forms/Binder.php#L136-L146 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/FileProperty.php | FileProperty.setMimetype | public function setMimetype($type)
{
if ($type === null || $type === false) {
$this->mimetype = null;
return $this;
}
if (!is_string($type)) {
throw new InvalidArgumentException(
'Mimetype must be a string'
);
}
$this->mimetype = $type;
return $this;
} | php | public function setMimetype($type)
{
if ($type === null || $type === false) {
$this->mimetype = null;
return $this;
}
if (!is_string($type)) {
throw new InvalidArgumentException(
'Mimetype must be a string'
);
}
$this->mimetype = $type;
return $this;
} | [
"public",
"function",
"setMimetype",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"null",
"||",
"$",
"type",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"mimetype",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",... | Set the MIME type.
@param mixed $type The file MIME type.
@throws InvalidArgumentException If the MIME type argument is not a string.
@return FileProperty Chainable | [
"Set",
"the",
"MIME",
"type",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/FileProperty.php#L216-L233 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/FileProperty.php | FileProperty.mimetype | public function mimetype()
{
if (!$this->mimetype) {
$val = $this->val();
if (!$val) {
return '';
}
$this->setMimetype($this->mimetypeFor(strval($val)));
}
return $this->mimetype;
} | php | public function mimetype()
{
if (!$this->mimetype) {
$val = $this->val();
if (!$val) {
return '';
}
$this->setMimetype($this->mimetypeFor(strval($val)));
}
return $this->mimetype;
} | [
"public",
"function",
"mimetype",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"mimetype",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"val",
"(",
")",
";",
"if",
"(",
"!",
"$",
"val",
")",
"{",
"return",
"''",
";",
"}",
"$",
"this",
... | Retrieve the MIME type.
@return string | [
"Retrieve",
"the",
"MIME",
"type",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/FileProperty.php#L240-L253 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/FileProperty.php | FileProperty.dataUpload | public function dataUpload($fileData)
{
$filename = null;
if (is_array($fileData)) {
// retrieve tmp file from temp dir
$tmpDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
$tmpFile = $tmpDir.$fileData['id'];
if (!file_exists($tmpFile)) {
throw new Exception(
'File does not exists.'
);
}
$fileContent = file_get_contents($tmpFile);
$filename = (!empty($fileData['name'])) ? $fileData['name'] : null;
// delete tmp file
unlink($tmpFile);
} else {
$fileContent = file_get_contents($fileData);
}
if ($fileContent === false) {
throw new Exception(
'File content could not be decoded.'
);
}
$info = new finfo(FILEINFO_MIME_TYPE);
$this->setMimetype($info->buffer($fileContent));
$this->setFilesize(strlen($fileContent));
if (!$this->validateAcceptedMimetypes() || !$this->validateMaxFilesize()) {
return '';
}
$target = $this->uploadTarget($filename);
$ret = file_put_contents($target, $fileContent);
if ($ret === false) {
return '';
} else {
$basePath = $this->basePath();
$target = str_replace($basePath, '', $target);
return $target;
}
} | php | public function dataUpload($fileData)
{
$filename = null;
if (is_array($fileData)) {
// retrieve tmp file from temp dir
$tmpDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
$tmpFile = $tmpDir.$fileData['id'];
if (!file_exists($tmpFile)) {
throw new Exception(
'File does not exists.'
);
}
$fileContent = file_get_contents($tmpFile);
$filename = (!empty($fileData['name'])) ? $fileData['name'] : null;
// delete tmp file
unlink($tmpFile);
} else {
$fileContent = file_get_contents($fileData);
}
if ($fileContent === false) {
throw new Exception(
'File content could not be decoded.'
);
}
$info = new finfo(FILEINFO_MIME_TYPE);
$this->setMimetype($info->buffer($fileContent));
$this->setFilesize(strlen($fileContent));
if (!$this->validateAcceptedMimetypes() || !$this->validateMaxFilesize()) {
return '';
}
$target = $this->uploadTarget($filename);
$ret = file_put_contents($target, $fileContent);
if ($ret === false) {
return '';
} else {
$basePath = $this->basePath();
$target = str_replace($basePath, '', $target);
return $target;
}
} | [
"public",
"function",
"dataUpload",
"(",
"$",
"fileData",
")",
"{",
"$",
"filename",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"fileData",
")",
")",
"{",
"// retrieve tmp file from temp dir",
"$",
"tmpDir",
"=",
"rtrim",
"(",
"sys_get_temp_dir",
"("... | Upload to filesystem, from data URI.
@param string $fileData The file data, raw.
@throws Exception If data content decoding fails.
@return string | [
"Upload",
"to",
"filesystem",
"from",
"data",
"URI",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/FileProperty.php#L573-L618 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/FileProperty.php | FileProperty.renderFileRenamePattern | public function renderFileRenamePattern($from, $to, $args = null)
{
if (!is_string($from)) {
throw new InvalidArgumentException(sprintf(
'The target to rename must be a string, received %s',
(is_object($from) ? get_class($from) : gettype($from))
));
}
if (!is_string($to)) {
throw new InvalidArgumentException(sprintf(
'The rename pattern must be a string, received %s',
(is_object($to) ? get_class($to) : gettype($to))
));
}
$info = pathinfo($from);
$args = $this->renamePatternArgs($info, $args);
$to = strtr($to, $args);
if (strpos($to, '{{') !== false) {
preg_match_all('~\{\{\s*(.*?)\s*\}\}~i', $to, $matches);
throw new UnexpectedValueException(sprintf(
'The rename pattern failed. Leftover tokens found: %s',
implode(', ', $matches[1])
));
}
$to = str_replace($info['basename'], $to, $from);
return $to;
} | php | public function renderFileRenamePattern($from, $to, $args = null)
{
if (!is_string($from)) {
throw new InvalidArgumentException(sprintf(
'The target to rename must be a string, received %s',
(is_object($from) ? get_class($from) : gettype($from))
));
}
if (!is_string($to)) {
throw new InvalidArgumentException(sprintf(
'The rename pattern must be a string, received %s',
(is_object($to) ? get_class($to) : gettype($to))
));
}
$info = pathinfo($from);
$args = $this->renamePatternArgs($info, $args);
$to = strtr($to, $args);
if (strpos($to, '{{') !== false) {
preg_match_all('~\{\{\s*(.*?)\s*\}\}~i', $to, $matches);
throw new UnexpectedValueException(sprintf(
'The rename pattern failed. Leftover tokens found: %s',
implode(', ', $matches[1])
));
}
$to = str_replace($info['basename'], $to, $from);
return $to;
} | [
"public",
"function",
"renderFileRenamePattern",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"from",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"... | Render the given file to the given pattern.
This method does not rename the given path.
@uses strtr() To replace tokens in the form `{{foobar}}`.
@param string $from The string being rendered.
@param string $to The pattern replacing $from.
@param array|callable $args Extra rename tokens.
@throws InvalidArgumentException If the given arguments are invalid.
@throws UnexpectedValueException If the renaming failed.
@return string Returns the rendered target. | [
"Render",
"the",
"given",
"file",
"to",
"the",
"given",
"pattern",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/FileProperty.php#L772-L804 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/FileProperty.php | FileProperty.generateFilename | public function generateFilename()
{
$filename = $this->label().' '.date('Y-m-d H-i-s');
$extension = $this->generateExtension();
if ($extension) {
return $filename.'.'.$extension;
} else {
return $filename;
}
} | php | public function generateFilename()
{
$filename = $this->label().' '.date('Y-m-d H-i-s');
$extension = $this->generateExtension();
if ($extension) {
return $filename.'.'.$extension;
} else {
return $filename;
}
} | [
"public",
"function",
"generateFilename",
"(",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"label",
"(",
")",
".",
"' '",
".",
"date",
"(",
"'Y-m-d H-i-s'",
")",
";",
"$",
"extension",
"=",
"$",
"this",
"->",
"generateExtension",
"(",
")",
";",
... | Generate a new filename from the property.
@return string | [
"Generate",
"a",
"new",
"filename",
"from",
"the",
"property",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/FileProperty.php#L811-L821 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/FileProperty.php | FileProperty.parseIniSize | protected function parseIniSize($size)
{
if (is_numeric($size)) {
return $size;
}
if (!is_string($size)) {
throw new InvalidArgumentException(
'Size must be an integer (in bytes, e.g.: 1024) or a string (e.g.: 1M).'
);
}
$quant = 'bkmgtpezy';
$unit = preg_replace('/[^'.$quant.']/i', '', $size);
$size = preg_replace('/[^0-9\.]/', '', $size);
if ($unit) {
$size = ($size * pow(1024, stripos($quant, $unit[0])));
}
return round($size);
} | php | protected function parseIniSize($size)
{
if (is_numeric($size)) {
return $size;
}
if (!is_string($size)) {
throw new InvalidArgumentException(
'Size must be an integer (in bytes, e.g.: 1024) or a string (e.g.: 1M).'
);
}
$quant = 'bkmgtpezy';
$unit = preg_replace('/[^'.$quant.']/i', '', $size);
$size = preg_replace('/[^0-9\.]/', '', $size);
if ($unit) {
$size = ($size * pow(1024, stripos($quant, $unit[0])));
}
return round($size);
} | [
"protected",
"function",
"parseIniSize",
"(",
"$",
"size",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"size",
")",
")",
"{",
"return",
"$",
"size",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"size",
")",
")",
"{",
"throw",
"new",
"InvalidAr... | Converts a php.ini notation for size to an integer.
@param mixed $size A php.ini notation for size.
@throws InvalidArgumentException If the given parameter is invalid.
@return integer Returns the size in bytes. | [
"Converts",
"a",
"php",
".",
"ini",
"notation",
"for",
"size",
"to",
"an",
"integer",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/FileProperty.php#L928-L949 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/FileProperty.php | FileProperty.renamePatternArgs | private function renamePatternArgs($path, $args = null)
{
if (!is_string($path) && !is_array($path)) {
throw new InvalidArgumentException(sprintf(
'The target must be a string or an array from [pathfino()], received %s',
(is_object($path) ? get_class($path) : gettype($path))
));
}
if (is_string($path)) {
$info = pathinfo($path);
} else {
$info = $path;
}
if (!isset($info['basename']) || $info['basename'] === '') {
throw new UnexpectedValueException(
'The basename is missing from the target'
);
}
if (!isset($info['filename']) || $info['filename'] === '') {
throw new UnexpectedValueException(
'The filename is missing from the target'
);
}
$defaults = [
'{{property}}' => $this->ident(),
'{{label}}' => $this->label(),
'{{extension}}' => $info['extension'],
'{{basename}}' => $info['basename'],
'{{filename}}' => $info['filename']
];
if ($args === null) {
$args = $defaults;
} else {
if (is_callable($args)) {
/**
* Rename Arguments Callback Routine
*
* @param array $info Information about the file path from {@see pathinfo()}.
* @param PropertyInterface $prop The related image property.
* @return array
*/
$args = $args($info, $this);
}
if (is_array($args)) {
$args = array_replace($defaults, $args);
} else {
throw new InvalidArgumentException(sprintf(
'Arguments must be an array or a callable that returns an array, received %s',
(is_object($args) ? get_class($args) : gettype($args))
));
}
}
return $args;
} | php | private function renamePatternArgs($path, $args = null)
{
if (!is_string($path) && !is_array($path)) {
throw new InvalidArgumentException(sprintf(
'The target must be a string or an array from [pathfino()], received %s',
(is_object($path) ? get_class($path) : gettype($path))
));
}
if (is_string($path)) {
$info = pathinfo($path);
} else {
$info = $path;
}
if (!isset($info['basename']) || $info['basename'] === '') {
throw new UnexpectedValueException(
'The basename is missing from the target'
);
}
if (!isset($info['filename']) || $info['filename'] === '') {
throw new UnexpectedValueException(
'The filename is missing from the target'
);
}
$defaults = [
'{{property}}' => $this->ident(),
'{{label}}' => $this->label(),
'{{extension}}' => $info['extension'],
'{{basename}}' => $info['basename'],
'{{filename}}' => $info['filename']
];
if ($args === null) {
$args = $defaults;
} else {
if (is_callable($args)) {
/**
* Rename Arguments Callback Routine
*
* @param array $info Information about the file path from {@see pathinfo()}.
* @param PropertyInterface $prop The related image property.
* @return array
*/
$args = $args($info, $this);
}
if (is_array($args)) {
$args = array_replace($defaults, $args);
} else {
throw new InvalidArgumentException(sprintf(
'Arguments must be an array or a callable that returns an array, received %s',
(is_object($args) ? get_class($args) : gettype($args))
));
}
}
return $args;
} | [
"private",
"function",
"renamePatternArgs",
"(",
"$",
"path",
",",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
"&&",
"!",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException... | Retrieve the rename pattern tokens for the given file.
@param string|array $path The string to be parsed or an associative array of information about the file.
@param array|callable $args Extra rename tokens.
@throws InvalidArgumentException If the given arguments are invalid.
@throws UnexpectedValueException If the given path is invalid.
@return string Returns the rendered target. | [
"Retrieve",
"the",
"rename",
"pattern",
"tokens",
"for",
"the",
"given",
"file",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/FileProperty.php#L992-L1052 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheBuilder.php | CacheBuilder.build | public function build($cacheDriver, $poolOptions = null)
{
if (!($cacheDriver instanceof DriverInterface)) {
$cacheDriver = $this->resolveDriver($cacheDriver);
}
$poolOptions = $this->parsePoolOptions($poolOptions);
$poolInstance = new $poolOptions['pool_class']($cacheDriver);
$this->applyPoolOptions($poolInstance, $poolOptions);
return $poolInstance;
} | php | public function build($cacheDriver, $poolOptions = null)
{
if (!($cacheDriver instanceof DriverInterface)) {
$cacheDriver = $this->resolveDriver($cacheDriver);
}
$poolOptions = $this->parsePoolOptions($poolOptions);
$poolInstance = new $poolOptions['pool_class']($cacheDriver);
$this->applyPoolOptions($poolInstance, $poolOptions);
return $poolInstance;
} | [
"public",
"function",
"build",
"(",
"$",
"cacheDriver",
",",
"$",
"poolOptions",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"cacheDriver",
"instanceof",
"DriverInterface",
")",
")",
"{",
"$",
"cacheDriver",
"=",
"$",
"this",
"->",
"resolveDriver",
... | Create a new cache pool.
@param mixed $cacheDriver The name of a registered cache driver,
the class name or instance of a {@see DriverInterface cache driver}.
An array may be used to designate fallback drivers.
@param mixed $poolOptions Optional settings for the new pool.
If a string is specified, it is used as the namespace for the new pool.
If an array is specified, it is assumed to be associative and is merged with the default settings.
Otherwise, the default settings are used.
@return PoolInterface | [
"Create",
"a",
"new",
"cache",
"pool",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheBuilder.php#L109-L121 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheBuilder.php | CacheBuilder.parsePoolOptions | private function parsePoolOptions($options)
{
$defaults = [
'pool_class' => $this->poolClass,
'item_class' => $this->itemClass,
'namespace' => $this->namespace,
'logger' => $this->logger,
];
if ($options === null) {
return $defaults;
}
if (is_string($options)) {
$options = [
'namespace' => $options
];
}
if (!is_array($options)) {
return $defaults;
}
return array_replace($defaults, $options);
} | php | private function parsePoolOptions($options)
{
$defaults = [
'pool_class' => $this->poolClass,
'item_class' => $this->itemClass,
'namespace' => $this->namespace,
'logger' => $this->logger,
];
if ($options === null) {
return $defaults;
}
if (is_string($options)) {
$options = [
'namespace' => $options
];
}
if (!is_array($options)) {
return $defaults;
}
return array_replace($defaults, $options);
} | [
"private",
"function",
"parsePoolOptions",
"(",
"$",
"options",
")",
"{",
"$",
"defaults",
"=",
"[",
"'pool_class'",
"=>",
"$",
"this",
"->",
"poolClass",
",",
"'item_class'",
"=>",
"$",
"this",
"->",
"itemClass",
",",
"'namespace'",
"=>",
"$",
"this",
"->... | Prepare any pool options for the new pool object.
@param mixed $options Settings for the new pool.
@return array | [
"Prepare",
"any",
"pool",
"options",
"for",
"the",
"new",
"pool",
"object",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheBuilder.php#L129-L153 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheBuilder.php | CacheBuilder.applyPoolOptions | private function applyPoolOptions(PoolInterface $pool, array $options)
{
if (isset($options['logger'])) {
$pool->setLogger($options['logger']);
}
if (isset($options['item_class'])) {
$pool->setItemClass($options['item_class']);
}
if (isset($options['namespace'])) {
$pool->setNamespace($options['namespace']);
}
} | php | private function applyPoolOptions(PoolInterface $pool, array $options)
{
if (isset($options['logger'])) {
$pool->setLogger($options['logger']);
}
if (isset($options['item_class'])) {
$pool->setItemClass($options['item_class']);
}
if (isset($options['namespace'])) {
$pool->setNamespace($options['namespace']);
}
} | [
"private",
"function",
"applyPoolOptions",
"(",
"PoolInterface",
"$",
"pool",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'logger'",
"]",
")",
")",
"{",
"$",
"pool",
"->",
"setLogger",
"(",
"$",
"options",
"["... | Apply any pool options on the new pool object.
@param PoolInterface $pool The new pool.
@param array $options Settings for the new pool.
@return void | [
"Apply",
"any",
"pool",
"options",
"on",
"the",
"new",
"pool",
"object",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheBuilder.php#L162-L175 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheBuilder.php | CacheBuilder.resolveDriver | private function resolveDriver($driver)
{
if ($this->isIterable($driver)) {
foreach ($driver as $drv) {
try {
return $this->resolveOneDriver($drv);
} catch (InvalidArgumentException $e) {
continue;
}
}
throw new InvalidArgumentException(
'Drivers cannot be resolved'
);
}
return $this->resolveOneDriver($driver);
} | php | private function resolveDriver($driver)
{
if ($this->isIterable($driver)) {
foreach ($driver as $drv) {
try {
return $this->resolveOneDriver($drv);
} catch (InvalidArgumentException $e) {
continue;
}
}
throw new InvalidArgumentException(
'Drivers cannot be resolved'
);
}
return $this->resolveOneDriver($driver);
} | [
"private",
"function",
"resolveDriver",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isIterable",
"(",
"$",
"driver",
")",
")",
"{",
"foreach",
"(",
"$",
"driver",
"as",
"$",
"drv",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",... | Resolve one or many cache drivers, if available.
@param mixed $driver The name of a registered cache driver,
the class name or instance of a {@see DriverInterface cache driver}.
An array may be used to designate fallback drivers.
@throws InvalidArgumentException When an array of drivers cannot be resolved.
@return DriverInterface | [
"Resolve",
"one",
"or",
"many",
"cache",
"drivers",
"if",
"available",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheBuilder.php#L186-L203 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheBuilder.php | CacheBuilder.resolveOneDriver | private function resolveOneDriver($driver)
{
if (empty($driver)) {
throw new InvalidArgumentException(
'Driver is empty'
);
}
if (is_object($driver)) {
if ($driver instanceof DriverInterface) {
return $driver;
} else {
throw new InvalidArgumentException(sprintf(
'Driver class %s must implement %s',
get_class($driver),
DriverInterface::class
));
}
}
$name = $driver;
if (isset($this->drivers[$name])) {
$driver = $this->drivers[$name];
if (empty($driver)) {
throw new InvalidArgumentException(
sprintf('Driver "%s" does not exist', $name)
);
}
if (is_object($driver)) {
if ($driver instanceof DriverInterface) {
return $driver;
} else {
throw new InvalidArgumentException(sprintf(
'Driver "%s": Class %s must implement %s',
$name,
get_class($driver),
DriverInterface::class
));
}
}
}
if (is_a($driver, DriverInterface::class, true)) {
return new $driver();
}
throw new InvalidArgumentException(
sprintf('Driver "%s" cannot be resolved', $name)
);
} | php | private function resolveOneDriver($driver)
{
if (empty($driver)) {
throw new InvalidArgumentException(
'Driver is empty'
);
}
if (is_object($driver)) {
if ($driver instanceof DriverInterface) {
return $driver;
} else {
throw new InvalidArgumentException(sprintf(
'Driver class %s must implement %s',
get_class($driver),
DriverInterface::class
));
}
}
$name = $driver;
if (isset($this->drivers[$name])) {
$driver = $this->drivers[$name];
if (empty($driver)) {
throw new InvalidArgumentException(
sprintf('Driver "%s" does not exist', $name)
);
}
if (is_object($driver)) {
if ($driver instanceof DriverInterface) {
return $driver;
} else {
throw new InvalidArgumentException(sprintf(
'Driver "%s": Class %s must implement %s',
$name,
get_class($driver),
DriverInterface::class
));
}
}
}
if (is_a($driver, DriverInterface::class, true)) {
return new $driver();
}
throw new InvalidArgumentException(
sprintf('Driver "%s" cannot be resolved', $name)
);
} | [
"private",
"function",
"resolveOneDriver",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"driver",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Driver is empty'",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"driver",... | Resolve the given cache driver, if available.
@param mixed $driver The name of a registered cache driver,
the class name or instance of a {@see DriverInterface cache driver}.
@throws InvalidArgumentException When passed an invalid or nonexistant driver name, class name, or object.
@return DriverInterface | [
"Resolve",
"the",
"given",
"cache",
"driver",
"if",
"available",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheBuilder.php#L213-L264 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/CacheBuilder.php | CacheBuilder.setLogger | private function setLogger($logger)
{
$psr = 'Psr\\Log\\LoggerInterface';
if (!is_a($logger, $psr)) {
throw new InvalidArgumentException(
sprintf('Expected an instance of %s', $psr)
);
}
$this->logger = $logger;
} | php | private function setLogger($logger)
{
$psr = 'Psr\\Log\\LoggerInterface';
if (!is_a($logger, $psr)) {
throw new InvalidArgumentException(
sprintf('Expected an instance of %s', $psr)
);
}
$this->logger = $logger;
} | [
"private",
"function",
"setLogger",
"(",
"$",
"logger",
")",
"{",
"$",
"psr",
"=",
"'Psr\\\\Log\\\\LoggerInterface'",
";",
"if",
"(",
"!",
"is_a",
"(",
"$",
"logger",
",",
"$",
"psr",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf... | Sets the specific PSR logging client to enable the tracking of errors.
@param \Psr\Log\LoggerInterface $logger A PSR-3 logger.
@throws InvalidArgumentException If the logger is invalid PSR-3 client.
@return void | [
"Sets",
"the",
"specific",
"PSR",
"logging",
"client",
"to",
"enable",
"the",
"tracking",
"of",
"errors",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/CacheBuilder.php#L291-L301 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.