id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
236,300
|
anklimsk/cakephp-extended-test
|
Vendor/PHPHtmlParser/paquettg/string-encode/src/stringEncode/Encode.php
|
Encode.detect
|
public function detect($str, $encodingList = ['UTF-8', 'CP1252'])
{
$charset = mb_detect_encoding($str, $encodingList);
if ($charset === false)
{
// could not detect charset
return false;
}
$this->from = $charset;
return true;
}
|
php
|
public function detect($str, $encodingList = ['UTF-8', 'CP1252'])
{
$charset = mb_detect_encoding($str, $encodingList);
if ($charset === false)
{
// could not detect charset
return false;
}
$this->from = $charset;
return true;
}
|
[
"public",
"function",
"detect",
"(",
"$",
"str",
",",
"$",
"encodingList",
"=",
"[",
"'UTF-8'",
",",
"'CP1252'",
"]",
")",
"{",
"$",
"charset",
"=",
"mb_detect_encoding",
"(",
"$",
"str",
",",
"$",
"encodingList",
")",
";",
"if",
"(",
"$",
"charset",
"===",
"false",
")",
"{",
"// could not detect charset",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"from",
"=",
"$",
"charset",
";",
"return",
"true",
";",
"}"
] |
Attempts to detect the encoding of the given string from the encodingList.
@param string $str
@param array $encodingList
@return bool
|
[
"Attempts",
"to",
"detect",
"the",
"encoding",
"of",
"the",
"given",
"string",
"from",
"the",
"encodingList",
"."
] |
21691a3be8a198419feb92fb6ed3b35a14dc24b1
|
https://github.com/anklimsk/cakephp-extended-test/blob/21691a3be8a198419feb92fb6ed3b35a14dc24b1/Vendor/PHPHtmlParser/paquettg/string-encode/src/stringEncode/Encode.php#L75-L86
|
236,301
|
anklimsk/cakephp-extended-test
|
Vendor/PHPHtmlParser/paquettg/string-encode/src/stringEncode/Encode.php
|
Encode.convert
|
public function convert($str)
{
if ($this->from != $this->to)
{
$str = iconv($this->from, $this->to, $str);
}
if ($str === false)
{
// the convertion was a failure
throw new Exception('The convertion from "'.$this->from.'" to "'.$this->to.'" was a failure.');
}
// deal with BOM issue for utf-8 text
if ($this->to == 'UTF-8')
{
if (substr($str, 0, 3) == "\xef\xbb\xbf")
{
$str = substr($str, 3);
}
if (substr($str, -3, 3) == "\xef\xbb\xbf")
{
$str = substr($str, 0, -3);
}
}
return $str;
}
|
php
|
public function convert($str)
{
if ($this->from != $this->to)
{
$str = iconv($this->from, $this->to, $str);
}
if ($str === false)
{
// the convertion was a failure
throw new Exception('The convertion from "'.$this->from.'" to "'.$this->to.'" was a failure.');
}
// deal with BOM issue for utf-8 text
if ($this->to == 'UTF-8')
{
if (substr($str, 0, 3) == "\xef\xbb\xbf")
{
$str = substr($str, 3);
}
if (substr($str, -3, 3) == "\xef\xbb\xbf")
{
$str = substr($str, 0, -3);
}
}
return $str;
}
|
[
"public",
"function",
"convert",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"from",
"!=",
"$",
"this",
"->",
"to",
")",
"{",
"$",
"str",
"=",
"iconv",
"(",
"$",
"this",
"->",
"from",
",",
"$",
"this",
"->",
"to",
",",
"$",
"str",
")",
";",
"}",
"if",
"(",
"$",
"str",
"===",
"false",
")",
"{",
"// the convertion was a failure",
"throw",
"new",
"Exception",
"(",
"'The convertion from \"'",
".",
"$",
"this",
"->",
"from",
".",
"'\" to \"'",
".",
"$",
"this",
"->",
"to",
".",
"'\" was a failure.'",
")",
";",
"}",
"// deal with BOM issue for utf-8 text",
"if",
"(",
"$",
"this",
"->",
"to",
"==",
"'UTF-8'",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"3",
")",
"==",
"\"\\xef\\xbb\\xbf\"",
")",
"{",
"$",
"str",
"=",
"substr",
"(",
"$",
"str",
",",
"3",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"str",
",",
"-",
"3",
",",
"3",
")",
"==",
"\"\\xef\\xbb\\xbf\"",
")",
"{",
"$",
"str",
"=",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"-",
"3",
")",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
] |
Attempts to convert the string to the proper charset.
@return string
|
[
"Attempts",
"to",
"convert",
"the",
"string",
"to",
"the",
"proper",
"charset",
"."
] |
21691a3be8a198419feb92fb6ed3b35a14dc24b1
|
https://github.com/anklimsk/cakephp-extended-test/blob/21691a3be8a198419feb92fb6ed3b35a14dc24b1/Vendor/PHPHtmlParser/paquettg/string-encode/src/stringEncode/Encode.php#L93-L120
|
236,302
|
10usb/css-lib
|
src/Group.php
|
Group.add
|
public function add($child, $other = null){
if($other){
throw new \Exception('Inserting before not supported');
}else{
$this->children[] = $child;
}
return $child;
}
|
php
|
public function add($child, $other = null){
if($other){
throw new \Exception('Inserting before not supported');
}else{
$this->children[] = $child;
}
return $child;
}
|
[
"public",
"function",
"add",
"(",
"$",
"child",
",",
"$",
"other",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"other",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Inserting before not supported'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"children",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"return",
"$",
"child",
";",
"}"
] |
Adds an child to this group
@param \csslib\RuleSet $child Child to be added
@param \csslib\RuleSet $other If given the child to be added wil be inserted before the other child
@return \csslib\RuleSet The added child
|
[
"Adds",
"an",
"child",
"to",
"this",
"group"
] |
6370b1404bae3eecb44c214ed4eaaf33113858dd
|
https://github.com/10usb/css-lib/blob/6370b1404bae3eecb44c214ed4eaaf33113858dd/src/Group.php#L36-L43
|
236,303
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.getDetails
|
public function getDetails($purchaseId) {
$purchase = Purchase::findOrFail($purchaseId);
if (!in_array(Auth::user()->userId, [
$purchase->item->seller->userId,
$purchase->buyer->userId
])) {
return redirect('/inventory')->withErrors([
"You are not the buyer or seller of this item."
]);
}
return view('mustard::purchase.details', [
'purchase' => $purchase,
]);
}
|
php
|
public function getDetails($purchaseId) {
$purchase = Purchase::findOrFail($purchaseId);
if (!in_array(Auth::user()->userId, [
$purchase->item->seller->userId,
$purchase->buyer->userId
])) {
return redirect('/inventory')->withErrors([
"You are not the buyer or seller of this item."
]);
}
return view('mustard::purchase.details', [
'purchase' => $purchase,
]);
}
|
[
"public",
"function",
"getDetails",
"(",
"$",
"purchaseId",
")",
"{",
"$",
"purchase",
"=",
"Purchase",
"::",
"findOrFail",
"(",
"$",
"purchaseId",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
",",
"[",
"$",
"purchase",
"->",
"item",
"->",
"seller",
"->",
"userId",
",",
"$",
"purchase",
"->",
"buyer",
"->",
"userId",
"]",
")",
")",
"{",
"return",
"redirect",
"(",
"'/inventory'",
")",
"->",
"withErrors",
"(",
"[",
"\"You are not the buyer or seller of this item.\"",
"]",
")",
";",
"}",
"return",
"view",
"(",
"'mustard::purchase.details'",
",",
"[",
"'purchase'",
"=>",
"$",
"purchase",
",",
"]",
")",
";",
"}"
] |
Return the purchase details view.
@return \Illuminate\View\View
|
[
"Return",
"the",
"purchase",
"details",
"view",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L41-L56
|
236,304
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.getCheckout
|
public function getCheckout($itemId)
{
$item = Item::findOrFail($itemId);
if ($item->seller->userId == Auth::user()->userId) {
return redirect($item->url)->withErrors([
'You cannot purchase your own items.'
]);
}
if ($item->auction && !$item->isActive() && $item->purchases->count()) {
return redirect('/pay/' . $item->purchases->first()->purchaseId);
}
// Check for unpaid item
if ($unpaid = $item->purchases()->where('user_id', Auth::user()->userId)->where('paid', 0)->first()) {
return redirect('/pay/' . $unpaid->purchaseId);
}
if (!$item->isActive() && !$item->auction) {
return redirect($item->url)->withErrors([
'This item has ended.'
]);
}
if ($item->isActive() && !$item->hasFixed()) {
return redirect($item->url)->withErrors([
'This auction has no fixed price, so cannot be bought outright.'
]);
}
if (!$item->isActive() && $item->auction && !$item->winningBid) {
return redirect($item->url)->withStatus(
'Please wait while this auction is processed.'
);
}
return view('mustard::purchase.checkout', [
'countries' => Iso3166::all(),
'item' => $item,
'item_total' => ($item->auction && !$item->isActive())
? $item->biddingPrice
: $item->fixedPrice,
]);
}
|
php
|
public function getCheckout($itemId)
{
$item = Item::findOrFail($itemId);
if ($item->seller->userId == Auth::user()->userId) {
return redirect($item->url)->withErrors([
'You cannot purchase your own items.'
]);
}
if ($item->auction && !$item->isActive() && $item->purchases->count()) {
return redirect('/pay/' . $item->purchases->first()->purchaseId);
}
// Check for unpaid item
if ($unpaid = $item->purchases()->where('user_id', Auth::user()->userId)->where('paid', 0)->first()) {
return redirect('/pay/' . $unpaid->purchaseId);
}
if (!$item->isActive() && !$item->auction) {
return redirect($item->url)->withErrors([
'This item has ended.'
]);
}
if ($item->isActive() && !$item->hasFixed()) {
return redirect($item->url)->withErrors([
'This auction has no fixed price, so cannot be bought outright.'
]);
}
if (!$item->isActive() && $item->auction && !$item->winningBid) {
return redirect($item->url)->withStatus(
'Please wait while this auction is processed.'
);
}
return view('mustard::purchase.checkout', [
'countries' => Iso3166::all(),
'item' => $item,
'item_total' => ($item->auction && !$item->isActive())
? $item->biddingPrice
: $item->fixedPrice,
]);
}
|
[
"public",
"function",
"getCheckout",
"(",
"$",
"itemId",
")",
"{",
"$",
"item",
"=",
"Item",
"::",
"findOrFail",
"(",
"$",
"itemId",
")",
";",
"if",
"(",
"$",
"item",
"->",
"seller",
"->",
"userId",
"==",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
"{",
"return",
"redirect",
"(",
"$",
"item",
"->",
"url",
")",
"->",
"withErrors",
"(",
"[",
"'You cannot purchase your own items.'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"auction",
"&&",
"!",
"$",
"item",
"->",
"isActive",
"(",
")",
"&&",
"$",
"item",
"->",
"purchases",
"->",
"count",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
"'/pay/'",
".",
"$",
"item",
"->",
"purchases",
"->",
"first",
"(",
")",
"->",
"purchaseId",
")",
";",
"}",
"// Check for unpaid item",
"if",
"(",
"$",
"unpaid",
"=",
"$",
"item",
"->",
"purchases",
"(",
")",
"->",
"where",
"(",
"'user_id'",
",",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
"->",
"where",
"(",
"'paid'",
",",
"0",
")",
"->",
"first",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
"'/pay/'",
".",
"$",
"unpaid",
"->",
"purchaseId",
")",
";",
"}",
"if",
"(",
"!",
"$",
"item",
"->",
"isActive",
"(",
")",
"&&",
"!",
"$",
"item",
"->",
"auction",
")",
"{",
"return",
"redirect",
"(",
"$",
"item",
"->",
"url",
")",
"->",
"withErrors",
"(",
"[",
"'This item has ended.'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"isActive",
"(",
")",
"&&",
"!",
"$",
"item",
"->",
"hasFixed",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
"$",
"item",
"->",
"url",
")",
"->",
"withErrors",
"(",
"[",
"'This auction has no fixed price, so cannot be bought outright.'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"item",
"->",
"isActive",
"(",
")",
"&&",
"$",
"item",
"->",
"auction",
"&&",
"!",
"$",
"item",
"->",
"winningBid",
")",
"{",
"return",
"redirect",
"(",
"$",
"item",
"->",
"url",
")",
"->",
"withStatus",
"(",
"'Please wait while this auction is processed.'",
")",
";",
"}",
"return",
"view",
"(",
"'mustard::purchase.checkout'",
",",
"[",
"'countries'",
"=>",
"Iso3166",
"::",
"all",
"(",
")",
",",
"'item'",
"=>",
"$",
"item",
",",
"'item_total'",
"=>",
"(",
"$",
"item",
"->",
"auction",
"&&",
"!",
"$",
"item",
"->",
"isActive",
"(",
")",
")",
"?",
"$",
"item",
"->",
"biddingPrice",
":",
"$",
"item",
"->",
"fixedPrice",
",",
"]",
")",
";",
"}"
] |
Return the item checkout view.
@return \Illuminate\View\View
|
[
"Return",
"the",
"item",
"checkout",
"view",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L63-L107
|
236,305
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.getPay
|
public function getPay($purchaseId)
{
$purchase = Purchase::findOrFail($purchaseId);
if ($purchase->buyer->userId != Auth::user()->userId) {
return redirect('/inventory/bought')->withErrors([
"You are not the buyer of this item."
]);
}
if ($purchase->isPaid()) {
return redirect('/inventory/bought')->withStatus(
'You have already successfully paid for this item.'
);
}
return view('mustard::purchase.pay', [
'purchase' => $purchase,
]);
}
|
php
|
public function getPay($purchaseId)
{
$purchase = Purchase::findOrFail($purchaseId);
if ($purchase->buyer->userId != Auth::user()->userId) {
return redirect('/inventory/bought')->withErrors([
"You are not the buyer of this item."
]);
}
if ($purchase->isPaid()) {
return redirect('/inventory/bought')->withStatus(
'You have already successfully paid for this item.'
);
}
return view('mustard::purchase.pay', [
'purchase' => $purchase,
]);
}
|
[
"public",
"function",
"getPay",
"(",
"$",
"purchaseId",
")",
"{",
"$",
"purchase",
"=",
"Purchase",
"::",
"findOrFail",
"(",
"$",
"purchaseId",
")",
";",
"if",
"(",
"$",
"purchase",
"->",
"buyer",
"->",
"userId",
"!=",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/bought'",
")",
"->",
"withErrors",
"(",
"[",
"\"You are not the buyer of this item.\"",
"]",
")",
";",
"}",
"if",
"(",
"$",
"purchase",
"->",
"isPaid",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/bought'",
")",
"->",
"withStatus",
"(",
"'You have already successfully paid for this item.'",
")",
";",
"}",
"return",
"view",
"(",
"'mustard::purchase.pay'",
",",
"[",
"'purchase'",
"=>",
"$",
"purchase",
",",
"]",
")",
";",
"}"
] |
Return the purchase pay view.
@return \Illuminate\View\View
|
[
"Return",
"the",
"purchase",
"pay",
"view",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L114-L133
|
236,306
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.getDispatched
|
public function getDispatched($purchaseId)
{
$purchase = Purchase::findOrFail($purchaseId);
if ($purchase->item->seller->userId != Auth::user()->userId) {
return redirect('/inventory/sold')->withErrors([
"You are not seller of this item."
]);
}
if ($purchase->isDispatched()) {
return redirect('/inventory/sold')->withStatus(
'You have already marked this item as dispatched.'
);
}
if (!$purchase->deliveryOption) {
return redirect()->back()->withErrors([
"This item is due to be collected."
]);
}
return view('mustard::purchase.dispatched', [
'purchase' => $purchase,
]);
}
|
php
|
public function getDispatched($purchaseId)
{
$purchase = Purchase::findOrFail($purchaseId);
if ($purchase->item->seller->userId != Auth::user()->userId) {
return redirect('/inventory/sold')->withErrors([
"You are not seller of this item."
]);
}
if ($purchase->isDispatched()) {
return redirect('/inventory/sold')->withStatus(
'You have already marked this item as dispatched.'
);
}
if (!$purchase->deliveryOption) {
return redirect()->back()->withErrors([
"This item is due to be collected."
]);
}
return view('mustard::purchase.dispatched', [
'purchase' => $purchase,
]);
}
|
[
"public",
"function",
"getDispatched",
"(",
"$",
"purchaseId",
")",
"{",
"$",
"purchase",
"=",
"Purchase",
"::",
"findOrFail",
"(",
"$",
"purchaseId",
")",
";",
"if",
"(",
"$",
"purchase",
"->",
"item",
"->",
"seller",
"->",
"userId",
"!=",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withErrors",
"(",
"[",
"\"You are not seller of this item.\"",
"]",
")",
";",
"}",
"if",
"(",
"$",
"purchase",
"->",
"isDispatched",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withStatus",
"(",
"'You have already marked this item as dispatched.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"purchase",
"->",
"deliveryOption",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withErrors",
"(",
"[",
"\"This item is due to be collected.\"",
"]",
")",
";",
"}",
"return",
"view",
"(",
"'mustard::purchase.dispatched'",
",",
"[",
"'purchase'",
"=>",
"$",
"purchase",
",",
"]",
")",
";",
"}"
] |
Return the purchase dispatched view.
@return \Illuminate\View\View
|
[
"Return",
"the",
"purchase",
"dispatched",
"view",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L140-L165
|
236,307
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.getCollectionAddress
|
public function getCollectionAddress($purchaseId)
{
$purchase = Purchase::findOrFail($purchaseId);
if ($purchase->item->seller->userId != Auth::user()->userId) {
return redirect('/inventory/sold')->withErrors([
"You are not the seller of this item."
]);
}
if ($purchase->deliveryOption) {
return redirect('/inventory/sold')->withErrors([
"This item is not due to be collected."
]);
}
if ($purchase->hasAddress()) {
return redirect('/inventory/sold')->withErrors([
"You have already provided a collection address for this item."
]);
}
return view('mustard::purchase.collection-address', [
'countries' => Iso3166::all(),
'purchase' => $purchase,
]);
}
|
php
|
public function getCollectionAddress($purchaseId)
{
$purchase = Purchase::findOrFail($purchaseId);
if ($purchase->item->seller->userId != Auth::user()->userId) {
return redirect('/inventory/sold')->withErrors([
"You are not the seller of this item."
]);
}
if ($purchase->deliveryOption) {
return redirect('/inventory/sold')->withErrors([
"This item is not due to be collected."
]);
}
if ($purchase->hasAddress()) {
return redirect('/inventory/sold')->withErrors([
"You have already provided a collection address for this item."
]);
}
return view('mustard::purchase.collection-address', [
'countries' => Iso3166::all(),
'purchase' => $purchase,
]);
}
|
[
"public",
"function",
"getCollectionAddress",
"(",
"$",
"purchaseId",
")",
"{",
"$",
"purchase",
"=",
"Purchase",
"::",
"findOrFail",
"(",
"$",
"purchaseId",
")",
";",
"if",
"(",
"$",
"purchase",
"->",
"item",
"->",
"seller",
"->",
"userId",
"!=",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withErrors",
"(",
"[",
"\"You are not the seller of this item.\"",
"]",
")",
";",
"}",
"if",
"(",
"$",
"purchase",
"->",
"deliveryOption",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withErrors",
"(",
"[",
"\"This item is not due to be collected.\"",
"]",
")",
";",
"}",
"if",
"(",
"$",
"purchase",
"->",
"hasAddress",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withErrors",
"(",
"[",
"\"You have already provided a collection address for this item.\"",
"]",
")",
";",
"}",
"return",
"view",
"(",
"'mustard::purchase.collection-address'",
",",
"[",
"'countries'",
"=>",
"Iso3166",
"::",
"all",
"(",
")",
",",
"'purchase'",
"=>",
"$",
"purchase",
",",
"]",
")",
";",
"}"
] |
Return the purchase collection address view.
@return \Illuminate\View\View
|
[
"Return",
"the",
"purchase",
"collection",
"address",
"view",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L172-L198
|
236,308
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.postDispatched
|
public function postDispatched(Request $request)
{
$purchase = Purchase::findOrFail($request->input('purchase_id'));
if ($purchase->item->seller->userId != Auth::user()->userId) {
return redirect('/inventory/sold')->withErrors(["You are not seller of this item."]);
}
if ($purchase->isDispatched()) {
return redirect('/inventory/sold')->withErrors(["This item has already been marked as dispatched."]);
}
if (!$purchase->deliveryOption) {
return redirect('/inventory/sold')->withErrors(["This item is due to be collected."]);
}
$purchase->dispatched = time();
$purchase->trackingNumber = $request->input('tracking_number');
$purchase->save();
$purchase->buyer->sendEmail(
'Your item has been dispatched',
'emails.item.dispatched',
[
'item_name' => $purchase->item->name,
'delivery_service' => $purchase->deliveryOption->name,
'tracking_number' => $purchase->trackingNumber,
'arrival_time' => $purchase->deliveryOption->humanArrivalTime,
]
);
return redirect('/inventory/sold')->withStatus("This item has been marked as dispatched and the buyer notified.");
}
|
php
|
public function postDispatched(Request $request)
{
$purchase = Purchase::findOrFail($request->input('purchase_id'));
if ($purchase->item->seller->userId != Auth::user()->userId) {
return redirect('/inventory/sold')->withErrors(["You are not seller of this item."]);
}
if ($purchase->isDispatched()) {
return redirect('/inventory/sold')->withErrors(["This item has already been marked as dispatched."]);
}
if (!$purchase->deliveryOption) {
return redirect('/inventory/sold')->withErrors(["This item is due to be collected."]);
}
$purchase->dispatched = time();
$purchase->trackingNumber = $request->input('tracking_number');
$purchase->save();
$purchase->buyer->sendEmail(
'Your item has been dispatched',
'emails.item.dispatched',
[
'item_name' => $purchase->item->name,
'delivery_service' => $purchase->deliveryOption->name,
'tracking_number' => $purchase->trackingNumber,
'arrival_time' => $purchase->deliveryOption->humanArrivalTime,
]
);
return redirect('/inventory/sold')->withStatus("This item has been marked as dispatched and the buyer notified.");
}
|
[
"public",
"function",
"postDispatched",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"purchase",
"=",
"Purchase",
"::",
"findOrFail",
"(",
"$",
"request",
"->",
"input",
"(",
"'purchase_id'",
")",
")",
";",
"if",
"(",
"$",
"purchase",
"->",
"item",
"->",
"seller",
"->",
"userId",
"!=",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withErrors",
"(",
"[",
"\"You are not seller of this item.\"",
"]",
")",
";",
"}",
"if",
"(",
"$",
"purchase",
"->",
"isDispatched",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withErrors",
"(",
"[",
"\"This item has already been marked as dispatched.\"",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"purchase",
"->",
"deliveryOption",
")",
"{",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withErrors",
"(",
"[",
"\"This item is due to be collected.\"",
"]",
")",
";",
"}",
"$",
"purchase",
"->",
"dispatched",
"=",
"time",
"(",
")",
";",
"$",
"purchase",
"->",
"trackingNumber",
"=",
"$",
"request",
"->",
"input",
"(",
"'tracking_number'",
")",
";",
"$",
"purchase",
"->",
"save",
"(",
")",
";",
"$",
"purchase",
"->",
"buyer",
"->",
"sendEmail",
"(",
"'Your item has been dispatched'",
",",
"'emails.item.dispatched'",
",",
"[",
"'item_name'",
"=>",
"$",
"purchase",
"->",
"item",
"->",
"name",
",",
"'delivery_service'",
"=>",
"$",
"purchase",
"->",
"deliveryOption",
"->",
"name",
",",
"'tracking_number'",
"=>",
"$",
"purchase",
"->",
"trackingNumber",
",",
"'arrival_time'",
"=>",
"$",
"purchase",
"->",
"deliveryOption",
"->",
"humanArrivalTime",
",",
"]",
")",
";",
"return",
"redirect",
"(",
"'/inventory/sold'",
")",
"->",
"withStatus",
"(",
"\"This item has been marked as dispatched and the buyer notified.\"",
")",
";",
"}"
] |
Mark a purchase dispatched.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\RedirectResponse
|
[
"Mark",
"a",
"purchase",
"dispatched",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L344-L377
|
236,309
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.paymentReceived
|
public static function paymentReceived(Purchase $purchase, $amount)
{
$purchase->received += $amount;
if ($purchase->received >= $purchase->grandTotal) {
$purchase->paid = time();
$purchase->item->seller->sendEmail(
'You have received a payment',
'emails.item.paid',
[
'total' => $purchase->received,
'item_name' => $purchase->item->name,
'buyer_name' => $purchase->name,
'buyer_street1' => $purchase->street1,
'buyer_street2' => $purchase->street2,
'buyer_city' => $purchase->city,
'buyer_county' => $purchase->county,
'buyer_postcode' => $purchase->postcode,
'buyer_country' => Iso3166::get($purchase->country)->name,
'has_delivery' => $purchase->hasDelivery(),
'has_address' => $purchase->hasAddress(),
'purchase_id' => $purchase->purchaseId,
'full' => $purchase->received == 0,
]
);
$purchase->buyer->sendEmail(
'Receipt for your item',
'emails.item.receipt',
[
'total' => $purchase->received,
'item_name' => $purchase->item->name,
'seller_name' => $purchase->name,
'seller_street1' => $purchase->street1,
'seller_street2' => $purchase->street2,
'seller_city' => $purchase->city,
'seller_county' => $purchase->county,
'seller_postcode' => $purchase->postcode,
'seller_country' => Iso3166::get($purchase->country)->name,
'full' => $purchase->received == 0,
'has_delivery' => $purchase->hasDelivery(),
'has_address' => $purchase->hasAddress(),
'is_paid' => $purchase->isPaid()
]
);
}
$purchase->save();
}
|
php
|
public static function paymentReceived(Purchase $purchase, $amount)
{
$purchase->received += $amount;
if ($purchase->received >= $purchase->grandTotal) {
$purchase->paid = time();
$purchase->item->seller->sendEmail(
'You have received a payment',
'emails.item.paid',
[
'total' => $purchase->received,
'item_name' => $purchase->item->name,
'buyer_name' => $purchase->name,
'buyer_street1' => $purchase->street1,
'buyer_street2' => $purchase->street2,
'buyer_city' => $purchase->city,
'buyer_county' => $purchase->county,
'buyer_postcode' => $purchase->postcode,
'buyer_country' => Iso3166::get($purchase->country)->name,
'has_delivery' => $purchase->hasDelivery(),
'has_address' => $purchase->hasAddress(),
'purchase_id' => $purchase->purchaseId,
'full' => $purchase->received == 0,
]
);
$purchase->buyer->sendEmail(
'Receipt for your item',
'emails.item.receipt',
[
'total' => $purchase->received,
'item_name' => $purchase->item->name,
'seller_name' => $purchase->name,
'seller_street1' => $purchase->street1,
'seller_street2' => $purchase->street2,
'seller_city' => $purchase->city,
'seller_county' => $purchase->county,
'seller_postcode' => $purchase->postcode,
'seller_country' => Iso3166::get($purchase->country)->name,
'full' => $purchase->received == 0,
'has_delivery' => $purchase->hasDelivery(),
'has_address' => $purchase->hasAddress(),
'is_paid' => $purchase->isPaid()
]
);
}
$purchase->save();
}
|
[
"public",
"static",
"function",
"paymentReceived",
"(",
"Purchase",
"$",
"purchase",
",",
"$",
"amount",
")",
"{",
"$",
"purchase",
"->",
"received",
"+=",
"$",
"amount",
";",
"if",
"(",
"$",
"purchase",
"->",
"received",
">=",
"$",
"purchase",
"->",
"grandTotal",
")",
"{",
"$",
"purchase",
"->",
"paid",
"=",
"time",
"(",
")",
";",
"$",
"purchase",
"->",
"item",
"->",
"seller",
"->",
"sendEmail",
"(",
"'You have received a payment'",
",",
"'emails.item.paid'",
",",
"[",
"'total'",
"=>",
"$",
"purchase",
"->",
"received",
",",
"'item_name'",
"=>",
"$",
"purchase",
"->",
"item",
"->",
"name",
",",
"'buyer_name'",
"=>",
"$",
"purchase",
"->",
"name",
",",
"'buyer_street1'",
"=>",
"$",
"purchase",
"->",
"street1",
",",
"'buyer_street2'",
"=>",
"$",
"purchase",
"->",
"street2",
",",
"'buyer_city'",
"=>",
"$",
"purchase",
"->",
"city",
",",
"'buyer_county'",
"=>",
"$",
"purchase",
"->",
"county",
",",
"'buyer_postcode'",
"=>",
"$",
"purchase",
"->",
"postcode",
",",
"'buyer_country'",
"=>",
"Iso3166",
"::",
"get",
"(",
"$",
"purchase",
"->",
"country",
")",
"->",
"name",
",",
"'has_delivery'",
"=>",
"$",
"purchase",
"->",
"hasDelivery",
"(",
")",
",",
"'has_address'",
"=>",
"$",
"purchase",
"->",
"hasAddress",
"(",
")",
",",
"'purchase_id'",
"=>",
"$",
"purchase",
"->",
"purchaseId",
",",
"'full'",
"=>",
"$",
"purchase",
"->",
"received",
"==",
"0",
",",
"]",
")",
";",
"$",
"purchase",
"->",
"buyer",
"->",
"sendEmail",
"(",
"'Receipt for your item'",
",",
"'emails.item.receipt'",
",",
"[",
"'total'",
"=>",
"$",
"purchase",
"->",
"received",
",",
"'item_name'",
"=>",
"$",
"purchase",
"->",
"item",
"->",
"name",
",",
"'seller_name'",
"=>",
"$",
"purchase",
"->",
"name",
",",
"'seller_street1'",
"=>",
"$",
"purchase",
"->",
"street1",
",",
"'seller_street2'",
"=>",
"$",
"purchase",
"->",
"street2",
",",
"'seller_city'",
"=>",
"$",
"purchase",
"->",
"city",
",",
"'seller_county'",
"=>",
"$",
"purchase",
"->",
"county",
",",
"'seller_postcode'",
"=>",
"$",
"purchase",
"->",
"postcode",
",",
"'seller_country'",
"=>",
"Iso3166",
"::",
"get",
"(",
"$",
"purchase",
"->",
"country",
")",
"->",
"name",
",",
"'full'",
"=>",
"$",
"purchase",
"->",
"received",
"==",
"0",
",",
"'has_delivery'",
"=>",
"$",
"purchase",
"->",
"hasDelivery",
"(",
")",
",",
"'has_address'",
"=>",
"$",
"purchase",
"->",
"hasAddress",
"(",
")",
",",
"'is_paid'",
"=>",
"$",
"purchase",
"->",
"isPaid",
"(",
")",
"]",
")",
";",
"}",
"$",
"purchase",
"->",
"save",
"(",
")",
";",
"}"
] |
Register a received amount against a purchase.
@param \Hamjoint\Mustard\Commerce\Purchase $purchase
@param float $amount
@return void
|
[
"Register",
"a",
"received",
"amount",
"against",
"a",
"purchase",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L464-L513
|
236,310
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.paymentRefunded
|
public static function paymentRefunded(Purchase $purchase, $amount)
{
$purchase->refunded = time();
$purchase->refundedAmount = $amount;
$purchase->buyer->sendEmail(
'You have been refunded',
'emails.item.refunded',
[
'total' => $purchase->refundedAmount,
'item_name' => $purchase->item->name,
]
);
$purchase->save();
}
|
php
|
public static function paymentRefunded(Purchase $purchase, $amount)
{
$purchase->refunded = time();
$purchase->refundedAmount = $amount;
$purchase->buyer->sendEmail(
'You have been refunded',
'emails.item.refunded',
[
'total' => $purchase->refundedAmount,
'item_name' => $purchase->item->name,
]
);
$purchase->save();
}
|
[
"public",
"static",
"function",
"paymentRefunded",
"(",
"Purchase",
"$",
"purchase",
",",
"$",
"amount",
")",
"{",
"$",
"purchase",
"->",
"refunded",
"=",
"time",
"(",
")",
";",
"$",
"purchase",
"->",
"refundedAmount",
"=",
"$",
"amount",
";",
"$",
"purchase",
"->",
"buyer",
"->",
"sendEmail",
"(",
"'You have been refunded'",
",",
"'emails.item.refunded'",
",",
"[",
"'total'",
"=>",
"$",
"purchase",
"->",
"refundedAmount",
",",
"'item_name'",
"=>",
"$",
"purchase",
"->",
"item",
"->",
"name",
",",
"]",
")",
";",
"$",
"purchase",
"->",
"save",
"(",
")",
";",
"}"
] |
Register a refunded amount against a purchase.
@param \Hamjoint\Mustard\Commerce\Purchase $purchase
@param float $amount
@return void
|
[
"Register",
"a",
"refunded",
"amount",
"against",
"a",
"purchase",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L522-L538
|
236,311
|
hamjoint/mustard-commerce
|
src/lib/Http/Controllers/PurchaseController.php
|
PurchaseController.paymentFailed
|
public static function paymentFailed(Purchase $purchase, $amount)
{
Log::info("Payment failed ({$purchase->purchaseId})");
$purchase->buyer->sendEmail(
'Your payment has failed',
'emails.item.failed',
[
'total' => $amount,
'item_name' => $purchase->item->name,
'payment_id' => $purchase->purchaseId,
]
);
}
|
php
|
public static function paymentFailed(Purchase $purchase, $amount)
{
Log::info("Payment failed ({$purchase->purchaseId})");
$purchase->buyer->sendEmail(
'Your payment has failed',
'emails.item.failed',
[
'total' => $amount,
'item_name' => $purchase->item->name,
'payment_id' => $purchase->purchaseId,
]
);
}
|
[
"public",
"static",
"function",
"paymentFailed",
"(",
"Purchase",
"$",
"purchase",
",",
"$",
"amount",
")",
"{",
"Log",
"::",
"info",
"(",
"\"Payment failed ({$purchase->purchaseId})\"",
")",
";",
"$",
"purchase",
"->",
"buyer",
"->",
"sendEmail",
"(",
"'Your payment has failed'",
",",
"'emails.item.failed'",
",",
"[",
"'total'",
"=>",
"$",
"amount",
",",
"'item_name'",
"=>",
"$",
"purchase",
"->",
"item",
"->",
"name",
",",
"'payment_id'",
"=>",
"$",
"purchase",
"->",
"purchaseId",
",",
"]",
")",
";",
"}"
] |
Register a failed amount against a purchase.
@param \Hamjoint\Mustard\Commerce\Purchase $purchase
@param float $amount
@return void
|
[
"Register",
"a",
"failed",
"amount",
"against",
"a",
"purchase",
"."
] |
886caeb5a88d827c8e9201e90020b64651dd87ad
|
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/Http/Controllers/PurchaseController.php#L547-L560
|
236,312
|
chestnut-framework/container
|
src/Container.php
|
Container.instance
|
public function instance($name, $instance) {
list($name, $alias) = $this->extractName($name);
$componentName = $this->getAlias($name);
if ($this->isSingleton($componentName) && $this->resolved($componentName)) {
throw new ComponentRegisterException('Can\'t register component, The ' . $name . ' component is singleton, and it had resolved');
}
if (!is_null($alias)) {
$this->alias($alias, $name);
}
$this->instances[$name] = $instance;
}
|
php
|
public function instance($name, $instance) {
list($name, $alias) = $this->extractName($name);
$componentName = $this->getAlias($name);
if ($this->isSingleton($componentName) && $this->resolved($componentName)) {
throw new ComponentRegisterException('Can\'t register component, The ' . $name . ' component is singleton, and it had resolved');
}
if (!is_null($alias)) {
$this->alias($alias, $name);
}
$this->instances[$name] = $instance;
}
|
[
"public",
"function",
"instance",
"(",
"$",
"name",
",",
"$",
"instance",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"alias",
")",
"=",
"$",
"this",
"->",
"extractName",
"(",
"$",
"name",
")",
";",
"$",
"componentName",
"=",
"$",
"this",
"->",
"getAlias",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isSingleton",
"(",
"$",
"componentName",
")",
"&&",
"$",
"this",
"->",
"resolved",
"(",
"$",
"componentName",
")",
")",
"{",
"throw",
"new",
"ComponentRegisterException",
"(",
"'Can\\'t register component, The '",
".",
"$",
"name",
".",
"' component is singleton, and it had resolved'",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"alias",
")",
")",
"{",
"$",
"this",
"->",
"alias",
"(",
"$",
"alias",
",",
"$",
"name",
")",
";",
"}",
"$",
"this",
"->",
"instances",
"[",
"$",
"name",
"]",
"=",
"$",
"instance",
";",
"}"
] |
Register component instance
@param string|array $name Component name
@param mixed $instance Component instance
@return void
|
[
"Register",
"component",
"instance"
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L101-L115
|
236,313
|
chestnut-framework/container
|
src/Container.php
|
Container.extend
|
public function extend($name, Closure $extender) {
$name = $this->getAlias($name);
$component = &$this->components[$name];
if (!isset($component['extender'])) {
$component['extender'] = [];
}
if ($this->isSingleton($name)) {
$component = $this->make($name);
$component = $this->resolveExtend($name, $component);
return $this->instance($name, $component);
}
array_push($component['extender'], $extender);
}
|
php
|
public function extend($name, Closure $extender) {
$name = $this->getAlias($name);
$component = &$this->components[$name];
if (!isset($component['extender'])) {
$component['extender'] = [];
}
if ($this->isSingleton($name)) {
$component = $this->make($name);
$component = $this->resolveExtend($name, $component);
return $this->instance($name, $component);
}
array_push($component['extender'], $extender);
}
|
[
"public",
"function",
"extend",
"(",
"$",
"name",
",",
"Closure",
"$",
"extender",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getAlias",
"(",
"$",
"name",
")",
";",
"$",
"component",
"=",
"&",
"$",
"this",
"->",
"components",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"component",
"[",
"'extender'",
"]",
")",
")",
"{",
"$",
"component",
"[",
"'extender'",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isSingleton",
"(",
"$",
"name",
")",
")",
"{",
"$",
"component",
"=",
"$",
"this",
"->",
"make",
"(",
"$",
"name",
")",
";",
"$",
"component",
"=",
"$",
"this",
"->",
"resolveExtend",
"(",
"$",
"name",
",",
"$",
"component",
")",
";",
"return",
"$",
"this",
"->",
"instance",
"(",
"$",
"name",
",",
"$",
"component",
")",
";",
"}",
"array_push",
"(",
"$",
"component",
"[",
"'extender'",
"]",
",",
"$",
"extender",
")",
";",
"}"
] |
Extend component.
If component is singleton, this method will resolve extend and return new instance.
@param string $name Component name
@param Closure $extender Component extender
@return void
|
[
"Extend",
"component",
".",
"If",
"component",
"is",
"singleton",
"this",
"method",
"will",
"resolve",
"extend",
"and",
"return",
"new",
"instance",
"."
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L125-L142
|
236,314
|
chestnut-framework/container
|
src/Container.php
|
Container.make
|
public function make($name, $parameters = []) {
$name = $this->getAlias($name);
if (is_string($name) && $this->resolved($name)) {
return $this->instances[$name];
}
if (is_callable($name) || (is_string($name) && !$this->registered($name))) {
return $this->build($name, $parameters ?: []);
}
list($builder, $singleton) = $this->extractComponentBuilder($name);
$component = $this->build($builder, $parameters);
if ($this->hasExtender($name)) {
$extenders = $this->getExtenders($name);
$component = $this->resolveExtend($component, $extenders);
}
if ($singleton) {
$this->instance($name, $component);
}
return $component;
}
|
php
|
public function make($name, $parameters = []) {
$name = $this->getAlias($name);
if (is_string($name) && $this->resolved($name)) {
return $this->instances[$name];
}
if (is_callable($name) || (is_string($name) && !$this->registered($name))) {
return $this->build($name, $parameters ?: []);
}
list($builder, $singleton) = $this->extractComponentBuilder($name);
$component = $this->build($builder, $parameters);
if ($this->hasExtender($name)) {
$extenders = $this->getExtenders($name);
$component = $this->resolveExtend($component, $extenders);
}
if ($singleton) {
$this->instance($name, $component);
}
return $component;
}
|
[
"public",
"function",
"make",
"(",
"$",
"name",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getAlias",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"name",
")",
"&&",
"$",
"this",
"->",
"resolved",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"instances",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"name",
")",
"||",
"(",
"is_string",
"(",
"$",
"name",
")",
"&&",
"!",
"$",
"this",
"->",
"registered",
"(",
"$",
"name",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"build",
"(",
"$",
"name",
",",
"$",
"parameters",
"?",
":",
"[",
"]",
")",
";",
"}",
"list",
"(",
"$",
"builder",
",",
"$",
"singleton",
")",
"=",
"$",
"this",
"->",
"extractComponentBuilder",
"(",
"$",
"name",
")",
";",
"$",
"component",
"=",
"$",
"this",
"->",
"build",
"(",
"$",
"builder",
",",
"$",
"parameters",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasExtender",
"(",
"$",
"name",
")",
")",
"{",
"$",
"extenders",
"=",
"$",
"this",
"->",
"getExtenders",
"(",
"$",
"name",
")",
";",
"$",
"component",
"=",
"$",
"this",
"->",
"resolveExtend",
"(",
"$",
"component",
",",
"$",
"extenders",
")",
";",
"}",
"if",
"(",
"$",
"singleton",
")",
"{",
"$",
"this",
"->",
"instance",
"(",
"$",
"name",
",",
"$",
"component",
")",
";",
"}",
"return",
"$",
"component",
";",
"}"
] |
Make component instance
@param string $name Component name
@param array $parameters Component parameter
@return mixed
|
[
"Make",
"component",
"instance"
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L151-L176
|
236,315
|
chestnut-framework/container
|
src/Container.php
|
Container.resolveExtend
|
public function resolveExtend($component, $extenders) {
foreach ($extenders as $extender) {
$component = $extender($component);
}
return $component;
}
|
php
|
public function resolveExtend($component, $extenders) {
foreach ($extenders as $extender) {
$component = $extender($component);
}
return $component;
}
|
[
"public",
"function",
"resolveExtend",
"(",
"$",
"component",
",",
"$",
"extenders",
")",
"{",
"foreach",
"(",
"$",
"extenders",
"as",
"$",
"extender",
")",
"{",
"$",
"component",
"=",
"$",
"extender",
"(",
"$",
"component",
")",
";",
"}",
"return",
"$",
"component",
";",
"}"
] |
Resolve component extention
@param mixed $component Component
@param Closure[] $extenders Component extenders
@return mixed
|
[
"Resolve",
"component",
"extention"
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L205-L211
|
236,316
|
chestnut-framework/container
|
src/Container.php
|
Container.extractComponentBuilder
|
protected function extractComponentBuilder($name) {
$componentBuilder = $this->components[$name];
if (!$componentBuilder) {
return [$name, false];
}
return [$componentBuilder['builder'], $componentBuilder['singleton']];
}
|
php
|
protected function extractComponentBuilder($name) {
$componentBuilder = $this->components[$name];
if (!$componentBuilder) {
return [$name, false];
}
return [$componentBuilder['builder'], $componentBuilder['singleton']];
}
|
[
"protected",
"function",
"extractComponentBuilder",
"(",
"$",
"name",
")",
"{",
"$",
"componentBuilder",
"=",
"$",
"this",
"->",
"components",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"!",
"$",
"componentBuilder",
")",
"{",
"return",
"[",
"$",
"name",
",",
"false",
"]",
";",
"}",
"return",
"[",
"$",
"componentBuilder",
"[",
"'builder'",
"]",
",",
"$",
"componentBuilder",
"[",
"'singleton'",
"]",
"]",
";",
"}"
] |
Extract component builder.
@param string $name Component name
@return array [componentBuilder, isSingleton]
|
[
"Extract",
"component",
"builder",
"."
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L218-L226
|
236,317
|
chestnut-framework/container
|
src/Container.php
|
Container.alias
|
public function alias($alias, $name) {
if (is_array($alias)) {
foreach ($alias as $key) {
$this->alias($key, $name);
}
return;
}
$this->aliases[$alias] = $name;
}
|
php
|
public function alias($alias, $name) {
if (is_array($alias)) {
foreach ($alias as $key) {
$this->alias($key, $name);
}
return;
}
$this->aliases[$alias] = $name;
}
|
[
"public",
"function",
"alias",
"(",
"$",
"alias",
",",
"$",
"name",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"alias",
")",
")",
"{",
"foreach",
"(",
"$",
"alias",
"as",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"alias",
"(",
"$",
"key",
",",
"$",
"name",
")",
";",
"}",
"return",
";",
"}",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"name",
";",
"}"
] |
Register component alias
@param string $alias Component alias
@param string $name Component name
@return void
|
[
"Register",
"component",
"alias"
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L235-L245
|
236,318
|
chestnut-framework/container
|
src/Container.php
|
Container.getAlias
|
public function getAlias($alias) {
if (!is_string($alias)) {
return $alias;
}
if (array_key_exists($alias, $this->aliases)) {
return $this->aliases[$alias];
}
return $alias;
}
|
php
|
public function getAlias($alias) {
if (!is_string($alias)) {
return $alias;
}
if (array_key_exists($alias, $this->aliases)) {
return $this->aliases[$alias];
}
return $alias;
}
|
[
"public",
"function",
"getAlias",
"(",
"$",
"alias",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"alias",
")",
")",
"{",
"return",
"$",
"alias",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"alias",
",",
"$",
"this",
"->",
"aliases",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
";",
"}",
"return",
"$",
"alias",
";",
"}"
] |
Get component name by alias
@param string $alias Component alias
@return string Component name
|
[
"Get",
"component",
"name",
"by",
"alias"
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L252-L262
|
236,319
|
chestnut-framework/container
|
src/Container.php
|
Container.registered
|
public function registered($name) {
$name = $this->getAlias($name);
return array_key_exists($name, $this->components);
}
|
php
|
public function registered($name) {
$name = $this->getAlias($name);
return array_key_exists($name, $this->components);
}
|
[
"public",
"function",
"registered",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getAlias",
"(",
"$",
"name",
")",
";",
"return",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"components",
")",
";",
"}"
] |
Determine component has been registered
@param string $name component name
@return boolean
|
[
"Determine",
"component",
"has",
"been",
"registered"
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L269-L273
|
236,320
|
chestnut-framework/container
|
src/Container.php
|
Container.resolved
|
public function resolved($name) {
$name = $this->getAlias($name);
return array_key_exists($name, $this->instances);
}
|
php
|
public function resolved($name) {
$name = $this->getAlias($name);
return array_key_exists($name, $this->instances);
}
|
[
"public",
"function",
"resolved",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getAlias",
"(",
"$",
"name",
")",
";",
"return",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"instances",
")",
";",
"}"
] |
Determine component has been resolved
@param string $name Component name
@return boolean
|
[
"Determine",
"component",
"has",
"been",
"resolved"
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L280-L284
|
236,321
|
chestnut-framework/container
|
src/Container.php
|
Container.extractName
|
private function extractName($name) {
if (is_string($name)) {
return [$name, null];
}
if (is_array($name)) {
return [key($name), current($name)];
}
throw new ComponentRegisterException('The services\'s name must be a string or an array, ' . gettype($name) . ' given.');
}
|
php
|
private function extractName($name) {
if (is_string($name)) {
return [$name, null];
}
if (is_array($name)) {
return [key($name), current($name)];
}
throw new ComponentRegisterException('The services\'s name must be a string or an array, ' . gettype($name) . ' given.');
}
|
[
"private",
"function",
"extractName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"return",
"[",
"$",
"name",
",",
"null",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"return",
"[",
"key",
"(",
"$",
"name",
")",
",",
"current",
"(",
"$",
"name",
")",
"]",
";",
"}",
"throw",
"new",
"ComponentRegisterException",
"(",
"'The services\\'s name must be a string or an array, '",
".",
"gettype",
"(",
"$",
"name",
")",
".",
"' given.'",
")",
";",
"}"
] |
Extract Name and Aliases.
@param string|array $name
@return array [$name, $aliases]
|
[
"Extract",
"Name",
"and",
"Aliases",
"."
] |
c64f09256ca316a64adc30c08c0457c49e974f66
|
https://github.com/chestnut-framework/container/blob/c64f09256ca316a64adc30c08c0457c49e974f66/src/Container.php#L374-L384
|
236,322
|
samurai-fw/samurai
|
src/Onikiri/Entity.php
|
Entity.getAttributes
|
public function getAttributes($updated = false)
{
if (! $updated) return $this->attributes;
$attributes = array();
foreach ($this->attributes as $key => $value) {
if (! array_key_exists($key, $this->o_attributes) || $value != $this->o_attributes[$key]) {
$attributes[$key] = $value;
}
}
return $attributes;
}
|
php
|
public function getAttributes($updated = false)
{
if (! $updated) return $this->attributes;
$attributes = array();
foreach ($this->attributes as $key => $value) {
if (! array_key_exists($key, $this->o_attributes) || $value != $this->o_attributes[$key]) {
$attributes[$key] = $value;
}
}
return $attributes;
}
|
[
"public",
"function",
"getAttributes",
"(",
"$",
"updated",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"updated",
")",
"return",
"$",
"this",
"->",
"attributes",
";",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"o_attributes",
")",
"||",
"$",
"value",
"!=",
"$",
"this",
"->",
"o_attributes",
"[",
"$",
"key",
"]",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"attributes",
";",
"}"
] |
get attributes.
@return array
|
[
"get",
"attributes",
"."
] |
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
|
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Onikiri/Entity.php#L207-L218
|
236,323
|
samurai-fw/samurai
|
src/Onikiri/Entity.php
|
Entity.toArray
|
public function toArray()
{
$args = func_get_args();
if ($args) {
$attributes = [];
foreach ($args as $key) {
if ($this->hasAttribute($key)) {
$attributes[$key] = $this->get($key);
}
}
return $attributes;
} else {
return $this->attributes;
}
}
|
php
|
public function toArray()
{
$args = func_get_args();
if ($args) {
$attributes = [];
foreach ($args as $key) {
if ($this->hasAttribute($key)) {
$attributes[$key] = $this->get($key);
}
}
return $attributes;
} else {
return $this->attributes;
}
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"$",
"args",
")",
"{",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasAttribute",
"(",
"$",
"key",
")",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"attributes",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"attributes",
";",
"}",
"}"
] |
convert to Array
@return array
|
[
"convert",
"to",
"Array"
] |
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
|
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Onikiri/Entity.php#L279-L293
|
236,324
|
hirnsturm/typo3-extbase-services
|
TYPO3/Extbase/Domain/Utility/EntityUtility.php
|
EntityUtility.mergeArrayIntoEntity
|
public static function mergeArrayIntoEntity($targetEntity, $array)
{
foreach ($array as $property => $value) {
if (!empty($value)) {
if (is_a($targetEntity->{'get' . ucfirst($property)}(),
'\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage')
) {
$targetEntity->{'set' . ucfirst($property)}(new ObjectStorage());
if (is_array($value)) {
$singular = (preg_match('~s$~i', $property) > 0) ? rtrim($property, 's') : sprintf('%ss',
$property);
foreach ($value as $item) {
$targetEntity->{'add' . ucfirst($singular)}($item);
}
}
} else {
$targetEntity->{'set' . ucfirst($property)}($value);
}
}
}
return $targetEntity;
}
|
php
|
public static function mergeArrayIntoEntity($targetEntity, $array)
{
foreach ($array as $property => $value) {
if (!empty($value)) {
if (is_a($targetEntity->{'get' . ucfirst($property)}(),
'\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage')
) {
$targetEntity->{'set' . ucfirst($property)}(new ObjectStorage());
if (is_array($value)) {
$singular = (preg_match('~s$~i', $property) > 0) ? rtrim($property, 's') : sprintf('%ss',
$property);
foreach ($value as $item) {
$targetEntity->{'add' . ucfirst($singular)}($item);
}
}
} else {
$targetEntity->{'set' . ucfirst($property)}($value);
}
}
}
return $targetEntity;
}
|
[
"public",
"static",
"function",
"mergeArrayIntoEntity",
"(",
"$",
"targetEntity",
",",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"targetEntity",
"->",
"{",
"'get'",
".",
"ucfirst",
"(",
"$",
"property",
")",
"}",
"(",
")",
",",
"'\\\\TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectStorage'",
")",
")",
"{",
"$",
"targetEntity",
"->",
"{",
"'set'",
".",
"ucfirst",
"(",
"$",
"property",
")",
"}",
"(",
"new",
"ObjectStorage",
"(",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"singular",
"=",
"(",
"preg_match",
"(",
"'~s$~i'",
",",
"$",
"property",
")",
">",
"0",
")",
"?",
"rtrim",
"(",
"$",
"property",
",",
"'s'",
")",
":",
"sprintf",
"(",
"'%ss'",
",",
"$",
"property",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"item",
")",
"{",
"$",
"targetEntity",
"->",
"{",
"'add'",
".",
"ucfirst",
"(",
"$",
"singular",
")",
"}",
"(",
"$",
"item",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"targetEntity",
"->",
"{",
"'set'",
".",
"ucfirst",
"(",
"$",
"property",
")",
"}",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}",
"return",
"$",
"targetEntity",
";",
"}"
] |
Merges array data into an entity
@param object $targetEntity
@param array $array
@return mixed
|
[
"Merges",
"array",
"data",
"into",
"an",
"entity"
] |
1cdb97eb260267ea5e5610e802d20a5453296bb1
|
https://github.com/hirnsturm/typo3-extbase-services/blob/1cdb97eb260267ea5e5610e802d20a5453296bb1/TYPO3/Extbase/Domain/Utility/EntityUtility.php#L41-L63
|
236,325
|
hirnsturm/typo3-extbase-services
|
TYPO3/Extbase/Domain/Utility/EntityUtility.php
|
EntityUtility.arrayToObjectStorage
|
public static function arrayToObjectStorage($entity, $array)
{
$storage = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
foreach ($array as $item) {
$storage->attach(EntityUtility::mergeArrayIntoEntity($entity, $item));
}
return $storage;
}
|
php
|
public static function arrayToObjectStorage($entity, $array)
{
$storage = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
foreach ($array as $item) {
$storage->attach(EntityUtility::mergeArrayIntoEntity($entity, $item));
}
return $storage;
}
|
[
"public",
"static",
"function",
"arrayToObjectStorage",
"(",
"$",
"entity",
",",
"$",
"array",
")",
"{",
"$",
"storage",
"=",
"GeneralUtility",
"::",
"makeInstance",
"(",
"'TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectStorage'",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"item",
")",
"{",
"$",
"storage",
"->",
"attach",
"(",
"EntityUtility",
"::",
"mergeArrayIntoEntity",
"(",
"$",
"entity",
",",
"$",
"item",
")",
")",
";",
"}",
"return",
"$",
"storage",
";",
"}"
] |
Transforms an array into ObjectStorage
@param $entity
@param $array
@return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
|
[
"Transforms",
"an",
"array",
"into",
"ObjectStorage"
] |
1cdb97eb260267ea5e5610e802d20a5453296bb1
|
https://github.com/hirnsturm/typo3-extbase-services/blob/1cdb97eb260267ea5e5610e802d20a5453296bb1/TYPO3/Extbase/Domain/Utility/EntityUtility.php#L72-L80
|
236,326
|
hirnsturm/typo3-extbase-services
|
TYPO3/Extbase/Domain/Utility/EntityUtility.php
|
EntityUtility.mergeEntities
|
public static function mergeEntities($targetEntity, $mergeEntity)
{
$reflect = new \ReflectionClass($mergeEntity);
$properties = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED);
foreach ($properties as $property) {
if (!method_exists($mergeEntity, 'get' . ucfirst($property->getName()))) {
continue;
}
$value = $mergeEntity->{'get' . ucfirst($property->getName())}();
if (is_a($value, '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage')) {
$targetEntity->{'set' . ucfirst($property->getName())}(new ObjectStorage());
$singular = (preg_match('~s$~i', $property->getName()) > 0)
? rtrim($property->getName(), 's')
: sprintf('%ss', $property->getName());
foreach ($value->toArray() as $item) {
$targetEntity->{'add' . ucfirst($singular)}($item);
}
} elseif (!empty(trim($value))) {
$targetEntity->{'set' . ucfirst($property->getName())}($value);
}
}
return $targetEntity;
}
|
php
|
public static function mergeEntities($targetEntity, $mergeEntity)
{
$reflect = new \ReflectionClass($mergeEntity);
$properties = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED);
foreach ($properties as $property) {
if (!method_exists($mergeEntity, 'get' . ucfirst($property->getName()))) {
continue;
}
$value = $mergeEntity->{'get' . ucfirst($property->getName())}();
if (is_a($value, '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage')) {
$targetEntity->{'set' . ucfirst($property->getName())}(new ObjectStorage());
$singular = (preg_match('~s$~i', $property->getName()) > 0)
? rtrim($property->getName(), 's')
: sprintf('%ss', $property->getName());
foreach ($value->toArray() as $item) {
$targetEntity->{'add' . ucfirst($singular)}($item);
}
} elseif (!empty(trim($value))) {
$targetEntity->{'set' . ucfirst($property->getName())}($value);
}
}
return $targetEntity;
}
|
[
"public",
"static",
"function",
"mergeEntities",
"(",
"$",
"targetEntity",
",",
"$",
"mergeEntity",
")",
"{",
"$",
"reflect",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"mergeEntity",
")",
";",
"$",
"properties",
"=",
"$",
"reflect",
"->",
"getProperties",
"(",
"\\",
"ReflectionProperty",
"::",
"IS_PUBLIC",
"|",
"\\",
"ReflectionProperty",
"::",
"IS_PROTECTED",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"mergeEntity",
",",
"'get'",
".",
"ucfirst",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"$",
"mergeEntity",
"->",
"{",
"'get'",
".",
"ucfirst",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
"}",
"(",
")",
";",
"if",
"(",
"is_a",
"(",
"$",
"value",
",",
"'\\\\TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectStorage'",
")",
")",
"{",
"$",
"targetEntity",
"->",
"{",
"'set'",
".",
"ucfirst",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
"}",
"(",
"new",
"ObjectStorage",
"(",
")",
")",
";",
"$",
"singular",
"=",
"(",
"preg_match",
"(",
"'~s$~i'",
",",
"$",
"property",
"->",
"getName",
"(",
")",
")",
">",
"0",
")",
"?",
"rtrim",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"'s'",
")",
":",
"sprintf",
"(",
"'%ss'",
",",
"$",
"property",
"->",
"getName",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"value",
"->",
"toArray",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"targetEntity",
"->",
"{",
"'add'",
".",
"ucfirst",
"(",
"$",
"singular",
")",
"}",
"(",
"$",
"item",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"trim",
"(",
"$",
"value",
")",
")",
")",
"{",
"$",
"targetEntity",
"->",
"{",
"'set'",
".",
"ucfirst",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
"}",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"targetEntity",
";",
"}"
] |
Merges two equal entities into the target entity
@param $targetEntity
@param $mergeEntity
@return mixed
|
[
"Merges",
"two",
"equal",
"entities",
"into",
"the",
"target",
"entity"
] |
1cdb97eb260267ea5e5610e802d20a5453296bb1
|
https://github.com/hirnsturm/typo3-extbase-services/blob/1cdb97eb260267ea5e5610e802d20a5453296bb1/TYPO3/Extbase/Domain/Utility/EntityUtility.php#L89-L116
|
236,327
|
renancavalieri/pollus-mvc
|
src/MvcApplication.php
|
MvcApplication.run
|
public function run()
{
if (PHP_SAPI === 'cli' && is_subclass_of($this, ConsoleAppInterface::class))
{
$this->execConsoleApp();
}
else if (is_subclass_of($this, WebAppInterface::class))
{
$this->execWebApp();
}
else
{
throw new \Exception("No interface was implemented");
}
}
|
php
|
public function run()
{
if (PHP_SAPI === 'cli' && is_subclass_of($this, ConsoleAppInterface::class))
{
$this->execConsoleApp();
}
else if (is_subclass_of($this, WebAppInterface::class))
{
$this->execWebApp();
}
else
{
throw new \Exception("No interface was implemented");
}
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"PHP_SAPI",
"===",
"'cli'",
"&&",
"is_subclass_of",
"(",
"$",
"this",
",",
"ConsoleAppInterface",
"::",
"class",
")",
")",
"{",
"$",
"this",
"->",
"execConsoleApp",
"(",
")",
";",
"}",
"else",
"if",
"(",
"is_subclass_of",
"(",
"$",
"this",
",",
"WebAppInterface",
"::",
"class",
")",
")",
"{",
"$",
"this",
"->",
"execWebApp",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No interface was implemented\"",
")",
";",
"}",
"}"
] |
Executes the application
|
[
"Executes",
"the",
"application"
] |
50876d24da643ddd397ebab8b7478feda7a2d476
|
https://github.com/renancavalieri/pollus-mvc/blob/50876d24da643ddd397ebab8b7478feda7a2d476/src/MvcApplication.php#L26-L40
|
236,328
|
renancavalieri/pollus-mvc
|
src/MvcApplication.php
|
MvcApplication.execWebApp
|
protected function execWebApp()
{
$config = $this->getConfigArray();
$container = new Container(["settings" => $config]);
$app = new App($container);
$this->setupDependencies($container);
$this->setupMiddlewares($app, $container);
$this->setupErrorHandler($container);
$this->setupRoutes($app, $container);
$app->run();
}
|
php
|
protected function execWebApp()
{
$config = $this->getConfigArray();
$container = new Container(["settings" => $config]);
$app = new App($container);
$this->setupDependencies($container);
$this->setupMiddlewares($app, $container);
$this->setupErrorHandler($container);
$this->setupRoutes($app, $container);
$app->run();
}
|
[
"protected",
"function",
"execWebApp",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfigArray",
"(",
")",
";",
"$",
"container",
"=",
"new",
"Container",
"(",
"[",
"\"settings\"",
"=>",
"$",
"config",
"]",
")",
";",
"$",
"app",
"=",
"new",
"App",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"setupDependencies",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"setupMiddlewares",
"(",
"$",
"app",
",",
"$",
"container",
")",
";",
"$",
"this",
"->",
"setupErrorHandler",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"setupRoutes",
"(",
"$",
"app",
",",
"$",
"container",
")",
";",
"$",
"app",
"->",
"run",
"(",
")",
";",
"}"
] |
Executes a web application
|
[
"Executes",
"a",
"web",
"application"
] |
50876d24da643ddd397ebab8b7478feda7a2d476
|
https://github.com/renancavalieri/pollus-mvc/blob/50876d24da643ddd397ebab8b7478feda7a2d476/src/MvcApplication.php#L45-L55
|
236,329
|
renancavalieri/pollus-mvc
|
src/MvcApplication.php
|
MvcApplication.execConsoleApp
|
protected function execConsoleApp()
{
$app = new Application();
$config = $this->getConfigArray();
$container = new Container(["settings" => $config]);
$this->setupDependencies($container);
$this->setupCommands($app, $container);
$app->run();
}
|
php
|
protected function execConsoleApp()
{
$app = new Application();
$config = $this->getConfigArray();
$container = new Container(["settings" => $config]);
$this->setupDependencies($container);
$this->setupCommands($app, $container);
$app->run();
}
|
[
"protected",
"function",
"execConsoleApp",
"(",
")",
"{",
"$",
"app",
"=",
"new",
"Application",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfigArray",
"(",
")",
";",
"$",
"container",
"=",
"new",
"Container",
"(",
"[",
"\"settings\"",
"=>",
"$",
"config",
"]",
")",
";",
"$",
"this",
"->",
"setupDependencies",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"setupCommands",
"(",
"$",
"app",
",",
"$",
"container",
")",
";",
"$",
"app",
"->",
"run",
"(",
")",
";",
"}"
] |
Executes a console application
|
[
"Executes",
"a",
"console",
"application"
] |
50876d24da643ddd397ebab8b7478feda7a2d476
|
https://github.com/renancavalieri/pollus-mvc/blob/50876d24da643ddd397ebab8b7478feda7a2d476/src/MvcApplication.php#L60-L68
|
236,330
|
arvici/framework
|
src/Arvici/Component/View/Render.php
|
Render.add
|
public function add(View $view)
{
// Append to the stack.
$this->stack->append($view);
if ($view->getType() === View::PART_BODY_PLACEHOLDER) {
$this->bodyKey = (count($this->stack) - 1);
}
return count($this->stack);
}
|
php
|
public function add(View $view)
{
// Append to the stack.
$this->stack->append($view);
if ($view->getType() === View::PART_BODY_PLACEHOLDER) {
$this->bodyKey = (count($this->stack) - 1);
}
return count($this->stack);
}
|
[
"public",
"function",
"add",
"(",
"View",
"$",
"view",
")",
"{",
"// Append to the stack.",
"$",
"this",
"->",
"stack",
"->",
"append",
"(",
"$",
"view",
")",
";",
"if",
"(",
"$",
"view",
"->",
"getType",
"(",
")",
"===",
"View",
"::",
"PART_BODY_PLACEHOLDER",
")",
"{",
"$",
"this",
"->",
"bodyKey",
"=",
"(",
"count",
"(",
"$",
"this",
"->",
"stack",
")",
"-",
"1",
")",
";",
"}",
"return",
"count",
"(",
"$",
"this",
"->",
"stack",
")",
";",
"}"
] |
Add a view instance to the stack.
@param View $view The view to add to the stack.
@return int number of views in the stack.
|
[
"Add",
"a",
"view",
"instance",
"to",
"the",
"stack",
"."
] |
4d0933912fef8f9edc756ef1ace009e96d9fc4b1
|
https://github.com/arvici/framework/blob/4d0933912fef8f9edc756ef1ace009e96d9fc4b1/src/Arvici/Component/View/Render.php#L67-L77
|
236,331
|
arvici/framework
|
src/Arvici/Component/View/Render.php
|
Render.body
|
public function body(View $view)
{
if ($view->getType() !== View::PART_BODY) {
throw new RendererException("You are replacing the body with a non-body view!");
}
if ($this->bodyKey === null) {
throw new RendererException("No body is defined in the template!");
}
$this->stack[$this->bodyKey] = $view;
}
|
php
|
public function body(View $view)
{
if ($view->getType() !== View::PART_BODY) {
throw new RendererException("You are replacing the body with a non-body view!");
}
if ($this->bodyKey === null) {
throw new RendererException("No body is defined in the template!");
}
$this->stack[$this->bodyKey] = $view;
}
|
[
"public",
"function",
"body",
"(",
"View",
"$",
"view",
")",
"{",
"if",
"(",
"$",
"view",
"->",
"getType",
"(",
")",
"!==",
"View",
"::",
"PART_BODY",
")",
"{",
"throw",
"new",
"RendererException",
"(",
"\"You are replacing the body with a non-body view!\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"bodyKey",
"===",
"null",
")",
"{",
"throw",
"new",
"RendererException",
"(",
"\"No body is defined in the template!\"",
")",
";",
"}",
"$",
"this",
"->",
"stack",
"[",
"$",
"this",
"->",
"bodyKey",
"]",
"=",
"$",
"view",
";",
"}"
] |
Set the body replacement view.
@param View $view body view
@throws RendererException
|
[
"Set",
"the",
"body",
"replacement",
"view",
"."
] |
4d0933912fef8f9edc756ef1ace009e96d9fc4b1
|
https://github.com/arvici/framework/blob/4d0933912fef8f9edc756ef1ace009e96d9fc4b1/src/Arvici/Component/View/Render.php#L102-L113
|
236,332
|
arvici/framework
|
src/Arvici/Component/View/Render.php
|
Render.hasBodyPlaceholderEmpty
|
public function hasBodyPlaceholderEmpty()
{
if ($this->bodyKey !== null) {
if (isset($this->stack[$this->bodyKey])) {
if ($this->stack[$this->bodyKey]->getType() === View::PART_BODY_PLACEHOLDER) {
return true;
}
}
}
return false;
}
|
php
|
public function hasBodyPlaceholderEmpty()
{
if ($this->bodyKey !== null) {
if (isset($this->stack[$this->bodyKey])) {
if ($this->stack[$this->bodyKey]->getType() === View::PART_BODY_PLACEHOLDER) {
return true;
}
}
}
return false;
}
|
[
"public",
"function",
"hasBodyPlaceholderEmpty",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bodyKey",
"!==",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"stack",
"[",
"$",
"this",
"->",
"bodyKey",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stack",
"[",
"$",
"this",
"->",
"bodyKey",
"]",
"->",
"getType",
"(",
")",
"===",
"View",
"::",
"PART_BODY_PLACEHOLDER",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if we have a body placeholder still empty.
@return bool
|
[
"Check",
"if",
"we",
"have",
"a",
"body",
"placeholder",
"still",
"empty",
"."
] |
4d0933912fef8f9edc756ef1ace009e96d9fc4b1
|
https://github.com/arvici/framework/blob/4d0933912fef8f9edc756ef1ace009e96d9fc4b1/src/Arvici/Component/View/Render.php#L131-L141
|
236,333
|
arvici/framework
|
src/Arvici/Component/View/Render.php
|
Render.replaceAll
|
public function replaceAll($stack, $resetBodyKey = true)
{
if (! $stack instanceof DataCollection) {
$stack = new DataCollection($stack);
}
$this->stack = $stack;
if ($resetBodyKey) {
$this->bodyKey = null;
foreach ($stack as $key => $view) {
if ($view->getType() === View::PART_BODY_PLACEHOLDER) {
$this->bodyKey = $key;
}
}
}
}
|
php
|
public function replaceAll($stack, $resetBodyKey = true)
{
if (! $stack instanceof DataCollection) {
$stack = new DataCollection($stack);
}
$this->stack = $stack;
if ($resetBodyKey) {
$this->bodyKey = null;
foreach ($stack as $key => $view) {
if ($view->getType() === View::PART_BODY_PLACEHOLDER) {
$this->bodyKey = $key;
}
}
}
}
|
[
"public",
"function",
"replaceAll",
"(",
"$",
"stack",
",",
"$",
"resetBodyKey",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"stack",
"instanceof",
"DataCollection",
")",
"{",
"$",
"stack",
"=",
"new",
"DataCollection",
"(",
"$",
"stack",
")",
";",
"}",
"$",
"this",
"->",
"stack",
"=",
"$",
"stack",
";",
"if",
"(",
"$",
"resetBodyKey",
")",
"{",
"$",
"this",
"->",
"bodyKey",
"=",
"null",
";",
"foreach",
"(",
"$",
"stack",
"as",
"$",
"key",
"=>",
"$",
"view",
")",
"{",
"if",
"(",
"$",
"view",
"->",
"getType",
"(",
")",
"===",
"View",
"::",
"PART_BODY_PLACEHOLDER",
")",
"{",
"$",
"this",
"->",
"bodyKey",
"=",
"$",
"key",
";",
"}",
"}",
"}",
"}"
] |
Replace all stack items for the array given
@param array|DataCollection $stack
@param bool $resetBodyKey Reset the body placeholder. Will reindex the new stack for it.
|
[
"Replace",
"all",
"stack",
"items",
"for",
"the",
"array",
"given"
] |
4d0933912fef8f9edc756ef1ace009e96d9fc4b1
|
https://github.com/arvici/framework/blob/4d0933912fef8f9edc756ef1ace009e96d9fc4b1/src/Arvici/Component/View/Render.php#L159-L176
|
236,334
|
arvici/framework
|
src/Arvici/Component/View/Render.php
|
Render.run
|
public function run($return = false)
{
$output = "";
foreach ($this->stack as $view) { /** @var View $view */
$data = $view->getData();
if (! is_array($data)) {
$data = array();
}
if ($view->getType() === View::PART_BODY_PLACEHOLDER) {
throw new RendererException("The body placeholder isn't replaced!"); // @codeCoverageIgnore
}
if (! empty($this->globalData)) {
$data = array_merge($data, $this->globalData);
}
$engineClass = $view->getEngine();
/** @var RendererInterface $engine */
$engine = $engineClass->newInstance();
if (! $engine instanceof RendererInterface) { // @codeCoverageIgnore
throw new RendererException("Engine is not instance of the RendererInterface."); // @codeCoverageIgnore
} // @codeCoverageIgnore
// Render it!
$output .= $engine->render($view, $data);
}
// If we need to return. Then just return it.
if ($return) {
return $output;
}
// Instead, create response object and return it.
return new Response($output, 200); // @codeCoverageIgnore
}
|
php
|
public function run($return = false)
{
$output = "";
foreach ($this->stack as $view) { /** @var View $view */
$data = $view->getData();
if (! is_array($data)) {
$data = array();
}
if ($view->getType() === View::PART_BODY_PLACEHOLDER) {
throw new RendererException("The body placeholder isn't replaced!"); // @codeCoverageIgnore
}
if (! empty($this->globalData)) {
$data = array_merge($data, $this->globalData);
}
$engineClass = $view->getEngine();
/** @var RendererInterface $engine */
$engine = $engineClass->newInstance();
if (! $engine instanceof RendererInterface) { // @codeCoverageIgnore
throw new RendererException("Engine is not instance of the RendererInterface."); // @codeCoverageIgnore
} // @codeCoverageIgnore
// Render it!
$output .= $engine->render($view, $data);
}
// If we need to return. Then just return it.
if ($return) {
return $output;
}
// Instead, create response object and return it.
return new Response($output, 200); // @codeCoverageIgnore
}
|
[
"public",
"function",
"run",
"(",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"output",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"stack",
"as",
"$",
"view",
")",
"{",
"/** @var View $view */",
"$",
"data",
"=",
"$",
"view",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"view",
"->",
"getType",
"(",
")",
"===",
"View",
"::",
"PART_BODY_PLACEHOLDER",
")",
"{",
"throw",
"new",
"RendererException",
"(",
"\"The body placeholder isn't replaced!\"",
")",
";",
"// @codeCoverageIgnore",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"globalData",
")",
")",
"{",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"globalData",
")",
";",
"}",
"$",
"engineClass",
"=",
"$",
"view",
"->",
"getEngine",
"(",
")",
";",
"/** @var RendererInterface $engine */",
"$",
"engine",
"=",
"$",
"engineClass",
"->",
"newInstance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"engine",
"instanceof",
"RendererInterface",
")",
"{",
"// @codeCoverageIgnore",
"throw",
"new",
"RendererException",
"(",
"\"Engine is not instance of the RendererInterface.\"",
")",
";",
"// @codeCoverageIgnore",
"}",
"// @codeCoverageIgnore",
"// Render it!",
"$",
"output",
".=",
"$",
"engine",
"->",
"render",
"(",
"$",
"view",
",",
"$",
"data",
")",
";",
"}",
"// If we need to return. Then just return it.",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"output",
";",
"}",
"// Instead, create response object and return it.",
"return",
"new",
"Response",
"(",
"$",
"output",
",",
"200",
")",
";",
"// @codeCoverageIgnore",
"}"
] |
Render all views in the stack.
@param bool $return Return the rendered output?
@return Response|string
@throws RendererException
|
[
"Render",
"all",
"views",
"in",
"the",
"stack",
"."
] |
4d0933912fef8f9edc756ef1ace009e96d9fc4b1
|
https://github.com/arvici/framework/blob/4d0933912fef8f9edc756ef1ace009e96d9fc4b1/src/Arvici/Component/View/Render.php#L187-L225
|
236,335
|
rafaelbeecker/phpbreaker
|
src/Exceptions/ExceptionTrait.php
|
ExceptionTrait.setExceptionDetails
|
protected function setExceptionDetails(string $reason, int $code, array $stack = [])
{
$this->setErrorDetails($reason, $code);
$this->setDebugDetails($stack);
}
|
php
|
protected function setExceptionDetails(string $reason, int $code, array $stack = [])
{
$this->setErrorDetails($reason, $code);
$this->setDebugDetails($stack);
}
|
[
"protected",
"function",
"setExceptionDetails",
"(",
"string",
"$",
"reason",
",",
"int",
"$",
"code",
",",
"array",
"$",
"stack",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setErrorDetails",
"(",
"$",
"reason",
",",
"$",
"code",
")",
";",
"$",
"this",
"->",
"setDebugDetails",
"(",
"$",
"stack",
")",
";",
"}"
] |
Set the exception details, building its error and debug entry.
@param string $reason
@param int $code
@param array $stack
|
[
"Set",
"the",
"exception",
"details",
"building",
"its",
"error",
"and",
"debug",
"entry",
"."
] |
12965552d889dd3eafe9bea3f11c3fa512e23f28
|
https://github.com/rafaelbeecker/phpbreaker/blob/12965552d889dd3eafe9bea3f11c3fa512e23f28/src/Exceptions/ExceptionTrait.php#L193-L198
|
236,336
|
rafaelbeecker/phpbreaker
|
src/Exceptions/ExceptionTrait.php
|
ExceptionTrait.setDebugDetails
|
protected function setDebugDetails(array $stack)
{
$stackInfo = new StackInfo($stack);
$this->setDebug(ArrayContainer::make([
'class' => $stackInfo->getClassNameFromLastStack(),
'method' => $stackInfo->getMethodNameFromLastStack(),
'args' => $stackInfo->getArgsFromLastStack(),
]));
}
|
php
|
protected function setDebugDetails(array $stack)
{
$stackInfo = new StackInfo($stack);
$this->setDebug(ArrayContainer::make([
'class' => $stackInfo->getClassNameFromLastStack(),
'method' => $stackInfo->getMethodNameFromLastStack(),
'args' => $stackInfo->getArgsFromLastStack(),
]));
}
|
[
"protected",
"function",
"setDebugDetails",
"(",
"array",
"$",
"stack",
")",
"{",
"$",
"stackInfo",
"=",
"new",
"StackInfo",
"(",
"$",
"stack",
")",
";",
"$",
"this",
"->",
"setDebug",
"(",
"ArrayContainer",
"::",
"make",
"(",
"[",
"'class'",
"=>",
"$",
"stackInfo",
"->",
"getClassNameFromLastStack",
"(",
")",
",",
"'method'",
"=>",
"$",
"stackInfo",
"->",
"getMethodNameFromLastStack",
"(",
")",
",",
"'args'",
"=>",
"$",
"stackInfo",
"->",
"getArgsFromLastStack",
"(",
")",
",",
"]",
")",
")",
";",
"}"
] |
Set the exception debug details
@param array $stack
|
[
"Set",
"the",
"exception",
"debug",
"details"
] |
12965552d889dd3eafe9bea3f11c3fa512e23f28
|
https://github.com/rafaelbeecker/phpbreaker/blob/12965552d889dd3eafe9bea3f11c3fa512e23f28/src/Exceptions/ExceptionTrait.php#L205-L213
|
236,337
|
rafaelbeecker/phpbreaker
|
src/Exceptions/ExceptionTrait.php
|
ExceptionTrait.setErrorDetails
|
protected function setErrorDetails(string $reason, int $code)
{
$this->setError(ArrayContainer::make([
'code' => $code,
'message' => $reason,
]));
}
|
php
|
protected function setErrorDetails(string $reason, int $code)
{
$this->setError(ArrayContainer::make([
'code' => $code,
'message' => $reason,
]));
}
|
[
"protected",
"function",
"setErrorDetails",
"(",
"string",
"$",
"reason",
",",
"int",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"ArrayContainer",
"::",
"make",
"(",
"[",
"'code'",
"=>",
"$",
"code",
",",
"'message'",
"=>",
"$",
"reason",
",",
"]",
")",
")",
";",
"}"
] |
Set the exception error details
@param string $reason
@param int $code
|
[
"Set",
"the",
"exception",
"error",
"details"
] |
12965552d889dd3eafe9bea3f11c3fa512e23f28
|
https://github.com/rafaelbeecker/phpbreaker/blob/12965552d889dd3eafe9bea3f11c3fa512e23f28/src/Exceptions/ExceptionTrait.php#L221-L227
|
236,338
|
glendmaatita/Tolkien
|
src/Tolkien/Model/Post.php
|
Post.setUrl
|
public function setUrl($date, $urlFormat = ':year/:month/:date/:title')
{
// $this->url = '/' . implode('/', explode('-', $this->getFileName(), 4)) . '.html';
$year = date('Y', strtotime($date));
$month = date('m', strtotime($date));
$day = date('d', strtotime($date));
$title = explode('-', $this->getFileName(), 4);
// replacing variable in the comment above with proper value
$this->url = '/' . str_replace(array(':date', ':month', ':year', ':title'), array($day, $month, $year, $title[3] . '.html'), $urlFormat);
}
|
php
|
public function setUrl($date, $urlFormat = ':year/:month/:date/:title')
{
// $this->url = '/' . implode('/', explode('-', $this->getFileName(), 4)) . '.html';
$year = date('Y', strtotime($date));
$month = date('m', strtotime($date));
$day = date('d', strtotime($date));
$title = explode('-', $this->getFileName(), 4);
// replacing variable in the comment above with proper value
$this->url = '/' . str_replace(array(':date', ':month', ':year', ':title'), array($day, $month, $year, $title[3] . '.html'), $urlFormat);
}
|
[
"public",
"function",
"setUrl",
"(",
"$",
"date",
",",
"$",
"urlFormat",
"=",
"':year/:month/:date/:title'",
")",
"{",
"// $this->url = '/' . implode('/', explode('-', $this->getFileName(), 4)) . '.html';",
"$",
"year",
"=",
"date",
"(",
"'Y'",
",",
"strtotime",
"(",
"$",
"date",
")",
")",
";",
"$",
"month",
"=",
"date",
"(",
"'m'",
",",
"strtotime",
"(",
"$",
"date",
")",
")",
";",
"$",
"day",
"=",
"date",
"(",
"'d'",
",",
"strtotime",
"(",
"$",
"date",
")",
")",
";",
"$",
"title",
"=",
"explode",
"(",
"'-'",
",",
"$",
"this",
"->",
"getFileName",
"(",
")",
",",
"4",
")",
";",
"// replacing variable in the comment above with proper value",
"$",
"this",
"->",
"url",
"=",
"'/'",
".",
"str_replace",
"(",
"array",
"(",
"':date'",
",",
"':month'",
",",
"':year'",
",",
"':title'",
")",
",",
"array",
"(",
"$",
"day",
",",
"$",
"month",
",",
"$",
"year",
",",
"$",
"title",
"[",
"3",
"]",
".",
"'.html'",
")",
",",
"$",
"urlFormat",
")",
";",
"}"
] |
Set URL to Post
URL format is set in post file, with such variable that can be used
:date, :month, :year -> taken from date section
:title -> title of file, taken from filename
@param string $urlFormat
@param string $date
@return void
|
[
"Set",
"URL",
"to",
"Post"
] |
e7c27a103f1a87411dfb8eef626cba381b27d233
|
https://github.com/glendmaatita/Tolkien/blob/e7c27a103f1a87411dfb8eef626cba381b27d233/src/Tolkien/Model/Post.php#L179-L190
|
236,339
|
yii2-tools/yii2-base
|
components/PathFilter.php
|
PathFilter.buildFilterCallback
|
public function buildFilterCallback(array $except = [])
{
$filter = $this;
return function ($path) use ($filter, $except) {
return !$filter->filter([$path], $except, true);
};
}
|
php
|
public function buildFilterCallback(array $except = [])
{
$filter = $this;
return function ($path) use ($filter, $except) {
return !$filter->filter([$path], $except, true);
};
}
|
[
"public",
"function",
"buildFilterCallback",
"(",
"array",
"$",
"except",
"=",
"[",
"]",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
";",
"return",
"function",
"(",
"$",
"path",
")",
"use",
"(",
"$",
"filter",
",",
"$",
"except",
")",
"{",
"return",
"!",
"$",
"filter",
"->",
"filter",
"(",
"[",
"$",
"path",
"]",
",",
"$",
"except",
",",
"true",
")",
";",
"}",
";",
"}"
] |
Returns callable which can be used by third-party code
for determining what some file should be excluded from result set.
Callable signature support $path parameter:
```
function ($path) {
...
}
```
@param array $except
@return callable
|
[
"Returns",
"callable",
"which",
"can",
"be",
"used",
"by",
"third",
"-",
"party",
"code",
"for",
"determining",
"what",
"some",
"file",
"should",
"be",
"excluded",
"from",
"result",
"set",
"."
] |
10f6bb6b0b9396c3d942e0f2ec06784fa9bbf72a
|
https://github.com/yii2-tools/yii2-base/blob/10f6bb6b0b9396c3d942e0f2ec06784fa9bbf72a/components/PathFilter.php#L112-L119
|
236,340
|
nano7/Database
|
src/Connection.php
|
Connection.getCollections
|
public function getCollections($options = [])
{
$list = [];
foreach ($this->db->listCollections($options) as $coll) {
$list[] = $coll->getName();
}
return $list;
}
|
php
|
public function getCollections($options = [])
{
$list = [];
foreach ($this->db->listCollections($options) as $coll) {
$list[] = $coll->getName();
}
return $list;
}
|
[
"public",
"function",
"getCollections",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"db",
"->",
"listCollections",
"(",
"$",
"options",
")",
"as",
"$",
"coll",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"coll",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
Get collections list.
@param array $options
@return array
|
[
"Get",
"collections",
"list",
"."
] |
7d8c10af415c469a317f40471f657104e4d5b52a
|
https://github.com/nano7/Database/blob/7d8c10af415c469a317f40471f657104e4d5b52a/src/Connection.php#L68-L76
|
236,341
|
nano7/Database
|
src/Connection.php
|
Connection.collection
|
public function collection($name)
{
$builder = new Builder($this, $name, $this->db->selectCollection($name));
return $builder;
}
|
php
|
public function collection($name)
{
$builder = new Builder($this, $name, $this->db->selectCollection($name));
return $builder;
}
|
[
"public",
"function",
"collection",
"(",
"$",
"name",
")",
"{",
"$",
"builder",
"=",
"new",
"Builder",
"(",
"$",
"this",
",",
"$",
"name",
",",
"$",
"this",
"->",
"db",
"->",
"selectCollection",
"(",
"$",
"name",
")",
")",
";",
"return",
"$",
"builder",
";",
"}"
] |
Get collection by name.
@param $name
@return Builder
|
[
"Get",
"collection",
"by",
"name",
"."
] |
7d8c10af415c469a317f40471f657104e4d5b52a
|
https://github.com/nano7/Database/blob/7d8c10af415c469a317f40471f657104e4d5b52a/src/Connection.php#L84-L89
|
236,342
|
nano7/Database
|
src/Connection.php
|
Connection.getIndexs
|
public function getIndexs($collection, $options = [])
{
if (! $this->hasCollection($collection)) {
return [];
}
$list = [];
foreach ($this->db->selectCollection($collection)->listIndexes($options) as $index) {
$list[] = $index->getName();
}
return $list;
}
|
php
|
public function getIndexs($collection, $options = [])
{
if (! $this->hasCollection($collection)) {
return [];
}
$list = [];
foreach ($this->db->selectCollection($collection)->listIndexes($options) as $index) {
$list[] = $index->getName();
}
return $list;
}
|
[
"public",
"function",
"getIndexs",
"(",
"$",
"collection",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCollection",
"(",
"$",
"collection",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"db",
"->",
"selectCollection",
"(",
"$",
"collection",
")",
"->",
"listIndexes",
"(",
"$",
"options",
")",
"as",
"$",
"index",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"index",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
Get index list in collection.
@param string $collection
@param array $options
@return array
|
[
"Get",
"index",
"list",
"in",
"collection",
"."
] |
7d8c10af415c469a317f40471f657104e4d5b52a
|
https://github.com/nano7/Database/blob/7d8c10af415c469a317f40471f657104e4d5b52a/src/Connection.php#L132-L144
|
236,343
|
nano7/Database
|
src/Connection.php
|
Connection.createIndex
|
public function createIndex($collection, $columns, array $options = [])
{
$col = $this->db->selectCollection($collection);
return $col->createIndex($columns, $options);
}
|
php
|
public function createIndex($collection, $columns, array $options = [])
{
$col = $this->db->selectCollection($collection);
return $col->createIndex($columns, $options);
}
|
[
"public",
"function",
"createIndex",
"(",
"$",
"collection",
",",
"$",
"columns",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"col",
"=",
"$",
"this",
"->",
"db",
"->",
"selectCollection",
"(",
"$",
"collection",
")",
";",
"return",
"$",
"col",
"->",
"createIndex",
"(",
"$",
"columns",
",",
"$",
"options",
")",
";",
"}"
] |
Create new index.
@param $collection
@param $columns
@param array $options
@return string
|
[
"Create",
"new",
"index",
"."
] |
7d8c10af415c469a317f40471f657104e4d5b52a
|
https://github.com/nano7/Database/blob/7d8c10af415c469a317f40471f657104e4d5b52a/src/Connection.php#L154-L159
|
236,344
|
nano7/Database
|
src/Connection.php
|
Connection.dropIndex
|
public function dropIndex($collection, $indexName, array $options = [])
{
$col = $this->db->selectCollection($collection);
return $col->dropIndex($indexName, $options);
}
|
php
|
public function dropIndex($collection, $indexName, array $options = [])
{
$col = $this->db->selectCollection($collection);
return $col->dropIndex($indexName, $options);
}
|
[
"public",
"function",
"dropIndex",
"(",
"$",
"collection",
",",
"$",
"indexName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"col",
"=",
"$",
"this",
"->",
"db",
"->",
"selectCollection",
"(",
"$",
"collection",
")",
";",
"return",
"$",
"col",
"->",
"dropIndex",
"(",
"$",
"indexName",
",",
"$",
"options",
")",
";",
"}"
] |
Drop a index.
@param $collection
@param $indexName
@param array $options
@return array|object
|
[
"Drop",
"a",
"index",
"."
] |
7d8c10af415c469a317f40471f657104e4d5b52a
|
https://github.com/nano7/Database/blob/7d8c10af415c469a317f40471f657104e4d5b52a/src/Connection.php#L169-L174
|
236,345
|
nano7/Database
|
src/Connection.php
|
Connection.createClient
|
protected function createClient($dsn, array $config, array $options)
{
// By default driver options is an empty array.
$driverOptions = [];
if (isset($config['driver_options']) && is_array($config['driver_options'])) {
$driverOptions = $config['driver_options'];
}
// Check if the credentials are not already set in the options
if (!isset($options['username']) && !empty($config['username'])) {
$options['username'] = $config['username'];
}
if (!isset($options['password']) && !empty($config['password'])) {
$options['password'] = $config['password'];
}
return new Client($dsn, $options, $driverOptions);
}
|
php
|
protected function createClient($dsn, array $config, array $options)
{
// By default driver options is an empty array.
$driverOptions = [];
if (isset($config['driver_options']) && is_array($config['driver_options'])) {
$driverOptions = $config['driver_options'];
}
// Check if the credentials are not already set in the options
if (!isset($options['username']) && !empty($config['username'])) {
$options['username'] = $config['username'];
}
if (!isset($options['password']) && !empty($config['password'])) {
$options['password'] = $config['password'];
}
return new Client($dsn, $options, $driverOptions);
}
|
[
"protected",
"function",
"createClient",
"(",
"$",
"dsn",
",",
"array",
"$",
"config",
",",
"array",
"$",
"options",
")",
"{",
"// By default driver options is an empty array.",
"$",
"driverOptions",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'driver_options'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'driver_options'",
"]",
")",
")",
"{",
"$",
"driverOptions",
"=",
"$",
"config",
"[",
"'driver_options'",
"]",
";",
"}",
"// Check if the credentials are not already set in the options",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'username'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"config",
"[",
"'username'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'username'",
"]",
"=",
"$",
"config",
"[",
"'username'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'password'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"config",
"[",
"'password'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'password'",
"]",
"=",
"$",
"config",
"[",
"'password'",
"]",
";",
"}",
"return",
"new",
"Client",
"(",
"$",
"dsn",
",",
"$",
"options",
",",
"$",
"driverOptions",
")",
";",
"}"
] |
Create a new MongoDB client connection.
@param string $dsn
@param array $config
@param array $options
@return Client
|
[
"Create",
"a",
"new",
"MongoDB",
"client",
"connection",
"."
] |
7d8c10af415c469a317f40471f657104e4d5b52a
|
https://github.com/nano7/Database/blob/7d8c10af415c469a317f40471f657104e4d5b52a/src/Connection.php#L204-L222
|
236,346
|
MLukman/Securilex
|
src/Firewall.php
|
Firewall.isPathCovered
|
public function isPathCovered($path)
{
foreach ($this->patterns as $pattern) {
if (1 === preg_match('{'.$pattern.'}', $path)) {
return true;
}
}
return false;
}
|
php
|
public function isPathCovered($path)
{
foreach ($this->patterns as $pattern) {
if (1 === preg_match('{'.$pattern.'}', $path)) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"isPathCovered",
"(",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"patterns",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"1",
"===",
"preg_match",
"(",
"'{'",
".",
"$",
"pattern",
".",
"'}'",
",",
"$",
"path",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if the provided path is covered by this firewall or not
@param string $path
@return boolean
|
[
"Check",
"if",
"the",
"provided",
"path",
"is",
"covered",
"by",
"this",
"firewall",
"or",
"not"
] |
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
|
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Firewall.php#L126-L134
|
236,347
|
MLukman/Securilex
|
src/Firewall.php
|
Firewall.addAuthenticationFactory
|
public function addAuthenticationFactory(AuthenticationFactoryInterface $authFactory,
UserProviderInterface $userProvider)
{
$id = $authFactory->getId();
$this->authFactories[$id] = array(
'factory' => $authFactory,
'userProvider' => $userProvider,
);
$this->userProviders[] = $userProvider;
if ($this->provider) {
$this->registerAuthenticationFactory($this->provider->getApp(), $id, $authFactory, $userProvider);
}
return $this;
}
|
php
|
public function addAuthenticationFactory(AuthenticationFactoryInterface $authFactory,
UserProviderInterface $userProvider)
{
$id = $authFactory->getId();
$this->authFactories[$id] = array(
'factory' => $authFactory,
'userProvider' => $userProvider,
);
$this->userProviders[] = $userProvider;
if ($this->provider) {
$this->registerAuthenticationFactory($this->provider->getApp(), $id, $authFactory, $userProvider);
}
return $this;
}
|
[
"public",
"function",
"addAuthenticationFactory",
"(",
"AuthenticationFactoryInterface",
"$",
"authFactory",
",",
"UserProviderInterface",
"$",
"userProvider",
")",
"{",
"$",
"id",
"=",
"$",
"authFactory",
"->",
"getId",
"(",
")",
";",
"$",
"this",
"->",
"authFactories",
"[",
"$",
"id",
"]",
"=",
"array",
"(",
"'factory'",
"=>",
"$",
"authFactory",
",",
"'userProvider'",
"=>",
"$",
"userProvider",
",",
")",
";",
"$",
"this",
"->",
"userProviders",
"[",
"]",
"=",
"$",
"userProvider",
";",
"if",
"(",
"$",
"this",
"->",
"provider",
")",
"{",
"$",
"this",
"->",
"registerAuthenticationFactory",
"(",
"$",
"this",
"->",
"provider",
"->",
"getApp",
"(",
")",
",",
"$",
"id",
",",
"$",
"authFactory",
",",
"$",
"userProvider",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add additional authentication factory and corresponding user provider.
@param AuthenticationFactoryInterface $authFactory
@param UserProviderInterface $userProvider
@return $this Returning $this to allow method chaining
|
[
"Add",
"additional",
"authentication",
"factory",
"and",
"corresponding",
"user",
"provider",
"."
] |
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
|
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Firewall.php#L160-L177
|
236,348
|
MLukman/Securilex
|
src/Firewall.php
|
Firewall.register
|
public function register(SecurityServiceProvider $provider)
{
$this->provider = $provider;
if ($this->loginPath) {
$this->provider->addUnsecurePattern("^{$this->loginPath}$");
}
$config = array(
'logout' => array('logout_path' => $this->logoutPath),
'pattern' => implode('|', $this->patterns)
);
$app = $this->provider->getApp();
foreach ($this->authFactories as $id => $authFactory) {
$this->registerAuthenticationFactory($app, $id, $authFactory['factory'], $authFactory['userProvider']);
$config[$id] = array();
if ($this->loginPath) {
$config[$id]['login_path'] = $this->loginPath;
$config[$id]['check_path'] = $this->loginCheckPath;
}
}
$this->registerUserProvider($app);
$this->registerContextListener($app);
$this->registerEntryPoint($app);
$this->provider->appendFirewallConfig($this->name, $config);
}
|
php
|
public function register(SecurityServiceProvider $provider)
{
$this->provider = $provider;
if ($this->loginPath) {
$this->provider->addUnsecurePattern("^{$this->loginPath}$");
}
$config = array(
'logout' => array('logout_path' => $this->logoutPath),
'pattern' => implode('|', $this->patterns)
);
$app = $this->provider->getApp();
foreach ($this->authFactories as $id => $authFactory) {
$this->registerAuthenticationFactory($app, $id, $authFactory['factory'], $authFactory['userProvider']);
$config[$id] = array();
if ($this->loginPath) {
$config[$id]['login_path'] = $this->loginPath;
$config[$id]['check_path'] = $this->loginCheckPath;
}
}
$this->registerUserProvider($app);
$this->registerContextListener($app);
$this->registerEntryPoint($app);
$this->provider->appendFirewallConfig($this->name, $config);
}
|
[
"public",
"function",
"register",
"(",
"SecurityServiceProvider",
"$",
"provider",
")",
"{",
"$",
"this",
"->",
"provider",
"=",
"$",
"provider",
";",
"if",
"(",
"$",
"this",
"->",
"loginPath",
")",
"{",
"$",
"this",
"->",
"provider",
"->",
"addUnsecurePattern",
"(",
"\"^{$this->loginPath}$\"",
")",
";",
"}",
"$",
"config",
"=",
"array",
"(",
"'logout'",
"=>",
"array",
"(",
"'logout_path'",
"=>",
"$",
"this",
"->",
"logoutPath",
")",
",",
"'pattern'",
"=>",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"patterns",
")",
")",
";",
"$",
"app",
"=",
"$",
"this",
"->",
"provider",
"->",
"getApp",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"authFactories",
"as",
"$",
"id",
"=>",
"$",
"authFactory",
")",
"{",
"$",
"this",
"->",
"registerAuthenticationFactory",
"(",
"$",
"app",
",",
"$",
"id",
",",
"$",
"authFactory",
"[",
"'factory'",
"]",
",",
"$",
"authFactory",
"[",
"'userProvider'",
"]",
")",
";",
"$",
"config",
"[",
"$",
"id",
"]",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"loginPath",
")",
"{",
"$",
"config",
"[",
"$",
"id",
"]",
"[",
"'login_path'",
"]",
"=",
"$",
"this",
"->",
"loginPath",
";",
"$",
"config",
"[",
"$",
"id",
"]",
"[",
"'check_path'",
"]",
"=",
"$",
"this",
"->",
"loginCheckPath",
";",
"}",
"}",
"$",
"this",
"->",
"registerUserProvider",
"(",
"$",
"app",
")",
";",
"$",
"this",
"->",
"registerContextListener",
"(",
"$",
"app",
")",
";",
"$",
"this",
"->",
"registerEntryPoint",
"(",
"$",
"app",
")",
";",
"$",
"this",
"->",
"provider",
"->",
"appendFirewallConfig",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"config",
")",
";",
"}"
] |
Register the Firewall
@param SecurityServiceProvider $provider Service Provider
|
[
"Register",
"the",
"Firewall"
] |
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
|
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Firewall.php#L193-L222
|
236,349
|
MLukman/Securilex
|
src/Firewall.php
|
Firewall.registerAuthenticationFactory
|
protected function registerAuthenticationFactory(\Silex\Application $app,
$id,
AuthenticationFactoryInterface $authFactory,
UserProviderInterface $userProvider)
{
$fac = 'security.authentication_listener.factory.'.$id;
if (isset($app[$fac])) {
return;
}
$app[$fac] = $app->protect(function ($name, $options) use ($app, $id, $authFactory, $userProvider) {
// the authentication type
$type = (isset($options['login_path']) ? 'form' : 'http');
$entry_point = "security.entry_point.$name.$type";
if ($type == 'form') {
$options['failure_forward'] = true;
}
// the authentication provider id
$auth_provider = "security.authentication_provider.$name.$id";
$app[$auth_provider] = $app->share(function () use ($app, $name, $authFactory, $userProvider) {
return $authFactory->createAuthenticationProvider($app, $userProvider, $name);
});
// the authentication listener id
$auth_listener = "security.authentication_listener.$name.$type";
if (!isset($app[$auth_listener])) {
$app[$auth_listener] = $app["security.authentication_listener.$type._proto"]($name, $options);
}
return array($auth_provider, $auth_listener, $entry_point, 'pre_auth');
});
}
|
php
|
protected function registerAuthenticationFactory(\Silex\Application $app,
$id,
AuthenticationFactoryInterface $authFactory,
UserProviderInterface $userProvider)
{
$fac = 'security.authentication_listener.factory.'.$id;
if (isset($app[$fac])) {
return;
}
$app[$fac] = $app->protect(function ($name, $options) use ($app, $id, $authFactory, $userProvider) {
// the authentication type
$type = (isset($options['login_path']) ? 'form' : 'http');
$entry_point = "security.entry_point.$name.$type";
if ($type == 'form') {
$options['failure_forward'] = true;
}
// the authentication provider id
$auth_provider = "security.authentication_provider.$name.$id";
$app[$auth_provider] = $app->share(function () use ($app, $name, $authFactory, $userProvider) {
return $authFactory->createAuthenticationProvider($app, $userProvider, $name);
});
// the authentication listener id
$auth_listener = "security.authentication_listener.$name.$type";
if (!isset($app[$auth_listener])) {
$app[$auth_listener] = $app["security.authentication_listener.$type._proto"]($name, $options);
}
return array($auth_provider, $auth_listener, $entry_point, 'pre_auth');
});
}
|
[
"protected",
"function",
"registerAuthenticationFactory",
"(",
"\\",
"Silex",
"\\",
"Application",
"$",
"app",
",",
"$",
"id",
",",
"AuthenticationFactoryInterface",
"$",
"authFactory",
",",
"UserProviderInterface",
"$",
"userProvider",
")",
"{",
"$",
"fac",
"=",
"'security.authentication_listener.factory.'",
".",
"$",
"id",
";",
"if",
"(",
"isset",
"(",
"$",
"app",
"[",
"$",
"fac",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"app",
"[",
"$",
"fac",
"]",
"=",
"$",
"app",
"->",
"protect",
"(",
"function",
"(",
"$",
"name",
",",
"$",
"options",
")",
"use",
"(",
"$",
"app",
",",
"$",
"id",
",",
"$",
"authFactory",
",",
"$",
"userProvider",
")",
"{",
"// the authentication type",
"$",
"type",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'login_path'",
"]",
")",
"?",
"'form'",
":",
"'http'",
")",
";",
"$",
"entry_point",
"=",
"\"security.entry_point.$name.$type\"",
";",
"if",
"(",
"$",
"type",
"==",
"'form'",
")",
"{",
"$",
"options",
"[",
"'failure_forward'",
"]",
"=",
"true",
";",
"}",
"// the authentication provider id",
"$",
"auth_provider",
"=",
"\"security.authentication_provider.$name.$id\"",
";",
"$",
"app",
"[",
"$",
"auth_provider",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
",",
"$",
"name",
",",
"$",
"authFactory",
",",
"$",
"userProvider",
")",
"{",
"return",
"$",
"authFactory",
"->",
"createAuthenticationProvider",
"(",
"$",
"app",
",",
"$",
"userProvider",
",",
"$",
"name",
")",
";",
"}",
")",
";",
"// the authentication listener id",
"$",
"auth_listener",
"=",
"\"security.authentication_listener.$name.$type\"",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"app",
"[",
"$",
"auth_listener",
"]",
")",
")",
"{",
"$",
"app",
"[",
"$",
"auth_listener",
"]",
"=",
"$",
"app",
"[",
"\"security.authentication_listener.$type._proto\"",
"]",
"(",
"$",
"name",
",",
"$",
"options",
")",
";",
"}",
"return",
"array",
"(",
"$",
"auth_provider",
",",
"$",
"auth_listener",
",",
"$",
"entry_point",
",",
"'pre_auth'",
")",
";",
"}",
")",
";",
"}"
] |
Register authentication factory and user provider.
@param \Silex\Application $app
@param string $id
@param AuthenticationFactoryInterface $authFactory
@param UserProviderInterface $userProvider
|
[
"Register",
"authentication",
"factory",
"and",
"user",
"provider",
"."
] |
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
|
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Firewall.php#L231-L263
|
236,350
|
MLukman/Securilex
|
src/Firewall.php
|
Firewall.registerUserProvider
|
protected function registerUserProvider(\Silex\Application $app)
{
$user_provider = 'security.user_provider.'.$this->name;
$app[$user_provider] = $app->share(function () {
return new ChainUserProvider($this->userProviders);
});
return $user_provider;
}
|
php
|
protected function registerUserProvider(\Silex\Application $app)
{
$user_provider = 'security.user_provider.'.$this->name;
$app[$user_provider] = $app->share(function () {
return new ChainUserProvider($this->userProviders);
});
return $user_provider;
}
|
[
"protected",
"function",
"registerUserProvider",
"(",
"\\",
"Silex",
"\\",
"Application",
"$",
"app",
")",
"{",
"$",
"user_provider",
"=",
"'security.user_provider.'",
".",
"$",
"this",
"->",
"name",
";",
"$",
"app",
"[",
"$",
"user_provider",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"{",
"return",
"new",
"ChainUserProvider",
"(",
"$",
"this",
"->",
"userProviders",
")",
";",
"}",
")",
";",
"return",
"$",
"user_provider",
";",
"}"
] |
Register User Provider
@param \Silex\Application $app
|
[
"Register",
"User",
"Provider"
] |
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
|
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Firewall.php#L269-L276
|
236,351
|
MLukman/Securilex
|
src/Firewall.php
|
Firewall.registerContextListener
|
protected function registerContextListener(\Silex\Application $app)
{
$context_listener = 'security.context_listener.'.$this->name;
$app[$context_listener] = $app->share(function () use ($app) {
return new ContextListener(
$app['security.token_storage'], $this->userProviders, $this->name, $app['logger'], $app['dispatcher']
);
});
return $context_listener;
}
|
php
|
protected function registerContextListener(\Silex\Application $app)
{
$context_listener = 'security.context_listener.'.$this->name;
$app[$context_listener] = $app->share(function () use ($app) {
return new ContextListener(
$app['security.token_storage'], $this->userProviders, $this->name, $app['logger'], $app['dispatcher']
);
});
return $context_listener;
}
|
[
"protected",
"function",
"registerContextListener",
"(",
"\\",
"Silex",
"\\",
"Application",
"$",
"app",
")",
"{",
"$",
"context_listener",
"=",
"'security.context_listener.'",
".",
"$",
"this",
"->",
"name",
";",
"$",
"app",
"[",
"$",
"context_listener",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"ContextListener",
"(",
"$",
"app",
"[",
"'security.token_storage'",
"]",
",",
"$",
"this",
"->",
"userProviders",
",",
"$",
"this",
"->",
"name",
",",
"$",
"app",
"[",
"'logger'",
"]",
",",
"$",
"app",
"[",
"'dispatcher'",
"]",
")",
";",
"}",
")",
";",
"return",
"$",
"context_listener",
";",
"}"
] |
Register Context Listener
@param \Silex\Application $app
|
[
"Register",
"Context",
"Listener"
] |
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
|
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Firewall.php#L282-L291
|
236,352
|
MLukman/Securilex
|
src/Firewall.php
|
Firewall.registerEntryPoint
|
protected function registerEntryPoint(\Silex\Application $app)
{
$entry_point = 'security.entry_point.'.$this->name.
(empty($this->loginPath) ? '.http' : '.form');
$app[$entry_point] = $app->share(function () use ($app) {
return $this->loginPath ?
new FormAuthenticationEntryPoint($app, $app['security.http_utils'], $this->loginPath, true)
:
new BasicAuthenticationEntryPoint('Secured');
});
return $entry_point;
}
|
php
|
protected function registerEntryPoint(\Silex\Application $app)
{
$entry_point = 'security.entry_point.'.$this->name.
(empty($this->loginPath) ? '.http' : '.form');
$app[$entry_point] = $app->share(function () use ($app) {
return $this->loginPath ?
new FormAuthenticationEntryPoint($app, $app['security.http_utils'], $this->loginPath, true)
:
new BasicAuthenticationEntryPoint('Secured');
});
return $entry_point;
}
|
[
"protected",
"function",
"registerEntryPoint",
"(",
"\\",
"Silex",
"\\",
"Application",
"$",
"app",
")",
"{",
"$",
"entry_point",
"=",
"'security.entry_point.'",
".",
"$",
"this",
"->",
"name",
".",
"(",
"empty",
"(",
"$",
"this",
"->",
"loginPath",
")",
"?",
"'.http'",
":",
"'.form'",
")",
";",
"$",
"app",
"[",
"$",
"entry_point",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"this",
"->",
"loginPath",
"?",
"new",
"FormAuthenticationEntryPoint",
"(",
"$",
"app",
",",
"$",
"app",
"[",
"'security.http_utils'",
"]",
",",
"$",
"this",
"->",
"loginPath",
",",
"true",
")",
":",
"new",
"BasicAuthenticationEntryPoint",
"(",
"'Secured'",
")",
";",
"}",
")",
";",
"return",
"$",
"entry_point",
";",
"}"
] |
Register Entry Point
@param \Silex\Application $app
|
[
"Register",
"Entry",
"Point"
] |
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
|
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Firewall.php#L297-L308
|
236,353
|
MLukman/Securilex
|
src/Firewall.php
|
Firewall.generatePaths
|
protected function generatePaths()
{
if ($this->loginPath && !$this->loginCheckPath) {
foreach ($this->patterns as $pattern) {
// remove the ^ prefix
$base = substr($pattern, 1);
// skip a regex pattern
if (preg_quote($base) != $base) {
continue;
}
// now that we found one
if (substr($base, -1) != '/') {
$base .= '/';
}
$this->loginCheckPath = $base.'login_check';
$this->logoutPath = $base.'logout';
break;
}
// unable to generate since all patterns are regex
if (!$this->loginCheckPath) {
static $underscorePad = 0;
$underscorePad++;
$this->loginCheckPath = '/'.str_repeat('_', $underscorePad).'login_check';
$this->logoutPath = '/'.str_repeat('_', $underscorePad).'logout';
$this->patterns[] = "^{$this->loginCheckPath}$";
$this->patterns[] = "^{$this->logoutPath}$";
}
}
}
|
php
|
protected function generatePaths()
{
if ($this->loginPath && !$this->loginCheckPath) {
foreach ($this->patterns as $pattern) {
// remove the ^ prefix
$base = substr($pattern, 1);
// skip a regex pattern
if (preg_quote($base) != $base) {
continue;
}
// now that we found one
if (substr($base, -1) != '/') {
$base .= '/';
}
$this->loginCheckPath = $base.'login_check';
$this->logoutPath = $base.'logout';
break;
}
// unable to generate since all patterns are regex
if (!$this->loginCheckPath) {
static $underscorePad = 0;
$underscorePad++;
$this->loginCheckPath = '/'.str_repeat('_', $underscorePad).'login_check';
$this->logoutPath = '/'.str_repeat('_', $underscorePad).'logout';
$this->patterns[] = "^{$this->loginCheckPath}$";
$this->patterns[] = "^{$this->logoutPath}$";
}
}
}
|
[
"protected",
"function",
"generatePaths",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"loginPath",
"&&",
"!",
"$",
"this",
"->",
"loginCheckPath",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"patterns",
"as",
"$",
"pattern",
")",
"{",
"// remove the ^ prefix",
"$",
"base",
"=",
"substr",
"(",
"$",
"pattern",
",",
"1",
")",
";",
"// skip a regex pattern",
"if",
"(",
"preg_quote",
"(",
"$",
"base",
")",
"!=",
"$",
"base",
")",
"{",
"continue",
";",
"}",
"// now that we found one",
"if",
"(",
"substr",
"(",
"$",
"base",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"base",
".=",
"'/'",
";",
"}",
"$",
"this",
"->",
"loginCheckPath",
"=",
"$",
"base",
".",
"'login_check'",
";",
"$",
"this",
"->",
"logoutPath",
"=",
"$",
"base",
".",
"'logout'",
";",
"break",
";",
"}",
"// unable to generate since all patterns are regex",
"if",
"(",
"!",
"$",
"this",
"->",
"loginCheckPath",
")",
"{",
"static",
"$",
"underscorePad",
"=",
"0",
";",
"$",
"underscorePad",
"++",
";",
"$",
"this",
"->",
"loginCheckPath",
"=",
"'/'",
".",
"str_repeat",
"(",
"'_'",
",",
"$",
"underscorePad",
")",
".",
"'login_check'",
";",
"$",
"this",
"->",
"logoutPath",
"=",
"'/'",
".",
"str_repeat",
"(",
"'_'",
",",
"$",
"underscorePad",
")",
".",
"'logout'",
";",
"$",
"this",
"->",
"patterns",
"[",
"]",
"=",
"\"^{$this->loginCheckPath}$\"",
";",
"$",
"this",
"->",
"patterns",
"[",
"]",
"=",
"\"^{$this->logoutPath}$\"",
";",
"}",
"}",
"}"
] |
Generate loginCheckPath & logoutPath.
|
[
"Generate",
"loginCheckPath",
"&",
"logoutPath",
"."
] |
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
|
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Firewall.php#L313-L341
|
236,354
|
laradic/service-provider
|
src/Plugins/Resources.php
|
Resources.startResourcesPlugin
|
protected function startResourcesPlugin()
{
$this->requiresPlugins(Paths::class);
$this->onBoot('resources', function () {
foreach ($this->viewDirs as $dirName => $namespace) {
$viewPath = $this->resolvePath('viewsPath', compact('dirName'));
$this->loadViewsFrom($viewPath, $namespace);
$this->publishes([ $viewPath => $this->resolvePath('viewsDestinationPath', compact('namespace')) ], 'views');
}
foreach ($this->translationDirs as $dirName => $namespace) {
$transPath = $this->resolvePath('translationPath', compact('dirName'));
$this->loadTranslationsFrom($transPath, $namespace);
$this->publishes([ $transPath => $this->resolvePath('translationDestinationPath', compact('namespace')) ], 'translations');
}
foreach ($this->assetDirs as $dirName => $namespace) {
$this->publishes([
$this->resolvePath('assetsPath', compact('dirName')) => $this->resolvePath('assetsDestinationPath', compact('namespace')),
], 'public');
}
foreach ($this->migrationDirs as $dirName) {
$migrationPaths = $this->resolvePath('migrationsPath', compact('dirName'));
$this->loadMigrationsFrom($migrationPaths);
if ($this->publishMigrations) {
$this->publishes([ $migrationPaths => $this->resolvePath('migrationDestinationPath') ], 'database');
}
}
foreach ($this->seedDirs as $dirName) {
$this->publishes([ $this->resolvePath('seedsPath', compact('dirName')) => $this->resolvePath('seedsDestinationPath') ], 'database');
}
});
}
|
php
|
protected function startResourcesPlugin()
{
$this->requiresPlugins(Paths::class);
$this->onBoot('resources', function () {
foreach ($this->viewDirs as $dirName => $namespace) {
$viewPath = $this->resolvePath('viewsPath', compact('dirName'));
$this->loadViewsFrom($viewPath, $namespace);
$this->publishes([ $viewPath => $this->resolvePath('viewsDestinationPath', compact('namespace')) ], 'views');
}
foreach ($this->translationDirs as $dirName => $namespace) {
$transPath = $this->resolvePath('translationPath', compact('dirName'));
$this->loadTranslationsFrom($transPath, $namespace);
$this->publishes([ $transPath => $this->resolvePath('translationDestinationPath', compact('namespace')) ], 'translations');
}
foreach ($this->assetDirs as $dirName => $namespace) {
$this->publishes([
$this->resolvePath('assetsPath', compact('dirName')) => $this->resolvePath('assetsDestinationPath', compact('namespace')),
], 'public');
}
foreach ($this->migrationDirs as $dirName) {
$migrationPaths = $this->resolvePath('migrationsPath', compact('dirName'));
$this->loadMigrationsFrom($migrationPaths);
if ($this->publishMigrations) {
$this->publishes([ $migrationPaths => $this->resolvePath('migrationDestinationPath') ], 'database');
}
}
foreach ($this->seedDirs as $dirName) {
$this->publishes([ $this->resolvePath('seedsPath', compact('dirName')) => $this->resolvePath('seedsDestinationPath') ], 'database');
}
});
}
|
[
"protected",
"function",
"startResourcesPlugin",
"(",
")",
"{",
"$",
"this",
"->",
"requiresPlugins",
"(",
"Paths",
"::",
"class",
")",
";",
"$",
"this",
"->",
"onBoot",
"(",
"'resources'",
",",
"function",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"viewDirs",
"as",
"$",
"dirName",
"=>",
"$",
"namespace",
")",
"{",
"$",
"viewPath",
"=",
"$",
"this",
"->",
"resolvePath",
"(",
"'viewsPath'",
",",
"compact",
"(",
"'dirName'",
")",
")",
";",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"$",
"viewPath",
",",
"$",
"namespace",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"viewPath",
"=>",
"$",
"this",
"->",
"resolvePath",
"(",
"'viewsDestinationPath'",
",",
"compact",
"(",
"'namespace'",
")",
")",
"]",
",",
"'views'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"translationDirs",
"as",
"$",
"dirName",
"=>",
"$",
"namespace",
")",
"{",
"$",
"transPath",
"=",
"$",
"this",
"->",
"resolvePath",
"(",
"'translationPath'",
",",
"compact",
"(",
"'dirName'",
")",
")",
";",
"$",
"this",
"->",
"loadTranslationsFrom",
"(",
"$",
"transPath",
",",
"$",
"namespace",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"transPath",
"=>",
"$",
"this",
"->",
"resolvePath",
"(",
"'translationDestinationPath'",
",",
"compact",
"(",
"'namespace'",
")",
")",
"]",
",",
"'translations'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"assetDirs",
"as",
"$",
"dirName",
"=>",
"$",
"namespace",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"this",
"->",
"resolvePath",
"(",
"'assetsPath'",
",",
"compact",
"(",
"'dirName'",
")",
")",
"=>",
"$",
"this",
"->",
"resolvePath",
"(",
"'assetsDestinationPath'",
",",
"compact",
"(",
"'namespace'",
")",
")",
",",
"]",
",",
"'public'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"migrationDirs",
"as",
"$",
"dirName",
")",
"{",
"$",
"migrationPaths",
"=",
"$",
"this",
"->",
"resolvePath",
"(",
"'migrationsPath'",
",",
"compact",
"(",
"'dirName'",
")",
")",
";",
"$",
"this",
"->",
"loadMigrationsFrom",
"(",
"$",
"migrationPaths",
")",
";",
"if",
"(",
"$",
"this",
"->",
"publishMigrations",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"migrationPaths",
"=>",
"$",
"this",
"->",
"resolvePath",
"(",
"'migrationDestinationPath'",
")",
"]",
",",
"'database'",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"seedDirs",
"as",
"$",
"dirName",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"this",
"->",
"resolvePath",
"(",
"'seedsPath'",
",",
"compact",
"(",
"'dirName'",
")",
")",
"=>",
"$",
"this",
"->",
"resolvePath",
"(",
"'seedsDestinationPath'",
")",
"]",
",",
"'database'",
")",
";",
"}",
"}",
")",
";",
"}"
] |
startPathsPlugin method.
@param \Illuminate\Foundation\Application $app
|
[
"startPathsPlugin",
"method",
"."
] |
b1428d566b97b3662b405c64ff0cad8a89102033
|
https://github.com/laradic/service-provider/blob/b1428d566b97b3662b405c64ff0cad8a89102033/src/Plugins/Resources.php#L221-L255
|
236,355
|
interactivesolutions/honeycomb-acl
|
src/app/console/commands/HCForms.php
|
HCForms.generateFormData
|
private function generateFormData ()
{
$files = $this->getConfigFiles ();
$formDataHolder = [];
if (!empty($files)) {
foreach ($files as $file) {
$file = json_decode (file_get_contents ($file), true);
if (isset($file['formData']))
$formDataHolder = array_merge ($formDataHolder, $file['formData']);
}
}
Cache::forget ('hc-forms');
Cache::put ('hc-forms', $formDataHolder, Carbon::now ()->addMonth ());
}
|
php
|
private function generateFormData ()
{
$files = $this->getConfigFiles ();
$formDataHolder = [];
if (!empty($files)) {
foreach ($files as $file) {
$file = json_decode (file_get_contents ($file), true);
if (isset($file['formData']))
$formDataHolder = array_merge ($formDataHolder, $file['formData']);
}
}
Cache::forget ('hc-forms');
Cache::put ('hc-forms', $formDataHolder, Carbon::now ()->addMonth ());
}
|
[
"private",
"function",
"generateFormData",
"(",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"getConfigFiles",
"(",
")",
";",
"$",
"formDataHolder",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"file",
"[",
"'formData'",
"]",
")",
")",
"$",
"formDataHolder",
"=",
"array_merge",
"(",
"$",
"formDataHolder",
",",
"$",
"file",
"[",
"'formData'",
"]",
")",
";",
"}",
"}",
"Cache",
"::",
"forget",
"(",
"'hc-forms'",
")",
";",
"Cache",
"::",
"put",
"(",
"'hc-forms'",
",",
"$",
"formDataHolder",
",",
"Carbon",
"::",
"now",
"(",
")",
"->",
"addMonth",
"(",
")",
")",
";",
"}"
] |
Generating form data
|
[
"Generating",
"form",
"data"
] |
6c73d7d1c5d17ef730593e03386236a746bab12c
|
https://github.com/interactivesolutions/honeycomb-acl/blob/6c73d7d1c5d17ef730593e03386236a746bab12c/src/app/console/commands/HCForms.php#L41-L59
|
236,356
|
themichaelhall/bluemvc-core
|
src/Collections/HeaderCollection.php
|
HeaderCollection.add
|
public function add(string $name, string $value): void
{
$key = strtolower($name);
if (!isset($this->headers[$key])) {
$this->headers[$key] = [$name, $value];
return;
}
$this->headers[$key] = [$name, $this->headers[$key][1] . ', ' . $value];
}
|
php
|
public function add(string $name, string $value): void
{
$key = strtolower($name);
if (!isset($this->headers[$key])) {
$this->headers[$key] = [$name, $value];
return;
}
$this->headers[$key] = [$name, $this->headers[$key][1] . ', ' . $value];
}
|
[
"public",
"function",
"add",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
")",
":",
"void",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"name",
",",
"$",
"value",
"]",
";",
"return",
";",
"}",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"name",
",",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
"[",
"1",
"]",
".",
"', '",
".",
"$",
"value",
"]",
";",
"}"
] |
Adds a header value by header name.
@since 1.0.0
@param string $name The header name.
@param string $value The header value.
|
[
"Adds",
"a",
"header",
"value",
"by",
"header",
"name",
"."
] |
cbc8ccf8ed4f15ec6105837b29c2bd3db3f93680
|
https://github.com/themichaelhall/bluemvc-core/blob/cbc8ccf8ed4f15ec6105837b29c2bd3db3f93680/src/Collections/HeaderCollection.php#L38-L48
|
236,357
|
themichaelhall/bluemvc-core
|
src/Collections/HeaderCollection.php
|
HeaderCollection.get
|
public function get(string $name): ?string
{
$key = strtolower($name);
if (!isset($this->headers[$key])) {
return null;
}
return $this->headers[$key][1];
}
|
php
|
public function get(string $name): ?string
{
$key = strtolower($name);
if (!isset($this->headers[$key])) {
return null;
}
return $this->headers[$key][1];
}
|
[
"public",
"function",
"get",
"(",
"string",
"$",
"name",
")",
":",
"?",
"string",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
"[",
"1",
"]",
";",
"}"
] |
Returns the header value by header name if it exists, null otherwise.
@since 1.0.0
@param string $name The header name.
@return string|null The header value by header name if it exists, null otherwise.
|
[
"Returns",
"the",
"header",
"value",
"by",
"header",
"name",
"if",
"it",
"exists",
"null",
"otherwise",
"."
] |
cbc8ccf8ed4f15ec6105837b29c2bd3db3f93680
|
https://github.com/themichaelhall/bluemvc-core/blob/cbc8ccf8ed4f15ec6105837b29c2bd3db3f93680/src/Collections/HeaderCollection.php#L83-L91
|
236,358
|
themichaelhall/bluemvc-core
|
src/Collections/HeaderCollection.php
|
HeaderCollection.set
|
public function set(string $name, string $value): void
{
$key = strtolower($name);
$this->headers[$key] = [$name, $value];
}
|
php
|
public function set(string $name, string $value): void
{
$key = strtolower($name);
$this->headers[$key] = [$name, $value];
}
|
[
"public",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
")",
":",
"void",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"name",
",",
"$",
"value",
"]",
";",
"}"
] |
Sets a header value by header name.
@since 1.0.0
@param string $name The header name.
@param string $value The header value.
|
[
"Sets",
"a",
"header",
"value",
"by",
"header",
"name",
"."
] |
cbc8ccf8ed4f15ec6105837b29c2bd3db3f93680
|
https://github.com/themichaelhall/bluemvc-core/blob/cbc8ccf8ed4f15ec6105837b29c2bd3db3f93680/src/Collections/HeaderCollection.php#L133-L137
|
236,359
|
raidros/collection
|
src/Collection.php
|
Collection.put
|
public function put($name, $value)
{
if (is_object($value) && !$this->isValidObjectInstance($value)) {
throw new InvalidCollectionItemInstanceException(sprintf('%s must implement %s', $name, $this->classname));
}
$this->items[$name] = $value;
return $this->items[$name];
}
|
php
|
public function put($name, $value)
{
if (is_object($value) && !$this->isValidObjectInstance($value)) {
throw new InvalidCollectionItemInstanceException(sprintf('%s must implement %s', $name, $this->classname));
}
$this->items[$name] = $value;
return $this->items[$name];
}
|
[
"public",
"function",
"put",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"!",
"$",
"this",
"->",
"isValidObjectInstance",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidCollectionItemInstanceException",
"(",
"sprintf",
"(",
"'%s must implement %s'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"classname",
")",
")",
";",
"}",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
";",
"}"
] |
Add a new item to collection.
@param string $name
@param mixed $value
@return self
|
[
"Add",
"a",
"new",
"item",
"to",
"collection",
"."
] |
0673330523a9c12c4eb0556b1a4c1059a37c0e7f
|
https://github.com/raidros/collection/blob/0673330523a9c12c4eb0556b1a4c1059a37c0e7f/src/Collection.php#L44-L53
|
236,360
|
raidros/collection
|
src/Collection.php
|
Collection.isValidObjectInstance
|
private function isValidObjectInstance($object)
{
if (!is_null($this->classname) && !$this->isInstanceOrSubclassOf($object)) {
return false;
}
return true;
}
|
php
|
private function isValidObjectInstance($object)
{
if (!is_null($this->classname) && !$this->isInstanceOrSubclassOf($object)) {
return false;
}
return true;
}
|
[
"private",
"function",
"isValidObjectInstance",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"classname",
")",
"&&",
"!",
"$",
"this",
"->",
"isInstanceOrSubclassOf",
"(",
"$",
"object",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Verify's if the given object has a valid instance.
@param object $object
@return bool
|
[
"Verify",
"s",
"if",
"the",
"given",
"object",
"has",
"a",
"valid",
"instance",
"."
] |
0673330523a9c12c4eb0556b1a4c1059a37c0e7f
|
https://github.com/raidros/collection/blob/0673330523a9c12c4eb0556b1a4c1059a37c0e7f/src/Collection.php#L62-L69
|
236,361
|
raidros/collection
|
src/Collection.php
|
Collection.findOrFail
|
public function findOrFail($name)
{
$result = $this->find($name);
if (is_null($result)) {
throw new CollectionItemNotFoundException(sprintf('Collection item "%s" not found', $name));
}
return $result;
}
|
php
|
public function findOrFail($name)
{
$result = $this->find($name);
if (is_null($result)) {
throw new CollectionItemNotFoundException(sprintf('Collection item "%s" not found', $name));
}
return $result;
}
|
[
"public",
"function",
"findOrFail",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"CollectionItemNotFoundException",
"(",
"sprintf",
"(",
"'Collection item \"%s\" not found'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Find a specific collection item or throw's an exception.
@param string $name
@return mixed
|
[
"Find",
"a",
"specific",
"collection",
"item",
"or",
"throw",
"s",
"an",
"exception",
"."
] |
0673330523a9c12c4eb0556b1a4c1059a37c0e7f
|
https://github.com/raidros/collection/blob/0673330523a9c12c4eb0556b1a4c1059a37c0e7f/src/Collection.php#L126-L135
|
236,362
|
raidros/collection
|
src/Collection.php
|
Collection.filterByKeys
|
private function filterByKeys(array $keys)
{
$results = [];
foreach ($this->items as $key => $value) {
if (!in_array($key, $keys)) {
continue;
}
$results[$key] = $value;
}
return $results;
}
|
php
|
private function filterByKeys(array $keys)
{
$results = [];
foreach ($this->items as $key => $value) {
if (!in_array($key, $keys)) {
continue;
}
$results[$key] = $value;
}
return $results;
}
|
[
"private",
"function",
"filterByKeys",
"(",
"array",
"$",
"keys",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"keys",
")",
")",
"{",
"continue",
";",
"}",
"$",
"results",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"results",
";",
"}"
] |
Filter items by key name.
@param array $keys
@return array
|
[
"Filter",
"items",
"by",
"key",
"name",
"."
] |
0673330523a9c12c4eb0556b1a4c1059a37c0e7f
|
https://github.com/raidros/collection/blob/0673330523a9c12c4eb0556b1a4c1059a37c0e7f/src/Collection.php#L200-L213
|
236,363
|
raidros/collection
|
src/Collection.php
|
Collection.only
|
public function only($key)
{
$keys = is_array($key) ? $key : func_get_args();
return new static($this->classname, $this->filterByKeys($keys));
}
|
php
|
public function only($key)
{
$keys = is_array($key) ? $key : func_get_args();
return new static($this->classname, $this->filterByKeys($keys));
}
|
[
"public",
"function",
"only",
"(",
"$",
"key",
")",
"{",
"$",
"keys",
"=",
"is_array",
"(",
"$",
"key",
")",
"?",
"$",
"key",
":",
"func_get_args",
"(",
")",
";",
"return",
"new",
"static",
"(",
"$",
"this",
"->",
"classname",
",",
"$",
"this",
"->",
"filterByKeys",
"(",
"$",
"keys",
")",
")",
";",
"}"
] |
Get all items with the specified keys.
@param mixed $key
@return static
|
[
"Get",
"all",
"items",
"with",
"the",
"specified",
"keys",
"."
] |
0673330523a9c12c4eb0556b1a4c1059a37c0e7f
|
https://github.com/raidros/collection/blob/0673330523a9c12c4eb0556b1a4c1059a37c0e7f/src/Collection.php#L237-L242
|
236,364
|
raidros/collection
|
src/Collection.php
|
Collection.filter
|
public function filter(callable $callback = null)
{
if (is_null($callback)) {
return new static($this->classname, array_filter($this->items));
}
return new static($this->classname, array_filter($this->items, $callback));
}
|
php
|
public function filter(callable $callback = null)
{
if (is_null($callback)) {
return new static($this->classname, array_filter($this->items));
}
return new static($this->classname, array_filter($this->items, $callback));
}
|
[
"public",
"function",
"filter",
"(",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"new",
"static",
"(",
"$",
"this",
"->",
"classname",
",",
"array_filter",
"(",
"$",
"this",
"->",
"items",
")",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"this",
"->",
"classname",
",",
"array_filter",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"callback",
")",
")",
";",
"}"
] |
Filter the elements in the collection using a callback function.
@param callable|null $callback
@return static
|
[
"Filter",
"the",
"elements",
"in",
"the",
"collection",
"using",
"a",
"callback",
"function",
"."
] |
0673330523a9c12c4eb0556b1a4c1059a37c0e7f
|
https://github.com/raidros/collection/blob/0673330523a9c12c4eb0556b1a4c1059a37c0e7f/src/Collection.php#L251-L258
|
236,365
|
railsphp/framework
|
src/Rails/ActiveRecord/Relation/Predicate.php
|
Predicate.nest
|
public function nest()
{
$target = $this->getCurrentPredicate();
if ($operator = $this->getDefaultOperator()) {
$target->$operator;
}
$this->nestings[] = $target->nest();
$this->nestedOperators[] = $this->getDefaultOperator();
return $this;
}
|
php
|
public function nest()
{
$target = $this->getCurrentPredicate();
if ($operator = $this->getDefaultOperator()) {
$target->$operator;
}
$this->nestings[] = $target->nest();
$this->nestedOperators[] = $this->getDefaultOperator();
return $this;
}
|
[
"public",
"function",
"nest",
"(",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"getCurrentPredicate",
"(",
")",
";",
"if",
"(",
"$",
"operator",
"=",
"$",
"this",
"->",
"getDefaultOperator",
"(",
")",
")",
"{",
"$",
"target",
"->",
"$",
"operator",
";",
"}",
"$",
"this",
"->",
"nestings",
"[",
"]",
"=",
"$",
"target",
"->",
"nest",
"(",
")",
";",
"$",
"this",
"->",
"nestedOperators",
"[",
"]",
"=",
"$",
"this",
"->",
"getDefaultOperator",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Begings a new nesting.
|
[
"Begings",
"a",
"new",
"nesting",
"."
] |
2ac9d3e493035dcc68f3c3812423327127327cd5
|
https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActiveRecord/Relation/Predicate.php#L190-L202
|
236,366
|
railsphp/framework
|
src/Rails/ActiveRecord/Relation/Predicate.php
|
Predicate.wOr
|
public function wOr()
{
$this->setDefaultOperator(PredicateSet::OP_OR);
if (func_num_args()) {
call_user_func_array([$this, 'condition'], func_get_args());
$this->endOr();
}
return $this;
}
|
php
|
public function wOr()
{
$this->setDefaultOperator(PredicateSet::OP_OR);
if (func_num_args()) {
call_user_func_array([$this, 'condition'], func_get_args());
$this->endOr();
}
return $this;
}
|
[
"public",
"function",
"wOr",
"(",
")",
"{",
"$",
"this",
"->",
"setDefaultOperator",
"(",
"PredicateSet",
"::",
"OP_OR",
")",
";",
"if",
"(",
"func_num_args",
"(",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'condition'",
"]",
",",
"func_get_args",
"(",
")",
")",
";",
"$",
"this",
"->",
"endOr",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Same as wAnd.
@see wAnd()
|
[
"Same",
"as",
"wAnd",
"."
] |
2ac9d3e493035dcc68f3c3812423327127327cd5
|
https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActiveRecord/Relation/Predicate.php#L253-L262
|
236,367
|
railsphp/framework
|
src/Rails/ActiveRecord/Relation/Predicate.php
|
Predicate.addCondition
|
protected function addCondition($method, array $params)
{
$target = $this->getCurrentPredicate();
# Set default operator if any.
if ($operator = $this->getDefaultOperator()) {
$target->$operator;
}
call_user_func_array([$target, $method], $params);
}
|
php
|
protected function addCondition($method, array $params)
{
$target = $this->getCurrentPredicate();
# Set default operator if any.
if ($operator = $this->getDefaultOperator()) {
$target->$operator;
}
call_user_func_array([$target, $method], $params);
}
|
[
"protected",
"function",
"addCondition",
"(",
"$",
"method",
",",
"array",
"$",
"params",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"getCurrentPredicate",
"(",
")",
";",
"# Set default operator if any.",
"if",
"(",
"$",
"operator",
"=",
"$",
"this",
"->",
"getDefaultOperator",
"(",
")",
")",
"{",
"$",
"target",
"->",
"$",
"operator",
";",
"}",
"call_user_func_array",
"(",
"[",
"$",
"target",
",",
"$",
"method",
"]",
",",
"$",
"params",
")",
";",
"}"
] |
Actually adds the condition to the proper target.
|
[
"Actually",
"adds",
"the",
"condition",
"to",
"the",
"proper",
"target",
"."
] |
2ac9d3e493035dcc68f3c3812423327127327cd5
|
https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActiveRecord/Relation/Predicate.php#L471-L481
|
236,368
|
ekyna/CartBundle
|
Provider/CartProvider.php
|
CartProvider.newCart
|
private function newCart()
{
$this->clearCart();
$this->setCart($this->repository->createNew(OrderTypes::TYPE_CART));
return $this->cart;
}
|
php
|
private function newCart()
{
$this->clearCart();
$this->setCart($this->repository->createNew(OrderTypes::TYPE_CART));
return $this->cart;
}
|
[
"private",
"function",
"newCart",
"(",
")",
"{",
"$",
"this",
"->",
"clearCart",
"(",
")",
";",
"$",
"this",
"->",
"setCart",
"(",
"$",
"this",
"->",
"repository",
"->",
"createNew",
"(",
"OrderTypes",
"::",
"TYPE_CART",
")",
")",
";",
"return",
"$",
"this",
"->",
"cart",
";",
"}"
] |
Creates a new cart.
@return \Ekyna\Component\Sale\Order\OrderInterface
|
[
"Creates",
"a",
"new",
"cart",
"."
] |
c486af3d027873c81c7b61ef71980e8062c3dddd
|
https://github.com/ekyna/CartBundle/blob/c486af3d027873c81c7b61ef71980e8062c3dddd/Provider/CartProvider.php#L119-L125
|
236,369
|
harvestcloud/CoreBundle
|
Entity/Order.php
|
Order.getOpenStatusCodes
|
public static function getOpenStatusCodes()
{
return array(
self::STATUS_NEW,
self::STATUS_ACCEPTED_BY_SELLER,
self::STATUS_REJECTED_BY_SELLER,
self::STATUS_IN_PICK_AT_SELLER,
self::STATUS_READY_FOR_DISPATCH_TO_HUB,
self::STATUS_IN_TRANSIT_TO_HUB,
self::STATUS_READY_FOR_PICKUP_FROM_HUB,
self::STATUS_AT_HUB,
);
}
|
php
|
public static function getOpenStatusCodes()
{
return array(
self::STATUS_NEW,
self::STATUS_ACCEPTED_BY_SELLER,
self::STATUS_REJECTED_BY_SELLER,
self::STATUS_IN_PICK_AT_SELLER,
self::STATUS_READY_FOR_DISPATCH_TO_HUB,
self::STATUS_IN_TRANSIT_TO_HUB,
self::STATUS_READY_FOR_PICKUP_FROM_HUB,
self::STATUS_AT_HUB,
);
}
|
[
"public",
"static",
"function",
"getOpenStatusCodes",
"(",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"STATUS_NEW",
",",
"self",
"::",
"STATUS_ACCEPTED_BY_SELLER",
",",
"self",
"::",
"STATUS_REJECTED_BY_SELLER",
",",
"self",
"::",
"STATUS_IN_PICK_AT_SELLER",
",",
"self",
"::",
"STATUS_READY_FOR_DISPATCH_TO_HUB",
",",
"self",
"::",
"STATUS_IN_TRANSIT_TO_HUB",
",",
"self",
"::",
"STATUS_READY_FOR_PICKUP_FROM_HUB",
",",
"self",
"::",
"STATUS_AT_HUB",
",",
")",
";",
"}"
] |
Get open status codes
@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since 2012-05-15
@return array
|
[
"Get",
"open",
"status",
"codes"
] |
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
|
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Entity/Order.php#L225-L237
|
236,370
|
harvestcloud/CoreBundle
|
Entity/Order.php
|
Order.getSumOfLineItems
|
public function getSumOfLineItems()
{
$amount = 0;
foreach ($this->getLineItems() as $lineItem)
{
$amount += $lineItem->getPrice()*$lineItem->getQuantity();
}
return round($amount, 2);
}
|
php
|
public function getSumOfLineItems()
{
$amount = 0;
foreach ($this->getLineItems() as $lineItem)
{
$amount += $lineItem->getPrice()*$lineItem->getQuantity();
}
return round($amount, 2);
}
|
[
"public",
"function",
"getSumOfLineItems",
"(",
")",
"{",
"$",
"amount",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"getLineItems",
"(",
")",
"as",
"$",
"lineItem",
")",
"{",
"$",
"amount",
"+=",
"$",
"lineItem",
"->",
"getPrice",
"(",
")",
"*",
"$",
"lineItem",
"->",
"getQuantity",
"(",
")",
";",
"}",
"return",
"round",
"(",
"$",
"amount",
",",
"2",
")",
";",
"}"
] |
Get sum of line items
@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since 2012-05-13
@return float
|
[
"Get",
"sum",
"of",
"line",
"items"
] |
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
|
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Entity/Order.php#L261-L271
|
236,371
|
harvestcloud/CoreBundle
|
Entity/Order.php
|
Order.getLineItemForProduct
|
public function getLineItemForProduct(Product $product)
{
foreach ($this->getLineItems() as $lineItem)
{
if ($lineItem->getProduct()->getId() == $product->getId())
{
return $lineItem;
}
}
return $this->createLineItemForProduct($product);
}
|
php
|
public function getLineItemForProduct(Product $product)
{
foreach ($this->getLineItems() as $lineItem)
{
if ($lineItem->getProduct()->getId() == $product->getId())
{
return $lineItem;
}
}
return $this->createLineItemForProduct($product);
}
|
[
"public",
"function",
"getLineItemForProduct",
"(",
"Product",
"$",
"product",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getLineItems",
"(",
")",
"as",
"$",
"lineItem",
")",
"{",
"if",
"(",
"$",
"lineItem",
"->",
"getProduct",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"$",
"product",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"$",
"lineItem",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"createLineItemForProduct",
"(",
"$",
"product",
")",
";",
"}"
] |
Get OrderLineItem for given Product
@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since 2012-04-10
@param HarvestCloud\CoreBundle\Entity\Product
@return HarvestCloud\CoreBundle\Entity\OrderLineItem
|
[
"Get",
"OrderLineItem",
"for",
"given",
"Product"
] |
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
|
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Entity/Order.php#L350-L361
|
236,372
|
harvestcloud/CoreBundle
|
Entity/Order.php
|
Order.createLineItemForProduct
|
public function createLineItemForProduct(Product $product)
{
$lineItem = new OrderLineItem();
$lineItem->setProduct($product);
// Don't assume any quantity here
// We will add it later
$lineItem->setQuantity(0);
$this->addLineItem($lineItem);
// Copy SellerWindow
if ($this->getSellerWindow()) {
$lineItem->setSellerWindow($this->getSellerWindow());
}
return $lineItem;
}
|
php
|
public function createLineItemForProduct(Product $product)
{
$lineItem = new OrderLineItem();
$lineItem->setProduct($product);
// Don't assume any quantity here
// We will add it later
$lineItem->setQuantity(0);
$this->addLineItem($lineItem);
// Copy SellerWindow
if ($this->getSellerWindow()) {
$lineItem->setSellerWindow($this->getSellerWindow());
}
return $lineItem;
}
|
[
"public",
"function",
"createLineItemForProduct",
"(",
"Product",
"$",
"product",
")",
"{",
"$",
"lineItem",
"=",
"new",
"OrderLineItem",
"(",
")",
";",
"$",
"lineItem",
"->",
"setProduct",
"(",
"$",
"product",
")",
";",
"// Don't assume any quantity here",
"// We will add it later",
"$",
"lineItem",
"->",
"setQuantity",
"(",
"0",
")",
";",
"$",
"this",
"->",
"addLineItem",
"(",
"$",
"lineItem",
")",
";",
"// Copy SellerWindow",
"if",
"(",
"$",
"this",
"->",
"getSellerWindow",
"(",
")",
")",
"{",
"$",
"lineItem",
"->",
"setSellerWindow",
"(",
"$",
"this",
"->",
"getSellerWindow",
"(",
")",
")",
";",
"}",
"return",
"$",
"lineItem",
";",
"}"
] |
Create OrderLineItem for given Product
@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since 2012-04-10
@todo Work out better default quantity
@param HarvestCloud\CoreBundle\Entity\Product
@return HarvestCloud\CoreBundle\Entity\OrderLineItem
|
[
"Create",
"OrderLineItem",
"for",
"given",
"Product"
] |
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
|
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Entity/Order.php#L375-L392
|
236,373
|
harvestcloud/CoreBundle
|
Entity/Order.php
|
Order.getInvoiceIdForPaymentGateway
|
public function getInvoiceIdForPaymentGateway()
{
return
implode(str_split(str_pad($this->getSeller()->getId(), 6, 0, STR_PAD_LEFT),3), '-')
.' / '
.implode(str_split(str_pad($this->getId(), 6, 0, STR_PAD_LEFT),3), '-')
.' / '
.$this->getSeller()->getName();
}
|
php
|
public function getInvoiceIdForPaymentGateway()
{
return
implode(str_split(str_pad($this->getSeller()->getId(), 6, 0, STR_PAD_LEFT),3), '-')
.' / '
.implode(str_split(str_pad($this->getId(), 6, 0, STR_PAD_LEFT),3), '-')
.' / '
.$this->getSeller()->getName();
}
|
[
"public",
"function",
"getInvoiceIdForPaymentGateway",
"(",
")",
"{",
"return",
"implode",
"(",
"str_split",
"(",
"str_pad",
"(",
"$",
"this",
"->",
"getSeller",
"(",
")",
"->",
"getId",
"(",
")",
",",
"6",
",",
"0",
",",
"STR_PAD_LEFT",
")",
",",
"3",
")",
",",
"'-'",
")",
".",
"' / '",
".",
"implode",
"(",
"str_split",
"(",
"str_pad",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"6",
",",
"0",
",",
"STR_PAD_LEFT",
")",
",",
"3",
")",
",",
"'-'",
")",
".",
"' / '",
".",
"$",
"this",
"->",
"getSeller",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}"
] |
Get invoiceId for PaymentGateway
@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since 2012-05-01
@todo Maybe use a similar format system wide
@return string
|
[
"Get",
"invoiceId",
"for",
"PaymentGateway"
] |
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
|
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Entity/Order.php#L758-L766
|
236,374
|
harvestcloud/CoreBundle
|
Entity/Order.php
|
Order.canBeDispatchedBySeller
|
public function canBeDispatchedBySeller()
{
switch ($this->getStatusCode())
{
case self::STATUS_ACCEPTED_BY_SELLER:
case self::STATUS_IN_PICK_AT_SELLER:
case self::STATUS_READY_FOR_DISPATCH_TO_HUB:
return true;
default:
return false;
}
}
|
php
|
public function canBeDispatchedBySeller()
{
switch ($this->getStatusCode())
{
case self::STATUS_ACCEPTED_BY_SELLER:
case self::STATUS_IN_PICK_AT_SELLER:
case self::STATUS_READY_FOR_DISPATCH_TO_HUB:
return true;
default:
return false;
}
}
|
[
"public",
"function",
"canBeDispatchedBySeller",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
")",
"{",
"case",
"self",
"::",
"STATUS_ACCEPTED_BY_SELLER",
":",
"case",
"self",
"::",
"STATUS_IN_PICK_AT_SELLER",
":",
"case",
"self",
"::",
"STATUS_READY_FOR_DISPATCH_TO_HUB",
":",
"return",
"true",
";",
"default",
":",
"return",
"false",
";",
"}",
"}"
] |
Can be dispatched by Seller
@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since 2012-05-14
@return bool
|
[
"Can",
"be",
"dispatched",
"by",
"Seller"
] |
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
|
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Entity/Order.php#L955-L969
|
236,375
|
watoki/deli
|
src/Delivery.php
|
Delivery.error
|
protected function error(Request $request, \Exception $exception) {
return $request->getTarget() . ' threw '
. get_class($exception) . ': '
. $exception->getMessage() . "\n"
. $exception->getTraceAsString();
}
|
php
|
protected function error(Request $request, \Exception $exception) {
return $request->getTarget() . ' threw '
. get_class($exception) . ': '
. $exception->getMessage() . "\n"
. $exception->getTraceAsString();
}
|
[
"protected",
"function",
"error",
"(",
"Request",
"$",
"request",
",",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"return",
"$",
"request",
"->",
"getTarget",
"(",
")",
".",
"' threw '",
".",
"get_class",
"(",
"$",
"exception",
")",
".",
"': '",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
".",
"\"\\n\"",
".",
"$",
"exception",
"->",
"getTraceAsString",
"(",
")",
";",
"}"
] |
Is called if an error is caught while running the delivery
@param Request $request
@param \Exception $exception
@return mixed
|
[
"Is",
"called",
"if",
"an",
"error",
"is",
"caught",
"while",
"running",
"the",
"delivery"
] |
cdc369f29d37cb51addbd9547acee5abf8b5c3e4
|
https://github.com/watoki/deli/blob/cdc369f29d37cb51addbd9547acee5abf8b5c3e4/src/Delivery.php#L58-L63
|
236,376
|
rozaverta/cmf
|
core/Database/Query/ExpressionWrap.php
|
ExpressionWrap.getValue
|
public function getValue()
{
$grammar = Manager::connection()->getQueryGrammar();
return vsprintf( $this->value, array_map(function($val) use($grammar) {
return $grammar->wrap($val);
}, $this->replace) );
}
|
php
|
public function getValue()
{
$grammar = Manager::connection()->getQueryGrammar();
return vsprintf( $this->value, array_map(function($val) use($grammar) {
return $grammar->wrap($val);
}, $this->replace) );
}
|
[
"public",
"function",
"getValue",
"(",
")",
"{",
"$",
"grammar",
"=",
"Manager",
"::",
"connection",
"(",
")",
"->",
"getQueryGrammar",
"(",
")",
";",
"return",
"vsprintf",
"(",
"$",
"this",
"->",
"value",
",",
"array_map",
"(",
"function",
"(",
"$",
"val",
")",
"use",
"(",
"$",
"grammar",
")",
"{",
"return",
"$",
"grammar",
"->",
"wrap",
"(",
"$",
"val",
")",
";",
"}",
",",
"$",
"this",
"->",
"replace",
")",
")",
";",
"}"
] |
Get the value of the expression.
@return mixed
|
[
"Get",
"the",
"value",
"of",
"the",
"expression",
"."
] |
95ed38362e397d1c700ee255f7200234ef98d356
|
https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Database/Query/ExpressionWrap.php#L33-L39
|
236,377
|
ideaconnect/idct-php-array-file-cache
|
src/FileArrayCache.php
|
FileArrayCache.clearCache
|
public function clearCache()
{
$objects = scandir($this->getCachePath());
$dir = $this->getCachePath();
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (is_dir($dir.$object)) {
self::rrmdir($dir.$object);
} elseif ($object !== 'cache_config') {
unlink($dir.$object);
}
}
}
return $this;
}
|
php
|
public function clearCache()
{
$objects = scandir($this->getCachePath());
$dir = $this->getCachePath();
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (is_dir($dir.$object)) {
self::rrmdir($dir.$object);
} elseif ($object !== 'cache_config') {
unlink($dir.$object);
}
}
}
return $this;
}
|
[
"public",
"function",
"clearCache",
"(",
")",
"{",
"$",
"objects",
"=",
"scandir",
"(",
"$",
"this",
"->",
"getCachePath",
"(",
")",
")",
";",
"$",
"dir",
"=",
"$",
"this",
"->",
"getCachePath",
"(",
")",
";",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"object",
"!=",
"\".\"",
"&&",
"$",
"object",
"!=",
"\"..\"",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
".",
"$",
"object",
")",
")",
"{",
"self",
"::",
"rrmdir",
"(",
"$",
"dir",
".",
"$",
"object",
")",
";",
"}",
"elseif",
"(",
"$",
"object",
"!==",
"'cache_config'",
")",
"{",
"unlink",
"(",
"$",
"dir",
".",
"$",
"object",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Removes all entries in the cache. Keeps `cache_config` and cache's folder.
@return $this
|
[
"Removes",
"all",
"entries",
"in",
"the",
"cache",
".",
"Keeps",
"cache_config",
"and",
"cache",
"s",
"folder",
"."
] |
08b3e54fe719dfb2988224fedb16730ba8b2920f
|
https://github.com/ideaconnect/idct-php-array-file-cache/blob/08b3e54fe719dfb2988224fedb16730ba8b2920f/src/FileArrayCache.php#L127-L142
|
236,378
|
ideaconnect/idct-php-array-file-cache
|
src/FileArrayCache.php
|
FileArrayCache.buildLevelsString
|
private function buildLevelsString($levels)
{
$this->levelsString = join(DIRECTORY_SEPARATOR, array_fill(0, $levels, '%s')) . DIRECTORY_SEPARATOR;
return $this;
}
|
php
|
private function buildLevelsString($levels)
{
$this->levelsString = join(DIRECTORY_SEPARATOR, array_fill(0, $levels, '%s')) . DIRECTORY_SEPARATOR;
return $this;
}
|
[
"private",
"function",
"buildLevelsString",
"(",
"$",
"levels",
")",
"{",
"$",
"this",
"->",
"levelsString",
"=",
"join",
"(",
"DIRECTORY_SEPARATOR",
",",
"array_fill",
"(",
"0",
",",
"$",
"levels",
",",
"'%s'",
")",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"return",
"$",
"this",
";",
"}"
] |
Builds a string with placeholders and directory separators required to
create a path for saving a final cache entry.
For example if $levels = 3 and DIRECTORY_SEPARATOR = '/':
%s/%s/%s/
@param int $levels
@return $this
|
[
"Builds",
"a",
"string",
"with",
"placeholders",
"and",
"directory",
"separators",
"required",
"to",
"create",
"a",
"path",
"for",
"saving",
"a",
"final",
"cache",
"entry",
"."
] |
08b3e54fe719dfb2988224fedb16730ba8b2920f
|
https://github.com/ideaconnect/idct-php-array-file-cache/blob/08b3e54fe719dfb2988224fedb16730ba8b2920f/src/FileArrayCache.php#L323-L328
|
236,379
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.create
|
public static function create(
DictionaryInterface $sourceDictionary,
WritableDictionaryInterface $targetDictionary,
LoggerInterface $logger = null
): CopyDictionaryJob {
$instance = new static($sourceDictionary, $targetDictionary);
if ($logger) {
$instance->setLogger($logger);
}
return $instance;
}
|
php
|
public static function create(
DictionaryInterface $sourceDictionary,
WritableDictionaryInterface $targetDictionary,
LoggerInterface $logger = null
): CopyDictionaryJob {
$instance = new static($sourceDictionary, $targetDictionary);
if ($logger) {
$instance->setLogger($logger);
}
return $instance;
}
|
[
"public",
"static",
"function",
"create",
"(",
"DictionaryInterface",
"$",
"sourceDictionary",
",",
"WritableDictionaryInterface",
"$",
"targetDictionary",
",",
"LoggerInterface",
"$",
"logger",
"=",
"null",
")",
":",
"CopyDictionaryJob",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
"$",
"sourceDictionary",
",",
"$",
"targetDictionary",
")",
";",
"if",
"(",
"$",
"logger",
")",
"{",
"$",
"instance",
"->",
"setLogger",
"(",
"$",
"logger",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Static helper for fluent coding.
@param DictionaryInterface $sourceDictionary The source dictionary.
@param WritableDictionaryInterface $targetDictionary The target dictionary.
@param LoggerInterface|null $logger The logger to use.
@return CopyDictionaryJob
|
[
"Static",
"helper",
"for",
"fluent",
"coding",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L136-L147
|
236,380
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.setCopySource
|
public function setCopySource(int $copySource = self::COPY): CopyDictionaryJob
{
$this->copySource = $copySource;
return $this;
}
|
php
|
public function setCopySource(int $copySource = self::COPY): CopyDictionaryJob
{
$this->copySource = $copySource;
return $this;
}
|
[
"public",
"function",
"setCopySource",
"(",
"int",
"$",
"copySource",
"=",
"self",
"::",
"COPY",
")",
":",
"CopyDictionaryJob",
"{",
"$",
"this",
"->",
"copySource",
"=",
"$",
"copySource",
";",
"return",
"$",
"this",
";",
"}"
] |
Set copySource.
@param int $copySource The new value.
@return CopyDictionaryJob
|
[
"Set",
"copySource",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L156-L161
|
236,381
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.setCopyTarget
|
public function setCopyTarget(int $copyTarget = self::COPY): CopyDictionaryJob
{
$this->copyTarget = $copyTarget;
return $this;
}
|
php
|
public function setCopyTarget(int $copyTarget = self::COPY): CopyDictionaryJob
{
$this->copyTarget = $copyTarget;
return $this;
}
|
[
"public",
"function",
"setCopyTarget",
"(",
"int",
"$",
"copyTarget",
"=",
"self",
"::",
"COPY",
")",
":",
"CopyDictionaryJob",
"{",
"$",
"this",
"->",
"copyTarget",
"=",
"$",
"copyTarget",
";",
"return",
"$",
"this",
";",
"}"
] |
Set copyTarget.
@param int $copyTarget The new value.
@return CopyDictionaryJob
|
[
"Set",
"copyTarget",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L180-L185
|
236,382
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.addFilter
|
public function addFilter(string $expression): CopyDictionaryJob
{
// Check if the first and last char match - if not, we must encapsulate with '/'.
if ($expression[0] !== substr($expression, -1)) {
$expression = '/' . $expression . '/';
}
// Test if the regex is valid.
try {
preg_match($expression, '');
} catch (\Throwable $error) {
throw new \InvalidArgumentException(
sprintf('Filter "%s" is not a valid regular expression - Error: %s', $expression, $error->getMessage()),
0,
$error
);
}
$this->filters[] = $expression;
return $this;
}
|
php
|
public function addFilter(string $expression): CopyDictionaryJob
{
// Check if the first and last char match - if not, we must encapsulate with '/'.
if ($expression[0] !== substr($expression, -1)) {
$expression = '/' . $expression . '/';
}
// Test if the regex is valid.
try {
preg_match($expression, '');
} catch (\Throwable $error) {
throw new \InvalidArgumentException(
sprintf('Filter "%s" is not a valid regular expression - Error: %s', $expression, $error->getMessage()),
0,
$error
);
}
$this->filters[] = $expression;
return $this;
}
|
[
"public",
"function",
"addFilter",
"(",
"string",
"$",
"expression",
")",
":",
"CopyDictionaryJob",
"{",
"// Check if the first and last char match - if not, we must encapsulate with '/'.",
"if",
"(",
"$",
"expression",
"[",
"0",
"]",
"!==",
"substr",
"(",
"$",
"expression",
",",
"-",
"1",
")",
")",
"{",
"$",
"expression",
"=",
"'/'",
".",
"$",
"expression",
".",
"'/'",
";",
"}",
"// Test if the regex is valid.",
"try",
"{",
"preg_match",
"(",
"$",
"expression",
",",
"''",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"error",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Filter \"%s\" is not a valid regular expression - Error: %s'",
",",
"$",
"expression",
",",
"$",
"error",
"->",
"getMessage",
"(",
")",
")",
",",
"0",
",",
"$",
"error",
")",
";",
"}",
"$",
"this",
"->",
"filters",
"[",
"]",
"=",
"$",
"expression",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a regular expression.
@param string $expression The regular expression matching keys to filter away.
@return CopyDictionaryJob
@throws \InvalidArgumentException When the regex is invalid.
|
[
"Add",
"a",
"regular",
"expression",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L254-L275
|
236,383
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.setFilters
|
public function setFilters(array $expressions): CopyDictionaryJob
{
$this->filters = [];
foreach ($expressions as $expression) {
$this->addFilter($expression);
}
return $this;
}
|
php
|
public function setFilters(array $expressions): CopyDictionaryJob
{
$this->filters = [];
foreach ($expressions as $expression) {
$this->addFilter($expression);
}
return $this;
}
|
[
"public",
"function",
"setFilters",
"(",
"array",
"$",
"expressions",
")",
":",
"CopyDictionaryJob",
"{",
"$",
"this",
"->",
"filters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"expressions",
"as",
"$",
"expression",
")",
"{",
"$",
"this",
"->",
"addFilter",
"(",
"$",
"expression",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the filter expressions.
@param array $expressions
@return CopyDictionaryJob
|
[
"Set",
"the",
"filter",
"expressions",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L284-L292
|
236,384
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.copyKey
|
private function copyKey(string $key): void
{
$source = $this->sourceDictionary->get($key);
if ($source->isSourceEmpty()) {
$this->logger->debug(
'{key}: Is empty in source language and therefore skipped.',
['key' => $key]
);
return;
}
if (!$this->targetDictionary->has($key)) {
$this->logger->log($this->logLevel, 'Adding key {key}.', ['key' => $key]);
if ($this->dryRun) {
return;
}
$this->targetDictionary->add($key);
}
$target = $this->targetDictionary->getWritable($key);
$this->copySource($source, $target);
$this->copyTarget($source, $target);
}
|
php
|
private function copyKey(string $key): void
{
$source = $this->sourceDictionary->get($key);
if ($source->isSourceEmpty()) {
$this->logger->debug(
'{key}: Is empty in source language and therefore skipped.',
['key' => $key]
);
return;
}
if (!$this->targetDictionary->has($key)) {
$this->logger->log($this->logLevel, 'Adding key {key}.', ['key' => $key]);
if ($this->dryRun) {
return;
}
$this->targetDictionary->add($key);
}
$target = $this->targetDictionary->getWritable($key);
$this->copySource($source, $target);
$this->copyTarget($source, $target);
}
|
[
"private",
"function",
"copyKey",
"(",
"string",
"$",
"key",
")",
":",
"void",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"sourceDictionary",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"source",
"->",
"isSourceEmpty",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'{key}: Is empty in source language and therefore skipped.'",
",",
"[",
"'key'",
"=>",
"$",
"key",
"]",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"targetDictionary",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"this",
"->",
"logLevel",
",",
"'Adding key {key}.'",
",",
"[",
"'key'",
"=>",
"$",
"key",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dryRun",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"targetDictionary",
"->",
"add",
"(",
"$",
"key",
")",
";",
"}",
"$",
"target",
"=",
"$",
"this",
"->",
"targetDictionary",
"->",
"getWritable",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"copySource",
"(",
"$",
"source",
",",
"$",
"target",
")",
";",
"$",
"this",
"->",
"copyTarget",
"(",
"$",
"source",
",",
"$",
"target",
")",
";",
"}"
] |
Copy a key.
@param string $key The key.
@return void
|
[
"Copy",
"a",
"key",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L339-L362
|
236,385
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.copySource
|
private function copySource(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
{
if (self::DO_NOT_COPY === $this->copySource) {
return;
}
if (($oldValue = $target->getSource()) === ($newValue = $source->getSource())) {
$this->logger->log(
$this->logLevel,
'{key}: Source is same, no need to update.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
return;
}
if ((self::COPY_IF_EMPTY === $this->copySource) && !$target->isSourceEmpty()) {
$this->logger->log(
$this->logLevel,
'{key}: Source is not empty, no need to update.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
return;
}
$this->logger->log(
LogLevel::NOTICE,
'{key}: Updating source value.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
if ($this->dryRun) {
return;
}
$target->setSource($newValue);
}
|
php
|
private function copySource(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
{
if (self::DO_NOT_COPY === $this->copySource) {
return;
}
if (($oldValue = $target->getSource()) === ($newValue = $source->getSource())) {
$this->logger->log(
$this->logLevel,
'{key}: Source is same, no need to update.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
return;
}
if ((self::COPY_IF_EMPTY === $this->copySource) && !$target->isSourceEmpty()) {
$this->logger->log(
$this->logLevel,
'{key}: Source is not empty, no need to update.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
return;
}
$this->logger->log(
LogLevel::NOTICE,
'{key}: Updating source value.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
if ($this->dryRun) {
return;
}
$target->setSource($newValue);
}
|
[
"private",
"function",
"copySource",
"(",
"TranslationValueInterface",
"$",
"source",
",",
"WritableTranslationValueInterface",
"$",
"target",
")",
":",
"void",
"{",
"if",
"(",
"self",
"::",
"DO_NOT_COPY",
"===",
"$",
"this",
"->",
"copySource",
")",
"{",
"return",
";",
"}",
"if",
"(",
"(",
"$",
"oldValue",
"=",
"$",
"target",
"->",
"getSource",
"(",
")",
")",
"===",
"(",
"$",
"newValue",
"=",
"$",
"source",
"->",
"getSource",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"this",
"->",
"logLevel",
",",
"'{key}: Source is same, no need to update.'",
",",
"[",
"'key'",
"=>",
"$",
"target",
"->",
"getKey",
"(",
")",
",",
"'old'",
"=>",
"$",
"oldValue",
",",
"'new'",
"=>",
"$",
"newValue",
"]",
")",
";",
"return",
";",
"}",
"if",
"(",
"(",
"self",
"::",
"COPY_IF_EMPTY",
"===",
"$",
"this",
"->",
"copySource",
")",
"&&",
"!",
"$",
"target",
"->",
"isSourceEmpty",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"this",
"->",
"logLevel",
",",
"'{key}: Source is not empty, no need to update.'",
",",
"[",
"'key'",
"=>",
"$",
"target",
"->",
"getKey",
"(",
")",
",",
"'old'",
"=>",
"$",
"oldValue",
",",
"'new'",
"=>",
"$",
"newValue",
"]",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"LogLevel",
"::",
"NOTICE",
",",
"'{key}: Updating source value.'",
",",
"[",
"'key'",
"=>",
"$",
"target",
"->",
"getKey",
"(",
")",
",",
"'old'",
"=>",
"$",
"oldValue",
",",
"'new'",
"=>",
"$",
"newValue",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dryRun",
")",
"{",
"return",
";",
"}",
"$",
"target",
"->",
"setSource",
"(",
"$",
"newValue",
")",
";",
"}"
] |
Copy the source value.
@param TranslationValueInterface $source The source value.
@param WritableTranslationValueInterface $target The target value.
@return void
|
[
"Copy",
"the",
"source",
"value",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L372-L408
|
236,386
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.copyTarget
|
private function copyTarget(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
{
if (self::DO_NOT_COPY === $this->copyTarget) {
return;
}
if ((($oldValue = $target->getTarget()) === ($newValue = $source->getTarget()))
|| ($target->isTargetEmpty() && $source->isTargetEmpty())
) {
$this->logger->log(
$this->logLevel,
'{key}: Target is same, no need to update.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
return;
}
if ((self::COPY_IF_EMPTY === $this->copyTarget) && !$target->isTargetEmpty()) {
$this->logger->log(
$this->logLevel,
'{key}: Target is not empty, no need to update.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
return;
}
$this->logger->log(
LogLevel::NOTICE,
'{key}: Updating target value.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
if ($this->dryRun) {
return;
}
if (null === $value = $source->getTarget()) {
$target->clearTarget();
return;
}
$target->setTarget($value);
}
|
php
|
private function copyTarget(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
{
if (self::DO_NOT_COPY === $this->copyTarget) {
return;
}
if ((($oldValue = $target->getTarget()) === ($newValue = $source->getTarget()))
|| ($target->isTargetEmpty() && $source->isTargetEmpty())
) {
$this->logger->log(
$this->logLevel,
'{key}: Target is same, no need to update.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
return;
}
if ((self::COPY_IF_EMPTY === $this->copyTarget) && !$target->isTargetEmpty()) {
$this->logger->log(
$this->logLevel,
'{key}: Target is not empty, no need to update.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
return;
}
$this->logger->log(
LogLevel::NOTICE,
'{key}: Updating target value.',
['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
);
if ($this->dryRun) {
return;
}
if (null === $value = $source->getTarget()) {
$target->clearTarget();
return;
}
$target->setTarget($value);
}
|
[
"private",
"function",
"copyTarget",
"(",
"TranslationValueInterface",
"$",
"source",
",",
"WritableTranslationValueInterface",
"$",
"target",
")",
":",
"void",
"{",
"if",
"(",
"self",
"::",
"DO_NOT_COPY",
"===",
"$",
"this",
"->",
"copyTarget",
")",
"{",
"return",
";",
"}",
"if",
"(",
"(",
"(",
"$",
"oldValue",
"=",
"$",
"target",
"->",
"getTarget",
"(",
")",
")",
"===",
"(",
"$",
"newValue",
"=",
"$",
"source",
"->",
"getTarget",
"(",
")",
")",
")",
"||",
"(",
"$",
"target",
"->",
"isTargetEmpty",
"(",
")",
"&&",
"$",
"source",
"->",
"isTargetEmpty",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"this",
"->",
"logLevel",
",",
"'{key}: Target is same, no need to update.'",
",",
"[",
"'key'",
"=>",
"$",
"target",
"->",
"getKey",
"(",
")",
",",
"'old'",
"=>",
"$",
"oldValue",
",",
"'new'",
"=>",
"$",
"newValue",
"]",
")",
";",
"return",
";",
"}",
"if",
"(",
"(",
"self",
"::",
"COPY_IF_EMPTY",
"===",
"$",
"this",
"->",
"copyTarget",
")",
"&&",
"!",
"$",
"target",
"->",
"isTargetEmpty",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"this",
"->",
"logLevel",
",",
"'{key}: Target is not empty, no need to update.'",
",",
"[",
"'key'",
"=>",
"$",
"target",
"->",
"getKey",
"(",
")",
",",
"'old'",
"=>",
"$",
"oldValue",
",",
"'new'",
"=>",
"$",
"newValue",
"]",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"LogLevel",
"::",
"NOTICE",
",",
"'{key}: Updating target value.'",
",",
"[",
"'key'",
"=>",
"$",
"target",
"->",
"getKey",
"(",
")",
",",
"'old'",
"=>",
"$",
"oldValue",
",",
"'new'",
"=>",
"$",
"newValue",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dryRun",
")",
"{",
"return",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"value",
"=",
"$",
"source",
"->",
"getTarget",
"(",
")",
")",
"{",
"$",
"target",
"->",
"clearTarget",
"(",
")",
";",
"return",
";",
"}",
"$",
"target",
"->",
"setTarget",
"(",
"$",
"value",
")",
";",
"}"
] |
Copy the target value.
@param TranslationValueInterface $source The source value.
@param WritableTranslationValueInterface $target The target value.
@return void
|
[
"Copy",
"the",
"target",
"value",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L418-L460
|
236,387
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.cleanTarget
|
private function cleanTarget(): void
{
foreach ($this->targetDictionary->keys() as $key) {
if (!$this->sourceDictionary->has($key) || $this->sourceDictionary->get($key)->isSourceEmpty()) {
$this->logger->log($this->logLevel, 'Removing obsolete {key}.', ['key' => $key]);
if ($this->dryRun) {
continue;
}
$this->targetDictionary->remove($key);
}
}
}
|
php
|
private function cleanTarget(): void
{
foreach ($this->targetDictionary->keys() as $key) {
if (!$this->sourceDictionary->has($key) || $this->sourceDictionary->get($key)->isSourceEmpty()) {
$this->logger->log($this->logLevel, 'Removing obsolete {key}.', ['key' => $key]);
if ($this->dryRun) {
continue;
}
$this->targetDictionary->remove($key);
}
}
}
|
[
"private",
"function",
"cleanTarget",
"(",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"targetDictionary",
"->",
"keys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"sourceDictionary",
"->",
"has",
"(",
"$",
"key",
")",
"||",
"$",
"this",
"->",
"sourceDictionary",
"->",
"get",
"(",
"$",
"key",
")",
"->",
"isSourceEmpty",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"this",
"->",
"logLevel",
",",
"'Removing obsolete {key}.'",
",",
"[",
"'key'",
"=>",
"$",
"key",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dryRun",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"targetDictionary",
"->",
"remove",
"(",
"$",
"key",
")",
";",
"}",
"}",
"}"
] |
Clean the target language.
@return void
|
[
"Clean",
"the",
"target",
"language",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L467-L479
|
236,388
|
cyberspectrum/i18n
|
src/Job/CopyDictionaryJob.php
|
CopyDictionaryJob.isFiltered
|
private function isFiltered($key): bool
{
foreach ($this->filters as $expression) {
if (preg_match($expression, $key)) {
$this->logger->debug(sprintf('"%1$s" is filtered by "%2$s', $key, $expression));
return true;
}
}
return false;
}
|
php
|
private function isFiltered($key): bool
{
foreach ($this->filters as $expression) {
if (preg_match($expression, $key)) {
$this->logger->debug(sprintf('"%1$s" is filtered by "%2$s', $key, $expression));
return true;
}
}
return false;
}
|
[
"private",
"function",
"isFiltered",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"expression",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"expression",
",",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'\"%1$s\" is filtered by \"%2$s'",
",",
"$",
"key",
",",
"$",
"expression",
")",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if the passed key is filtered by any of the regexes.
@param string $key The key to check.
@return bool
|
[
"Check",
"if",
"the",
"passed",
"key",
"is",
"filtered",
"by",
"any",
"of",
"the",
"regexes",
"."
] |
138e81d7119db82c2420bd33967a566e02b1d2f5
|
https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Job/CopyDictionaryJob.php#L488-L498
|
236,389
|
dngo-io/steem-api
|
src/API/Post.php
|
Post.getContentReplies
|
public function getContentReplies(string $author, string $permalink)
{
$request = [
'route' => 'get_content_replies',
'query' =>
[
'author' => $author,
'permlink' => $permalink,
]
];
return parent::call($request);
}
|
php
|
public function getContentReplies(string $author, string $permalink)
{
$request = [
'route' => 'get_content_replies',
'query' =>
[
'author' => $author,
'permlink' => $permalink,
]
];
return parent::call($request);
}
|
[
"public",
"function",
"getContentReplies",
"(",
"string",
"$",
"author",
",",
"string",
"$",
"permalink",
")",
"{",
"$",
"request",
"=",
"[",
"'route'",
"=>",
"'get_content_replies'",
",",
"'query'",
"=>",
"[",
"'author'",
"=>",
"$",
"author",
",",
"'permlink'",
"=>",
"$",
"permalink",
",",
"]",
"]",
";",
"return",
"parent",
"::",
"call",
"(",
"$",
"request",
")",
";",
"}"
] |
Get content replies
@param string $author Author's account name
@param string $permalink Post's permalink
@return array
|
[
"Get",
"content",
"replies"
] |
1117e903a882354ac143b28cbfb9ee00a2351e09
|
https://github.com/dngo-io/steem-api/blob/1117e903a882354ac143b28cbfb9ee00a2351e09/src/API/Post.php#L55-L67
|
236,390
|
dngo-io/steem-api
|
src/API/Post.php
|
Post.getContentAllReplies
|
public function getContentAllReplies(string $author, string $permalink)
{
$request = $this->getContentReplies($author, $permalink);
if(is_array($request))
{
foreach ($request as $key => $item)
{
if($item['children'] > 0)
$request[$key]['replies'] = $this->getContentAllReplies($item['author'], $item['permlink']);
else
$request[$key]['replies'] = [];
}
}
return $request;
}
|
php
|
public function getContentAllReplies(string $author, string $permalink)
{
$request = $this->getContentReplies($author, $permalink);
if(is_array($request))
{
foreach ($request as $key => $item)
{
if($item['children'] > 0)
$request[$key]['replies'] = $this->getContentAllReplies($item['author'], $item['permlink']);
else
$request[$key]['replies'] = [];
}
}
return $request;
}
|
[
"public",
"function",
"getContentAllReplies",
"(",
"string",
"$",
"author",
",",
"string",
"$",
"permalink",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getContentReplies",
"(",
"$",
"author",
",",
"$",
"permalink",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"request",
")",
")",
"{",
"foreach",
"(",
"$",
"request",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'children'",
"]",
">",
"0",
")",
"$",
"request",
"[",
"$",
"key",
"]",
"[",
"'replies'",
"]",
"=",
"$",
"this",
"->",
"getContentAllReplies",
"(",
"$",
"item",
"[",
"'author'",
"]",
",",
"$",
"item",
"[",
"'permlink'",
"]",
")",
";",
"else",
"$",
"request",
"[",
"$",
"key",
"]",
"[",
"'replies'",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"return",
"$",
"request",
";",
"}"
] |
Get all content replies
@param string $author Author's account name
@param string $permalink Post's permalink
@return array
|
[
"Get",
"all",
"content",
"replies"
] |
1117e903a882354ac143b28cbfb9ee00a2351e09
|
https://github.com/dngo-io/steem-api/blob/1117e903a882354ac143b28cbfb9ee00a2351e09/src/API/Post.php#L76-L92
|
236,391
|
pokap/pool-dbm
|
src/Pok/PoolDBM/Console/ConsoleRunner.php
|
ConsoleRunner.run
|
public static function run(HelperSet $helperSet, $commands = array())
{
$cli = new Application('PoolDBM Command Line Interface', Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet(new HelperSet($helperSet));
self::addDefaultCommands($cli);
$cli->addCommands($commands);
$cli->run();
}
|
php
|
public static function run(HelperSet $helperSet, $commands = array())
{
$cli = new Application('PoolDBM Command Line Interface', Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet(new HelperSet($helperSet));
self::addDefaultCommands($cli);
$cli->addCommands($commands);
$cli->run();
}
|
[
"public",
"static",
"function",
"run",
"(",
"HelperSet",
"$",
"helperSet",
",",
"$",
"commands",
"=",
"array",
"(",
")",
")",
"{",
"$",
"cli",
"=",
"new",
"Application",
"(",
"'PoolDBM Command Line Interface'",
",",
"Version",
"::",
"VERSION",
")",
";",
"$",
"cli",
"->",
"setCatchExceptions",
"(",
"true",
")",
";",
"$",
"cli",
"->",
"setHelperSet",
"(",
"new",
"HelperSet",
"(",
"$",
"helperSet",
")",
")",
";",
"self",
"::",
"addDefaultCommands",
"(",
"$",
"cli",
")",
";",
"$",
"cli",
"->",
"addCommands",
"(",
"$",
"commands",
")",
";",
"$",
"cli",
"->",
"run",
"(",
")",
";",
"}"
] |
Runs console with the given helperset.
@param HelperSet $helperSet
@param \Symfony\Component\Console\Command\Command[] $commands
@return void
|
[
"Runs",
"console",
"with",
"the",
"given",
"helperset",
"."
] |
cce32d7cb5f13f42c358c8140b2f97ddf1d9435a
|
https://github.com/pokap/pool-dbm/blob/cce32d7cb5f13f42c358c8140b2f97ddf1d9435a/src/Pok/PoolDBM/Console/ConsoleRunner.php#L52-L60
|
236,392
|
pletfix/core
|
src/Services/Stdio.php
|
Stdio.block
|
private function block($textblock)
{
$length = 0;
foreach ($textblock as $line) {
$n = strlen($line);
if ($length < $n) {
$length = $n;
}
}
foreach ($textblock as $i => $line) {
$textblock[$i] .= str_repeat(' ', $length - strlen($line));
}
return $textblock;
}
|
php
|
private function block($textblock)
{
$length = 0;
foreach ($textblock as $line) {
$n = strlen($line);
if ($length < $n) {
$length = $n;
}
}
foreach ($textblock as $i => $line) {
$textblock[$i] .= str_repeat(' ', $length - strlen($line));
}
return $textblock;
}
|
[
"private",
"function",
"block",
"(",
"$",
"textblock",
")",
"{",
"$",
"length",
"=",
"0",
";",
"foreach",
"(",
"$",
"textblock",
"as",
"$",
"line",
")",
"{",
"$",
"n",
"=",
"strlen",
"(",
"$",
"line",
")",
";",
"if",
"(",
"$",
"length",
"<",
"$",
"n",
")",
"{",
"$",
"length",
"=",
"$",
"n",
";",
"}",
"}",
"foreach",
"(",
"$",
"textblock",
"as",
"$",
"i",
"=>",
"$",
"line",
")",
"{",
"$",
"textblock",
"[",
"$",
"i",
"]",
".=",
"str_repeat",
"(",
"' '",
",",
"$",
"length",
"-",
"strlen",
"(",
"$",
"line",
")",
")",
";",
"}",
"return",
"$",
"textblock",
";",
"}"
] |
Fill each line with spaces, so that all are equal in length.
@param string[] $textblock
@return string[]
|
[
"Fill",
"each",
"line",
"with",
"spaces",
"so",
"that",
"all",
"are",
"equal",
"in",
"length",
"."
] |
974945500f278eb6c1779832e08bbfca1007a7b3
|
https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/Stdio.php#L437-L452
|
236,393
|
juanparati/Emoji
|
src/EmojiDictionary.php
|
EmojiDictionary.get
|
public static function get($symbol)
{
$symbol = strtolower($symbol);
if (isset(static::$dictionary[$symbol]))
return static::$dictionary[$symbol];
else
return false;
}
|
php
|
public static function get($symbol)
{
$symbol = strtolower($symbol);
if (isset(static::$dictionary[$symbol]))
return static::$dictionary[$symbol];
else
return false;
}
|
[
"public",
"static",
"function",
"get",
"(",
"$",
"symbol",
")",
"{",
"$",
"symbol",
"=",
"strtolower",
"(",
"$",
"symbol",
")",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"dictionary",
"[",
"$",
"symbol",
"]",
")",
")",
"return",
"static",
"::",
"$",
"dictionary",
"[",
"$",
"symbol",
"]",
";",
"else",
"return",
"false",
";",
"}"
] |
Get symbol by name
@param $symbol
@return mixed
|
[
"Get",
"symbol",
"by",
"name"
] |
53a34e1d3714f2a11ddc0451030eee06ea2f8f21
|
https://github.com/juanparati/Emoji/blob/53a34e1d3714f2a11ddc0451030eee06ea2f8f21/src/EmojiDictionary.php#L1832-L1841
|
236,394
|
flowcode/AmulenShopBundle
|
src/Flowcode/ShopBundle/Controller/AdminProductOrderController.php
|
AdminProductOrderController.newAction
|
public function newAction()
{
$entity = new ProductOrder();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
|
php
|
public function newAction()
{
$entity = new ProductOrder();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
|
[
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"entity",
"=",
"new",
"ProductOrder",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"entity",
")",
";",
"return",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] |
Displays a form to create a new ProductOrder entity.
@Route("/new", name="admin_order_new")
@Method("GET")
@Template()
|
[
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"ProductOrder",
"entity",
"."
] |
500aaf4364be3c42fca69ecd10a449da03993814
|
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/AdminProductOrderController.php#L107-L116
|
236,395
|
monolyth-php/formulaic
|
src/Validate/Element.php
|
Element.errors
|
public function errors() : array
{
$errors = [];
foreach ($this->tests as $error => $test) {
if (!$test($this->getValue())) {
$errors[] = $error;
}
}
return $errors;
}
|
php
|
public function errors() : array
{
$errors = [];
foreach ($this->tests as $error => $test) {
if (!$test($this->getValue())) {
$errors[] = $error;
}
}
return $errors;
}
|
[
"public",
"function",
"errors",
"(",
")",
":",
"array",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"tests",
"as",
"$",
"error",
"=>",
"$",
"test",
")",
"{",
"if",
"(",
"!",
"$",
"test",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"$",
"error",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Get array of errors for element.
@return array
|
[
"Get",
"array",
"of",
"errors",
"for",
"element",
"."
] |
4bf7853a0c29cc17957f1b26c79f633867742c14
|
https://github.com/monolyth-php/formulaic/blob/4bf7853a0c29cc17957f1b26c79f633867742c14/src/Validate/Element.php#L22-L31
|
236,396
|
JackieDo/Omnipay-Validator
|
src/Traits/ValidatorTrait.php
|
ValidatorTrait.validateWithRules
|
public function validateWithRules(array $validateRules, array $validateMessages = [], array $parametricConverter = [])
{
$this->validateDataWithRules($this->getParameters(), $validateRules, $validateMessages, $parametricConverter);
}
|
php
|
public function validateWithRules(array $validateRules, array $validateMessages = [], array $parametricConverter = [])
{
$this->validateDataWithRules($this->getParameters(), $validateRules, $validateMessages, $parametricConverter);
}
|
[
"public",
"function",
"validateWithRules",
"(",
"array",
"$",
"validateRules",
",",
"array",
"$",
"validateMessages",
"=",
"[",
"]",
",",
"array",
"$",
"parametricConverter",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"validateDataWithRules",
"(",
"$",
"this",
"->",
"getParameters",
"(",
")",
",",
"$",
"validateRules",
",",
"$",
"validateMessages",
",",
"$",
"parametricConverter",
")",
";",
"}"
] |
Validate all parameters of request with defined rules.
This method is called internally by gateways to avoid wasting time with an API call
when the request is clearly invalid.
@param array $validateRules
@param array $validateMessages
@param array $parametricConverter
@throws InvalidRequestException
@throws BadMethodCallException
|
[
"Validate",
"all",
"parameters",
"of",
"request",
"with",
"defined",
"rules",
"."
] |
5aa780712fb0eddec28d0745a036859c95f96a34
|
https://github.com/JackieDo/Omnipay-Validator/blob/5aa780712fb0eddec28d0745a036859c95f96a34/src/Traits/ValidatorTrait.php#L73-L76
|
236,397
|
JackieDo/Omnipay-Validator
|
src/Traits/ValidatorTrait.php
|
ValidatorTrait.validateDataWithRules
|
public function validateDataWithRules(array $data, array $validateRules, array $validateMessages = [], array $parametricConverter = [])
{
foreach ($validateRules as $key => $rules) {
$value = array_key_exists($key, $data) ? $data[$key] : null;
if (array_key_exists('nullable', $rules) && $rules['nullable'] && is_null($value)) {
continue;
}
unset($rules['nullable']);
$defaultParametricConverter = (method_exists($this, 'getParametricConverter') && is_array($this->getParametricConverter())) ? $this->getParametricConverter() : [];
$parametricConverter = array_merge($defaultParametricConverter, $parametricConverter);
$parameter = (array_key_exists($key, $parametricConverter)) ? $parametricConverter[$key] : $key;
foreach ($rules as $ruleName => $ruleParameter) {
if ($ruleName === 'callback') {
if (!is_callable($ruleParameter)) {
throw new BadMethodCallException('The reference of rule named `callback` must be a valid callable. You provided ' . $this->getValueDescription($ruleParameter) . '.');
}
call_user_func($ruleParameter, $value, InvalidRequestException::class);
} else {
$method = 'check'.ucfirst(Helper::camelCase($ruleName));
if (!method_exists($this, $method)) {
throw new BadMethodCallException('Call to undefined the ' .get_class($this). '::' .$method. '() validator that associated with the `' .$ruleName. '` rule');
}
if (!$this->$method($value, $ruleParameter)) {
$message = isset($validateMessages[$key][$ruleName]) ? $validateMessages[$key][$ruleName] : null;
throw new InvalidRequestException($this->formatMessage($parameter, $ruleName, $ruleParameter, $message));
}
}
}
}
}
|
php
|
public function validateDataWithRules(array $data, array $validateRules, array $validateMessages = [], array $parametricConverter = [])
{
foreach ($validateRules as $key => $rules) {
$value = array_key_exists($key, $data) ? $data[$key] : null;
if (array_key_exists('nullable', $rules) && $rules['nullable'] && is_null($value)) {
continue;
}
unset($rules['nullable']);
$defaultParametricConverter = (method_exists($this, 'getParametricConverter') && is_array($this->getParametricConverter())) ? $this->getParametricConverter() : [];
$parametricConverter = array_merge($defaultParametricConverter, $parametricConverter);
$parameter = (array_key_exists($key, $parametricConverter)) ? $parametricConverter[$key] : $key;
foreach ($rules as $ruleName => $ruleParameter) {
if ($ruleName === 'callback') {
if (!is_callable($ruleParameter)) {
throw new BadMethodCallException('The reference of rule named `callback` must be a valid callable. You provided ' . $this->getValueDescription($ruleParameter) . '.');
}
call_user_func($ruleParameter, $value, InvalidRequestException::class);
} else {
$method = 'check'.ucfirst(Helper::camelCase($ruleName));
if (!method_exists($this, $method)) {
throw new BadMethodCallException('Call to undefined the ' .get_class($this). '::' .$method. '() validator that associated with the `' .$ruleName. '` rule');
}
if (!$this->$method($value, $ruleParameter)) {
$message = isset($validateMessages[$key][$ruleName]) ? $validateMessages[$key][$ruleName] : null;
throw new InvalidRequestException($this->formatMessage($parameter, $ruleName, $ruleParameter, $message));
}
}
}
}
}
|
[
"public",
"function",
"validateDataWithRules",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"validateRules",
",",
"array",
"$",
"validateMessages",
"=",
"[",
"]",
",",
"array",
"$",
"parametricConverter",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"validateRules",
"as",
"$",
"key",
"=>",
"$",
"rules",
")",
"{",
"$",
"value",
"=",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
"?",
"$",
"data",
"[",
"$",
"key",
"]",
":",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"'nullable'",
",",
"$",
"rules",
")",
"&&",
"$",
"rules",
"[",
"'nullable'",
"]",
"&&",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"unset",
"(",
"$",
"rules",
"[",
"'nullable'",
"]",
")",
";",
"$",
"defaultParametricConverter",
"=",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'getParametricConverter'",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"getParametricConverter",
"(",
")",
")",
")",
"?",
"$",
"this",
"->",
"getParametricConverter",
"(",
")",
":",
"[",
"]",
";",
"$",
"parametricConverter",
"=",
"array_merge",
"(",
"$",
"defaultParametricConverter",
",",
"$",
"parametricConverter",
")",
";",
"$",
"parameter",
"=",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"parametricConverter",
")",
")",
"?",
"$",
"parametricConverter",
"[",
"$",
"key",
"]",
":",
"$",
"key",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"ruleName",
"=>",
"$",
"ruleParameter",
")",
"{",
"if",
"(",
"$",
"ruleName",
"===",
"'callback'",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"ruleParameter",
")",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'The reference of rule named `callback` must be a valid callable. You provided '",
".",
"$",
"this",
"->",
"getValueDescription",
"(",
"$",
"ruleParameter",
")",
".",
"'.'",
")",
";",
"}",
"call_user_func",
"(",
"$",
"ruleParameter",
",",
"$",
"value",
",",
"InvalidRequestException",
"::",
"class",
")",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"'check'",
".",
"ucfirst",
"(",
"Helper",
"::",
"camelCase",
"(",
"$",
"ruleName",
")",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'Call to undefined the '",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"'::'",
".",
"$",
"method",
".",
"'() validator that associated with the `'",
".",
"$",
"ruleName",
".",
"'` rule'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"value",
",",
"$",
"ruleParameter",
")",
")",
"{",
"$",
"message",
"=",
"isset",
"(",
"$",
"validateMessages",
"[",
"$",
"key",
"]",
"[",
"$",
"ruleName",
"]",
")",
"?",
"$",
"validateMessages",
"[",
"$",
"key",
"]",
"[",
"$",
"ruleName",
"]",
":",
"null",
";",
"throw",
"new",
"InvalidRequestException",
"(",
"$",
"this",
"->",
"formatMessage",
"(",
"$",
"parameter",
",",
"$",
"ruleName",
",",
"$",
"ruleParameter",
",",
"$",
"message",
")",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Validate data with defined rules
@param array $data
@param array $validateRules
@param array $validateMessages
@param array $parametricConverter
@throws InvalidRequestException
@throws BadMethodCallException
|
[
"Validate",
"data",
"with",
"defined",
"rules"
] |
5aa780712fb0eddec28d0745a036859c95f96a34
|
https://github.com/JackieDo/Omnipay-Validator/blob/5aa780712fb0eddec28d0745a036859c95f96a34/src/Traits/ValidatorTrait.php#L88-L125
|
236,398
|
JackieDo/Omnipay-Validator
|
src/Traits/ValidatorTrait.php
|
ValidatorTrait.formatMessage
|
protected function formatMessage($parameter, $ruleName, $ruleParameter, $message = null)
{
$message = $message ?: (isset($this->validateMessages[$ruleName]) ? $this->validateMessages[$ruleName] : $this->validateMessages['default']);
$message = str_replace(':parameter', $parameter, $message);
$method = 'format'.ucfirst(Helper::camelCase($ruleName)).'Message';
if (method_exists($this, $method)) {
return $this->$method($ruleParameter, $message);
}
return $message;
}
|
php
|
protected function formatMessage($parameter, $ruleName, $ruleParameter, $message = null)
{
$message = $message ?: (isset($this->validateMessages[$ruleName]) ? $this->validateMessages[$ruleName] : $this->validateMessages['default']);
$message = str_replace(':parameter', $parameter, $message);
$method = 'format'.ucfirst(Helper::camelCase($ruleName)).'Message';
if (method_exists($this, $method)) {
return $this->$method($ruleParameter, $message);
}
return $message;
}
|
[
"protected",
"function",
"formatMessage",
"(",
"$",
"parameter",
",",
"$",
"ruleName",
",",
"$",
"ruleParameter",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"message",
"=",
"$",
"message",
"?",
":",
"(",
"isset",
"(",
"$",
"this",
"->",
"validateMessages",
"[",
"$",
"ruleName",
"]",
")",
"?",
"$",
"this",
"->",
"validateMessages",
"[",
"$",
"ruleName",
"]",
":",
"$",
"this",
"->",
"validateMessages",
"[",
"'default'",
"]",
")",
";",
"$",
"message",
"=",
"str_replace",
"(",
"':parameter'",
",",
"$",
"parameter",
",",
"$",
"message",
")",
";",
"$",
"method",
"=",
"'format'",
".",
"ucfirst",
"(",
"Helper",
"::",
"camelCase",
"(",
"$",
"ruleName",
")",
")",
".",
"'Message'",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"ruleParameter",
",",
"$",
"message",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
] |
Format message for special rule
@param string $parameter
@param string $ruleName
@param mixed $ruleParameter
@param string $customMessage
@return string
|
[
"Format",
"message",
"for",
"special",
"rule"
] |
5aa780712fb0eddec28d0745a036859c95f96a34
|
https://github.com/JackieDo/Omnipay-Validator/blob/5aa780712fb0eddec28d0745a036859c95f96a34/src/Traits/ValidatorTrait.php#L137-L148
|
236,399
|
JackieDo/Omnipay-Validator
|
src/Traits/ValidatorTrait.php
|
ValidatorTrait.getValueDescription
|
protected function getValueDescription($value)
{
switch (true) {
case (is_numeric($value)):
$value = strval($value);
break;
case (is_bool($value) && $value):
$value = '(boolean) true';
break;
case (is_bool($value) && !$value):
$value = '(boolean) false';
break;
case (is_null($value)):
$value = 'null value';
break;
default:
break;
}
return $value;
}
|
php
|
protected function getValueDescription($value)
{
switch (true) {
case (is_numeric($value)):
$value = strval($value);
break;
case (is_bool($value) && $value):
$value = '(boolean) true';
break;
case (is_bool($value) && !$value):
$value = '(boolean) false';
break;
case (is_null($value)):
$value = 'null value';
break;
default:
break;
}
return $value;
}
|
[
"protected",
"function",
"getValueDescription",
"(",
"$",
"value",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
":",
"$",
"value",
"=",
"strval",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"(",
"is_bool",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
")",
":",
"$",
"value",
"=",
"'(boolean) true'",
";",
"break",
";",
"case",
"(",
"is_bool",
"(",
"$",
"value",
")",
"&&",
"!",
"$",
"value",
")",
":",
"$",
"value",
"=",
"'(boolean) false'",
";",
"break",
";",
"case",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
":",
"$",
"value",
"=",
"'null value'",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Get description of value
@param mixed $value
@return string
|
[
"Get",
"description",
"of",
"value"
] |
5aa780712fb0eddec28d0745a036859c95f96a34
|
https://github.com/JackieDo/Omnipay-Validator/blob/5aa780712fb0eddec28d0745a036859c95f96a34/src/Traits/ValidatorTrait.php#L157-L181
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.