repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.fetchSubscriptions | public function fetchSubscriptions(array $conditions = null)
{
$cursor = new DrupalSubscriptionCursor($this);
if (!empty($conditions)) {
$cursor->setConditions($conditions);
}
return $cursor;
} | php | public function fetchSubscriptions(array $conditions = null)
{
$cursor = new DrupalSubscriptionCursor($this);
if (!empty($conditions)) {
$cursor->setConditions($conditions);
}
return $cursor;
} | [
"public",
"function",
"fetchSubscriptions",
"(",
"array",
"$",
"conditions",
"=",
"null",
")",
"{",
"$",
"cursor",
"=",
"new",
"DrupalSubscriptionCursor",
"(",
"$",
"this",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"cursor",
"->",
"setConditions",
"(",
"$",
"conditions",
")",
";",
"}",
"return",
"$",
"cursor",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L233-L242 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.getSubscriber | public function getSubscriber($id)
{
if (isset($this->subscribersCache[$id])) {
return $this->subscribersCache[$id];
}
$idList = $this
->db
// This query will also remove non existing stalling subscriptions
// from the subscriber map thanks to the JOIN statements, thus
// avoiding potential exceptions being thrown at single subscription
// get time
->query("
SELECT c.name, s.id
FROM {apb_sub} s
JOIN {apb_chan} c ON c.id = s.chan_id
WHERE s.name = :name", array(
':name' => $id,
))
->fetchAllKeyed();
return $this->subscribersCache[$id] = new DefaultSubscriber($id, $this, $idList);
} | php | public function getSubscriber($id)
{
if (isset($this->subscribersCache[$id])) {
return $this->subscribersCache[$id];
}
$idList = $this
->db
// This query will also remove non existing stalling subscriptions
// from the subscriber map thanks to the JOIN statements, thus
// avoiding potential exceptions being thrown at single subscription
// get time
->query("
SELECT c.name, s.id
FROM {apb_sub} s
JOIN {apb_chan} c ON c.id = s.chan_id
WHERE s.name = :name", array(
':name' => $id,
))
->fetchAllKeyed();
return $this->subscribersCache[$id] = new DefaultSubscriber($id, $this, $idList);
} | [
"public",
"function",
"getSubscriber",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"subscribersCache",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"subscribersCache",
"[",
"$",
"id",
"]",
";",
"}",
"$",
"idList",
"=",
"$",
"this",
"->",
"db",
"// This query will also remove non existing stalling subscriptions",
"// from the subscriber map thanks to the JOIN statements, thus",
"// avoiding potential exceptions being thrown at single subscription",
"// get time",
"->",
"query",
"(",
"\"\n SELECT c.name, s.id\n FROM {apb_sub} s\n JOIN {apb_chan} c ON c.id = s.chan_id\n WHERE s.name = :name\"",
",",
"array",
"(",
"':name'",
"=>",
"$",
"id",
",",
")",
")",
"->",
"fetchAllKeyed",
"(",
")",
";",
"return",
"$",
"this",
"->",
"subscribersCache",
"[",
"$",
"id",
"]",
"=",
"new",
"DefaultSubscriber",
"(",
"$",
"id",
",",
"$",
"this",
",",
"$",
"idList",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L247-L269 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.deleteSubscriber | public function deleteSubscriber($id)
{
$cx = $this->db;
$tx = null;
$subscriber = $this->getSubscriber($id);
try {
$tx = $cx->startTransaction();
// FIXME: SELECT FOR UPDATE here in all tables
// Start by deleting all subscriptions.
$subIdList = [];
foreach ($subscriber->getSubscriptions() as $subscription) {
$subIdList[] = $subscription->getId();
}
if (!empty($subIdList)) {
$this
->fetchSubscriptions([Field::SUB_ID => $subIdList])
->delete()
;
}
unset($tx); // Explicit commit
if (isset($this->subscribersCache[$id])) {
unset($this->subscribersCache[$id]);
}
} catch (\Exception $e) {
if ($tx) {
try {
$tx->rollback();
} catch (\Exception $e2) {}
}
throw $e;
}
} | php | public function deleteSubscriber($id)
{
$cx = $this->db;
$tx = null;
$subscriber = $this->getSubscriber($id);
try {
$tx = $cx->startTransaction();
// FIXME: SELECT FOR UPDATE here in all tables
// Start by deleting all subscriptions.
$subIdList = [];
foreach ($subscriber->getSubscriptions() as $subscription) {
$subIdList[] = $subscription->getId();
}
if (!empty($subIdList)) {
$this
->fetchSubscriptions([Field::SUB_ID => $subIdList])
->delete()
;
}
unset($tx); // Explicit commit
if (isset($this->subscribersCache[$id])) {
unset($this->subscribersCache[$id]);
}
} catch (\Exception $e) {
if ($tx) {
try {
$tx->rollback();
} catch (\Exception $e2) {}
}
throw $e;
}
} | [
"public",
"function",
"deleteSubscriber",
"(",
"$",
"id",
")",
"{",
"$",
"cx",
"=",
"$",
"this",
"->",
"db",
";",
"$",
"tx",
"=",
"null",
";",
"$",
"subscriber",
"=",
"$",
"this",
"->",
"getSubscriber",
"(",
"$",
"id",
")",
";",
"try",
"{",
"$",
"tx",
"=",
"$",
"cx",
"->",
"startTransaction",
"(",
")",
";",
"// FIXME: SELECT FOR UPDATE here in all tables",
"// Start by deleting all subscriptions.",
"$",
"subIdList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"subscriber",
"->",
"getSubscriptions",
"(",
")",
"as",
"$",
"subscription",
")",
"{",
"$",
"subIdList",
"[",
"]",
"=",
"$",
"subscription",
"->",
"getId",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"subIdList",
")",
")",
"{",
"$",
"this",
"->",
"fetchSubscriptions",
"(",
"[",
"Field",
"::",
"SUB_ID",
"=>",
"$",
"subIdList",
"]",
")",
"->",
"delete",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"tx",
")",
";",
"// Explicit commit",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"subscribersCache",
"[",
"$",
"id",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"subscribersCache",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"tx",
")",
"{",
"try",
"{",
"$",
"tx",
"->",
"rollback",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e2",
")",
"{",
"}",
"}",
"throw",
"$",
"e",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L274-L313 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.subscribe | public function subscribe($chanId, $subscriberId = null)
{
$deactivated = new \DateTime();
$created = $deactivated;
$cx = $this->db;
$tx = null;
$chan = $this->getChannel($chanId);
$subscriber = null;
$subscription = null;
if ($subscriberId) {
$subscriber = $this->getSubscriber($subscriberId);
if ($subscriber->hasSubscriptionFor($chanId)) {
return $subscriber->getSubscriptionFor($chanId);
}
}
try {
$tx = $cx->startTransaction();
$cx
->insert('apb_sub')
->fields([
'chan_id' => $chan->getDatabaseId(),
'status' => (int)(bool)$subscriberId,
'created' => $created->format(Misc::SQL_DATETIME),
'activated' => $deactivated->format(Misc::SQL_DATETIME),
'deactivated' => $deactivated->format(Misc::SQL_DATETIME),
'name' => $subscriberId,
])
->execute()
;
// Specify the name of the sequence object for PDO_PGSQL.
// @see http://php.net/manual/en/pdo.lastinsertid.php.
$seq = ($cx->driver() === 'pgsql') ? 'apb_sub_id_seq' : null;
$id = (int)$cx->lastInsertId($seq);
$subscription = new DefaultSubscription($chanId, $id, $created, $deactivated, $deactivated, null, false, $subscriberId, $this);
unset($tx); // Explicit commit
// We also have to set the new subscription to subscriber data
// because we did cache it
if ($subscriberId) {
unset($this->subscribersCache[$subscriberId]);
}
return $subscription;
} catch (\Exception $e) {
if ($tx) {
try {
$tx->rollback();
} catch (\Exception $e2) {}
}
throw $e;
}
} | php | public function subscribe($chanId, $subscriberId = null)
{
$deactivated = new \DateTime();
$created = $deactivated;
$cx = $this->db;
$tx = null;
$chan = $this->getChannel($chanId);
$subscriber = null;
$subscription = null;
if ($subscriberId) {
$subscriber = $this->getSubscriber($subscriberId);
if ($subscriber->hasSubscriptionFor($chanId)) {
return $subscriber->getSubscriptionFor($chanId);
}
}
try {
$tx = $cx->startTransaction();
$cx
->insert('apb_sub')
->fields([
'chan_id' => $chan->getDatabaseId(),
'status' => (int)(bool)$subscriberId,
'created' => $created->format(Misc::SQL_DATETIME),
'activated' => $deactivated->format(Misc::SQL_DATETIME),
'deactivated' => $deactivated->format(Misc::SQL_DATETIME),
'name' => $subscriberId,
])
->execute()
;
// Specify the name of the sequence object for PDO_PGSQL.
// @see http://php.net/manual/en/pdo.lastinsertid.php.
$seq = ($cx->driver() === 'pgsql') ? 'apb_sub_id_seq' : null;
$id = (int)$cx->lastInsertId($seq);
$subscription = new DefaultSubscription($chanId, $id, $created, $deactivated, $deactivated, null, false, $subscriberId, $this);
unset($tx); // Explicit commit
// We also have to set the new subscription to subscriber data
// because we did cache it
if ($subscriberId) {
unset($this->subscribersCache[$subscriberId]);
}
return $subscription;
} catch (\Exception $e) {
if ($tx) {
try {
$tx->rollback();
} catch (\Exception $e2) {}
}
throw $e;
}
} | [
"public",
"function",
"subscribe",
"(",
"$",
"chanId",
",",
"$",
"subscriberId",
"=",
"null",
")",
"{",
"$",
"deactivated",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"created",
"=",
"$",
"deactivated",
";",
"$",
"cx",
"=",
"$",
"this",
"->",
"db",
";",
"$",
"tx",
"=",
"null",
";",
"$",
"chan",
"=",
"$",
"this",
"->",
"getChannel",
"(",
"$",
"chanId",
")",
";",
"$",
"subscriber",
"=",
"null",
";",
"$",
"subscription",
"=",
"null",
";",
"if",
"(",
"$",
"subscriberId",
")",
"{",
"$",
"subscriber",
"=",
"$",
"this",
"->",
"getSubscriber",
"(",
"$",
"subscriberId",
")",
";",
"if",
"(",
"$",
"subscriber",
"->",
"hasSubscriptionFor",
"(",
"$",
"chanId",
")",
")",
"{",
"return",
"$",
"subscriber",
"->",
"getSubscriptionFor",
"(",
"$",
"chanId",
")",
";",
"}",
"}",
"try",
"{",
"$",
"tx",
"=",
"$",
"cx",
"->",
"startTransaction",
"(",
")",
";",
"$",
"cx",
"->",
"insert",
"(",
"'apb_sub'",
")",
"->",
"fields",
"(",
"[",
"'chan_id'",
"=>",
"$",
"chan",
"->",
"getDatabaseId",
"(",
")",
",",
"'status'",
"=>",
"(",
"int",
")",
"(",
"bool",
")",
"$",
"subscriberId",
",",
"'created'",
"=>",
"$",
"created",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
",",
"'activated'",
"=>",
"$",
"deactivated",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
",",
"'deactivated'",
"=>",
"$",
"deactivated",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
",",
"'name'",
"=>",
"$",
"subscriberId",
",",
"]",
")",
"->",
"execute",
"(",
")",
";",
"// Specify the name of the sequence object for PDO_PGSQL.",
"// @see http://php.net/manual/en/pdo.lastinsertid.php.",
"$",
"seq",
"=",
"(",
"$",
"cx",
"->",
"driver",
"(",
")",
"===",
"'pgsql'",
")",
"?",
"'apb_sub_id_seq'",
":",
"null",
";",
"$",
"id",
"=",
"(",
"int",
")",
"$",
"cx",
"->",
"lastInsertId",
"(",
"$",
"seq",
")",
";",
"$",
"subscription",
"=",
"new",
"DefaultSubscription",
"(",
"$",
"chanId",
",",
"$",
"id",
",",
"$",
"created",
",",
"$",
"deactivated",
",",
"$",
"deactivated",
",",
"null",
",",
"false",
",",
"$",
"subscriberId",
",",
"$",
"this",
")",
";",
"unset",
"(",
"$",
"tx",
")",
";",
"// Explicit commit",
"// We also have to set the new subscription to subscriber data",
"// because we did cache it",
"if",
"(",
"$",
"subscriberId",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"subscribersCache",
"[",
"$",
"subscriberId",
"]",
")",
";",
"}",
"return",
"$",
"subscription",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"tx",
")",
"{",
"try",
"{",
"$",
"tx",
"->",
"rollback",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e2",
")",
"{",
"}",
"}",
"throw",
"$",
"e",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L329-L389 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.fetchSubscribers | public function fetchSubscribers(array $conditions = null)
{
$cursor = new DrupalSubscriberCursor($this);
if (!empty($conditions)) {
$cursor->setConditions($conditions);
}
return $cursor;
} | php | public function fetchSubscribers(array $conditions = null)
{
$cursor = new DrupalSubscriberCursor($this);
if (!empty($conditions)) {
$cursor->setConditions($conditions);
}
return $cursor;
} | [
"public",
"function",
"fetchSubscribers",
"(",
"array",
"$",
"conditions",
"=",
"null",
")",
"{",
"$",
"cursor",
"=",
"new",
"DrupalSubscriberCursor",
"(",
"$",
"this",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"cursor",
"->",
"setConditions",
"(",
"$",
"conditions",
")",
";",
"}",
"return",
"$",
"cursor",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L394-L403 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.send | public function send(
$chanId,
$contents,
$type = null,
$origin = null,
$level = 0,
array $excluded = null,
\DateTime $sentAt = null)
{
if (!is_array($chanId)) { // Ensure this is a list
$chanId = array($chanId);
}
if (empty($chanId)) { // Short-circuit empty chan list
return;
}
$cx = $this->db;
$tx = null;
$id = null;
$typeId = 0;
$chanList = $this->getChannels($chanId);
$dbIdList = array();
foreach ($chanList as $channel) {
$dbIdList[] = $channel->getDatabaseId();
}
if (null !== $type) {
$typeId = $this->typeRegistry->getTypeId($type);
}
if (null === $sentAt) {
$sentAt = new \DateTime();
}
try {
$tx = $cx->startTransaction();
$cx
->insert('apb_msg')
->fields([
'created' => $sentAt->format(Misc::SQL_DATETIME),
'contents' => serialize($contents),
'type_id' => $typeId,
'level' => $level,
'origin' => $origin,
])
->execute()
;
$seq = ($cx->driver() === 'pgsql') ? 'apb_msg_id_seq' : null;
$id = (int)$cx->lastInsertId($seq);
// Insert channel references
$q = $cx->insert('apb_msg_chan')->fields(['msg_id', 'chan_id']);
foreach ($dbIdList as $dbId) {
$q->values([$id, $dbId]);
}
$q->execute();
// Send message to all subscribers
if (empty($excluded)) {
$cx
->query("
INSERT INTO {apb_queue} (msg_id, sub_id, type_id, unread, created)
SELECT
:msgId AS msg_id,
s.id AS sub_id,
:typeId AS type_id,
1 AS unread,
:created AS created
FROM {apb_sub} s
WHERE s.chan_id IN (:chanId)
AND s.status = 1
", [
':msgId' => $id,
':typeId' => $typeId,
':chanId' => $dbIdList,
':created' => $sentAt->format(Misc::SQL_DATETIME),
])
;
} else {
$cx
->query("
INSERT INTO {apb_queue} (msg_id, sub_id, type_id, unread, created)
SELECT
:msgId AS msg_id,
s.id AS sub_id,
:typeId AS type_id,
1 AS unread,
:created AS created
FROM {apb_sub} s
WHERE
s.chan_id IN (:chanId)
AND s.status = 1
AND s.id NOT IN (:excluded)
", [
':msgId' => $id,
':typeId' => $typeId,
':chanId' => $dbIdList,
':created' => $sentAt->format(Misc::SQL_DATETIME),
':excluded' => $excluded,
])
;
}
$cx
->update('apb_chan')
->fields([
'updated' => (new \DateTime())->format(Misc::SQL_DATETIME),
])
->condition('id', $dbIdList)
->execute()
;
unset($tx); // Explicit commit
} catch (\Exception $e) {
if ($tx) {
try {
$tx->rollback();
} catch (\Exception $e2) {}
}
throw $e;
}
return new DefaultMessage($contents, $id, $type, $level, $origin);
} | php | public function send(
$chanId,
$contents,
$type = null,
$origin = null,
$level = 0,
array $excluded = null,
\DateTime $sentAt = null)
{
if (!is_array($chanId)) { // Ensure this is a list
$chanId = array($chanId);
}
if (empty($chanId)) { // Short-circuit empty chan list
return;
}
$cx = $this->db;
$tx = null;
$id = null;
$typeId = 0;
$chanList = $this->getChannels($chanId);
$dbIdList = array();
foreach ($chanList as $channel) {
$dbIdList[] = $channel->getDatabaseId();
}
if (null !== $type) {
$typeId = $this->typeRegistry->getTypeId($type);
}
if (null === $sentAt) {
$sentAt = new \DateTime();
}
try {
$tx = $cx->startTransaction();
$cx
->insert('apb_msg')
->fields([
'created' => $sentAt->format(Misc::SQL_DATETIME),
'contents' => serialize($contents),
'type_id' => $typeId,
'level' => $level,
'origin' => $origin,
])
->execute()
;
$seq = ($cx->driver() === 'pgsql') ? 'apb_msg_id_seq' : null;
$id = (int)$cx->lastInsertId($seq);
// Insert channel references
$q = $cx->insert('apb_msg_chan')->fields(['msg_id', 'chan_id']);
foreach ($dbIdList as $dbId) {
$q->values([$id, $dbId]);
}
$q->execute();
// Send message to all subscribers
if (empty($excluded)) {
$cx
->query("
INSERT INTO {apb_queue} (msg_id, sub_id, type_id, unread, created)
SELECT
:msgId AS msg_id,
s.id AS sub_id,
:typeId AS type_id,
1 AS unread,
:created AS created
FROM {apb_sub} s
WHERE s.chan_id IN (:chanId)
AND s.status = 1
", [
':msgId' => $id,
':typeId' => $typeId,
':chanId' => $dbIdList,
':created' => $sentAt->format(Misc::SQL_DATETIME),
])
;
} else {
$cx
->query("
INSERT INTO {apb_queue} (msg_id, sub_id, type_id, unread, created)
SELECT
:msgId AS msg_id,
s.id AS sub_id,
:typeId AS type_id,
1 AS unread,
:created AS created
FROM {apb_sub} s
WHERE
s.chan_id IN (:chanId)
AND s.status = 1
AND s.id NOT IN (:excluded)
", [
':msgId' => $id,
':typeId' => $typeId,
':chanId' => $dbIdList,
':created' => $sentAt->format(Misc::SQL_DATETIME),
':excluded' => $excluded,
])
;
}
$cx
->update('apb_chan')
->fields([
'updated' => (new \DateTime())->format(Misc::SQL_DATETIME),
])
->condition('id', $dbIdList)
->execute()
;
unset($tx); // Explicit commit
} catch (\Exception $e) {
if ($tx) {
try {
$tx->rollback();
} catch (\Exception $e2) {}
}
throw $e;
}
return new DefaultMessage($contents, $id, $type, $level, $origin);
} | [
"public",
"function",
"send",
"(",
"$",
"chanId",
",",
"$",
"contents",
",",
"$",
"type",
"=",
"null",
",",
"$",
"origin",
"=",
"null",
",",
"$",
"level",
"=",
"0",
",",
"array",
"$",
"excluded",
"=",
"null",
",",
"\\",
"DateTime",
"$",
"sentAt",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"chanId",
")",
")",
"{",
"// Ensure this is a list",
"$",
"chanId",
"=",
"array",
"(",
"$",
"chanId",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"chanId",
")",
")",
"{",
"// Short-circuit empty chan list",
"return",
";",
"}",
"$",
"cx",
"=",
"$",
"this",
"->",
"db",
";",
"$",
"tx",
"=",
"null",
";",
"$",
"id",
"=",
"null",
";",
"$",
"typeId",
"=",
"0",
";",
"$",
"chanList",
"=",
"$",
"this",
"->",
"getChannels",
"(",
"$",
"chanId",
")",
";",
"$",
"dbIdList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"chanList",
"as",
"$",
"channel",
")",
"{",
"$",
"dbIdList",
"[",
"]",
"=",
"$",
"channel",
"->",
"getDatabaseId",
"(",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"type",
")",
"{",
"$",
"typeId",
"=",
"$",
"this",
"->",
"typeRegistry",
"->",
"getTypeId",
"(",
"$",
"type",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"sentAt",
")",
"{",
"$",
"sentAt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}",
"try",
"{",
"$",
"tx",
"=",
"$",
"cx",
"->",
"startTransaction",
"(",
")",
";",
"$",
"cx",
"->",
"insert",
"(",
"'apb_msg'",
")",
"->",
"fields",
"(",
"[",
"'created'",
"=>",
"$",
"sentAt",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
",",
"'contents'",
"=>",
"serialize",
"(",
"$",
"contents",
")",
",",
"'type_id'",
"=>",
"$",
"typeId",
",",
"'level'",
"=>",
"$",
"level",
",",
"'origin'",
"=>",
"$",
"origin",
",",
"]",
")",
"->",
"execute",
"(",
")",
";",
"$",
"seq",
"=",
"(",
"$",
"cx",
"->",
"driver",
"(",
")",
"===",
"'pgsql'",
")",
"?",
"'apb_msg_id_seq'",
":",
"null",
";",
"$",
"id",
"=",
"(",
"int",
")",
"$",
"cx",
"->",
"lastInsertId",
"(",
"$",
"seq",
")",
";",
"// Insert channel references",
"$",
"q",
"=",
"$",
"cx",
"->",
"insert",
"(",
"'apb_msg_chan'",
")",
"->",
"fields",
"(",
"[",
"'msg_id'",
",",
"'chan_id'",
"]",
")",
";",
"foreach",
"(",
"$",
"dbIdList",
"as",
"$",
"dbId",
")",
"{",
"$",
"q",
"->",
"values",
"(",
"[",
"$",
"id",
",",
"$",
"dbId",
"]",
")",
";",
"}",
"$",
"q",
"->",
"execute",
"(",
")",
";",
"// Send message to all subscribers",
"if",
"(",
"empty",
"(",
"$",
"excluded",
")",
")",
"{",
"$",
"cx",
"->",
"query",
"(",
"\"\n INSERT INTO {apb_queue} (msg_id, sub_id, type_id, unread, created)\n SELECT\n :msgId AS msg_id,\n s.id AS sub_id,\n :typeId AS type_id,\n 1 AS unread,\n :created AS created\n FROM {apb_sub} s\n WHERE s.chan_id IN (:chanId)\n AND s.status = 1\n \"",
",",
"[",
"':msgId'",
"=>",
"$",
"id",
",",
"':typeId'",
"=>",
"$",
"typeId",
",",
"':chanId'",
"=>",
"$",
"dbIdList",
",",
"':created'",
"=>",
"$",
"sentAt",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
",",
"]",
")",
";",
"}",
"else",
"{",
"$",
"cx",
"->",
"query",
"(",
"\"\n INSERT INTO {apb_queue} (msg_id, sub_id, type_id, unread, created)\n SELECT\n :msgId AS msg_id,\n s.id AS sub_id,\n :typeId AS type_id,\n 1 AS unread,\n :created AS created\n FROM {apb_sub} s\n WHERE\n s.chan_id IN (:chanId)\n AND s.status = 1\n AND s.id NOT IN (:excluded)\n \"",
",",
"[",
"':msgId'",
"=>",
"$",
"id",
",",
"':typeId'",
"=>",
"$",
"typeId",
",",
"':chanId'",
"=>",
"$",
"dbIdList",
",",
"':created'",
"=>",
"$",
"sentAt",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
",",
"':excluded'",
"=>",
"$",
"excluded",
",",
"]",
")",
";",
"}",
"$",
"cx",
"->",
"update",
"(",
"'apb_chan'",
")",
"->",
"fields",
"(",
"[",
"'updated'",
"=>",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
",",
"]",
")",
"->",
"condition",
"(",
"'id'",
",",
"$",
"dbIdList",
")",
"->",
"execute",
"(",
")",
";",
"unset",
"(",
"$",
"tx",
")",
";",
"// Explicit commit",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"tx",
")",
"{",
"try",
"{",
"$",
"tx",
"->",
"rollback",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e2",
")",
"{",
"}",
"}",
"throw",
"$",
"e",
";",
"}",
"return",
"new",
"DefaultMessage",
"(",
"$",
"contents",
",",
"$",
"id",
",",
"$",
"type",
",",
"$",
"level",
",",
"$",
"origin",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L408-L536 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.copyQueue | public function copyQueue($chanId, $subIdList, $isUnread = true)
{
if (!is_array($subIdList)) {
$subIdList = [$subIdList];
}
if (!$channel = $this->getChannel($chanId)) {
throw new ChannelDoesNotExistException();
}
// FIXME: Could do better than foreach.
foreach ($subIdList as $subId) {
$this
->getConnection()
->query("
INSERT INTO {apb_queue} (msg_id, sub_id, type_id, created, unread)
SELECT m.id, :subId, m.type_id, m.created, :isUnread
FROM apb_msg m
JOIN apb_msg_chan mc ON m.id = mc.msg_id
WHERE
mc.chan_id = :chanId
AND NOT EXISTS (
SELECT 1 FROM apb_queue q
WHERE q.msg_id = m.id AND q.sub_id = :subId2
)
", [
':subId' => $subId,
':isUnread' => (int)$isUnread,
':chanId' => $channel->getDatabaseId(),
':subId2' => $subId,
])
;
}
} | php | public function copyQueue($chanId, $subIdList, $isUnread = true)
{
if (!is_array($subIdList)) {
$subIdList = [$subIdList];
}
if (!$channel = $this->getChannel($chanId)) {
throw new ChannelDoesNotExistException();
}
// FIXME: Could do better than foreach.
foreach ($subIdList as $subId) {
$this
->getConnection()
->query("
INSERT INTO {apb_queue} (msg_id, sub_id, type_id, created, unread)
SELECT m.id, :subId, m.type_id, m.created, :isUnread
FROM apb_msg m
JOIN apb_msg_chan mc ON m.id = mc.msg_id
WHERE
mc.chan_id = :chanId
AND NOT EXISTS (
SELECT 1 FROM apb_queue q
WHERE q.msg_id = m.id AND q.sub_id = :subId2
)
", [
':subId' => $subId,
':isUnread' => (int)$isUnread,
':chanId' => $channel->getDatabaseId(),
':subId2' => $subId,
])
;
}
} | [
"public",
"function",
"copyQueue",
"(",
"$",
"chanId",
",",
"$",
"subIdList",
",",
"$",
"isUnread",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"subIdList",
")",
")",
"{",
"$",
"subIdList",
"=",
"[",
"$",
"subIdList",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"channel",
"=",
"$",
"this",
"->",
"getChannel",
"(",
"$",
"chanId",
")",
")",
"{",
"throw",
"new",
"ChannelDoesNotExistException",
"(",
")",
";",
"}",
"// FIXME: Could do better than foreach.",
"foreach",
"(",
"$",
"subIdList",
"as",
"$",
"subId",
")",
"{",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"query",
"(",
"\"\n INSERT INTO {apb_queue} (msg_id, sub_id, type_id, created, unread)\n SELECT m.id, :subId, m.type_id, m.created, :isUnread\n FROM apb_msg m\n JOIN apb_msg_chan mc ON m.id = mc.msg_id\n WHERE\n mc.chan_id = :chanId\n AND NOT EXISTS (\n SELECT 1 FROM apb_queue q\n WHERE q.msg_id = m.id AND q.sub_id = :subId2\n )\n \"",
",",
"[",
"':subId'",
"=>",
"$",
"subId",
",",
"':isUnread'",
"=>",
"(",
"int",
")",
"$",
"isUnread",
",",
"':chanId'",
"=>",
"$",
"channel",
"->",
"getDatabaseId",
"(",
")",
",",
"':subId2'",
"=>",
"$",
"subId",
",",
"]",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L541-L574 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.garbageCollection | public function garbageCollection()
{
// Drop all messages for inactive subscriptions
// FIXME: When volatile only
$this
->db
->query("
DELETE
FROM {apb_queue}
WHERE sub_id IN (
SELECT id
FROM {apb_sub}
WHERE status = 0
)
");
// Clean up expired messages
if (false /* Max message lifetime */) {
$this
->db
->query("DELETE FROM {apb_msg} WHERE created < :time", array(
':time' => time() - $this->context->messageMaxLifetime,
));
}
// Limit queue size if configured for
if (false /* Global queue limit */) {
$min = $this
->db
->query("
SELECT msg_id
FROM {apb_queue}
ORDER BY msg_id DESC
OFFSET :max LIMIT 1
", array(
':max' => $this->context->queueGlobalLimit,
))
->fetchField();
if ($min) {
// If the same message exists in many queues, we will never
// reach the exact global limit: deleting all messages with
// a lower id ensures that we may be close enought to this
// limit
$this
->db
->query("DELETE FROM {apb_queue} WHERE msg_id < :min", array(
':min' => $min,
));
}
}
// Clean up orphaned messages
$this
->db
->query("
DELETE FROM {apb_msg}
WHERE id NOT IN (
SELECT msg_id FROM {apb_queue}
)
")
;
} | php | public function garbageCollection()
{
// Drop all messages for inactive subscriptions
// FIXME: When volatile only
$this
->db
->query("
DELETE
FROM {apb_queue}
WHERE sub_id IN (
SELECT id
FROM {apb_sub}
WHERE status = 0
)
");
// Clean up expired messages
if (false /* Max message lifetime */) {
$this
->db
->query("DELETE FROM {apb_msg} WHERE created < :time", array(
':time' => time() - $this->context->messageMaxLifetime,
));
}
// Limit queue size if configured for
if (false /* Global queue limit */) {
$min = $this
->db
->query("
SELECT msg_id
FROM {apb_queue}
ORDER BY msg_id DESC
OFFSET :max LIMIT 1
", array(
':max' => $this->context->queueGlobalLimit,
))
->fetchField();
if ($min) {
// If the same message exists in many queues, we will never
// reach the exact global limit: deleting all messages with
// a lower id ensures that we may be close enought to this
// limit
$this
->db
->query("DELETE FROM {apb_queue} WHERE msg_id < :min", array(
':min' => $min,
));
}
}
// Clean up orphaned messages
$this
->db
->query("
DELETE FROM {apb_msg}
WHERE id NOT IN (
SELECT msg_id FROM {apb_queue}
)
")
;
} | [
"public",
"function",
"garbageCollection",
"(",
")",
"{",
"// Drop all messages for inactive subscriptions",
"// FIXME: When volatile only",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"\n DELETE\n FROM {apb_queue}\n WHERE sub_id IN (\n SELECT id\n FROM {apb_sub}\n WHERE status = 0\n )\n \"",
")",
";",
"// Clean up expired messages",
"if",
"(",
"false",
"/* Max message lifetime */",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"DELETE FROM {apb_msg} WHERE created < :time\"",
",",
"array",
"(",
"':time'",
"=>",
"time",
"(",
")",
"-",
"$",
"this",
"->",
"context",
"->",
"messageMaxLifetime",
",",
")",
")",
";",
"}",
"// Limit queue size if configured for",
"if",
"(",
"false",
"/* Global queue limit */",
")",
"{",
"$",
"min",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"\n SELECT msg_id\n FROM {apb_queue}\n ORDER BY msg_id DESC\n OFFSET :max LIMIT 1\n \"",
",",
"array",
"(",
"':max'",
"=>",
"$",
"this",
"->",
"context",
"->",
"queueGlobalLimit",
",",
")",
")",
"->",
"fetchField",
"(",
")",
";",
"if",
"(",
"$",
"min",
")",
"{",
"// If the same message exists in many queues, we will never",
"// reach the exact global limit: deleting all messages with",
"// a lower id ensures that we may be close enought to this",
"// limit",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"DELETE FROM {apb_queue} WHERE msg_id < :min\"",
",",
"array",
"(",
"':min'",
"=>",
"$",
"min",
",",
")",
")",
";",
"}",
"}",
"// Clean up orphaned messages",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"\n DELETE FROM {apb_msg}\n WHERE id NOT IN (\n SELECT msg_id FROM {apb_queue}\n )\n \"",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L586-L649 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.getAnalysis | public function getAnalysis()
{
$cx = $this->db;
$chanCount = (int)$cx->query("SELECT COUNT(*) FROM {apb_chan}")->fetchField();
$msgCount = (int)$cx->query("SELECT COUNT(*) FROM {apb_msg}")->fetchField();
$subCount = (int)$cx->query("SELECT COUNT(*) FROM {apb_sub}")->fetchField();
$subscriberCount = (int)$cx->query("SELECT COUNT(name) FROM {apb_sub} GROUP BY name")->fetchField();
$queueSize = (int)$cx->query("SELECT COUNT(*) FROM {apb_queue}")->fetchField();
return array(
"Channel count" => $chanCount,
"Message count" => $msgCount,
"Subscriptions count" => $subCount,
"Subscribers count" => $subscriberCount,
"Total queue size" => $queueSize,
);
} | php | public function getAnalysis()
{
$cx = $this->db;
$chanCount = (int)$cx->query("SELECT COUNT(*) FROM {apb_chan}")->fetchField();
$msgCount = (int)$cx->query("SELECT COUNT(*) FROM {apb_msg}")->fetchField();
$subCount = (int)$cx->query("SELECT COUNT(*) FROM {apb_sub}")->fetchField();
$subscriberCount = (int)$cx->query("SELECT COUNT(name) FROM {apb_sub} GROUP BY name")->fetchField();
$queueSize = (int)$cx->query("SELECT COUNT(*) FROM {apb_queue}")->fetchField();
return array(
"Channel count" => $chanCount,
"Message count" => $msgCount,
"Subscriptions count" => $subCount,
"Subscribers count" => $subscriberCount,
"Total queue size" => $queueSize,
);
} | [
"public",
"function",
"getAnalysis",
"(",
")",
"{",
"$",
"cx",
"=",
"$",
"this",
"->",
"db",
";",
"$",
"chanCount",
"=",
"(",
"int",
")",
"$",
"cx",
"->",
"query",
"(",
"\"SELECT COUNT(*) FROM {apb_chan}\"",
")",
"->",
"fetchField",
"(",
")",
";",
"$",
"msgCount",
"=",
"(",
"int",
")",
"$",
"cx",
"->",
"query",
"(",
"\"SELECT COUNT(*) FROM {apb_msg}\"",
")",
"->",
"fetchField",
"(",
")",
";",
"$",
"subCount",
"=",
"(",
"int",
")",
"$",
"cx",
"->",
"query",
"(",
"\"SELECT COUNT(*) FROM {apb_sub}\"",
")",
"->",
"fetchField",
"(",
")",
";",
"$",
"subscriberCount",
"=",
"(",
"int",
")",
"$",
"cx",
"->",
"query",
"(",
"\"SELECT COUNT(name) FROM {apb_sub} GROUP BY name\"",
")",
"->",
"fetchField",
"(",
")",
";",
"$",
"queueSize",
"=",
"(",
"int",
")",
"$",
"cx",
"->",
"query",
"(",
"\"SELECT COUNT(*) FROM {apb_queue}\"",
")",
"->",
"fetchField",
"(",
")",
";",
"return",
"array",
"(",
"\"Channel count\"",
"=>",
"$",
"chanCount",
",",
"\"Message count\"",
"=>",
"$",
"msgCount",
",",
"\"Subscriptions count\"",
"=>",
"$",
"subCount",
",",
"\"Subscribers count\"",
"=>",
"$",
"subscriberCount",
",",
"\"Total queue size\"",
"=>",
"$",
"queueSize",
",",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L654-L671 |
opis-colibri/core | src/ComposerPlugin.php | ComposerPlugin.activate | public function activate(Composer $composer, IOInterface $io)
{
$this->io = $io;
$this->composer = $composer;
$rootDir = realpath($this->composer->getConfig()->get('vendor-dir') . '/../');
$settings = $this->composer->getPackage()->getExtra()['application'] ?? [];
$this->appInfo = new AppInfo($rootDir, $settings);
$this->isProject = $composer->getPackage()->getType() === 'project';
if ($this->isProject) {
$this->packageInstaller = new PackageInstaller($this->appInfo, $io, $composer);
$this->composer
->getInstallationManager()
->addInstaller($this->packageInstaller);
}
} | php | public function activate(Composer $composer, IOInterface $io)
{
$this->io = $io;
$this->composer = $composer;
$rootDir = realpath($this->composer->getConfig()->get('vendor-dir') . '/../');
$settings = $this->composer->getPackage()->getExtra()['application'] ?? [];
$this->appInfo = new AppInfo($rootDir, $settings);
$this->isProject = $composer->getPackage()->getType() === 'project';
if ($this->isProject) {
$this->packageInstaller = new PackageInstaller($this->appInfo, $io, $composer);
$this->composer
->getInstallationManager()
->addInstaller($this->packageInstaller);
}
} | [
"public",
"function",
"activate",
"(",
"Composer",
"$",
"composer",
",",
"IOInterface",
"$",
"io",
")",
"{",
"$",
"this",
"->",
"io",
"=",
"$",
"io",
";",
"$",
"this",
"->",
"composer",
"=",
"$",
"composer",
";",
"$",
"rootDir",
"=",
"realpath",
"(",
"$",
"this",
"->",
"composer",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'vendor-dir'",
")",
".",
"'/../'",
")",
";",
"$",
"settings",
"=",
"$",
"this",
"->",
"composer",
"->",
"getPackage",
"(",
")",
"->",
"getExtra",
"(",
")",
"[",
"'application'",
"]",
"??",
"[",
"]",
";",
"$",
"this",
"->",
"appInfo",
"=",
"new",
"AppInfo",
"(",
"$",
"rootDir",
",",
"$",
"settings",
")",
";",
"$",
"this",
"->",
"isProject",
"=",
"$",
"composer",
"->",
"getPackage",
"(",
")",
"->",
"getType",
"(",
")",
"===",
"'project'",
";",
"if",
"(",
"$",
"this",
"->",
"isProject",
")",
"{",
"$",
"this",
"->",
"packageInstaller",
"=",
"new",
"PackageInstaller",
"(",
"$",
"this",
"->",
"appInfo",
",",
"$",
"io",
",",
"$",
"composer",
")",
";",
"$",
"this",
"->",
"composer",
"->",
"getInstallationManager",
"(",
")",
"->",
"addInstaller",
"(",
"$",
"this",
"->",
"packageInstaller",
")",
";",
"}",
"}"
] | Apply plugin modifications to Composer
@param Composer $composer
@param IOInterface $io | [
"Apply",
"plugin",
"modifications",
"to",
"Composer"
] | train | https://github.com/opis-colibri/core/blob/77efaf8e2034293588d3759e0b8711e96757d954/src/ComposerPlugin.php#L49-L64 |
leogitpro/php-zf3-base-module | module/src/Controller/BaseController.php | BaseController.setData | protected function setData($data = [])
{
if (!isset($data[self::RS_KEY_CODE])) {
$data[self::RS_KEY_CODE] = 0;
}
if (!isset($data[self::RS_KEY_MSG])) {
$data[self::RS_KEY_MSG] = 'Success';
}
if (!isset($data[self::RS_KEY_TYPE])) {
$data[self::RS_KEY_TYPE] = self::RESPONSE_XHTML;
}
if (!isset($data[self::RS_KEY_DATA])) {
$data[self::RS_KEY_DATA] = new \stdClass();
} else {
if (!$data instanceof \stdClass) {
$data[self::RS_KEY_DATA] = new \stdClass();
}
}
$this->data = $data;
} | php | protected function setData($data = [])
{
if (!isset($data[self::RS_KEY_CODE])) {
$data[self::RS_KEY_CODE] = 0;
}
if (!isset($data[self::RS_KEY_MSG])) {
$data[self::RS_KEY_MSG] = 'Success';
}
if (!isset($data[self::RS_KEY_TYPE])) {
$data[self::RS_KEY_TYPE] = self::RESPONSE_XHTML;
}
if (!isset($data[self::RS_KEY_DATA])) {
$data[self::RS_KEY_DATA] = new \stdClass();
} else {
if (!$data instanceof \stdClass) {
$data[self::RS_KEY_DATA] = new \stdClass();
}
}
$this->data = $data;
} | [
"protected",
"function",
"setData",
"(",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_CODE",
"]",
")",
")",
"{",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_CODE",
"]",
"=",
"0",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_MSG",
"]",
")",
")",
"{",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_MSG",
"]",
"=",
"'Success'",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_TYPE",
"]",
")",
")",
"{",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_TYPE",
"]",
"=",
"self",
"::",
"RESPONSE_XHTML",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_DATA",
"]",
")",
")",
"{",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_DATA",
"]",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"data",
"instanceof",
"\\",
"stdClass",
")",
"{",
"$",
"data",
"[",
"self",
"::",
"RS_KEY_DATA",
"]",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"}"
] | Set data
@param array $data | [
"Set",
"data"
] | train | https://github.com/leogitpro/php-zf3-base-module/blob/596fc89c25033eaef8f796418a4a3399c47a9638/module/src/Controller/BaseController.php#L50-L70 |
leogitpro/php-zf3-base-module | module/src/Controller/BaseController.php | BaseController.addData | protected function addData($key, $data = null)
{
$this->data[self::RS_KEY_DATA]->{$key} = $data;
} | php | protected function addData($key, $data = null)
{
$this->data[self::RS_KEY_DATA]->{$key} = $data;
} | [
"protected",
"function",
"addData",
"(",
"$",
"key",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"self",
"::",
"RS_KEY_DATA",
"]",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"data",
";",
"}"
] | Add data to result object
@param string $key
@param null|string|array|\stdClass $data | [
"Add",
"data",
"to",
"result",
"object"
] | train | https://github.com/leogitpro/php-zf3-base-module/blob/596fc89c25033eaef8f796418a4a3399c47a9638/module/src/Controller/BaseController.php#L87-L90 |
loevgaard/dandomain-foundation-entities | src/Entity/Product.php | Product.addDisabledVariant | public function addDisabledVariant(VariantInterface $variant): ProductInterface
{
if (!$this->disabledVariants->contains($variant)) {
$this->disabledVariants->add($variant);
}
return $this;
} | php | public function addDisabledVariant(VariantInterface $variant): ProductInterface
{
if (!$this->disabledVariants->contains($variant)) {
$this->disabledVariants->add($variant);
}
return $this;
} | [
"public",
"function",
"addDisabledVariant",
"(",
"VariantInterface",
"$",
"variant",
")",
":",
"ProductInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"disabledVariants",
"->",
"contains",
"(",
"$",
"variant",
")",
")",
"{",
"$",
"this",
"->",
"disabledVariants",
"->",
"add",
"(",
"$",
"variant",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | /*
Collection/relation methods | [
"/",
"*",
"Collection",
"/",
"relation",
"methods"
] | train | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L452-L459 |
loevgaard/dandomain-foundation-entities | src/Entity/Product.php | Product.findCategory | public function findCategory(CategoryInterface $searchCategory): ?CategoryInterface
{
foreach ($this->categories as $category) {
if($category->getNumber() === $searchCategory->getNumber()) {
return $category;
}
}
return null;
} | php | public function findCategory(CategoryInterface $searchCategory): ?CategoryInterface
{
foreach ($this->categories as $category) {
if($category->getNumber() === $searchCategory->getNumber()) {
return $category;
}
}
return null;
} | [
"public",
"function",
"findCategory",
"(",
"CategoryInterface",
"$",
"searchCategory",
")",
":",
"?",
"CategoryInterface",
"{",
"foreach",
"(",
"$",
"this",
"->",
"categories",
"as",
"$",
"category",
")",
"{",
"if",
"(",
"$",
"category",
"->",
"getNumber",
"(",
")",
"===",
"$",
"searchCategory",
"->",
"getNumber",
"(",
")",
")",
"{",
"return",
"$",
"category",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | This method will try to find a category based on the number (which is unique)
Returns null if it does not exist
@param CategoryInterface $searchCategory
@return CategoryInterface|null | [
"This",
"method",
"will",
"try",
"to",
"find",
"a",
"category",
"based",
"on",
"the",
"number",
"(",
"which",
"is",
"unique",
")",
"Returns",
"null",
"if",
"it",
"does",
"not",
"exist"
] | train | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L531-L540 |
loevgaard/dandomain-foundation-entities | src/Entity/Product.php | Product.addManufacturer | public function addManufacturer(ManufacturerInterface $manufacturer): ProductInterface
{
if (!$this->hasManufacturer($manufacturer)) {
$this->manufacturers->add($manufacturer);
}
return $this;
} | php | public function addManufacturer(ManufacturerInterface $manufacturer): ProductInterface
{
if (!$this->hasManufacturer($manufacturer)) {
$this->manufacturers->add($manufacturer);
}
return $this;
} | [
"public",
"function",
"addManufacturer",
"(",
"ManufacturerInterface",
"$",
"manufacturer",
")",
":",
"ProductInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasManufacturer",
"(",
"$",
"manufacturer",
")",
")",
"{",
"$",
"this",
"->",
"manufacturers",
"->",
"add",
"(",
"$",
"manufacturer",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | /*
Manufacturer collection methods | [
"/",
"*",
"Manufacturer",
"collection",
"methods"
] | train | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L545-L552 |
loevgaard/dandomain-foundation-entities | src/Entity/Product.php | Product.addVariantGroup | public function addVariantGroup(VariantGroupInterface $variantGroup): ProductInterface
{
if (!$this->hasVariantGroup($variantGroup)) {
$this->variantGroups->add($variantGroup);
}
return $this;
} | php | public function addVariantGroup(VariantGroupInterface $variantGroup): ProductInterface
{
if (!$this->hasVariantGroup($variantGroup)) {
$this->variantGroups->add($variantGroup);
}
return $this;
} | [
"public",
"function",
"addVariantGroup",
"(",
"VariantGroupInterface",
"$",
"variantGroup",
")",
":",
"ProductInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasVariantGroup",
"(",
"$",
"variantGroup",
")",
")",
"{",
"$",
"this",
"->",
"variantGroups",
"->",
"add",
"(",
"$",
"variantGroup",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | /*
Variant group collection methods | [
"/",
"*",
"Variant",
"group",
"collection",
"methods"
] | train | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L574-L581 |
loevgaard/dandomain-foundation-entities | src/Entity/Product.php | Product.addPrice | public function addPrice(PriceInterface $price): ProductInterface
{
if (!$this->prices->contains($price)) {
$this->prices->add($price);
$price->setProduct($this);
}
return $this;
} | php | public function addPrice(PriceInterface $price): ProductInterface
{
if (!$this->prices->contains($price)) {
$this->prices->add($price);
$price->setProduct($this);
}
return $this;
} | [
"public",
"function",
"addPrice",
"(",
"PriceInterface",
"$",
"price",
")",
":",
"ProductInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"prices",
"->",
"contains",
"(",
"$",
"price",
")",
")",
"{",
"$",
"this",
"->",
"prices",
"->",
"add",
"(",
"$",
"price",
")",
";",
"$",
"price",
"->",
"setProduct",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | /*
Price collection methods | [
"/",
"*",
"Price",
"collection",
"methods"
] | train | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L607-L615 |
loevgaard/dandomain-foundation-entities | src/Entity/Product.php | Product.findPriceByCurrency | public function findPriceByCurrency($currency): ?PriceInterface
{
if ($currency instanceof \Money\Currency) {
$currency = $currency->getCode();
} elseif ($currency instanceof CurrencyInterface) {
$currency = $currency->getIsoCodeAlpha();
}
if (!is_string($currency)) {
throw new \InvalidArgumentException('$currency has to be a string');
}
foreach ($this->prices as $price) {
if ($price->getCurrency()->getIsoCodeAlpha() === $currency) {
return $price;
}
}
return null;
} | php | public function findPriceByCurrency($currency): ?PriceInterface
{
if ($currency instanceof \Money\Currency) {
$currency = $currency->getCode();
} elseif ($currency instanceof CurrencyInterface) {
$currency = $currency->getIsoCodeAlpha();
}
if (!is_string($currency)) {
throw new \InvalidArgumentException('$currency has to be a string');
}
foreach ($this->prices as $price) {
if ($price->getCurrency()->getIsoCodeAlpha() === $currency) {
return $price;
}
}
return null;
} | [
"public",
"function",
"findPriceByCurrency",
"(",
"$",
"currency",
")",
":",
"?",
"PriceInterface",
"{",
"if",
"(",
"$",
"currency",
"instanceof",
"\\",
"Money",
"\\",
"Currency",
")",
"{",
"$",
"currency",
"=",
"$",
"currency",
"->",
"getCode",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"currency",
"instanceof",
"CurrencyInterface",
")",
"{",
"$",
"currency",
"=",
"$",
"currency",
"->",
"getIsoCodeAlpha",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"currency",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$currency has to be a string'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"prices",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getIsoCodeAlpha",
"(",
")",
"===",
"$",
"currency",
")",
"{",
"return",
"$",
"price",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Will try to find a price based on currency.
@param string|\Money\Currency|CurrencyInterface $currency
@return PriceInterface|null | [
"Will",
"try",
"to",
"find",
"a",
"price",
"based",
"on",
"currency",
"."
] | train | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L669-L688 |
loevgaard/dandomain-foundation-entities | src/Entity/Product.php | Product.findPrice | protected function findPrice(PriceInterface $searchPrice): ?PriceInterface
{
foreach ($this->prices as $price) {
if ($price->getAmount() == $searchPrice->getAmount() && $price->getB2bGroupId() == $searchPrice->getB2bGroupId() && $price->getCurrency()->getId() == $searchPrice->getCurrency()->getId()) {
return $price;
}
}
return null;
} | php | protected function findPrice(PriceInterface $searchPrice): ?PriceInterface
{
foreach ($this->prices as $price) {
if ($price->getAmount() == $searchPrice->getAmount() && $price->getB2bGroupId() == $searchPrice->getB2bGroupId() && $price->getCurrency()->getId() == $searchPrice->getCurrency()->getId()) {
return $price;
}
}
return null;
} | [
"protected",
"function",
"findPrice",
"(",
"PriceInterface",
"$",
"searchPrice",
")",
":",
"?",
"PriceInterface",
"{",
"foreach",
"(",
"$",
"this",
"->",
"prices",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getAmount",
"(",
")",
"==",
"$",
"searchPrice",
"->",
"getAmount",
"(",
")",
"&&",
"$",
"price",
"->",
"getB2bGroupId",
"(",
")",
"==",
"$",
"searchPrice",
"->",
"getB2bGroupId",
"(",
")",
"&&",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"$",
"searchPrice",
"->",
"getCurrency",
"(",
")",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"$",
"price",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | This method will try to find a price based on the unique constraint defined in price.
@param PriceInterface $searchPrice
@return PriceInterface|null | [
"This",
"method",
"will",
"try",
"to",
"find",
"a",
"price",
"based",
"on",
"the",
"unique",
"constraint",
"defined",
"in",
"price",
"."
] | train | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Product.php#L1756-L1765 |
helikopterspark/FlashMsg | src/FlashMsg/FlashMsg.php | FlashMsg.setMessage | public function setMessage($type, $message) {
if (!$this->session->has('flashmsgs')) {
$this->session->set('flashmsgs', array());
}
$temp = $this->session->get('flashmsgs');
$temp[] = array('type' => $type, 'content' => $message);
$this->session->set('flashmsgs', $temp);
} | php | public function setMessage($type, $message) {
if (!$this->session->has('flashmsgs')) {
$this->session->set('flashmsgs', array());
}
$temp = $this->session->get('flashmsgs');
$temp[] = array('type' => $type, 'content' => $message);
$this->session->set('flashmsgs', $temp);
} | [
"public",
"function",
"setMessage",
"(",
"$",
"type",
",",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"session",
"->",
"has",
"(",
"'flashmsgs'",
")",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'flashmsgs'",
",",
"array",
"(",
")",
")",
";",
"}",
"$",
"temp",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'flashmsgs'",
")",
";",
"$",
"temp",
"[",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"type",
",",
"'content'",
"=>",
"$",
"message",
")",
";",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'flashmsgs'",
",",
"$",
"temp",
")",
";",
"}"
] | Add message to session array
@param $type string with message type
@param $message string with message text
@return void | [
"Add",
"message",
"to",
"session",
"array"
] | train | https://github.com/helikopterspark/FlashMsg/blob/85c2f16ca94db6dd800ed292d84f2e7422b3e7f5/src/FlashMsg/FlashMsg.php#L20-L27 |
helikopterspark/FlashMsg | src/FlashMsg/FlashMsg.php | FlashMsg.outputMsgs | public function outputMsgs() {
$messages = $this->session->get('flashmsgs');
$output = null;
if ($messages) {
foreach ($messages as $key => $message) {
$output .= '<div class="' . $message['type'] . '"><p>' . $message['content'] . '</p></div>';
}
}
return $output;
} | php | public function outputMsgs() {
$messages = $this->session->get('flashmsgs');
$output = null;
if ($messages) {
foreach ($messages as $key => $message) {
$output .= '<div class="' . $message['type'] . '"><p>' . $message['content'] . '</p></div>';
}
}
return $output;
} | [
"public",
"function",
"outputMsgs",
"(",
")",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'flashmsgs'",
")",
";",
"$",
"output",
"=",
"null",
";",
"if",
"(",
"$",
"messages",
")",
"{",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"key",
"=>",
"$",
"message",
")",
"{",
"$",
"output",
".=",
"'<div class=\"'",
".",
"$",
"message",
"[",
"'type'",
"]",
".",
"'\"><p>'",
".",
"$",
"message",
"[",
"'content'",
"]",
".",
"'</p></div>'",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Build HTML of messages in session array
@return $output HTML string with messages | [
"Build",
"HTML",
"of",
"messages",
"in",
"session",
"array"
] | train | https://github.com/helikopterspark/FlashMsg/blob/85c2f16ca94db6dd800ed292d84f2e7422b3e7f5/src/FlashMsg/FlashMsg.php#L100-L111 |
TiMESPLiNTER/tsfw-i18n | src/timesplinter/tsfw/i18n/common/AbstractTranslator.php | AbstractTranslator.dGetText | public function dGetText($domain, $message, $pluralMessage = null, $n = 0)
{
$oldTextDomain = $this->currentTextDomain;
$this->setTextDomain($domain);
$message = $this->getText($message, $pluralMessage, $n);
$this->setTextDomain($oldTextDomain);
return $message;
} | php | public function dGetText($domain, $message, $pluralMessage = null, $n = 0)
{
$oldTextDomain = $this->currentTextDomain;
$this->setTextDomain($domain);
$message = $this->getText($message, $pluralMessage, $n);
$this->setTextDomain($oldTextDomain);
return $message;
} | [
"public",
"function",
"dGetText",
"(",
"$",
"domain",
",",
"$",
"message",
",",
"$",
"pluralMessage",
"=",
"null",
",",
"$",
"n",
"=",
"0",
")",
"{",
"$",
"oldTextDomain",
"=",
"$",
"this",
"->",
"currentTextDomain",
";",
"$",
"this",
"->",
"setTextDomain",
"(",
"$",
"domain",
")",
";",
"$",
"message",
"=",
"$",
"this",
"->",
"getText",
"(",
"$",
"message",
",",
"$",
"pluralMessage",
",",
"$",
"n",
")",
";",
"$",
"this",
"->",
"setTextDomain",
"(",
"$",
"oldTextDomain",
")",
";",
"return",
"$",
"message",
";",
"}"
] | Lookup a message in the specified domain
@param string $domain
@param string $message
@param string|null $pluralMessage
@param int $n
@return string Returns a translated string if one is found in the translation table, or the submitted message if not found. | [
"Lookup",
"a",
"message",
"in",
"the",
"specified",
"domain"
] | train | https://github.com/TiMESPLiNTER/tsfw-i18n/blob/31769efe75ecab2757911a296ad4c5a9c6158b6d/src/timesplinter/tsfw/i18n/common/AbstractTranslator.php#L63-L74 |
TiMESPLiNTER/tsfw-i18n | src/timesplinter/tsfw/i18n/common/AbstractTranslator.php | AbstractTranslator._ | public final function _($message, $pluralMessage = null, $n = 0)
{
return $this->getText($message, $pluralMessage, $n);
} | php | public final function _($message, $pluralMessage = null, $n = 0)
{
return $this->getText($message, $pluralMessage, $n);
} | [
"public",
"final",
"function",
"_",
"(",
"$",
"message",
",",
"$",
"pluralMessage",
"=",
"null",
",",
"$",
"n",
"=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"getText",
"(",
"$",
"message",
",",
"$",
"pluralMessage",
",",
"$",
"n",
")",
";",
"}"
] | Lookup a message in the current domain
@param string $message The message being translated.
@param string|null $pluralMessage
@param int $n
@return string Returns a translated string if one is found in the translation table, or the submitted message if not found. | [
"Lookup",
"a",
"message",
"in",
"the",
"current",
"domain"
] | train | https://github.com/TiMESPLiNTER/tsfw-i18n/blob/31769efe75ecab2757911a296ad4c5a9c6158b6d/src/timesplinter/tsfw/i18n/common/AbstractTranslator.php#L85-L88 |
TiMESPLiNTER/tsfw-i18n | src/timesplinter/tsfw/i18n/common/AbstractTranslator.php | AbstractTranslator._d | public final function _d($domain, $message, $pluralMessage = null, $n = 0)
{
return $this->dGetText($domain, $message, $pluralMessage, $n);
} | php | public final function _d($domain, $message, $pluralMessage = null, $n = 0)
{
return $this->dGetText($domain, $message, $pluralMessage, $n);
} | [
"public",
"final",
"function",
"_d",
"(",
"$",
"domain",
",",
"$",
"message",
",",
"$",
"pluralMessage",
"=",
"null",
",",
"$",
"n",
"=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"dGetText",
"(",
"$",
"domain",
",",
"$",
"message",
",",
"$",
"pluralMessage",
",",
"$",
"n",
")",
";",
"}"
] | Lookup a message in the specified domain
@param string $domain
@param string $message
@param string|null $pluralMessage
@param int $n
@return string Returns a translated string if one is found in the translation table, or the submitted message if not found. | [
"Lookup",
"a",
"message",
"in",
"the",
"specified",
"domain"
] | train | https://github.com/TiMESPLiNTER/tsfw-i18n/blob/31769efe75ecab2757911a296ad4c5a9c6158b6d/src/timesplinter/tsfw/i18n/common/AbstractTranslator.php#L100-L103 |
anime-db/item-folder-filler-bundle | src/Controller/FillerController.php | FillerController.fillAction | public function fillAction(Item $item)
{
// do fill
$this->get('anime_db.item_folder_filler.filler_folder')->fillFolder($item);
return $this->render('AnimeDbItemFolderFillerBundle:Filler:fill.html.twig', [
'item' => $item
]);
} | php | public function fillAction(Item $item)
{
// do fill
$this->get('anime_db.item_folder_filler.filler_folder')->fillFolder($item);
return $this->render('AnimeDbItemFolderFillerBundle:Filler:fill.html.twig', [
'item' => $item
]);
} | [
"public",
"function",
"fillAction",
"(",
"Item",
"$",
"item",
")",
"{",
"// do fill",
"$",
"this",
"->",
"get",
"(",
"'anime_db.item_folder_filler.filler_folder'",
")",
"->",
"fillFolder",
"(",
"$",
"item",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'AnimeDbItemFolderFillerBundle:Filler:fill.html.twig'",
",",
"[",
"'item'",
"=>",
"$",
"item",
"]",
")",
";",
"}"
] | Fill item folder
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@return \Symfony\Component\HttpFoundation\Response | [
"Fill",
"item",
"folder"
] | train | https://github.com/anime-db/item-folder-filler-bundle/blob/9b5d02628fa235171a42123aaa9b54ddab5d94d1/src/Controller/FillerController.php#L31-L39 |
vpg/titon.utility | src/Titon/Utility/Sanitize.php | Sanitize.escape | public static function escape($value, array $options = array()) {
$options = $options + array(
'encoding' => 'UTF-8',
'flags' => ENT_QUOTES,
'double' => false
);
return htmlentities($value, $options['flags'], $options['encoding'], $options['double']);
} | php | public static function escape($value, array $options = array()) {
$options = $options + array(
'encoding' => 'UTF-8',
'flags' => ENT_QUOTES,
'double' => false
);
return htmlentities($value, $options['flags'], $options['encoding'], $options['double']);
} | [
"public",
"static",
"function",
"escape",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'encoding'",
"=>",
"'UTF-8'",
",",
"'flags'",
"=>",
"ENT_QUOTES",
",",
"'double'",
"=>",
"false",
")",
";",
"return",
"htmlentities",
"(",
"$",
"value",
",",
"$",
"options",
"[",
"'flags'",
"]",
",",
"$",
"options",
"[",
"'encoding'",
"]",
",",
"$",
"options",
"[",
"'double'",
"]",
")",
";",
"}"
] | Escape a string using the apps encoding.
@param string $value
@param array $options {
@type string $encoding Character encoding set; defaults to UTF-8
@type int $flags Encoding flags; defaults to ENT_QUOTES
@type bool $double Will double escape existing entities
}
@return string | [
"Escape",
"a",
"string",
"using",
"the",
"apps",
"encoding",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L39-L47 |
vpg/titon.utility | src/Titon/Utility/Sanitize.php | Sanitize.html | public static function html($value, array $options = array()) {
$options = $options + array(
'strip' => true,
'whitelist' => ''
);
if ($options['strip']) {
$value = strip_tags($value, $options['whitelist']);
}
return static::escape($value, $options);
} | php | public static function html($value, array $options = array()) {
$options = $options + array(
'strip' => true,
'whitelist' => ''
);
if ($options['strip']) {
$value = strip_tags($value, $options['whitelist']);
}
return static::escape($value, $options);
} | [
"public",
"static",
"function",
"html",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'strip'",
"=>",
"true",
",",
"'whitelist'",
"=>",
"''",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'strip'",
"]",
")",
"{",
"$",
"value",
"=",
"strip_tags",
"(",
"$",
"value",
",",
"$",
"options",
"[",
"'whitelist'",
"]",
")",
";",
"}",
"return",
"static",
"::",
"escape",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"}"
] | Sanitize a string by removing xor escaping HTML characters and entities.
@param string $value
@param array $options {
@type bool $strip Will remove HTML tags
@type string $whitelist List of tags to not strip
}
@return string | [
"Sanitize",
"a",
"string",
"by",
"removing",
"xor",
"escaping",
"HTML",
"characters",
"and",
"entities",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L69-L80 |
vpg/titon.utility | src/Titon/Utility/Sanitize.php | Sanitize.newlines | public static function newlines($value, array $options = array()) {
$options = $options + array(
'cr' => true,
'lf' => true,
'crlf' => true,
'limit' => 2,
'trim' => true
);
if ($options['limit']) {
$pattern = '/(?:%s){' . $options['limit'] . ',}/u';
} else {
$pattern = '/(?:%s)+/u';
$replace = '';
}
if ($options['crlf']) {
$value = preg_replace(sprintf($pattern, '\r\n'), (isset($replace) ? $replace : "\r\n"), $value);
}
if ($options['cr']) {
$value = preg_replace(sprintf($pattern, '\r'), (isset($replace) ? $replace : "\r"), $value);
}
if ($options['lf']) {
$value = preg_replace(sprintf($pattern, '\n'), (isset($replace) ? $replace : "\n"), $value);
}
if ($options['trim']) {
$value = trim($value);
}
return $value;
} | php | public static function newlines($value, array $options = array()) {
$options = $options + array(
'cr' => true,
'lf' => true,
'crlf' => true,
'limit' => 2,
'trim' => true
);
if ($options['limit']) {
$pattern = '/(?:%s){' . $options['limit'] . ',}/u';
} else {
$pattern = '/(?:%s)+/u';
$replace = '';
}
if ($options['crlf']) {
$value = preg_replace(sprintf($pattern, '\r\n'), (isset($replace) ? $replace : "\r\n"), $value);
}
if ($options['cr']) {
$value = preg_replace(sprintf($pattern, '\r'), (isset($replace) ? $replace : "\r"), $value);
}
if ($options['lf']) {
$value = preg_replace(sprintf($pattern, '\n'), (isset($replace) ? $replace : "\n"), $value);
}
if ($options['trim']) {
$value = trim($value);
}
return $value;
} | [
"public",
"static",
"function",
"newlines",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'cr'",
"=>",
"true",
",",
"'lf'",
"=>",
"true",
",",
"'crlf'",
"=>",
"true",
",",
"'limit'",
"=>",
"2",
",",
"'trim'",
"=>",
"true",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
"{",
"$",
"pattern",
"=",
"'/(?:%s){'",
".",
"$",
"options",
"[",
"'limit'",
"]",
".",
"',}/u'",
";",
"}",
"else",
"{",
"$",
"pattern",
"=",
"'/(?:%s)+/u'",
";",
"$",
"replace",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'crlf'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"'\\r\\n'",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"\"\\r\\n\"",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'cr'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"'\\r'",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"\"\\r\"",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'lf'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"'\\n'",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"\"\\n\"",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'trim'",
"]",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Sanitize a string by removing excess CRLF characters.
@param string $value
@param array $options {
@type bool $cr Will remove carriage returns \r
@type bool $lf Will remove line feeds \n
@type bool $crlf Will remove CRLF \r\n
@type bool $trim Will remove whitespace and newlines around the edges
@type int $limit The start limit to remove extraneous characters
}
@return string | [
"Sanitize",
"a",
"string",
"by",
"removing",
"excess",
"CRLF",
"characters",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L106-L140 |
vpg/titon.utility | src/Titon/Utility/Sanitize.php | Sanitize.whitespace | public static function whitespace($value, array $options = array()) {
$options = $options + array(
'space' => true,
'tab' => true,
'limit' => 2,
'strip' => true,
'trim' => true
);
if ($options['limit']) {
$pattern = '/%s{' . $options['limit'] . ',}/u';
} else {
$pattern = '/%s+/u';
$replace = '';
}
if ($options['tab']) {
$value = preg_replace(sprintf($pattern, '\t'), (isset($replace) ? $replace : "\t"), $value);
}
if ($options['space']) {
$value = preg_replace(sprintf($pattern, ' '), (isset($replace) ? $replace : ' '), $value); // \s replaces other whitespace characters
}
if ($options['strip']) {
$value = str_replace(chr(0xCA), ' ', $value);
}
if ($options['trim']) {
$value = trim($value);
}
return $value;
} | php | public static function whitespace($value, array $options = array()) {
$options = $options + array(
'space' => true,
'tab' => true,
'limit' => 2,
'strip' => true,
'trim' => true
);
if ($options['limit']) {
$pattern = '/%s{' . $options['limit'] . ',}/u';
} else {
$pattern = '/%s+/u';
$replace = '';
}
if ($options['tab']) {
$value = preg_replace(sprintf($pattern, '\t'), (isset($replace) ? $replace : "\t"), $value);
}
if ($options['space']) {
$value = preg_replace(sprintf($pattern, ' '), (isset($replace) ? $replace : ' '), $value); // \s replaces other whitespace characters
}
if ($options['strip']) {
$value = str_replace(chr(0xCA), ' ', $value);
}
if ($options['trim']) {
$value = trim($value);
}
return $value;
} | [
"public",
"static",
"function",
"whitespace",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'space'",
"=>",
"true",
",",
"'tab'",
"=>",
"true",
",",
"'limit'",
"=>",
"2",
",",
"'strip'",
"=>",
"true",
",",
"'trim'",
"=>",
"true",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
"{",
"$",
"pattern",
"=",
"'/%s{'",
".",
"$",
"options",
"[",
"'limit'",
"]",
".",
"',}/u'",
";",
"}",
"else",
"{",
"$",
"pattern",
"=",
"'/%s+/u'",
";",
"$",
"replace",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'tab'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"'\\t'",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"\"\\t\"",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'space'",
"]",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"sprintf",
"(",
"$",
"pattern",
",",
"' '",
")",
",",
"(",
"isset",
"(",
"$",
"replace",
")",
"?",
"$",
"replace",
":",
"' '",
")",
",",
"$",
"value",
")",
";",
"// \\s replaces other whitespace characters",
"}",
"if",
"(",
"$",
"options",
"[",
"'strip'",
"]",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"chr",
"(",
"0xCA",
")",
",",
"' '",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'trim'",
"]",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Sanitize a string by removing excess whitespace and tab characters.
@param string $value
@param array $options {
@type bool $space Will remove white space
@type bool $tab Will remove tabs
@type bool $strip Will remove non-standard white space character
@type bool $trim Will remove whitespace and newlines around the edges
@type int $limit The start limit to remove extraneous characters
}
@return string | [
"Sanitize",
"a",
"string",
"by",
"removing",
"excess",
"whitespace",
"and",
"tab",
"characters",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L166-L200 |
vpg/titon.utility | src/Titon/Utility/Sanitize.php | Sanitize.xss | public static function xss($value, array $options = array()) {
$options = $options + array('strip' => true);
$value = str_replace("\0", '', $value);
if (!$options['strip']) {
// Remove any attribute starting with on or xmlns
$value = preg_replace('/\s?(?:on[a-z]+|xmlns)\s?=\s?"(?:.*?)"/isu', '', $value);
// Remove namespaced elements
$value = preg_replace('/<\/?\w+:\w+(?:.*?)>/isu', '', $value);
// Remove really unwanted tags
do {
$old = $value;
$value = preg_replace('/<\/?(?:applet|base|bgsound|embed|frame|frameset|iframe|layer|link|meta|object|script|style|title|xml|audio|video)(?:.*?)>/isu', '', $value);
} while ($old !== $value);
}
return static::html($value, $options);
} | php | public static function xss($value, array $options = array()) {
$options = $options + array('strip' => true);
$value = str_replace("\0", '', $value);
if (!$options['strip']) {
// Remove any attribute starting with on or xmlns
$value = preg_replace('/\s?(?:on[a-z]+|xmlns)\s?=\s?"(?:.*?)"/isu', '', $value);
// Remove namespaced elements
$value = preg_replace('/<\/?\w+:\w+(?:.*?)>/isu', '', $value);
// Remove really unwanted tags
do {
$old = $value;
$value = preg_replace('/<\/?(?:applet|base|bgsound|embed|frame|frameset|iframe|layer|link|meta|object|script|style|title|xml|audio|video)(?:.*?)>/isu', '', $value);
} while ($old !== $value);
}
return static::html($value, $options);
} | [
"public",
"static",
"function",
"xss",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'strip'",
"=>",
"true",
")",
";",
"$",
"value",
"=",
"str_replace",
"(",
"\"\\0\"",
",",
"''",
",",
"$",
"value",
")",
";",
"if",
"(",
"!",
"$",
"options",
"[",
"'strip'",
"]",
")",
"{",
"// Remove any attribute starting with on or xmlns",
"$",
"value",
"=",
"preg_replace",
"(",
"'/\\s?(?:on[a-z]+|xmlns)\\s?=\\s?\"(?:.*?)\"/isu'",
",",
"''",
",",
"$",
"value",
")",
";",
"// Remove namespaced elements",
"$",
"value",
"=",
"preg_replace",
"(",
"'/<\\/?\\w+:\\w+(?:.*?)>/isu'",
",",
"''",
",",
"$",
"value",
")",
";",
"// Remove really unwanted tags",
"do",
"{",
"$",
"old",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'/<\\/?(?:applet|base|bgsound|embed|frame|frameset|iframe|layer|link|meta|object|script|style|title|xml|audio|video)(?:.*?)>/isu'",
",",
"''",
",",
"$",
"value",
")",
";",
"}",
"while",
"(",
"$",
"old",
"!==",
"$",
"value",
")",
";",
"}",
"return",
"static",
"::",
"html",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"}"
] | Sanitize a string by removing any XSS attack vectors.
Will bubble up to html() and escape().
@param string $value
@param array $options {
@type bool $strip Remove HTML tags
}
@return string | [
"Sanitize",
"a",
"string",
"by",
"removing",
"any",
"XSS",
"attack",
"vectors",
".",
"Will",
"bubble",
"up",
"to",
"html",
"()",
"and",
"escape",
"()",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Sanitize.php#L212-L233 |
Fenzland/php-http-client | libs/FormData.php | FormData.setFile | public function setFile( string$key, string$fileName ):self
{
if( !file_exists($fileName) || is_dir($fileName) || is_link($fileName) ){
throw new Exception("$fileName is not a regular file.");
}
$this->files[$key]= [
'fileName'=> $fileName,
'contentType'=> mime_content_type($fileName),
'content'=> file_get_contents($fileName),
];
return $this;
} | php | public function setFile( string$key, string$fileName ):self
{
if( !file_exists($fileName) || is_dir($fileName) || is_link($fileName) ){
throw new Exception("$fileName is not a regular file.");
}
$this->files[$key]= [
'fileName'=> $fileName,
'contentType'=> mime_content_type($fileName),
'content'=> file_get_contents($fileName),
];
return $this;
} | [
"public",
"function",
"setFile",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"fileName",
")",
":",
"self",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
"||",
"is_dir",
"(",
"$",
"fileName",
")",
"||",
"is_link",
"(",
"$",
"fileName",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"$fileName is not a regular file.\"",
")",
";",
"}",
"$",
"this",
"->",
"files",
"[",
"$",
"key",
"]",
"=",
"[",
"'fileName'",
"=>",
"$",
"fileName",
",",
"'contentType'",
"=>",
"mime_content_type",
"(",
"$",
"fileName",
")",
",",
"'content'",
"=>",
"file_get_contents",
"(",
"$",
"fileName",
")",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Method setFile
@access public
@param string $key
@param string $fileName
@return self | [
"Method",
"setFile"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/FormData.php#L90-L102 |
Fenzland/php-http-client | libs/FormData.php | FormData.setFileRaw | public function setFileRaw( string$key, string$contentType, string$content, string$fileName=null ):self
{
$this->files[$key]= [
'fileName'=> $fileName??md5($content),
'contentType'=> $contentType,
'content'=> $content,
];
return $this;
} | php | public function setFileRaw( string$key, string$contentType, string$content, string$fileName=null ):self
{
$this->files[$key]= [
'fileName'=> $fileName??md5($content),
'contentType'=> $contentType,
'content'=> $content,
];
return $this;
} | [
"public",
"function",
"setFileRaw",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"contentType",
",",
"string",
"$",
"content",
",",
"string",
"$",
"fileName",
"=",
"null",
")",
":",
"self",
"{",
"$",
"this",
"->",
"files",
"[",
"$",
"key",
"]",
"=",
"[",
"'fileName'",
"=>",
"$",
"fileName",
"??",
"md5",
"(",
"$",
"content",
")",
",",
"'contentType'",
"=>",
"$",
"contentType",
",",
"'content'",
"=>",
"$",
"content",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Method setFileRaw
@access public
@param string $key
@param string $contentType
@param string $content
@param string $fileName
@return self | [
"Method",
"setFileRaw"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/FormData.php#L116-L125 |
ezra-obiwale/dSCore | src/Core/AService.php | AService.setModel | public function setModel(IModel $model, $initRepo = true) {
$this->model = $model;
if ($initRepo)
$this->initRepository();
return $this;
} | php | public function setModel(IModel $model, $initRepo = true) {
$this->model = $model;
if ($initRepo)
$this->initRepository();
return $this;
} | [
"public",
"function",
"setModel",
"(",
"IModel",
"$",
"model",
",",
"$",
"initRepo",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"model",
";",
"if",
"(",
"$",
"initRepo",
")",
"$",
"this",
"->",
"initRepository",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the model to class
@param IModel $model | [
"Sets",
"the",
"model",
"to",
"class"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AService.php#L43-L48 |
ezra-obiwale/dSCore | src/Core/AService.php | AService.initRepository | protected function initRepository() {
if ($this->model === null ||
($this->model !== null && !in_array('DScribe\Core\IModel', class_implements($this->model))))
return false;
if ($this->repository !== null && $this->model->getTableName() === $this->repository->getTableName())
return true;
$repository = ($this->repositoryClass !== null) ? $this->repositoryClass : 'DBScribe\Repository';
$this->repository = new $repository($this->model, engineGet('DB'), true);
} | php | protected function initRepository() {
if ($this->model === null ||
($this->model !== null && !in_array('DScribe\Core\IModel', class_implements($this->model))))
return false;
if ($this->repository !== null && $this->model->getTableName() === $this->repository->getTableName())
return true;
$repository = ($this->repositoryClass !== null) ? $this->repositoryClass : 'DBScribe\Repository';
$this->repository = new $repository($this->model, engineGet('DB'), true);
} | [
"protected",
"function",
"initRepository",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"model",
"===",
"null",
"||",
"(",
"$",
"this",
"->",
"model",
"!==",
"null",
"&&",
"!",
"in_array",
"(",
"'DScribe\\Core\\IModel'",
",",
"class_implements",
"(",
"$",
"this",
"->",
"model",
")",
")",
")",
")",
"return",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"repository",
"!==",
"null",
"&&",
"$",
"this",
"->",
"model",
"->",
"getTableName",
"(",
")",
"===",
"$",
"this",
"->",
"repository",
"->",
"getTableName",
"(",
")",
")",
"return",
"true",
";",
"$",
"repository",
"=",
"(",
"$",
"this",
"->",
"repositoryClass",
"!==",
"null",
")",
"?",
"$",
"this",
"->",
"repositoryClass",
":",
"'DBScribe\\Repository'",
";",
"$",
"this",
"->",
"repository",
"=",
"new",
"$",
"repository",
"(",
"$",
"this",
"->",
"model",
",",
"engineGet",
"(",
"'DB'",
")",
",",
"true",
")",
";",
"}"
] | Initializes the repository
@return boolean | [
"Initializes",
"the",
"repository"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AService.php#L72-L82 |
ezra-obiwale/dSCore | src/Core/AService.php | AService.prepareInject | protected function prepareInject() {
$model = ($this->model) ? $this->model : $this->getModule() . '\Models\\' . $this->getClassName();
if (is_object($model))
$model = get_class($model);
if (!class_exists($model))
return array_merge(parent::prepareInject(), $this->getConfigInject('services'));
return array_merge(parent::prepareInject(), $this->getConfigInject('services'), array(
'model' => array(
'class' => $model
),
));
} | php | protected function prepareInject() {
$model = ($this->model) ? $this->model : $this->getModule() . '\Models\\' . $this->getClassName();
if (is_object($model))
$model = get_class($model);
if (!class_exists($model))
return array_merge(parent::prepareInject(), $this->getConfigInject('services'));
return array_merge(parent::prepareInject(), $this->getConfigInject('services'), array(
'model' => array(
'class' => $model
),
));
} | [
"protected",
"function",
"prepareInject",
"(",
")",
"{",
"$",
"model",
"=",
"(",
"$",
"this",
"->",
"model",
")",
"?",
"$",
"this",
"->",
"model",
":",
"$",
"this",
"->",
"getModule",
"(",
")",
".",
"'\\Models\\\\'",
".",
"$",
"this",
"->",
"getClassName",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"model",
")",
")",
"$",
"model",
"=",
"get_class",
"(",
"$",
"model",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"model",
")",
")",
"return",
"array_merge",
"(",
"parent",
"::",
"prepareInject",
"(",
")",
",",
"$",
"this",
"->",
"getConfigInject",
"(",
"'services'",
")",
")",
";",
"return",
"array_merge",
"(",
"parent",
"::",
"prepareInject",
"(",
")",
",",
"$",
"this",
"->",
"getConfigInject",
"(",
"'services'",
")",
",",
"array",
"(",
"'model'",
"=>",
"array",
"(",
"'class'",
"=>",
"$",
"model",
")",
",",
")",
")",
";",
"}"
] | prepares injection of classes
@return array | [
"prepares",
"injection",
"of",
"classes"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AService.php#L103-L117 |
davedevelopment/pimple-aware-event-dispatcher | src/PimpleAwareEventDispatcher/PimpleAwareEventDispatcher.php | PimpleAwareEventDispatcher.addListenerService | public function addListenerService($eventName, $callback, $priority = 0)
{
if (!is_array($callback) || 2 !== count($callback)) {
throw new \InvalidArgumentException('Expected an array("service", "method") argument');
}
$serviceId = $callback[0];
$method = $callback[1];
$container = $this->container;
$closure = function (Event $e) use ($container, $serviceId, $method) {
call_user_func(array($container[$serviceId], $method), $e);
};
$this->listenerIds[$eventName][] = array($callback, $closure);
$this->eventDispatcher->addListener($eventName, $closure, $priority);
} | php | public function addListenerService($eventName, $callback, $priority = 0)
{
if (!is_array($callback) || 2 !== count($callback)) {
throw new \InvalidArgumentException('Expected an array("service", "method") argument');
}
$serviceId = $callback[0];
$method = $callback[1];
$container = $this->container;
$closure = function (Event $e) use ($container, $serviceId, $method) {
call_user_func(array($container[$serviceId], $method), $e);
};
$this->listenerIds[$eventName][] = array($callback, $closure);
$this->eventDispatcher->addListener($eventName, $closure, $priority);
} | [
"public",
"function",
"addListenerService",
"(",
"$",
"eventName",
",",
"$",
"callback",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"callback",
")",
"||",
"2",
"!==",
"count",
"(",
"$",
"callback",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Expected an array(\"service\", \"method\") argument'",
")",
";",
"}",
"$",
"serviceId",
"=",
"$",
"callback",
"[",
"0",
"]",
";",
"$",
"method",
"=",
"$",
"callback",
"[",
"1",
"]",
";",
"$",
"container",
"=",
"$",
"this",
"->",
"container",
";",
"$",
"closure",
"=",
"function",
"(",
"Event",
"$",
"e",
")",
"use",
"(",
"$",
"container",
",",
"$",
"serviceId",
",",
"$",
"method",
")",
"{",
"call_user_func",
"(",
"array",
"(",
"$",
"container",
"[",
"$",
"serviceId",
"]",
",",
"$",
"method",
")",
",",
"$",
"e",
")",
";",
"}",
";",
"$",
"this",
"->",
"listenerIds",
"[",
"$",
"eventName",
"]",
"[",
"]",
"=",
"array",
"(",
"$",
"callback",
",",
"$",
"closure",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"addListener",
"(",
"$",
"eventName",
",",
"$",
"closure",
",",
"$",
"priority",
")",
";",
"}"
] | Adds a service as event listener
@param string $eventName Event for which the listener is added
@param array $callback The service ID of the listener service & the method
name that has to be called
@param integer $priority The higher this value, the earlier an event listener
will be triggered in the chain.
Defaults to 0. | [
"Adds",
"a",
"service",
"as",
"event",
"listener"
] | train | https://github.com/davedevelopment/pimple-aware-event-dispatcher/blob/e0864988219da254c46690379634bce3f22a0eba/src/PimpleAwareEventDispatcher/PimpleAwareEventDispatcher.php#L64-L79 |
davedevelopment/pimple-aware-event-dispatcher | src/PimpleAwareEventDispatcher/PimpleAwareEventDispatcher.php | PimpleAwareEventDispatcher.addSubscriberService | public function addSubscriberService($serviceId, $class)
{
$rfc = new \ReflectionClass($class);
if (!$rfc->implementsInterface('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
throw new \InvalidArgumentException(
"$class must implement Symfony\Component\EventDispatcher\EventSubscriberInterface"
);
}
foreach ($class::getSubscribedEvents() as $eventName => $params) {
if (is_string($params)) {
$this->addListenerService($eventName, array($serviceId, $params), 0);
} elseif (is_string($params[0])) {
$this->addListenerService($eventName, array($serviceId, $params[0]), isset($params[1]) ? $params[1] : 0);
} else {
foreach ($params as $listener) {
$this->addListenerService($eventName, array($serviceId, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
}
}
}
} | php | public function addSubscriberService($serviceId, $class)
{
$rfc = new \ReflectionClass($class);
if (!$rfc->implementsInterface('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
throw new \InvalidArgumentException(
"$class must implement Symfony\Component\EventDispatcher\EventSubscriberInterface"
);
}
foreach ($class::getSubscribedEvents() as $eventName => $params) {
if (is_string($params)) {
$this->addListenerService($eventName, array($serviceId, $params), 0);
} elseif (is_string($params[0])) {
$this->addListenerService($eventName, array($serviceId, $params[0]), isset($params[1]) ? $params[1] : 0);
} else {
foreach ($params as $listener) {
$this->addListenerService($eventName, array($serviceId, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
}
}
}
} | [
"public",
"function",
"addSubscriberService",
"(",
"$",
"serviceId",
",",
"$",
"class",
")",
"{",
"$",
"rfc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"$",
"rfc",
"->",
"implementsInterface",
"(",
"'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface'",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"$class must implement Symfony\\Component\\EventDispatcher\\EventSubscriberInterface\"",
")",
";",
"}",
"foreach",
"(",
"$",
"class",
"::",
"getSubscribedEvents",
"(",
")",
"as",
"$",
"eventName",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"addListenerService",
"(",
"$",
"eventName",
",",
"array",
"(",
"$",
"serviceId",
",",
"$",
"params",
")",
",",
"0",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addListenerService",
"(",
"$",
"eventName",
",",
"array",
"(",
"$",
"serviceId",
",",
"$",
"params",
"[",
"0",
"]",
")",
",",
"isset",
"(",
"$",
"params",
"[",
"1",
"]",
")",
"?",
"$",
"params",
"[",
"1",
"]",
":",
"0",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"listener",
")",
"{",
"$",
"this",
"->",
"addListenerService",
"(",
"$",
"eventName",
",",
"array",
"(",
"$",
"serviceId",
",",
"$",
"listener",
"[",
"0",
"]",
")",
",",
"isset",
"(",
"$",
"listener",
"[",
"1",
"]",
")",
"?",
"$",
"listener",
"[",
"1",
"]",
":",
"0",
")",
";",
"}",
"}",
"}",
"}"
] | Adds a service as event subscriber
@param string $serviceId The service ID of the subscriber service
@param string $class The service's class name (which must implement EventSubscriberInterface) | [
"Adds",
"a",
"service",
"as",
"event",
"subscriber"
] | train | https://github.com/davedevelopment/pimple-aware-event-dispatcher/blob/e0864988219da254c46690379634bce3f22a0eba/src/PimpleAwareEventDispatcher/PimpleAwareEventDispatcher.php#L102-L122 |
davedevelopment/pimple-aware-event-dispatcher | src/PimpleAwareEventDispatcher/PimpleAwareEventDispatcher.php | PimpleAwareEventDispatcher.dispatch | public function dispatch($eventName, Event $event = null)
{
return $this->eventDispatcher->dispatch($eventName, $event);
} | php | public function dispatch($eventName, Event $event = null)
{
return $this->eventDispatcher->dispatch($eventName, $event);
} | [
"public",
"function",
"dispatch",
"(",
"$",
"eventName",
",",
"Event",
"$",
"event",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"$",
"eventName",
",",
"$",
"event",
")",
";",
"}"
] | {@inheritdocs} | [
"{"
] | train | https://github.com/davedevelopment/pimple-aware-event-dispatcher/blob/e0864988219da254c46690379634bce3f22a0eba/src/PimpleAwareEventDispatcher/PimpleAwareEventDispatcher.php#L149-L152 |
brain-diminished/schema-version-control | src/Utils/SchemaNormalizer.php | SchemaNormalizer.normalize | public function normalize(Schema $schema): array
{
$this->schema = $schema;
$schemaDesc = [];
$schemaDesc['tables'] = [];
foreach ($schema->getTables() as $table) {
$schemaDesc['tables'][$table->getName()] = $this->normalizeTable($table);
}
return $schemaDesc;
} | php | public function normalize(Schema $schema): array
{
$this->schema = $schema;
$schemaDesc = [];
$schemaDesc['tables'] = [];
foreach ($schema->getTables() as $table) {
$schemaDesc['tables'][$table->getName()] = $this->normalizeTable($table);
}
return $schemaDesc;
} | [
"public",
"function",
"normalize",
"(",
"Schema",
"$",
"schema",
")",
":",
"array",
"{",
"$",
"this",
"->",
"schema",
"=",
"$",
"schema",
";",
"$",
"schemaDesc",
"=",
"[",
"]",
";",
"$",
"schemaDesc",
"[",
"'tables'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"schema",
"->",
"getTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"$",
"schemaDesc",
"[",
"'tables'",
"]",
"[",
"$",
"table",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"normalizeTable",
"(",
"$",
"table",
")",
";",
"}",
"return",
"$",
"schemaDesc",
";",
"}"
] | Normalize a Schema object into an array descriptor
@param Schema $schema
@return array | [
"Normalize",
"a",
"Schema",
"object",
"into",
"an",
"array",
"descriptor"
] | train | https://github.com/brain-diminished/schema-version-control/blob/215dd96394072720b61a682e10a55a6520470c46/src/Utils/SchemaNormalizer.php#L26-L35 |
sil-project/StockBundle | src/Domain/Query/StockItemQueries.php | StockItemQueries.getQty | public function getQty(StockItemInterface $item): UomQty
{
$units = $this->stockUnitRepository
->findByStockItem($item);
return $this->computeQtyForUnits($item->getUom(), $units);
} | php | public function getQty(StockItemInterface $item): UomQty
{
$units = $this->stockUnitRepository
->findByStockItem($item);
return $this->computeQtyForUnits($item->getUom(), $units);
} | [
"public",
"function",
"getQty",
"(",
"StockItemInterface",
"$",
"item",
")",
":",
"UomQty",
"{",
"$",
"units",
"=",
"$",
"this",
"->",
"stockUnitRepository",
"->",
"findByStockItem",
"(",
"$",
"item",
")",
";",
"return",
"$",
"this",
"->",
"computeQtyForUnits",
"(",
"$",
"item",
"->",
"getUom",
"(",
")",
",",
"$",
"units",
")",
";",
"}"
] | @param StockItemInterface $item
@return UomQty | [
"@param",
"StockItemInterface",
"$item"
] | train | https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Query/StockItemQueries.php#L47-L53 |
sil-project/StockBundle | src/Domain/Query/StockItemQueries.php | StockItemQueries.getReservedQty | public function getReservedQty(StockItemInterface $item): UomQty
{
$units = $this->stockUnitRepository
->findReservedByStockItem($item);
return $this->computeQtyForUnits($item->getUom(), $units);
} | php | public function getReservedQty(StockItemInterface $item): UomQty
{
$units = $this->stockUnitRepository
->findReservedByStockItem($item);
return $this->computeQtyForUnits($item->getUom(), $units);
} | [
"public",
"function",
"getReservedQty",
"(",
"StockItemInterface",
"$",
"item",
")",
":",
"UomQty",
"{",
"$",
"units",
"=",
"$",
"this",
"->",
"stockUnitRepository",
"->",
"findReservedByStockItem",
"(",
"$",
"item",
")",
";",
"return",
"$",
"this",
"->",
"computeQtyForUnits",
"(",
"$",
"item",
"->",
"getUom",
"(",
")",
",",
"$",
"units",
")",
";",
"}"
] | @param StockItemInterface $item
@return UomQty | [
"@param",
"StockItemInterface",
"$item"
] | train | https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Query/StockItemQueries.php#L60-L66 |
sil-project/StockBundle | src/Domain/Query/StockItemQueries.php | StockItemQueries.getAvailableQty | public function getAvailableQty(StockItemInterface $item): UomQty
{
$units = $this->stockUnitRepository
->findAvailableByStockItem($item);
return $this->computeQtyForUnits($item->getUom(), $units);
} | php | public function getAvailableQty(StockItemInterface $item): UomQty
{
$units = $this->stockUnitRepository
->findAvailableByStockItem($item);
return $this->computeQtyForUnits($item->getUom(), $units);
} | [
"public",
"function",
"getAvailableQty",
"(",
"StockItemInterface",
"$",
"item",
")",
":",
"UomQty",
"{",
"$",
"units",
"=",
"$",
"this",
"->",
"stockUnitRepository",
"->",
"findAvailableByStockItem",
"(",
"$",
"item",
")",
";",
"return",
"$",
"this",
"->",
"computeQtyForUnits",
"(",
"$",
"item",
"->",
"getUom",
"(",
")",
",",
"$",
"units",
")",
";",
"}"
] | @param StockItemInterface $item
@return UomQty | [
"@param",
"StockItemInterface",
"$item"
] | train | https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Query/StockItemQueries.php#L73-L79 |
sil-project/StockBundle | src/Domain/Query/StockItemQueries.php | StockItemQueries.getReservedQtyByMovement | public function getReservedQtyByMovement(StockItemInterface $item,
Movement $mvt): UomQty
{
$units = $this->stockUnitRepository
->findBy(['stockItem' => $item, 'reservationMovement' => $mvt]);
return $this->computeQtyForUnits($item->getUom(), $units);
} | php | public function getReservedQtyByMovement(StockItemInterface $item,
Movement $mvt): UomQty
{
$units = $this->stockUnitRepository
->findBy(['stockItem' => $item, 'reservationMovement' => $mvt]);
return $this->computeQtyForUnits($item->getUom(), $units);
} | [
"public",
"function",
"getReservedQtyByMovement",
"(",
"StockItemInterface",
"$",
"item",
",",
"Movement",
"$",
"mvt",
")",
":",
"UomQty",
"{",
"$",
"units",
"=",
"$",
"this",
"->",
"stockUnitRepository",
"->",
"findBy",
"(",
"[",
"'stockItem'",
"=>",
"$",
"item",
",",
"'reservationMovement'",
"=>",
"$",
"mvt",
"]",
")",
";",
"return",
"$",
"this",
"->",
"computeQtyForUnits",
"(",
"$",
"item",
"->",
"getUom",
"(",
")",
",",
"$",
"units",
")",
";",
"}"
] | @param StockItemInterface $item
@return UomQty | [
"@param",
"StockItemInterface",
"$item"
] | train | https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Query/StockItemQueries.php#L86-L93 |
sil-project/StockBundle | src/Domain/Query/StockItemQueries.php | StockItemQueries.getQtyByLocation | public function getQtyByLocation(StockItemInterface $item,
Location $location): UomQty
{
$units = $this->stockUnitRepository
->findByStockItemAndLocation($item, $location);
return $this->computeQtyForUnits($item->getUom(), $units);
} | php | public function getQtyByLocation(StockItemInterface $item,
Location $location): UomQty
{
$units = $this->stockUnitRepository
->findByStockItemAndLocation($item, $location);
return $this->computeQtyForUnits($item->getUom(), $units);
} | [
"public",
"function",
"getQtyByLocation",
"(",
"StockItemInterface",
"$",
"item",
",",
"Location",
"$",
"location",
")",
":",
"UomQty",
"{",
"$",
"units",
"=",
"$",
"this",
"->",
"stockUnitRepository",
"->",
"findByStockItemAndLocation",
"(",
"$",
"item",
",",
"$",
"location",
")",
";",
"return",
"$",
"this",
"->",
"computeQtyForUnits",
"(",
"$",
"item",
"->",
"getUom",
"(",
")",
",",
"$",
"units",
")",
";",
"}"
] | @param StockItemInterface $item
@param Location $location
@return UomQty | [
"@param",
"StockItemInterface",
"$item",
"@param",
"Location",
"$location"
] | train | https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Query/StockItemQueries.php#L101-L108 |
sil-project/StockBundle | src/Domain/Query/StockItemQueries.php | StockItemQueries.computeQtyForUnits | protected function computeQtyForUnits(Uom $uom, array $stockUnits): UomQty
{
$unitQties = array_map(function ($q) {
return $q->getQty()->getValue();
}, $stockUnits);
$sumQty = array_sum($unitQties);
return new UomQty($uom, $sumQty);
} | php | protected function computeQtyForUnits(Uom $uom, array $stockUnits): UomQty
{
$unitQties = array_map(function ($q) {
return $q->getQty()->getValue();
}, $stockUnits);
$sumQty = array_sum($unitQties);
return new UomQty($uom, $sumQty);
} | [
"protected",
"function",
"computeQtyForUnits",
"(",
"Uom",
"$",
"uom",
",",
"array",
"$",
"stockUnits",
")",
":",
"UomQty",
"{",
"$",
"unitQties",
"=",
"array_map",
"(",
"function",
"(",
"$",
"q",
")",
"{",
"return",
"$",
"q",
"->",
"getQty",
"(",
")",
"->",
"getValue",
"(",
")",
";",
"}",
",",
"$",
"stockUnits",
")",
";",
"$",
"sumQty",
"=",
"array_sum",
"(",
"$",
"unitQties",
")",
";",
"return",
"new",
"UomQty",
"(",
"$",
"uom",
",",
"$",
"sumQty",
")",
";",
"}"
] | @param Uom $uom
@param array|StockUnit[] $stockUnits
@return UomQty | [
"@param",
"Uom",
"$uom",
"@param",
"array|StockUnit",
"[]",
"$stockUnits"
] | train | https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Query/StockItemQueries.php#L116-L124 |
ekyna/MediaBundle | Model/Import/MediaUpload.php | MediaUpload.addMedia | public function addMedia(MediaInterface $media)
{
if (!$this->medias->contains($media)) {
$this->medias->add($media);
}
return $this;
} | php | public function addMedia(MediaInterface $media)
{
if (!$this->medias->contains($media)) {
$this->medias->add($media);
}
return $this;
} | [
"public",
"function",
"addMedia",
"(",
"MediaInterface",
"$",
"media",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"medias",
"->",
"contains",
"(",
"$",
"media",
")",
")",
"{",
"$",
"this",
"->",
"medias",
"->",
"add",
"(",
"$",
"media",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds the media.
@param MediaInterface $media
@return MediaUpload | [
"Adds",
"the",
"media",
"."
] | train | https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Model/Import/MediaUpload.php#L35-L41 |
ekyna/MediaBundle | Model/Import/MediaUpload.php | MediaUpload.removeMedia | public function removeMedia(MediaInterface $media)
{
if ($this->medias->contains($media)) {
$this->medias->removeElement($media);
}
return $this;
} | php | public function removeMedia(MediaInterface $media)
{
if ($this->medias->contains($media)) {
$this->medias->removeElement($media);
}
return $this;
} | [
"public",
"function",
"removeMedia",
"(",
"MediaInterface",
"$",
"media",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"medias",
"->",
"contains",
"(",
"$",
"media",
")",
")",
"{",
"$",
"this",
"->",
"medias",
"->",
"removeElement",
"(",
"$",
"media",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Removes the media.
@param MediaInterface $media
@return MediaUpload | [
"Removes",
"the",
"media",
"."
] | train | https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Model/Import/MediaUpload.php#L49-L55 |
DarvinStudio/fileman | src/Darvin/Fileman/Command/PullCommand.php | PullCommand.configure | protected function configure()
{
parent::configure();
if (null === $this->getName()) {
$this->setName('pull');
}
$this->setDescription('Pulls remote files to local directory');
} | php | protected function configure()
{
parent::configure();
if (null === $this->getName()) {
$this->setName('pull');
}
$this->setDescription('Pulls remote files to local directory');
} | [
"protected",
"function",
"configure",
"(",
")",
"{",
"parent",
"::",
"configure",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setName",
"(",
"'pull'",
")",
";",
"}",
"$",
"this",
"->",
"setDescription",
"(",
"'Pulls remote files to local directory'",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/DarvinStudio/fileman/blob/940055874d2b094e082aabfa6ad7fc0fc17c8396/src/Darvin/Fileman/Command/PullCommand.php#L25-L34 |
DarvinStudio/fileman | src/Darvin/Fileman/Command/PullCommand.php | PullCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$callback = [$io, 'success'];
$dirFetcher = $this->createDirectoryFetcher($input);
$localManager = $this->createLocalManager($input, $dirFetcher);
$remoteManager = $this->createRemoteManager($input, $dirFetcher, $io);
$io->comment('Archiving files...');
$archiveFilenames = $remoteManager->archiveFiles($callback);
$io->comment('Downloading archives...');
$remoteManager->downloadArchives($callback, $localManager->getProjectPath());
$io->comment('Removing remote archives...');
$remoteManager->removeArchives($callback);
$io->comment('Extracting files...');
$localManager->extractFiles($callback, $archiveFilenames);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$callback = [$io, 'success'];
$dirFetcher = $this->createDirectoryFetcher($input);
$localManager = $this->createLocalManager($input, $dirFetcher);
$remoteManager = $this->createRemoteManager($input, $dirFetcher, $io);
$io->comment('Archiving files...');
$archiveFilenames = $remoteManager->archiveFiles($callback);
$io->comment('Downloading archives...');
$remoteManager->downloadArchives($callback, $localManager->getProjectPath());
$io->comment('Removing remote archives...');
$remoteManager->removeArchives($callback);
$io->comment('Extracting files...');
$localManager->extractFiles($callback, $archiveFilenames);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"callback",
"=",
"[",
"$",
"io",
",",
"'success'",
"]",
";",
"$",
"dirFetcher",
"=",
"$",
"this",
"->",
"createDirectoryFetcher",
"(",
"$",
"input",
")",
";",
"$",
"localManager",
"=",
"$",
"this",
"->",
"createLocalManager",
"(",
"$",
"input",
",",
"$",
"dirFetcher",
")",
";",
"$",
"remoteManager",
"=",
"$",
"this",
"->",
"createRemoteManager",
"(",
"$",
"input",
",",
"$",
"dirFetcher",
",",
"$",
"io",
")",
";",
"$",
"io",
"->",
"comment",
"(",
"'Archiving files...'",
")",
";",
"$",
"archiveFilenames",
"=",
"$",
"remoteManager",
"->",
"archiveFiles",
"(",
"$",
"callback",
")",
";",
"$",
"io",
"->",
"comment",
"(",
"'Downloading archives...'",
")",
";",
"$",
"remoteManager",
"->",
"downloadArchives",
"(",
"$",
"callback",
",",
"$",
"localManager",
"->",
"getProjectPath",
"(",
")",
")",
";",
"$",
"io",
"->",
"comment",
"(",
"'Removing remote archives...'",
")",
";",
"$",
"remoteManager",
"->",
"removeArchives",
"(",
"$",
"callback",
")",
";",
"$",
"io",
"->",
"comment",
"(",
"'Extracting files...'",
")",
";",
"$",
"localManager",
"->",
"extractFiles",
"(",
"$",
"callback",
",",
"$",
"archiveFilenames",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/DarvinStudio/fileman/blob/940055874d2b094e082aabfa6ad7fc0fc17c8396/src/Darvin/Fileman/Command/PullCommand.php#L39-L61 |
cmsgears/module-sns-connect | frontend/controllers/GoogleController.php | GoogleController.actionAuthorise | public function actionAuthorise( $code, $state ) {
// Get Token
$accessToken = $this->googleService->getAccessToken( $code, $state );
$snsUser = $this->googleService->getUser( $accessToken );
if( isset( $snsUser ) ) {
// Get User
$user = $this->modelService->getUser( $snsUser, $accessToken );
// Login and Redirect to home page
$login = new GoogleLogin( $user );
if( $login->login() ) {
return $this->redirect( [ '/user/index' ] );
}
}
// Model not found
throw new NotFoundHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
} | php | public function actionAuthorise( $code, $state ) {
// Get Token
$accessToken = $this->googleService->getAccessToken( $code, $state );
$snsUser = $this->googleService->getUser( $accessToken );
if( isset( $snsUser ) ) {
// Get User
$user = $this->modelService->getUser( $snsUser, $accessToken );
// Login and Redirect to home page
$login = new GoogleLogin( $user );
if( $login->login() ) {
return $this->redirect( [ '/user/index' ] );
}
}
// Model not found
throw new NotFoundHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
} | [
"public",
"function",
"actionAuthorise",
"(",
"$",
"code",
",",
"$",
"state",
")",
"{",
"// Get Token",
"$",
"accessToken",
"=",
"$",
"this",
"->",
"googleService",
"->",
"getAccessToken",
"(",
"$",
"code",
",",
"$",
"state",
")",
";",
"$",
"snsUser",
"=",
"$",
"this",
"->",
"googleService",
"->",
"getUser",
"(",
"$",
"accessToken",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"snsUser",
")",
")",
"{",
"// Get User",
"$",
"user",
"=",
"$",
"this",
"->",
"modelService",
"->",
"getUser",
"(",
"$",
"snsUser",
",",
"$",
"accessToken",
")",
";",
"// Login and Redirect to home page",
"$",
"login",
"=",
"new",
"GoogleLogin",
"(",
"$",
"user",
")",
";",
"if",
"(",
"$",
"login",
"->",
"login",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'/user/index'",
"]",
")",
";",
"}",
"}",
"// Model not found",
"throw",
"new",
"NotFoundHttpException",
"(",
"Yii",
"::",
"$",
"app",
"->",
"coreMessage",
"->",
"getMessage",
"(",
"CoreGlobal",
"::",
"ERROR_NOT_FOUND",
")",
")",
";",
"}"
] | GoogleController ---------------------- | [
"GoogleController",
"----------------------"
] | train | https://github.com/cmsgears/module-sns-connect/blob/753ee4157d41c81a701689624f4c44760a6cada3/frontend/controllers/GoogleController.php#L82-L104 |
Subscribo/klarna-invoice-sdk-wrapped | src/klarnapclass.php | KlarnaPClass.toArray | public function toArray()
{
return array(
'eid' => $this->eid,
'id' => $this->id,
'description' => $this->description,
'months' => $this->months,
'startfee' => $this->startFee,
'invoicefee' => $this->invoiceFee,
'interestrate' => $this->interestRate,
'minamount' => $this->minAmount,
'country' => $this->country,
'type' => $this->type,
'expire' => $this->expire
);
} | php | public function toArray()
{
return array(
'eid' => $this->eid,
'id' => $this->id,
'description' => $this->description,
'months' => $this->months,
'startfee' => $this->startFee,
'invoicefee' => $this->invoiceFee,
'interestrate' => $this->interestRate,
'minamount' => $this->minAmount,
'country' => $this->country,
'type' => $this->type,
'expire' => $this->expire
);
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"array",
"(",
"'eid'",
"=>",
"$",
"this",
"->",
"eid",
",",
"'id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'description'",
"=>",
"$",
"this",
"->",
"description",
",",
"'months'",
"=>",
"$",
"this",
"->",
"months",
",",
"'startfee'",
"=>",
"$",
"this",
"->",
"startFee",
",",
"'invoicefee'",
"=>",
"$",
"this",
"->",
"invoiceFee",
",",
"'interestrate'",
"=>",
"$",
"this",
"->",
"interestRate",
",",
"'minamount'",
"=>",
"$",
"this",
"->",
"minAmount",
",",
"'country'",
"=>",
"$",
"this",
"->",
"country",
",",
"'type'",
"=>",
"$",
"this",
"->",
"type",
",",
"'expire'",
"=>",
"$",
"this",
"->",
"expire",
")",
";",
"}"
] | Returns an associative array mirroring this PClass.
@return array | [
"Returns",
"an",
"associative",
"array",
"mirroring",
"this",
"PClass",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnapclass.php#L268-L283 |
Subscribo/klarna-invoice-sdk-wrapped | src/klarnapclass.php | KlarnaPClass.isValid | public function isValid($now = null)
{
if ($this->expire == null
|| $this->expire == '-'
|| $this->expire <= 0
) {
//No expire, or unset? assume valid.
return true;
}
if ($now === null || !is_numeric($now)) {
$now = time();
}
//If now is before expire, it is still valid.
return ($now > $this->expire) ? false : true;
} | php | public function isValid($now = null)
{
if ($this->expire == null
|| $this->expire == '-'
|| $this->expire <= 0
) {
//No expire, or unset? assume valid.
return true;
}
if ($now === null || !is_numeric($now)) {
$now = time();
}
//If now is before expire, it is still valid.
return ($now > $this->expire) ? false : true;
} | [
"public",
"function",
"isValid",
"(",
"$",
"now",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"expire",
"==",
"null",
"||",
"$",
"this",
"->",
"expire",
"==",
"'-'",
"||",
"$",
"this",
"->",
"expire",
"<=",
"0",
")",
"{",
"//No expire, or unset? assume valid.",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"now",
"===",
"null",
"||",
"!",
"is_numeric",
"(",
"$",
"now",
")",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"}",
"//If now is before expire, it is still valid.",
"return",
"(",
"$",
"now",
">",
"$",
"this",
"->",
"expire",
")",
"?",
"false",
":",
"true",
";",
"}"
] | Checks whether this PClass is valid.
@param int $now Unix timestamp
@return bool | [
"Checks",
"whether",
"this",
"PClass",
"is",
"valid",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnapclass.php#L459-L475 |
Kris-Kuiper/sFire-Framework | src/MVC/MVCTrait.php | MVCTrait.helper | protected function helper($classname) {
$directories = explode('.', $classname); //Convert dots to directory seperators
$amount = count($directories) - 1;
$namespace = Router :: getRoute() -> getModule() . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', Application :: get(['directory', 'helper']));
foreach($directories as $index => $directory) {
if($amount === $index) {
$namespace .= Application :: get(['prefix', 'helper']) . $directory;
break;
}
$namespace .= $directory . '\\';
}
return new $namespace;
} | php | protected function helper($classname) {
$directories = explode('.', $classname); //Convert dots to directory seperators
$amount = count($directories) - 1;
$namespace = Router :: getRoute() -> getModule() . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', Application :: get(['directory', 'helper']));
foreach($directories as $index => $directory) {
if($amount === $index) {
$namespace .= Application :: get(['prefix', 'helper']) . $directory;
break;
}
$namespace .= $directory . '\\';
}
return new $namespace;
} | [
"protected",
"function",
"helper",
"(",
"$",
"classname",
")",
"{",
"$",
"directories",
"=",
"explode",
"(",
"'.'",
",",
"$",
"classname",
")",
";",
"//Convert dots to directory seperators\r",
"$",
"amount",
"=",
"count",
"(",
"$",
"directories",
")",
"-",
"1",
";",
"$",
"namespace",
"=",
"Router",
"::",
"getRoute",
"(",
")",
"->",
"getModule",
"(",
")",
".",
"'\\\\'",
".",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
",",
"Application",
"::",
"get",
"(",
"[",
"'directory'",
",",
"'helper'",
"]",
")",
")",
";",
"foreach",
"(",
"$",
"directories",
"as",
"$",
"index",
"=>",
"$",
"directory",
")",
"{",
"if",
"(",
"$",
"amount",
"===",
"$",
"index",
")",
"{",
"$",
"namespace",
".=",
"Application",
"::",
"get",
"(",
"[",
"'prefix'",
",",
"'helper'",
"]",
")",
".",
"$",
"directory",
";",
"break",
";",
"}",
"$",
"namespace",
".=",
"$",
"directory",
".",
"'\\\\'",
";",
"}",
"return",
"new",
"$",
"namespace",
";",
"}"
] | Loads a helper class in current module directory
@param string $classname
@return Object | [
"Loads",
"a",
"helper",
"class",
"in",
"current",
"module",
"directory"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/MVCTrait.php#L26-L44 |
Kris-Kuiper/sFire-Framework | src/MVC/MVCTrait.php | MVCTrait.fails | protected function fails($fieldname = null) {
$helper = new StringToArray();
return $helper -> execute($fieldname, null, Message :: getErrors(true));
} | php | protected function fails($fieldname = null) {
$helper = new StringToArray();
return $helper -> execute($fieldname, null, Message :: getErrors(true));
} | [
"protected",
"function",
"fails",
"(",
"$",
"fieldname",
"=",
"null",
")",
"{",
"$",
"helper",
"=",
"new",
"StringToArray",
"(",
")",
";",
"return",
"$",
"helper",
"->",
"execute",
"(",
"$",
"fieldname",
",",
"null",
",",
"Message",
"::",
"getErrors",
"(",
"true",
")",
")",
";",
"}"
] | Get the error message from the validator by fieldname
@param string $fieldname
@return string | [
"Get",
"the",
"error",
"message",
"from",
"the",
"validator",
"by",
"fieldname"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/MVCTrait.php#L52-L56 |
Kris-Kuiper/sFire-Framework | src/MVC/MVCTrait.php | MVCTrait.passes | protected function passes($fieldname = null) {
$helper = new StringToArray();
return true === Request :: isPost() && null === $helper -> execute($fieldname, null, Message :: getErrors(true));
} | php | protected function passes($fieldname = null) {
$helper = new StringToArray();
return true === Request :: isPost() && null === $helper -> execute($fieldname, null, Message :: getErrors(true));
} | [
"protected",
"function",
"passes",
"(",
"$",
"fieldname",
"=",
"null",
")",
"{",
"$",
"helper",
"=",
"new",
"StringToArray",
"(",
")",
";",
"return",
"true",
"===",
"Request",
"::",
"isPost",
"(",
")",
"&&",
"null",
"===",
"$",
"helper",
"->",
"execute",
"(",
"$",
"fieldname",
",",
"null",
",",
"Message",
"::",
"getErrors",
"(",
"true",
")",
")",
";",
"}"
] | Returns if there is no validation error for the given fieldname when request method is equal to POST
@param string $fieldname
@return boolean | [
"Returns",
"if",
"there",
"is",
"no",
"validation",
"error",
"for",
"the",
"given",
"fieldname",
"when",
"request",
"method",
"is",
"equal",
"to",
"POST"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/MVCTrait.php#L64-L68 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.group | public function group($prefix, callable $func)
{
$group = new self($this->router, $this->prefix . $prefix);
$func($group);
return $group;
} | php | public function group($prefix, callable $func)
{
$group = new self($this->router, $this->prefix . $prefix);
$func($group);
return $group;
} | [
"public",
"function",
"group",
"(",
"$",
"prefix",
",",
"callable",
"$",
"func",
")",
"{",
"$",
"group",
"=",
"new",
"self",
"(",
"$",
"this",
"->",
"router",
",",
"$",
"this",
"->",
"prefix",
".",
"$",
"prefix",
")",
";",
"$",
"func",
"(",
"$",
"group",
")",
";",
"return",
"$",
"group",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L24-L30 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.get | public function get($path, $handler)
{
return $this->router->get($this->prefix . $path, $handler);
} | php | public function get($path, $handler)
{
return $this->router->get($this->prefix . $path, $handler);
} | [
"public",
"function",
"get",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"get",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"path",
",",
"$",
"handler",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L35-L38 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.post | public function post($path, $handler)
{
return $this->router->post($this->prefix . $path, $handler);
} | php | public function post($path, $handler)
{
return $this->router->post($this->prefix . $path, $handler);
} | [
"public",
"function",
"post",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"post",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"path",
",",
"$",
"handler",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L43-L46 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.patch | public function patch($path, $handler)
{
return $this->router->patch($this->prefix . $path, $handler);
} | php | public function patch($path, $handler)
{
return $this->router->patch($this->prefix . $path, $handler);
} | [
"public",
"function",
"patch",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"patch",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"path",
",",
"$",
"handler",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L51-L54 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.put | public function put($path, $handler)
{
return $this->router->put($this->prefix . $path, $handler);
} | php | public function put($path, $handler)
{
return $this->router->put($this->prefix . $path, $handler);
} | [
"public",
"function",
"put",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"put",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"path",
",",
"$",
"handler",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L59-L62 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.delete | public function delete($path, $handler)
{
return $this->router->delete($this->prefix . $path, $handler);
} | php | public function delete($path, $handler)
{
return $this->router->delete($this->prefix . $path, $handler);
} | [
"public",
"function",
"delete",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"delete",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"path",
",",
"$",
"handler",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L67-L70 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.head | public function head($path, $handler)
{
return $this->router->head($this->prefix . $path, $handler);
} | php | public function head($path, $handler)
{
return $this->router->head($this->prefix . $path, $handler);
} | [
"public",
"function",
"head",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"head",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"path",
",",
"$",
"handler",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L75-L78 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.options | public function options($path, $handler)
{
return $this->router->options($this->prefix . $path, $handler);
} | php | public function options($path, $handler)
{
return $this->router->options($this->prefix . $path, $handler);
} | [
"public",
"function",
"options",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"options",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"path",
",",
"$",
"handler",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L83-L86 |
tonis-io-legacy/tonis | src/Router/Group.php | Group.any | public function any($path, $handler)
{
return $this->router->any($this->prefix . $path, $handler);
} | php | public function any($path, $handler)
{
return $this->router->any($this->prefix . $path, $handler);
} | [
"public",
"function",
"any",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
"->",
"router",
"->",
"any",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"path",
",",
"$",
"handler",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/Group.php#L91-L94 |
goncalomb/asbestos | src/classes/Html/Document.php | Document.ogTags | public function ogTags($data, $merge=true, $prefix='og')
{
$this->_headElement->ogTags($data, $merge, $prefix);
} | php | public function ogTags($data, $merge=true, $prefix='og')
{
$this->_headElement->ogTags($data, $merge, $prefix);
} | [
"public",
"function",
"ogTags",
"(",
"$",
"data",
",",
"$",
"merge",
"=",
"true",
",",
"$",
"prefix",
"=",
"'og'",
")",
"{",
"$",
"this",
"->",
"_headElement",
"->",
"ogTags",
"(",
"$",
"data",
",",
"$",
"merge",
",",
"$",
"prefix",
")",
";",
"}"
] | Set Open Graph tags.
@param array $data Tag names and values.
@param bool $merge Merge with current tags.
@param string $prefix Tag name prefix. | [
"Set",
"Open",
"Graph",
"tags",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Html/Document.php#L92-L95 |
goncalomb/asbestos | src/classes/Html/Document.php | Document.scriptFile | public function scriptFile($src, $end=false)
{
if ($end) {
$this->_bodyElement->scriptFile($src);
} else {
$this->_headElement->scriptFile($src);
}
} | php | public function scriptFile($src, $end=false)
{
if ($end) {
$this->_bodyElement->scriptFile($src);
} else {
$this->_headElement->scriptFile($src);
}
} | [
"public",
"function",
"scriptFile",
"(",
"$",
"src",
",",
"$",
"end",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"end",
")",
"{",
"$",
"this",
"->",
"_bodyElement",
"->",
"scriptFile",
"(",
"$",
"src",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_headElement",
"->",
"scriptFile",
"(",
"$",
"src",
")",
";",
"}",
"}"
] | Add script file.
@param string $src The script location.
@param bool $end Add script to end of body instead of head. | [
"Add",
"script",
"file",
"."
] | train | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Html/Document.php#L113-L120 |
ekyna/MediaBundle | Form/Type/Step/MediaImportSelectionType.php | MediaImportSelectionType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options)
{
$type = $this;
$builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) use ($type) {
/** @var \Ekyna\Bundle\MediaBundle\Model\Import\MediaImport $import */
if (null === $import = $event->getData()) {
throw new \Exception('Initial import object must be set.');
}
$form = $event->getForm();
$form->add('keys', 'choice', [
'label' => 'Choisissez des fichiers à importer.',
'choices' => $type->buildKeysChoices($import),
'expanded' => true,
'multiple' => true,
]);
});
} | php | public function buildForm(FormBuilderInterface $builder, array $options)
{
$type = $this;
$builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) use ($type) {
/** @var \Ekyna\Bundle\MediaBundle\Model\Import\MediaImport $import */
if (null === $import = $event->getData()) {
throw new \Exception('Initial import object must be set.');
}
$form = $event->getForm();
$form->add('keys', 'choice', [
'label' => 'Choisissez des fichiers à importer.',
'choices' => $type->buildKeysChoices($import),
'expanded' => true,
'multiple' => true,
]);
});
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"type",
"=",
"$",
"this",
";",
"$",
"builder",
"->",
"addEventListener",
"(",
"FormEvents",
"::",
"POST_SET_DATA",
",",
"function",
"(",
"FormEvent",
"$",
"event",
")",
"use",
"(",
"$",
"type",
")",
"{",
"/** @var \\Ekyna\\Bundle\\MediaBundle\\Model\\Import\\MediaImport $import */",
"if",
"(",
"null",
"===",
"$",
"import",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Initial import object must be set.'",
")",
";",
"}",
"$",
"form",
"=",
"$",
"event",
"->",
"getForm",
"(",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'keys'",
",",
"'choice'",
",",
"[",
"'label'",
"=>",
"'Choisissez des fichiers à importer.',",
"",
"'choices'",
"=>",
"$",
"type",
"->",
"buildKeysChoices",
"(",
"$",
"import",
")",
",",
"'expanded'",
"=>",
"true",
",",
"'multiple'",
"=>",
"true",
",",
"]",
")",
";",
"}",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Form/Type/Step/MediaImportSelectionType.php#L38-L56 |
ekyna/MediaBundle | Form/Type/Step/MediaImportSelectionType.php | MediaImportSelectionType.buildKeysChoices | public function buildKeysChoices(MediaImport $import)
{
$prefix = $import->getFilesystem();
$fs = $this->mountManager->getFilesystem($prefix);
$contents = $fs->listContents('', true);
$choices = [];
foreach ($contents as $object) {
if (!($object['type'] == 'dir' || substr($object['path'], 0, 1) == '.')) {
$key = sprintf('%s://%s', $prefix, $object['path']);
$choices[$key] = $object['path'];
}
}
return $choices;
} | php | public function buildKeysChoices(MediaImport $import)
{
$prefix = $import->getFilesystem();
$fs = $this->mountManager->getFilesystem($prefix);
$contents = $fs->listContents('', true);
$choices = [];
foreach ($contents as $object) {
if (!($object['type'] == 'dir' || substr($object['path'], 0, 1) == '.')) {
$key = sprintf('%s://%s', $prefix, $object['path']);
$choices[$key] = $object['path'];
}
}
return $choices;
} | [
"public",
"function",
"buildKeysChoices",
"(",
"MediaImport",
"$",
"import",
")",
"{",
"$",
"prefix",
"=",
"$",
"import",
"->",
"getFilesystem",
"(",
")",
";",
"$",
"fs",
"=",
"$",
"this",
"->",
"mountManager",
"->",
"getFilesystem",
"(",
"$",
"prefix",
")",
";",
"$",
"contents",
"=",
"$",
"fs",
"->",
"listContents",
"(",
"''",
",",
"true",
")",
";",
"$",
"choices",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"object",
"[",
"'type'",
"]",
"==",
"'dir'",
"||",
"substr",
"(",
"$",
"object",
"[",
"'path'",
"]",
",",
"0",
",",
"1",
")",
"==",
"'.'",
")",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"'%s://%s'",
",",
"$",
"prefix",
",",
"$",
"object",
"[",
"'path'",
"]",
")",
";",
"$",
"choices",
"[",
"$",
"key",
"]",
"=",
"$",
"object",
"[",
"'path'",
"]",
";",
"}",
"}",
"return",
"$",
"choices",
";",
"}"
] | Builds the keys choices.
@param MediaImport $import
@return array | [
"Builds",
"the",
"keys",
"choices",
"."
] | train | https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Form/Type/Step/MediaImportSelectionType.php#L64-L77 |
shrink0r/monatic | src/Eventually.php | Eventually.get | public function get(callable $codeBlock = null)
{
if ($this->result === null) {
$this->run(function ($value) use ($codeBlock) {
$this->result = $value;
if (is_callable($codeBlock)) {
$codeBlock($this->result);
}
});
return $this;
} else {
if (is_callable($codeBlock)) {
$codeBlock($this->result);
}
return $this->result;
}
} | php | public function get(callable $codeBlock = null)
{
if ($this->result === null) {
$this->run(function ($value) use ($codeBlock) {
$this->result = $value;
if (is_callable($codeBlock)) {
$codeBlock($this->result);
}
});
return $this;
} else {
if (is_callable($codeBlock)) {
$codeBlock($this->result);
}
return $this->result;
}
} | [
"public",
"function",
"get",
"(",
"callable",
"$",
"codeBlock",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"result",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"run",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"codeBlock",
")",
"{",
"$",
"this",
"->",
"result",
"=",
"$",
"value",
";",
"if",
"(",
"is_callable",
"(",
"$",
"codeBlock",
")",
")",
"{",
"$",
"codeBlock",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"this",
";",
"}",
"else",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"codeBlock",
")",
")",
"{",
"$",
"codeBlock",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"return",
"$",
"this",
"->",
"result",
";",
"}",
"}"
] | Eventually provides the a value resulting from running the monad's code-block.
If the value can not be provided at the moment,
a pointer to self is returned and the $codeBlock is executed when the value becomes available.
@param callable $codeBlock
@return mixed Returns an instance of Eventually, if the value wasn't available yet. | [
"Eventually",
"provides",
"the",
"a",
"value",
"resulting",
"from",
"running",
"the",
"monad",
"s",
"code",
"-",
"block",
".",
"If",
"the",
"value",
"can",
"not",
"be",
"provided",
"at",
"the",
"moment",
"a",
"pointer",
"to",
"self",
"is",
"returned",
"and",
"the",
"$codeBlock",
"is",
"executed",
"when",
"the",
"value",
"becomes",
"available",
"."
] | train | https://github.com/shrink0r/monatic/blob/f39b8b2ef68a397d31d844341487412b335fd107/src/Eventually.php#L44-L61 |
shrink0r/monatic | src/Eventually.php | Eventually.bind | public function bind(callable $codeBlock)
{
assert($this->result === null, "'Eventually' instance may not be mutated after code-block execution.");
return static::unit(function ($success) use ($codeBlock) {
$this->run(function ($value) use ($codeBlock, $success) {
return $codeBlock($value)->run($success);
});
});
} | php | public function bind(callable $codeBlock)
{
assert($this->result === null, "'Eventually' instance may not be mutated after code-block execution.");
return static::unit(function ($success) use ($codeBlock) {
$this->run(function ($value) use ($codeBlock, $success) {
return $codeBlock($value)->run($success);
});
});
} | [
"public",
"function",
"bind",
"(",
"callable",
"$",
"codeBlock",
")",
"{",
"assert",
"(",
"$",
"this",
"->",
"result",
"===",
"null",
",",
"\"'Eventually' instance may not be mutated after code-block execution.\"",
")",
";",
"return",
"static",
"::",
"unit",
"(",
"function",
"(",
"$",
"success",
")",
"use",
"(",
"$",
"codeBlock",
")",
"{",
"$",
"this",
"->",
"run",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"codeBlock",
",",
"$",
"success",
")",
"{",
"return",
"$",
"codeBlock",
"(",
"$",
"value",
")",
"->",
"run",
"(",
"$",
"success",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Binds the given callable to the monad's managed code-block's successful execution.
@param callable $codeBlock Is expected to return an instance of Eventually.
@return Eventually | [
"Binds",
"the",
"given",
"callable",
"to",
"the",
"monad",
"s",
"managed",
"code",
"-",
"block",
"s",
"successful",
"execution",
"."
] | train | https://github.com/shrink0r/monatic/blob/f39b8b2ef68a397d31d844341487412b335fd107/src/Eventually.php#L70-L79 |
dms-org/common.structure | src/Geo/Persistence/StreetAddressWithLatLngMapper.php | StreetAddressWithLatLngMapper.define | protected function define(MapperDefinition $map)
{
$map->type(StreetAddressWithLatLng::class);
$map->property(StreetAddressWithLatLng::ADDRESS)
->to($this->addressColumnName)->asVarchar(StreetAddress::MAX_LENGTH);
$map->embedded(StreetAddressWithLatLng::LAT_LNG)
->using(new LatLngMapper($this->latColumnName, $this->lngColumnName));
} | php | protected function define(MapperDefinition $map)
{
$map->type(StreetAddressWithLatLng::class);
$map->property(StreetAddressWithLatLng::ADDRESS)
->to($this->addressColumnName)->asVarchar(StreetAddress::MAX_LENGTH);
$map->embedded(StreetAddressWithLatLng::LAT_LNG)
->using(new LatLngMapper($this->latColumnName, $this->lngColumnName));
} | [
"protected",
"function",
"define",
"(",
"MapperDefinition",
"$",
"map",
")",
"{",
"$",
"map",
"->",
"type",
"(",
"StreetAddressWithLatLng",
"::",
"class",
")",
";",
"$",
"map",
"->",
"property",
"(",
"StreetAddressWithLatLng",
"::",
"ADDRESS",
")",
"->",
"to",
"(",
"$",
"this",
"->",
"addressColumnName",
")",
"->",
"asVarchar",
"(",
"StreetAddress",
"::",
"MAX_LENGTH",
")",
";",
"$",
"map",
"->",
"embedded",
"(",
"StreetAddressWithLatLng",
"::",
"LAT_LNG",
")",
"->",
"using",
"(",
"new",
"LatLngMapper",
"(",
"$",
"this",
"->",
"latColumnName",
",",
"$",
"this",
"->",
"lngColumnName",
")",
")",
";",
"}"
] | Defines the value object mapper
@param MapperDefinition $map
@return void | [
"Defines",
"the",
"value",
"object",
"mapper"
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Geo/Persistence/StreetAddressWithLatLngMapper.php#L55-L64 |
SteeinRu/steein-sdk-php | src/Steein/SDK/Core/SteeinUserAgent.php | SteeinUserAgent.getValue | public static function getValue($sdkName, $sdkVersion)
{
$featureList = array(
'platform-ver=' . PHP_VERSION,
'bit=' . self::_getPHPBit(),
'os=' . str_replace(' ', '_', php_uname('s') . ' ' . php_uname('r')),
'machine=' . php_uname('m')
);
if (defined('OPENSSL_VERSION_TEXT')) {
$opensslVersion = explode(' ', OPENSSL_VERSION_TEXT);
$featureList[] = 'crypto-lib-ver=' . $opensslVersion[1];
}
if (function_exists('curl_version')) {
$curlVersion = curl_version();
$featureList[] = 'curl=' . $curlVersion['version'];
}
return sprintf("SteeinSDK/%s %s (%s)", $sdkName, $sdkVersion, implode('; ', $featureList));
} | php | public static function getValue($sdkName, $sdkVersion)
{
$featureList = array(
'platform-ver=' . PHP_VERSION,
'bit=' . self::_getPHPBit(),
'os=' . str_replace(' ', '_', php_uname('s') . ' ' . php_uname('r')),
'machine=' . php_uname('m')
);
if (defined('OPENSSL_VERSION_TEXT')) {
$opensslVersion = explode(' ', OPENSSL_VERSION_TEXT);
$featureList[] = 'crypto-lib-ver=' . $opensslVersion[1];
}
if (function_exists('curl_version')) {
$curlVersion = curl_version();
$featureList[] = 'curl=' . $curlVersion['version'];
}
return sprintf("SteeinSDK/%s %s (%s)", $sdkName, $sdkVersion, implode('; ', $featureList));
} | [
"public",
"static",
"function",
"getValue",
"(",
"$",
"sdkName",
",",
"$",
"sdkVersion",
")",
"{",
"$",
"featureList",
"=",
"array",
"(",
"'platform-ver='",
".",
"PHP_VERSION",
",",
"'bit='",
".",
"self",
"::",
"_getPHPBit",
"(",
")",
",",
"'os='",
".",
"str_replace",
"(",
"' '",
",",
"'_'",
",",
"php_uname",
"(",
"'s'",
")",
".",
"' '",
".",
"php_uname",
"(",
"'r'",
")",
")",
",",
"'machine='",
".",
"php_uname",
"(",
"'m'",
")",
")",
";",
"if",
"(",
"defined",
"(",
"'OPENSSL_VERSION_TEXT'",
")",
")",
"{",
"$",
"opensslVersion",
"=",
"explode",
"(",
"' '",
",",
"OPENSSL_VERSION_TEXT",
")",
";",
"$",
"featureList",
"[",
"]",
"=",
"'crypto-lib-ver='",
".",
"$",
"opensslVersion",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'curl_version'",
")",
")",
"{",
"$",
"curlVersion",
"=",
"curl_version",
"(",
")",
";",
"$",
"featureList",
"[",
"]",
"=",
"'curl='",
".",
"$",
"curlVersion",
"[",
"'version'",
"]",
";",
"}",
"return",
"sprintf",
"(",
"\"SteeinSDK/%s %s (%s)\"",
",",
"$",
"sdkName",
",",
"$",
"sdkVersion",
",",
"implode",
"(",
"'; '",
",",
"$",
"featureList",
")",
")",
";",
"}"
] | Returns the value of the User-Agent header
Add environment values and php version numbers
@param string $sdkName
@param string $sdkVersion
@return string | [
"Returns",
"the",
"value",
"of",
"the",
"User",
"-",
"Agent",
"header",
"Add",
"environment",
"values",
"and",
"php",
"version",
"numbers"
] | train | https://github.com/SteeinRu/steein-sdk-php/blob/27113624a6582d27bb55d7c9724e8306739ef167/src/Steein/SDK/Core/SteeinUserAgent.php#L27-L44 |
waiter-coders/core | src/DB/Database.php | Database.transaction | public static function transaction(callable $method, $name = null)
{
try {
self::connection($name)->beginTransaction();
$result = $method();
self::connection($name)->commit();
return $result;
} catch (\Exception $exception) {
self::connection($name)->rollBack();
throw $exception;
}
} | php | public static function transaction(callable $method, $name = null)
{
try {
self::connection($name)->beginTransaction();
$result = $method();
self::connection($name)->commit();
return $result;
} catch (\Exception $exception) {
self::connection($name)->rollBack();
throw $exception;
}
} | [
"public",
"static",
"function",
"transaction",
"(",
"callable",
"$",
"method",
",",
"$",
"name",
"=",
"null",
")",
"{",
"try",
"{",
"self",
"::",
"connection",
"(",
"$",
"name",
")",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"result",
"=",
"$",
"method",
"(",
")",
";",
"self",
"::",
"connection",
"(",
"$",
"name",
")",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"result",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"self",
"::",
"connection",
"(",
"$",
"name",
")",
"->",
"rollBack",
"(",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"}"
] | 绑定事务区域 | [
"绑定事务区域"
] | train | https://github.com/waiter-coders/core/blob/6850fe73edede9564f29c42d78fa49c6866368ae/src/DB/Database.php#L74-L85 |
azhai/code-refactor | src/CodeRefactor/Visitor/LoadModelVisitor.php | LoadModelVisitor.checkModelName | public function checkModelName(array $args)
{
$arg1 = self::getExprAttr($args[0], 'value', 'value');
if ($arg1 && is_string($arg1)) {
$model = ['path' => null, 'name' => $arg1];
if ($pos = strrpos($arg1, '/')) {
$model['path'] = substr($arg1, 0, $pos);
$model['name'] = substr($arg1, $pos + 1);
}
$this->model_names[] = $model;
return $model;
}
} | php | public function checkModelName(array $args)
{
$arg1 = self::getExprAttr($args[0], 'value', 'value');
if ($arg1 && is_string($arg1)) {
$model = ['path' => null, 'name' => $arg1];
if ($pos = strrpos($arg1, '/')) {
$model['path'] = substr($arg1, 0, $pos);
$model['name'] = substr($arg1, $pos + 1);
}
$this->model_names[] = $model;
return $model;
}
} | [
"public",
"function",
"checkModelName",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"arg1",
"=",
"self",
"::",
"getExprAttr",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"'value'",
",",
"'value'",
")",
";",
"if",
"(",
"$",
"arg1",
"&&",
"is_string",
"(",
"$",
"arg1",
")",
")",
"{",
"$",
"model",
"=",
"[",
"'path'",
"=>",
"null",
",",
"'name'",
"=>",
"$",
"arg1",
"]",
";",
"if",
"(",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"arg1",
",",
"'/'",
")",
")",
"{",
"$",
"model",
"[",
"'path'",
"]",
"=",
"substr",
"(",
"$",
"arg1",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"model",
"[",
"'name'",
"]",
"=",
"substr",
"(",
"$",
"arg1",
",",
"$",
"pos",
"+",
"1",
")",
";",
"}",
"$",
"this",
"->",
"model_names",
"[",
"]",
"=",
"$",
"model",
";",
"return",
"$",
"model",
";",
"}",
"}"
] | 检查第一个参数是否字符串,并记录它 | [
"检查第一个参数是否字符串,并记录它"
] | train | https://github.com/azhai/code-refactor/blob/cddb437d72f8239957daeba8211dda5e9366d6ca/src/CodeRefactor/Visitor/LoadModelVisitor.php#L36-L48 |
azhai/code-refactor | src/CodeRefactor/Visitor/LoadModelVisitor.php | LoadModelVisitor.checkMethodArgs | public function checkMethodArgs(array $args)
{
$values = [];
foreach ($args as $arg) {
$value = $arg->value;
$type = $value->getType();
if ('Expr_ConstFetch' === $type) {
$value->summary = $value->name;
} elseif ('Expr_PropertyFetch' === $type) {
$value->summary = sprintf(
'$%s->%s',
$value->var->name,
$value->name
);
} elseif (starts_with($type, 'Scalar_')) {
$value->summary = $value->value;
} else {
$value->summary = "<$type>";
}
$values[] = $value;
}
$this->arg_values[] = $values;
return $values;
} | php | public function checkMethodArgs(array $args)
{
$values = [];
foreach ($args as $arg) {
$value = $arg->value;
$type = $value->getType();
if ('Expr_ConstFetch' === $type) {
$value->summary = $value->name;
} elseif ('Expr_PropertyFetch' === $type) {
$value->summary = sprintf(
'$%s->%s',
$value->var->name,
$value->name
);
} elseif (starts_with($type, 'Scalar_')) {
$value->summary = $value->value;
} else {
$value->summary = "<$type>";
}
$values[] = $value;
}
$this->arg_values[] = $values;
return $values;
} | [
"public",
"function",
"checkMethodArgs",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"$",
"value",
"=",
"$",
"arg",
"->",
"value",
";",
"$",
"type",
"=",
"$",
"value",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"'Expr_ConstFetch'",
"===",
"$",
"type",
")",
"{",
"$",
"value",
"->",
"summary",
"=",
"$",
"value",
"->",
"name",
";",
"}",
"elseif",
"(",
"'Expr_PropertyFetch'",
"===",
"$",
"type",
")",
"{",
"$",
"value",
"->",
"summary",
"=",
"sprintf",
"(",
"'$%s->%s'",
",",
"$",
"value",
"->",
"var",
"->",
"name",
",",
"$",
"value",
"->",
"name",
")",
";",
"}",
"elseif",
"(",
"starts_with",
"(",
"$",
"type",
",",
"'Scalar_'",
")",
")",
"{",
"$",
"value",
"->",
"summary",
"=",
"$",
"value",
"->",
"value",
";",
"}",
"else",
"{",
"$",
"value",
"->",
"summary",
"=",
"\"<$type>\"",
";",
"}",
"$",
"values",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"arg_values",
"[",
"]",
"=",
"$",
"values",
";",
"return",
"$",
"values",
";",
"}"
] | 收集方法的参数 | [
"收集方法的参数"
] | train | https://github.com/azhai/code-refactor/blob/cddb437d72f8239957daeba8211dda5e9366d6ca/src/CodeRefactor/Visitor/LoadModelVisitor.php#L53-L76 |
azhai/code-refactor | src/CodeRefactor/Visitor/LoadModelVisitor.php | LoadModelVisitor.ftExprLoadModel | public function ftExprLoadModel($node)
{
$name = self::getExprAttr($node, 'name');
$var_name = self::getExprAttr($node, 'var', 'name');
if ('model' === $name && 'load' === $var_name) {
if (count($node->args) >= 1) {
return $this->checkModelName($node->args);
}
}
} | php | public function ftExprLoadModel($node)
{
$name = self::getExprAttr($node, 'name');
$var_name = self::getExprAttr($node, 'var', 'name');
if ('model' === $name && 'load' === $var_name) {
if (count($node->args) >= 1) {
return $this->checkModelName($node->args);
}
}
} | [
"public",
"function",
"ftExprLoadModel",
"(",
"$",
"node",
")",
"{",
"$",
"name",
"=",
"self",
"::",
"getExprAttr",
"(",
"$",
"node",
",",
"'name'",
")",
";",
"$",
"var_name",
"=",
"self",
"::",
"getExprAttr",
"(",
"$",
"node",
",",
"'var'",
",",
"'name'",
")",
";",
"if",
"(",
"'model'",
"===",
"$",
"name",
"&&",
"'load'",
"===",
"$",
"var_name",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"node",
"->",
"args",
")",
">=",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"checkModelName",
"(",
"$",
"node",
"->",
"args",
")",
";",
"}",
"}",
"}"
] | MethodCall是否符合条件 | [
"MethodCall是否符合条件"
] | train | https://github.com/azhai/code-refactor/blob/cddb437d72f8239957daeba8211dda5e9366d6ca/src/CodeRefactor/Visitor/LoadModelVisitor.php#L81-L90 |
azhai/code-refactor | src/CodeRefactor/Visitor/LoadModelVisitor.php | LoadModelVisitor.cbExprLoadModel | public function cbExprLoadModel($node, $ft_result)
{
//修改Model类名首字母大写
$file = ucfirst($ft_result['name']);
if (isset($ft_result['path']) && $ft_result['path']) {
$file = $ft_result['path'] . '/' . $file;
}
$node->args[0]->value->value = $file;
//如果没有别名,使用全小写类名作为别名
if (1 === count($node->args)) {
$name = strtolower($ft_result['name']);
$node->args[] = self::createArg($name);
}
return $node; //提交修改
} | php | public function cbExprLoadModel($node, $ft_result)
{
//修改Model类名首字母大写
$file = ucfirst($ft_result['name']);
if (isset($ft_result['path']) && $ft_result['path']) {
$file = $ft_result['path'] . '/' . $file;
}
$node->args[0]->value->value = $file;
//如果没有别名,使用全小写类名作为别名
if (1 === count($node->args)) {
$name = strtolower($ft_result['name']);
$node->args[] = self::createArg($name);
}
return $node; //提交修改
} | [
"public",
"function",
"cbExprLoadModel",
"(",
"$",
"node",
",",
"$",
"ft_result",
")",
"{",
"//修改Model类名首字母大写",
"$",
"file",
"=",
"ucfirst",
"(",
"$",
"ft_result",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"ft_result",
"[",
"'path'",
"]",
")",
"&&",
"$",
"ft_result",
"[",
"'path'",
"]",
")",
"{",
"$",
"file",
"=",
"$",
"ft_result",
"[",
"'path'",
"]",
".",
"'/'",
".",
"$",
"file",
";",
"}",
"$",
"node",
"->",
"args",
"[",
"0",
"]",
"->",
"value",
"->",
"value",
"=",
"$",
"file",
";",
"//如果没有别名,使用全小写类名作为别名",
"if",
"(",
"1",
"===",
"count",
"(",
"$",
"node",
"->",
"args",
")",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"ft_result",
"[",
"'name'",
"]",
")",
";",
"$",
"node",
"->",
"args",
"[",
"]",
"=",
"self",
"::",
"createArg",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"node",
";",
"//提交修改",
"}"
] | Model类名首字母大写,没有别名的使用全小写作为别名 | [
"Model类名首字母大写,没有别名的使用全小写作为别名"
] | train | https://github.com/azhai/code-refactor/blob/cddb437d72f8239957daeba8211dda5e9366d6ca/src/CodeRefactor/Visitor/LoadModelVisitor.php#L95-L109 |
kaiohken1982/NeobazaarDocumentModule | src/Document/Utils/AbstractImage.php | AbstractImage.isYearMonthStrategy | public function isYearMonthStrategy(Document $doc = null, $prefix = '150_')
{
$datePart = $doc->getDateInsert()->format('\up\s/Y/m/');
return file_exists($this->cdnPath . $datePart . $prefix . $doc->getTitle());
} | php | public function isYearMonthStrategy(Document $doc = null, $prefix = '150_')
{
$datePart = $doc->getDateInsert()->format('\up\s/Y/m/');
return file_exists($this->cdnPath . $datePart . $prefix . $doc->getTitle());
} | [
"public",
"function",
"isYearMonthStrategy",
"(",
"Document",
"$",
"doc",
"=",
"null",
",",
"$",
"prefix",
"=",
"'150_'",
")",
"{",
"$",
"datePart",
"=",
"$",
"doc",
"->",
"getDateInsert",
"(",
")",
"->",
"format",
"(",
"'\\up\\s/Y/m/'",
")",
";",
"return",
"file_exists",
"(",
"$",
"this",
"->",
"cdnPath",
".",
"$",
"datePart",
".",
"$",
"prefix",
".",
"$",
"doc",
"->",
"getTitle",
"(",
")",
")",
";",
"}"
] | Check using Year/Month strategy | [
"Check",
"using",
"Year",
"/",
"Month",
"strategy"
] | train | https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Utils/AbstractImage.php#L21-L25 |
kaiohken1982/NeobazaarDocumentModule | src/Document/Utils/AbstractImage.php | AbstractImage.isNoDateStrategy | public function isNoDateStrategy(Document $doc = null, $prefix = '150_')
{
$prefix = 'ups/';
return file_exists($this->cdnPath . $prefix . $doc->getTitle());
} | php | public function isNoDateStrategy(Document $doc = null, $prefix = '150_')
{
$prefix = 'ups/';
return file_exists($this->cdnPath . $prefix . $doc->getTitle());
} | [
"public",
"function",
"isNoDateStrategy",
"(",
"Document",
"$",
"doc",
"=",
"null",
",",
"$",
"prefix",
"=",
"'150_'",
")",
"{",
"$",
"prefix",
"=",
"'ups/'",
";",
"return",
"file_exists",
"(",
"$",
"this",
"->",
"cdnPath",
".",
"$",
"prefix",
".",
"$",
"doc",
"->",
"getTitle",
"(",
")",
")",
";",
"}"
] | Check using no date strategy | [
"Check",
"using",
"no",
"date",
"strategy"
] | train | https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Utils/AbstractImage.php#L39-L43 |
TeknooSoftware/east-foundation | src/symfony/Router/Router.php | Router.matchRequest | private function matchRequest(ServerRequestInterface $request): ?callable
{
try {
$parameters = $this->matcher->match(
$this->cleanSymfonyHandler($request->getUri()->getPath())
);
} catch (ResourceNotFoundException $e) {
/* Do nothing, keep the framework to manage it */
}
if (empty($parameters['_controller'])) {
return null;
}
if (\is_callable($parameters['_controller'])) {
if (\is_string($parameters['_controller']) && false !== \strpos($parameters['_controller'], '::')) {
return \explode('::', $parameters['_controller']);
}
return $parameters['_controller'];
}
if (!$this->container->has($parameters['_controller'])) {
return null;
}
/**
* @var callable
*/
$entry = $this->container->get($parameters['_controller']);
if (\is_callable($entry)) {
return $entry;
}
return null;
} | php | private function matchRequest(ServerRequestInterface $request): ?callable
{
try {
$parameters = $this->matcher->match(
$this->cleanSymfonyHandler($request->getUri()->getPath())
);
} catch (ResourceNotFoundException $e) {
/* Do nothing, keep the framework to manage it */
}
if (empty($parameters['_controller'])) {
return null;
}
if (\is_callable($parameters['_controller'])) {
if (\is_string($parameters['_controller']) && false !== \strpos($parameters['_controller'], '::')) {
return \explode('::', $parameters['_controller']);
}
return $parameters['_controller'];
}
if (!$this->container->has($parameters['_controller'])) {
return null;
}
/**
* @var callable
*/
$entry = $this->container->get($parameters['_controller']);
if (\is_callable($entry)) {
return $entry;
}
return null;
} | [
"private",
"function",
"matchRequest",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"?",
"callable",
"{",
"try",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"matcher",
"->",
"match",
"(",
"$",
"this",
"->",
"cleanSymfonyHandler",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
")",
")",
";",
"}",
"catch",
"(",
"ResourceNotFoundException",
"$",
"e",
")",
"{",
"/* Do nothing, keep the framework to manage it */",
"}",
"if",
"(",
"empty",
"(",
"$",
"parameters",
"[",
"'_controller'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"parameters",
"[",
"'_controller'",
"]",
")",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"parameters",
"[",
"'_controller'",
"]",
")",
"&&",
"false",
"!==",
"\\",
"strpos",
"(",
"$",
"parameters",
"[",
"'_controller'",
"]",
",",
"'::'",
")",
")",
"{",
"return",
"\\",
"explode",
"(",
"'::'",
",",
"$",
"parameters",
"[",
"'_controller'",
"]",
")",
";",
"}",
"return",
"$",
"parameters",
"[",
"'_controller'",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"parameters",
"[",
"'_controller'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"/**\n * @var callable\n */",
"$",
"entry",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"parameters",
"[",
"'_controller'",
"]",
")",
";",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"entry",
")",
")",
"{",
"return",
"$",
"entry",
";",
"}",
"return",
"null",
";",
"}"
] | Method to find the controller to call for this method via the Symfony Matcher. Return only controller as service
(callable provided by the Symfony matcher), ignore other.
@param ServerRequestInterface $request
@return callable | [
"Method",
"to",
"find",
"the",
"controller",
"to",
"call",
"for",
"this",
"method",
"via",
"the",
"Symfony",
"Matcher",
".",
"Return",
"only",
"controller",
"as",
"service",
"(",
"callable",
"provided",
"by",
"the",
"Symfony",
"matcher",
")",
"ignore",
"other",
"."
] | train | https://github.com/TeknooSoftware/east-foundation/blob/45ca97c83ba08b973877a472c731f27ca1e82cdf/src/symfony/Router/Router.php#L104-L140 |
TeknooSoftware/east-foundation | src/symfony/Router/Router.php | Router.execute | public function execute(
ClientInterface $client,
ServerRequestInterface $request,
ManagerInterface $manager
): MiddlewareInterface {
$controller = $this->matchRequest($request);
if (\is_callable($controller)) {
$result = new Result($controller);
$manager->updateWorkPlan([ResultInterface::class => $result]);
$manager->continueExecution($client, $request);
}
return $this;
} | php | public function execute(
ClientInterface $client,
ServerRequestInterface $request,
ManagerInterface $manager
): MiddlewareInterface {
$controller = $this->matchRequest($request);
if (\is_callable($controller)) {
$result = new Result($controller);
$manager->updateWorkPlan([ResultInterface::class => $result]);
$manager->continueExecution($client, $request);
}
return $this;
} | [
"public",
"function",
"execute",
"(",
"ClientInterface",
"$",
"client",
",",
"ServerRequestInterface",
"$",
"request",
",",
"ManagerInterface",
"$",
"manager",
")",
":",
"MiddlewareInterface",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"matchRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"controller",
")",
")",
"{",
"$",
"result",
"=",
"new",
"Result",
"(",
"$",
"controller",
")",
";",
"$",
"manager",
"->",
"updateWorkPlan",
"(",
"[",
"ResultInterface",
"::",
"class",
"=>",
"$",
"result",
"]",
")",
";",
"$",
"manager",
"->",
"continueExecution",
"(",
"$",
"client",
",",
"$",
"request",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/TeknooSoftware/east-foundation/blob/45ca97c83ba08b973877a472c731f27ca1e82cdf/src/symfony/Router/Router.php#L145-L160 |
scaleplan/event | src/EventDispatcher.php | EventDispatcher.eventClassCheck | protected static function eventClassCheck(string $className) : void
{
if (!class_exists($className) || !is_subclass_of($className, EventInterface::class)) {
throw new ClassNotImplementsEventInterfaceException($className);
}
} | php | protected static function eventClassCheck(string $className) : void
{
if (!class_exists($className) || !is_subclass_of($className, EventInterface::class)) {
throw new ClassNotImplementsEventInterfaceException($className);
}
} | [
"protected",
"static",
"function",
"eventClassCheck",
"(",
"string",
"$",
"className",
")",
":",
"void",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
"||",
"!",
"is_subclass_of",
"(",
"$",
"className",
",",
"EventInterface",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"ClassNotImplementsEventInterfaceException",
"(",
"$",
"className",
")",
";",
"}",
"}"
] | @param string $className
@throws ClassNotImplementsEventInterfaceException | [
"@param",
"string",
"$className"
] | train | https://github.com/scaleplan/event/blob/248aa456e41c8a7949dd3b6be9bfe3dc108f5915/src/EventDispatcher.php#L33-L38 |
scaleplan/event | src/EventDispatcher.php | EventDispatcher.dispatch | public static function dispatch(string $className, object $object = null) : void
{
/** @var EventInterface $className */
static::eventClassCheck($className);
$className::dispatch($object);
} | php | public static function dispatch(string $className, object $object = null) : void
{
/** @var EventInterface $className */
static::eventClassCheck($className);
$className::dispatch($object);
} | [
"public",
"static",
"function",
"dispatch",
"(",
"string",
"$",
"className",
",",
"object",
"$",
"object",
"=",
"null",
")",
":",
"void",
"{",
"/** @var EventInterface $className */",
"static",
"::",
"eventClassCheck",
"(",
"$",
"className",
")",
";",
"$",
"className",
"::",
"dispatch",
"(",
"$",
"object",
")",
";",
"}"
] | @param string $className
@param object|null $object
@throws ClassNotImplementsEventInterfaceException | [
"@param",
"string",
"$className",
"@param",
"object|null",
"$object"
] | train | https://github.com/scaleplan/event/blob/248aa456e41c8a7949dd3b6be9bfe3dc108f5915/src/EventDispatcher.php#L46-L51 |
FuzeWorks/Core | src/FuzeWorks/Config.php | Config.getConfig | public function getConfig($configName, array $configPaths = array()): ConfigORM
{
// First determine what directories to use
$directories = (empty($configPaths) ? $this->configPaths : $configPaths);
// Determine the config name
$configName = strtolower($configName);
// If it's already loaded, return the existing object
if (isset($this->cfg[$configName]))
{
return $this->cfg[$configName];
}
// Otherwise try and load a new one
$this->cfg[$configName] = $this->loadConfigFile($configName, $directories);
return $this->cfg[$configName];
} | php | public function getConfig($configName, array $configPaths = array()): ConfigORM
{
// First determine what directories to use
$directories = (empty($configPaths) ? $this->configPaths : $configPaths);
// Determine the config name
$configName = strtolower($configName);
// If it's already loaded, return the existing object
if (isset($this->cfg[$configName]))
{
return $this->cfg[$configName];
}
// Otherwise try and load a new one
$this->cfg[$configName] = $this->loadConfigFile($configName, $directories);
return $this->cfg[$configName];
} | [
"public",
"function",
"getConfig",
"(",
"$",
"configName",
",",
"array",
"$",
"configPaths",
"=",
"array",
"(",
")",
")",
":",
"ConfigORM",
"{",
"// First determine what directories to use",
"$",
"directories",
"=",
"(",
"empty",
"(",
"$",
"configPaths",
")",
"?",
"$",
"this",
"->",
"configPaths",
":",
"$",
"configPaths",
")",
";",
"// Determine the config name",
"$",
"configName",
"=",
"strtolower",
"(",
"$",
"configName",
")",
";",
"// If it's already loaded, return the existing object",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"$",
"configName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cfg",
"[",
"$",
"configName",
"]",
";",
"}",
"// Otherwise try and load a new one",
"$",
"this",
"->",
"cfg",
"[",
"$",
"configName",
"]",
"=",
"$",
"this",
"->",
"loadConfigFile",
"(",
"$",
"configName",
",",
"$",
"directories",
")",
";",
"return",
"$",
"this",
"->",
"cfg",
"[",
"$",
"configName",
"]",
";",
"}"
] | Retrieve a config file object
@param string $configName Name of the config file. Eg. 'main'
@param array $configPaths Optional array of where to look for the config files
@return ConfigORM of the config file. Allows for easy reading and editing of the file
@throws ConfigException | [
"Retrieve",
"a",
"config",
"file",
"object"
] | train | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Config.php#L78-L95 |
FuzeWorks/Core | src/FuzeWorks/Config.php | Config.loadConfigFile | protected function loadConfigFile($configName, array $configPaths): ConfigORM
{
// Cycle through all directories
foreach ($configPaths as $directory)
{
// If file exists, load it and break the loop
$file = $directory . DS . 'config.'.$configName.'.php';
if (file_exists($file))
{
// Load object
return new ConfigORM($file);
break;
}
}
// Try fallback
$file = Core::$coreDir . DS . 'Config' . DS . 'config.' . $configName . '.php';
if (file_exists($file))
{
// Load object
return new ConfigORM($file);
}
throw new ConfigException("Could not load config. File $configName not found", 1);
} | php | protected function loadConfigFile($configName, array $configPaths): ConfigORM
{
// Cycle through all directories
foreach ($configPaths as $directory)
{
// If file exists, load it and break the loop
$file = $directory . DS . 'config.'.$configName.'.php';
if (file_exists($file))
{
// Load object
return new ConfigORM($file);
break;
}
}
// Try fallback
$file = Core::$coreDir . DS . 'Config' . DS . 'config.' . $configName . '.php';
if (file_exists($file))
{
// Load object
return new ConfigORM($file);
}
throw new ConfigException("Could not load config. File $configName not found", 1);
} | [
"protected",
"function",
"loadConfigFile",
"(",
"$",
"configName",
",",
"array",
"$",
"configPaths",
")",
":",
"ConfigORM",
"{",
"// Cycle through all directories",
"foreach",
"(",
"$",
"configPaths",
"as",
"$",
"directory",
")",
"{",
"// If file exists, load it and break the loop",
"$",
"file",
"=",
"$",
"directory",
".",
"DS",
".",
"'config.'",
".",
"$",
"configName",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"// Load object",
"return",
"new",
"ConfigORM",
"(",
"$",
"file",
")",
";",
"break",
";",
"}",
"}",
"// Try fallback",
"$",
"file",
"=",
"Core",
"::",
"$",
"coreDir",
".",
"DS",
".",
"'Config'",
".",
"DS",
".",
"'config.'",
".",
"$",
"configName",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"// Load object",
"return",
"new",
"ConfigORM",
"(",
"$",
"file",
")",
";",
"}",
"throw",
"new",
"ConfigException",
"(",
"\"Could not load config. File $configName not found\"",
",",
"1",
")",
";",
"}"
] | Determine whether the file exists and, if so, load the ConfigORM
@param string $configName Name of the config file. Eg. 'main'
@param array $configPaths Required array of where to look for the config files
@return ConfigORM of the config file. Allows for easy reading and editing of the file
@throws ConfigException | [
"Determine",
"whether",
"the",
"file",
"exists",
"and",
"if",
"so",
"load",
"the",
"ConfigORM"
] | train | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Config.php#L123-L147 |
FuzeWorks/Core | src/FuzeWorks/Config.php | Config.removeConfigPath | public function removeConfigPath($directory)
{
if (($key = array_search($directory, $this->configPaths)) !== false)
{
unset($this->configPaths[$key]);
}
} | php | public function removeConfigPath($directory)
{
if (($key = array_search($directory, $this->configPaths)) !== false)
{
unset($this->configPaths[$key]);
}
} | [
"public",
"function",
"removeConfigPath",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"directory",
",",
"$",
"this",
"->",
"configPaths",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"configPaths",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] | Remove a path where config files can be found
@param string $directory The directory
@return void | [
"Remove",
"a",
"path",
"where",
"config",
"files",
"can",
"be",
"found"
] | train | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Config.php#L169-L175 |
nguyenanhung/requests | src/GetContents.php | GetContents.getContent | public function getContent()
{
try {
if ($this->response) {
if (isset($this->response['content'])) {
return $this->response['content'];
} else {
return $this->response;
}
}
}
catch (Exception $e) {
$message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
return NULL;
} | php | public function getContent()
{
try {
if ($this->response) {
if (isset($this->response['content'])) {
return $this->response['content'];
} else {
return $this->response;
}
}
}
catch (Exception $e) {
$message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
return NULL;
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"response",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"response",
"[",
"'content'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"[",
"'content'",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"response",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"'Error File: '",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"' - Line: '",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"' - Code: '",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' - Message: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}",
"return",
"NULL",
";",
"}"
] | Function getContent - Get Body Content from Request
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:08
@return array|mixed|string Return Response content if exists
Full Response content if $this->response['content'] not exists
Exception Error Message if Exception Error
Null if Not | [
"Function",
"getContent",
"-",
"Get",
"Body",
"Content",
"from",
"Request"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L249-L268 |
nguyenanhung/requests | src/GetContents.php | GetContents.sendRequest | public function sendRequest()
{
try {
if (mb_strlen($this->url) >= 9) {
$response = $this->useFileGetContents();
$this->response = $response;
return $response;
}
}
catch (Exception $e) {
$message = "Error: " . __CLASS__ . ": Please make sure to set a URL to fetch - Line: " . $e->getLine() . ' - Msg: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
return NULL;
} | php | public function sendRequest()
{
try {
if (mb_strlen($this->url) >= 9) {
$response = $this->useFileGetContents();
$this->response = $response;
return $response;
}
}
catch (Exception $e) {
$message = "Error: " . __CLASS__ . ": Please make sure to set a URL to fetch - Line: " . $e->getLine() . ' - Msg: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
return NULL;
} | [
"public",
"function",
"sendRequest",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"this",
"->",
"url",
")",
">=",
"9",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"useFileGetContents",
"(",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"response",
";",
"return",
"$",
"response",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"\"Error: \"",
".",
"__CLASS__",
".",
"\": Please make sure to set a URL to fetch - Line: \"",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"' - Msg: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}",
"return",
"NULL",
";",
"}"
] | Let's go to Request
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:12
@return array|null|string Response from Request if Exists
Exception Error Message if Exception Error
Null if Not | [
"Let",
"s",
"go",
"to",
"Request"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L329-L347 |
nguyenanhung/requests | src/GetContents.php | GetContents.useFileGetContents | public function useFileGetContents()
{
$return = [];
$options = [
'http' => [
'method' => $this->method,
'timeout' => $this->timeout
]
];
if ($this->isSSL) {
// use SSL
$options['ssl'] = [
'verify_peer' => $this->verifyPeer,
'verify_peer_name' => $this->verifyPeer
];
}
$headers = $this->getHeaderArray();
if (count($headers) > 0) {
$options['http']['header'] = implode("\r\n", $headers);
}
if ($this->method == 'POST') {
$post = $this->getPostBody();
if (mb_strlen($post) > 0) {
$options['http']['content'] = $post;
}
$return['post'] = $post;
}
$context = stream_context_create($options);
$query_string = $this->getQueryString();
$this->debug->debug(__FUNCTION__, 'Options into Request: ', $options);
$this->debug->debug(__FUNCTION__, 'Data Query String into Request: ', $query_string);
$this->debug->debug(__FUNCTION__, 'Endpoint URL into Request: ', $this->url);
try {
$response = file_get_contents($this->url . $query_string, FALSE, $context);
$responseHeaders = $http_response_header;
$return['headers'] = $this->parseReturnHeaders($responseHeaders);
$return['url'] = $this->url . $query_string;
if ($response) {
$return['content'] = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($response));
if ($this->isJson === TRUE && $this->isDecodeJson === TRUE) {
$responseJson = json_decode(trim($return['content']));
if (json_last_error() == JSON_ERROR_NONE) {
$return['content'] = $responseJson;
$this->debug->debug(__FUNCTION__, 'Set Response is Json: ', $return['content']);
}
}
}
}
catch (Exception $e) {
$return['error'] = [
'code' => 500,
'message' => 'Could not file_get_contents.',
'extended' => $e
];
$this->debug->error(__FUNCTION__, 'Could not file_get_contents: ', $return['error']);
}
if (isset($return['headers']['reponse_code'])) {
$responseType = substr($return['headers']['reponse_code'], 0, 1);
if ($responseType != '2') {
$return['error'] = [
'code' => $return['headers']['reponse_code'],
'message' => 'Server returned an error.'
];
$this->debug->error(__FUNCTION__, 'Could not file_get_contents: ', $return['error']);
}
}
$cookies = [];
foreach ($http_response_header as $hdr) {
if (preg_match('/^Set-Cookie:\s*([^;]+)/i', $hdr, $matches)) {
parse_str($matches[1], $tmp);
$cookies += $tmp;
}
}
if ($this->trackCookies) {
$cookies = array_merge($this->cookies, $cookies);
$this->cookies = $cookies;
}
$return['cookies'] = $cookies;
$this->debug->info(__FUNCTION__, 'Final Result from Server: ', $return);
return $return;
} | php | public function useFileGetContents()
{
$return = [];
$options = [
'http' => [
'method' => $this->method,
'timeout' => $this->timeout
]
];
if ($this->isSSL) {
// use SSL
$options['ssl'] = [
'verify_peer' => $this->verifyPeer,
'verify_peer_name' => $this->verifyPeer
];
}
$headers = $this->getHeaderArray();
if (count($headers) > 0) {
$options['http']['header'] = implode("\r\n", $headers);
}
if ($this->method == 'POST') {
$post = $this->getPostBody();
if (mb_strlen($post) > 0) {
$options['http']['content'] = $post;
}
$return['post'] = $post;
}
$context = stream_context_create($options);
$query_string = $this->getQueryString();
$this->debug->debug(__FUNCTION__, 'Options into Request: ', $options);
$this->debug->debug(__FUNCTION__, 'Data Query String into Request: ', $query_string);
$this->debug->debug(__FUNCTION__, 'Endpoint URL into Request: ', $this->url);
try {
$response = file_get_contents($this->url . $query_string, FALSE, $context);
$responseHeaders = $http_response_header;
$return['headers'] = $this->parseReturnHeaders($responseHeaders);
$return['url'] = $this->url . $query_string;
if ($response) {
$return['content'] = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($response));
if ($this->isJson === TRUE && $this->isDecodeJson === TRUE) {
$responseJson = json_decode(trim($return['content']));
if (json_last_error() == JSON_ERROR_NONE) {
$return['content'] = $responseJson;
$this->debug->debug(__FUNCTION__, 'Set Response is Json: ', $return['content']);
}
}
}
}
catch (Exception $e) {
$return['error'] = [
'code' => 500,
'message' => 'Could not file_get_contents.',
'extended' => $e
];
$this->debug->error(__FUNCTION__, 'Could not file_get_contents: ', $return['error']);
}
if (isset($return['headers']['reponse_code'])) {
$responseType = substr($return['headers']['reponse_code'], 0, 1);
if ($responseType != '2') {
$return['error'] = [
'code' => $return['headers']['reponse_code'],
'message' => 'Server returned an error.'
];
$this->debug->error(__FUNCTION__, 'Could not file_get_contents: ', $return['error']);
}
}
$cookies = [];
foreach ($http_response_header as $hdr) {
if (preg_match('/^Set-Cookie:\s*([^;]+)/i', $hdr, $matches)) {
parse_str($matches[1], $tmp);
$cookies += $tmp;
}
}
if ($this->trackCookies) {
$cookies = array_merge($this->cookies, $cookies);
$this->cookies = $cookies;
}
$return['cookies'] = $cookies;
$this->debug->info(__FUNCTION__, 'Final Result from Server: ', $return);
return $return;
} | [
"public",
"function",
"useFileGetContents",
"(",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"$",
"options",
"=",
"[",
"'http'",
"=>",
"[",
"'method'",
"=>",
"$",
"this",
"->",
"method",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"timeout",
"]",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isSSL",
")",
"{",
"// use SSL",
"$",
"options",
"[",
"'ssl'",
"]",
"=",
"[",
"'verify_peer'",
"=>",
"$",
"this",
"->",
"verifyPeer",
",",
"'verify_peer_name'",
"=>",
"$",
"this",
"->",
"verifyPeer",
"]",
";",
"}",
"$",
"headers",
"=",
"$",
"this",
"->",
"getHeaderArray",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"headers",
")",
">",
"0",
")",
"{",
"$",
"options",
"[",
"'http'",
"]",
"[",
"'header'",
"]",
"=",
"implode",
"(",
"\"\\r\\n\"",
",",
"$",
"headers",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"method",
"==",
"'POST'",
")",
"{",
"$",
"post",
"=",
"$",
"this",
"->",
"getPostBody",
"(",
")",
";",
"if",
"(",
"mb_strlen",
"(",
"$",
"post",
")",
">",
"0",
")",
"{",
"$",
"options",
"[",
"'http'",
"]",
"[",
"'content'",
"]",
"=",
"$",
"post",
";",
"}",
"$",
"return",
"[",
"'post'",
"]",
"=",
"$",
"post",
";",
"}",
"$",
"context",
"=",
"stream_context_create",
"(",
"$",
"options",
")",
";",
"$",
"query_string",
"=",
"$",
"this",
"->",
"getQueryString",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Options into Request: '",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Data Query String into Request: '",
",",
"$",
"query_string",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Endpoint URL into Request: '",
",",
"$",
"this",
"->",
"url",
")",
";",
"try",
"{",
"$",
"response",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"url",
".",
"$",
"query_string",
",",
"FALSE",
",",
"$",
"context",
")",
";",
"$",
"responseHeaders",
"=",
"$",
"http_response_header",
";",
"$",
"return",
"[",
"'headers'",
"]",
"=",
"$",
"this",
"->",
"parseReturnHeaders",
"(",
"$",
"responseHeaders",
")",
";",
"$",
"return",
"[",
"'url'",
"]",
"=",
"$",
"this",
"->",
"url",
".",
"$",
"query_string",
";",
"if",
"(",
"$",
"response",
")",
"{",
"$",
"return",
"[",
"'content'",
"]",
"=",
"iconv",
"(",
"'UTF-8'",
",",
"'UTF-8//IGNORE'",
",",
"utf8_encode",
"(",
"$",
"response",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isJson",
"===",
"TRUE",
"&&",
"$",
"this",
"->",
"isDecodeJson",
"===",
"TRUE",
")",
"{",
"$",
"responseJson",
"=",
"json_decode",
"(",
"trim",
"(",
"$",
"return",
"[",
"'content'",
"]",
")",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"==",
"JSON_ERROR_NONE",
")",
"{",
"$",
"return",
"[",
"'content'",
"]",
"=",
"$",
"responseJson",
";",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Set Response is Json: '",
",",
"$",
"return",
"[",
"'content'",
"]",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"return",
"[",
"'error'",
"]",
"=",
"[",
"'code'",
"=>",
"500",
",",
"'message'",
"=>",
"'Could not file_get_contents.'",
",",
"'extended'",
"=>",
"$",
"e",
"]",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"'Could not file_get_contents: '",
",",
"$",
"return",
"[",
"'error'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"return",
"[",
"'headers'",
"]",
"[",
"'reponse_code'",
"]",
")",
")",
"{",
"$",
"responseType",
"=",
"substr",
"(",
"$",
"return",
"[",
"'headers'",
"]",
"[",
"'reponse_code'",
"]",
",",
"0",
",",
"1",
")",
";",
"if",
"(",
"$",
"responseType",
"!=",
"'2'",
")",
"{",
"$",
"return",
"[",
"'error'",
"]",
"=",
"[",
"'code'",
"=>",
"$",
"return",
"[",
"'headers'",
"]",
"[",
"'reponse_code'",
"]",
",",
"'message'",
"=>",
"'Server returned an error.'",
"]",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"'Could not file_get_contents: '",
",",
"$",
"return",
"[",
"'error'",
"]",
")",
";",
"}",
"}",
"$",
"cookies",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"http_response_header",
"as",
"$",
"hdr",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^Set-Cookie:\\s*([^;]+)/i'",
",",
"$",
"hdr",
",",
"$",
"matches",
")",
")",
"{",
"parse_str",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"tmp",
")",
";",
"$",
"cookies",
"+=",
"$",
"tmp",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"trackCookies",
")",
"{",
"$",
"cookies",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"cookies",
",",
"$",
"cookies",
")",
";",
"$",
"this",
"->",
"cookies",
"=",
"$",
"cookies",
";",
"}",
"$",
"return",
"[",
"'cookies'",
"]",
"=",
"$",
"cookies",
";",
"$",
"this",
"->",
"debug",
"->",
"info",
"(",
"__FUNCTION__",
",",
"'Final Result from Server: '",
",",
"$",
"return",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Function useFileGetContents
Use file_get_contents to perform the request
@return array The server response array
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:19 | [
"Function",
"useFileGetContents",
"Use",
"file_get_contents",
"to",
"perform",
"the",
"request"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L358-L447 |
nguyenanhung/requests | src/GetContents.php | GetContents.getHeaderArray | public function getHeaderArray()
{
$headerArray = (count($this->headers) > 0 ? $this->headers : []);
if ($this->isJson) {
$headerArray[] = 'Accept: application/json';
}
if ($this->isXML) {
$headerArray[] = 'Accept: text/xml';
}
if ($this->method == 'POST' && count($this->data) > 0 && $this->isJson) {
$headerArray[] = 'Content-type: application/json';
} elseif ($this->method == 'POST' && count($this->data) > 0 && $this->isXML) {
$headerArray[] = 'Content-type: text/xml';
} elseif ($this->method == 'POST' && count($this->data) > 0) {
$headerArray[] = 'Content-type: application/x-www-form-urlencoded';
}
if (count($this->cookies) > 0) {
$cookies = '';
foreach ($this->cookies as $key => $value) {
if (mb_strlen($cookies) > 0) {
$cookies .= '; ';
}
$cookies .= urlencode($key) . '=' . urlencode($value);
}
$headerArray[] = 'Cookie: ' . $cookies;
}
return $headerArray;
} | php | public function getHeaderArray()
{
$headerArray = (count($this->headers) > 0 ? $this->headers : []);
if ($this->isJson) {
$headerArray[] = 'Accept: application/json';
}
if ($this->isXML) {
$headerArray[] = 'Accept: text/xml';
}
if ($this->method == 'POST' && count($this->data) > 0 && $this->isJson) {
$headerArray[] = 'Content-type: application/json';
} elseif ($this->method == 'POST' && count($this->data) > 0 && $this->isXML) {
$headerArray[] = 'Content-type: text/xml';
} elseif ($this->method == 'POST' && count($this->data) > 0) {
$headerArray[] = 'Content-type: application/x-www-form-urlencoded';
}
if (count($this->cookies) > 0) {
$cookies = '';
foreach ($this->cookies as $key => $value) {
if (mb_strlen($cookies) > 0) {
$cookies .= '; ';
}
$cookies .= urlencode($key) . '=' . urlencode($value);
}
$headerArray[] = 'Cookie: ' . $cookies;
}
return $headerArray;
} | [
"public",
"function",
"getHeaderArray",
"(",
")",
"{",
"$",
"headerArray",
"=",
"(",
"count",
"(",
"$",
"this",
"->",
"headers",
")",
">",
"0",
"?",
"$",
"this",
"->",
"headers",
":",
"[",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isJson",
")",
"{",
"$",
"headerArray",
"[",
"]",
"=",
"'Accept: application/json'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isXML",
")",
"{",
"$",
"headerArray",
"[",
"]",
"=",
"'Accept: text/xml'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"method",
"==",
"'POST'",
"&&",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"isJson",
")",
"{",
"$",
"headerArray",
"[",
"]",
"=",
"'Content-type: application/json'",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"method",
"==",
"'POST'",
"&&",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"isXML",
")",
"{",
"$",
"headerArray",
"[",
"]",
"=",
"'Content-type: text/xml'",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"method",
"==",
"'POST'",
"&&",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
")",
"{",
"$",
"headerArray",
"[",
"]",
"=",
"'Content-type: application/x-www-form-urlencoded'",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"cookies",
")",
">",
"0",
")",
"{",
"$",
"cookies",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"cookies",
")",
">",
"0",
")",
"{",
"$",
"cookies",
".=",
"'; '",
";",
"}",
"$",
"cookies",
".=",
"urlencode",
"(",
"$",
"key",
")",
".",
"'='",
".",
"urlencode",
"(",
"$",
"value",
")",
";",
"}",
"$",
"headerArray",
"[",
"]",
"=",
"'Cookie: '",
".",
"$",
"cookies",
";",
"}",
"return",
"$",
"headerArray",
";",
"}"
] | Generate the complete header array
Merges the supplied (if any) headers with those needed by the
request.
@return array An array of headers
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:19 | [
"Generate",
"the",
"complete",
"header",
"array",
"Merges",
"the",
"supplied",
"(",
"if",
"any",
")",
"headers",
"with",
"those",
"needed",
"by",
"the",
"request",
"."
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L459-L487 |
nguyenanhung/requests | src/GetContents.php | GetContents.getPostBody | public function getPostBody()
{
$output = '';
if ($this->isJson) {
$jsonPretty = ($this->isJsonPretty ? JSON_PRETTY_PRINT : NULL);
if (count($this->data) > 0) {
$output = json_encode($this->data, $jsonPretty);
}
} elseif ($this->isXML) {
$output = $this->data;
} elseif (count($this->data) > 0) {
$output = http_build_query($this->data);
}
return $output;
} | php | public function getPostBody()
{
$output = '';
if ($this->isJson) {
$jsonPretty = ($this->isJsonPretty ? JSON_PRETTY_PRINT : NULL);
if (count($this->data) > 0) {
$output = json_encode($this->data, $jsonPretty);
}
} elseif ($this->isXML) {
$output = $this->data;
} elseif (count($this->data) > 0) {
$output = http_build_query($this->data);
}
return $output;
} | [
"public",
"function",
"getPostBody",
"(",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"isJson",
")",
"{",
"$",
"jsonPretty",
"=",
"(",
"$",
"this",
"->",
"isJsonPretty",
"?",
"JSON_PRETTY_PRINT",
":",
"NULL",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
")",
"{",
"$",
"output",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"jsonPretty",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isXML",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"data",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
")",
"{",
"$",
"output",
"=",
"http_build_query",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Get the post body - either JSON encoded or ready to be sent as a form post
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:19
@return array|false|string Data to be sent Request | [
"Get",
"the",
"post",
"body",
"-",
"either",
"JSON",
"encoded",
"or",
"ready",
"to",
"be",
"sent",
"as",
"a",
"form",
"post"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L497-L512 |
nguyenanhung/requests | src/GetContents.php | GetContents.getQueryString | public function getQueryString()
{
$query_string = '';
if (count($this->query_string) > 0) {
$query_string .= http_build_query($this->query_string);
}
if ($this->method != 'POST') {
if (count($this->data) > 0) {
$query_string .= http_build_query($this->data);
}
}
if (mb_strlen($query_string) > 0) {
$query_string = (mb_strpos($this->url, '?') ? '&' : '?') . $query_string;
}
return $query_string;
} | php | public function getQueryString()
{
$query_string = '';
if (count($this->query_string) > 0) {
$query_string .= http_build_query($this->query_string);
}
if ($this->method != 'POST') {
if (count($this->data) > 0) {
$query_string .= http_build_query($this->data);
}
}
if (mb_strlen($query_string) > 0) {
$query_string = (mb_strpos($this->url, '?') ? '&' : '?') . $query_string;
}
return $query_string;
} | [
"public",
"function",
"getQueryString",
"(",
")",
"{",
"$",
"query_string",
"=",
"''",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"query_string",
")",
">",
"0",
")",
"{",
"$",
"query_string",
".=",
"http_build_query",
"(",
"$",
"this",
"->",
"query_string",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"method",
"!=",
"'POST'",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
")",
"{",
"$",
"query_string",
".=",
"http_build_query",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}",
"}",
"if",
"(",
"mb_strlen",
"(",
"$",
"query_string",
")",
">",
"0",
")",
"{",
"$",
"query_string",
"=",
"(",
"mb_strpos",
"(",
"$",
"this",
"->",
"url",
",",
"'?'",
")",
"?",
"'&'",
":",
"'?'",
")",
".",
"$",
"query_string",
";",
"}",
"return",
"$",
"query_string",
";",
"}"
] | Get the query string by merging any supplied string
with that of the generated components.
@return string The query string
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:19 | [
"Get",
"the",
"query",
"string",
"by",
"merging",
"any",
"supplied",
"string",
"with",
"that",
"of",
"the",
"generated",
"components",
"."
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L523-L539 |
nguyenanhung/requests | src/GetContents.php | GetContents.setURL | public function setURL($url = '')
{
try {
if (mb_strlen($url) > 0) {
if (substr($url, 0, 8) == 'https://') {
$this->isSSL = TRUE;
$this->debug->debug(__FUNCTION__, 'Set SSL: ' . $this->isSSL);
} elseif (substr($url, 0, 7) == 'http://') {
$this->isSSL = TRUE;
$this->debug->debug(__FUNCTION__, 'Set SSL: ' . $this->isSSL);
}
}
$this->url = $url;
}
catch (Exception $e) {
$this->url = NULL;
$message = "Error: " . __CLASS__ . ": Invalid protocol specified. URL must start with http:// or https:// - " . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
$this->debug->debug(__FUNCTION__, 'Endpoint URL to Request: ', $this->url);
return $this;
} | php | public function setURL($url = '')
{
try {
if (mb_strlen($url) > 0) {
if (substr($url, 0, 8) == 'https://') {
$this->isSSL = TRUE;
$this->debug->debug(__FUNCTION__, 'Set SSL: ' . $this->isSSL);
} elseif (substr($url, 0, 7) == 'http://') {
$this->isSSL = TRUE;
$this->debug->debug(__FUNCTION__, 'Set SSL: ' . $this->isSSL);
}
}
$this->url = $url;
}
catch (Exception $e) {
$this->url = NULL;
$message = "Error: " . __CLASS__ . ": Invalid protocol specified. URL must start with http:// or https:// - " . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
$this->debug->error(__FUNCTION__, $message);
return $message;
}
$this->debug->debug(__FUNCTION__, 'Endpoint URL to Request: ', $this->url);
return $this;
} | [
"public",
"function",
"setURL",
"(",
"$",
"url",
"=",
"''",
")",
"{",
"try",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"url",
")",
">",
"0",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"8",
")",
"==",
"'https://'",
")",
"{",
"$",
"this",
"->",
"isSSL",
"=",
"TRUE",
";",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Set SSL: '",
".",
"$",
"this",
"->",
"isSSL",
")",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"7",
")",
"==",
"'http://'",
")",
"{",
"$",
"this",
"->",
"isSSL",
"=",
"TRUE",
";",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Set SSL: '",
".",
"$",
"this",
"->",
"isSSL",
")",
";",
"}",
"}",
"$",
"this",
"->",
"url",
"=",
"$",
"url",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"NULL",
";",
"$",
"message",
"=",
"\"Error: \"",
".",
"__CLASS__",
".",
"\": Invalid protocol specified. URL must start with http:// or https:// - \"",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"' - Line: '",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"' - Code: '",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' - Message: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Endpoint URL to Request: '",
",",
"$",
"this",
"->",
"url",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the target URL
Must include http:// or https://
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:10
@param string $url
@return string | [
"Set",
"the",
"target",
"URL",
"Must",
"include",
"http",
":",
"//",
"or",
"https",
":",
"//"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L552-L576 |
nguyenanhung/requests | src/GetContents.php | GetContents.setMethod | public function setMethod($method = '')
{
if (mb_strlen($method) == 0) {
$this->debug->debug(__FUNCTION__, 'Set Default Method = GET if $method is does not exist');
$method = 'GET';
} else {
$method = strtoupper($method);
$validMethods = [
'GET',
'HEAD',
'PUT',
'POST',
'DELETE'
];
if (!in_array($method, $validMethods)) {
$message = "Error: " . __CLASS__ . ": The requested method (${method}) is not valid here";
$this->debug->error(__FUNCTION__, $message);
return $message;
}
}
$this->method = $method;
return $this;
} | php | public function setMethod($method = '')
{
if (mb_strlen($method) == 0) {
$this->debug->debug(__FUNCTION__, 'Set Default Method = GET if $method is does not exist');
$method = 'GET';
} else {
$method = strtoupper($method);
$validMethods = [
'GET',
'HEAD',
'PUT',
'POST',
'DELETE'
];
if (!in_array($method, $validMethods)) {
$message = "Error: " . __CLASS__ . ": The requested method (${method}) is not valid here";
$this->debug->error(__FUNCTION__, $message);
return $message;
}
}
$this->method = $method;
return $this;
} | [
"public",
"function",
"setMethod",
"(",
"$",
"method",
"=",
"''",
")",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"method",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Set Default Method = GET if $method is does not exist'",
")",
";",
"$",
"method",
"=",
"'GET'",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"method",
")",
";",
"$",
"validMethods",
"=",
"[",
"'GET'",
",",
"'HEAD'",
",",
"'PUT'",
",",
"'POST'",
",",
"'DELETE'",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
",",
"$",
"validMethods",
")",
")",
"{",
"$",
"message",
"=",
"\"Error: \"",
".",
"__CLASS__",
".",
"\": The requested method (${method}) is not valid here\"",
";",
"$",
"this",
"->",
"debug",
"->",
"error",
"(",
"__FUNCTION__",
",",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}",
"}",
"$",
"this",
"->",
"method",
"=",
"$",
"method",
";",
"return",
"$",
"this",
";",
"}"
] | Set the HTTP method
GET, HEAD, PUT, POST are valid
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:15
@param string $method Method to Request GET, HEAD, PUT, POST are valid
@return $this|string Method | [
"Set",
"the",
"HTTP",
"method",
"GET",
"HEAD",
"PUT",
"POST",
"are",
"valid"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L589-L613 |
nguyenanhung/requests | src/GetContents.php | GetContents.setData | public function setData($data = [])
{
if (!is_array($data) && is_string($data)) {
$data = parse_str($data);
}
if (count($data) == 0) {
$this->data = [];
} else {
$this->data = $data;
}
$this->debug->debug(__FUNCTION__, 'Data into Request: ', $this->data);
} | php | public function setData($data = [])
{
if (!is_array($data) && is_string($data)) {
$data = parse_str($data);
}
if (count($data) == 0) {
$this->data = [];
} else {
$this->data = $data;
}
$this->debug->debug(__FUNCTION__, 'Data into Request: ', $this->data);
} | [
"public",
"function",
"setData",
"(",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"&&",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"parse_str",
"(",
"$",
"data",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"data",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"}",
"$",
"this",
"->",
"debug",
"->",
"debug",
"(",
"__FUNCTION__",
",",
"'Data into Request: '",
",",
"$",
"this",
"->",
"data",
")",
";",
"}"
] | Set Data contents
Must be supplied as an array
@param array $data The contents to be sent to the target URL
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:18 | [
"Set",
"Data",
"contents",
"Must",
"be",
"supplied",
"as",
"an",
"array"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L624-L635 |
nguyenanhung/requests | src/GetContents.php | GetContents.setQueryString | public function setQueryString($query_string = [])
{
if (!is_array($query_string) && is_string($query_string)) {
$query_string = parse_str($query_string);
}
if (count($query_string) == 0) {
$this->query_string = [];
} else {
$this->query_string = $query_string;
}
} | php | public function setQueryString($query_string = [])
{
if (!is_array($query_string) && is_string($query_string)) {
$query_string = parse_str($query_string);
}
if (count($query_string) == 0) {
$this->query_string = [];
} else {
$this->query_string = $query_string;
}
} | [
"public",
"function",
"setQueryString",
"(",
"$",
"query_string",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"query_string",
")",
"&&",
"is_string",
"(",
"$",
"query_string",
")",
")",
"{",
"$",
"query_string",
"=",
"parse_str",
"(",
"$",
"query_string",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"query_string",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"query_string",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"query_string",
"=",
"$",
"query_string",
";",
"}",
"}"
] | Set query string data
Must be supplied as an array
@param array $query_string The query string to be sent to the target URL
@author: 713uk13m <[email protected]>
@time : 10/7/18 01:36 | [
"Set",
"query",
"string",
"data",
"Must",
"be",
"supplied",
"as",
"an",
"array"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L646-L656 |
nguyenanhung/requests | src/GetContents.php | GetContents.setCookies | public function setCookies($cookies = [])
{
if (!is_array($cookies)) {
$this->cookies = [];
} else {
$this->cookies = $cookies;
$this->trackCookies = TRUE;
}
} | php | public function setCookies($cookies = [])
{
if (!is_array($cookies)) {
$this->cookies = [];
} else {
$this->cookies = $cookies;
$this->trackCookies = TRUE;
}
} | [
"public",
"function",
"setCookies",
"(",
"$",
"cookies",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"cookies",
")",
")",
"{",
"$",
"this",
"->",
"cookies",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cookies",
"=",
"$",
"cookies",
";",
"$",
"this",
"->",
"trackCookies",
"=",
"TRUE",
";",
"}",
"}"
] | Set any cookies to be included in the headers
Must be supplied as an array
@param array $cookies The array of cookies to be sent
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:18 | [
"Set",
"any",
"cookies",
"to",
"be",
"included",
"in",
"the",
"headers",
"Must",
"be",
"supplied",
"as",
"an",
"array"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L685-L693 |
nguyenanhung/requests | src/GetContents.php | GetContents.setTrackCookies | public function setTrackCookies($value = FALSE)
{
if (!$value) {
$this->trackCookies = FALSE;
} else {
$this->trackCookies = TRUE;
}
} | php | public function setTrackCookies($value = FALSE)
{
if (!$value) {
$this->trackCookies = FALSE;
} else {
$this->trackCookies = TRUE;
}
} | [
"public",
"function",
"setTrackCookies",
"(",
"$",
"value",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"trackCookies",
"=",
"FALSE",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"trackCookies",
"=",
"TRUE",
";",
"}",
"}"
] | Should cookies be tracked?
@param boolean $value true to track cookies
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:18 | [
"Should",
"cookies",
"be",
"tracked?"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L703-L710 |
nguyenanhung/requests | src/GetContents.php | GetContents.setXML | public function setXML($value = FALSE)
{
if (!$value) {
$this->isXML = FALSE;
} else {
$this->isXML = TRUE;
}
} | php | public function setXML($value = FALSE)
{
if (!$value) {
$this->isXML = FALSE;
} else {
$this->isXML = TRUE;
}
} | [
"public",
"function",
"setXML",
"(",
"$",
"value",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"isXML",
"=",
"FALSE",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"isXML",
"=",
"TRUE",
";",
"}",
"}"
] | Function setXML - Is this transaction sending / expecting XML
@author: 713uk13m <[email protected]>
@time : 10/7/18 01:38
@param bool $value true if XML is being used and is expected | [
"Function",
"setXML",
"-",
"Is",
"this",
"transaction",
"sending",
"/",
"expecting",
"XML"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L720-L727 |
nguyenanhung/requests | src/GetContents.php | GetContents.setJson | public function setJson($value = FALSE)
{
if (!$value) {
$this->isJson = FALSE;
} else {
$this->isJson = TRUE;
}
} | php | public function setJson($value = FALSE)
{
if (!$value) {
$this->isJson = FALSE;
} else {
$this->isJson = TRUE;
}
} | [
"public",
"function",
"setJson",
"(",
"$",
"value",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"isJson",
"=",
"FALSE",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"isJson",
"=",
"TRUE",
";",
"}",
"}"
] | Is this transaction sending / expecting JSON
@param boolean $value true if JSON is being used and is expected
@author: 713uk13m <[email protected]>
@time : 10/7/18 02:17 | [
"Is",
"this",
"transaction",
"sending",
"/",
"expecting",
"JSON"
] | train | https://github.com/nguyenanhung/requests/blob/fae98614a256be6a3ff9bea34a273d182a3ae730/src/GetContents.php#L737-L744 |
Subsets and Splits