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
229,800
pingpong-labs/widget
Widget.php
Widget.callGroup
public function callGroup($name, $parameters = array()) { if (!$this->hasGroup($name)) { return; } $result = ''; foreach ($this->groups[$name] as $key => $widget) { $result .= $this->get($widget, array_get($parameters, $key, array())); } return $result; }
php
public function callGroup($name, $parameters = array()) { if (!$this->hasGroup($name)) { return; } $result = ''; foreach ($this->groups[$name] as $key => $widget) { $result .= $this->get($widget, array_get($parameters, $key, array())); } return $result; }
[ "public", "function", "callGroup", "(", "$", "name", ",", "$", "parameters", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "this", "->", "hasGroup", "(", "$", "name", ")", ")", "{", "return", ";", "}", "$", "result", "=", "''", ";", "foreach", "(", "$", "this", "->", "groups", "[", "$", "name", "]", "as", "$", "key", "=>", "$", "widget", ")", "{", "$", "result", ".=", "$", "this", "->", "get", "(", "$", "widget", ",", "array_get", "(", "$", "parameters", ",", "$", "key", ",", "array", "(", ")", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Call a specific group of widgets. @param string $name @param array $parameters @return string
[ "Call", "a", "specific", "group", "of", "widgets", "." ]
4d3d4667da4b7037a0d00c42d1017e1edc0b8315
https://github.com/pingpong-labs/widget/blob/4d3d4667da4b7037a0d00c42d1017e1edc0b8315/Widget.php#L262-L275
229,801
pingpong-labs/widget
Widget.php
Widget.reorderWidgets
protected function reorderWidgets($widgets) { $formatted = []; foreach ($widgets as $key => $widget) { if (is_array($widget)) { $formatted[] = [ 'name' => array_get($widget, 0), 'order' => array_get($widget, 1), ]; } else { $formatted[] = [ 'name' => $widget, 'order' => $key, ]; } } return collect($formatted)->sortBy(function ($widget) { return $widget['order']; })->all(); }
php
protected function reorderWidgets($widgets) { $formatted = []; foreach ($widgets as $key => $widget) { if (is_array($widget)) { $formatted[] = [ 'name' => array_get($widget, 0), 'order' => array_get($widget, 1), ]; } else { $formatted[] = [ 'name' => $widget, 'order' => $key, ]; } } return collect($formatted)->sortBy(function ($widget) { return $widget['order']; })->all(); }
[ "protected", "function", "reorderWidgets", "(", "$", "widgets", ")", "{", "$", "formatted", "=", "[", "]", ";", "foreach", "(", "$", "widgets", "as", "$", "key", "=>", "$", "widget", ")", "{", "if", "(", "is_array", "(", "$", "widget", ")", ")", "{", "$", "formatted", "[", "]", "=", "[", "'name'", "=>", "array_get", "(", "$", "widget", ",", "0", ")", ",", "'order'", "=>", "array_get", "(", "$", "widget", ",", "1", ")", ",", "]", ";", "}", "else", "{", "$", "formatted", "[", "]", "=", "[", "'name'", "=>", "$", "widget", ",", "'order'", "=>", "$", "key", ",", "]", ";", "}", "}", "return", "collect", "(", "$", "formatted", ")", "->", "sortBy", "(", "function", "(", "$", "widget", ")", "{", "return", "$", "widget", "[", "'order'", "]", ";", "}", ")", "->", "all", "(", ")", ";", "}" ]
Reorder widgets. @param array $widgets @return array
[ "Reorder", "widgets", "." ]
4d3d4667da4b7037a0d00c42d1017e1edc0b8315
https://github.com/pingpong-labs/widget/blob/4d3d4667da4b7037a0d00c42d1017e1edc0b8315/Widget.php#L314-L335
229,802
ZenMagick/ZenCart
includes/modules/order_total/ot_gv.php
ot_gv.pre_confirmation_check
function pre_confirmation_check($order_total) { global $order, $currencies, $messageStack; // clean out negative values and strip common currency symbols $_SESSION['cot_gv'] = preg_replace('/[^0-9.%]/', '', $_SESSION['cot_gv']); $_SESSION['cot_gv'] = abs($_SESSION['cot_gv']); if ($_SESSION['cot_gv'] > 0) { // if cot_gv value contains any nonvalid characters, throw error if (preg_match('/[^0-9\.]/', trim($_SESSION['cot_gv']))) { $messageStack->add_session('checkout_payment', TEXT_INVALID_REDEEM_AMOUNT, error); zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); } // if requested redemption amount is greater than value of credits on account, throw error if ($_SESSION['cot_gv'] > $currencies->value($this->user_has_gv_account($_SESSION['customer_id']))) { $messageStack->add_session('checkout_payment', TEXT_INVALID_REDEEM_AMOUNT, error); zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); } $od_amount = $this->calculate_deductions($order_total); $order->info['total'] = $order->info['total'] - $od_amount['total']; if (DISPLAY_PRICE_WITH_TAX != 'true') { $order->info['total'] -= $tax; } return $od_amount['total'] + $od_amount['tax']; } return 0; }
php
function pre_confirmation_check($order_total) { global $order, $currencies, $messageStack; // clean out negative values and strip common currency symbols $_SESSION['cot_gv'] = preg_replace('/[^0-9.%]/', '', $_SESSION['cot_gv']); $_SESSION['cot_gv'] = abs($_SESSION['cot_gv']); if ($_SESSION['cot_gv'] > 0) { // if cot_gv value contains any nonvalid characters, throw error if (preg_match('/[^0-9\.]/', trim($_SESSION['cot_gv']))) { $messageStack->add_session('checkout_payment', TEXT_INVALID_REDEEM_AMOUNT, error); zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); } // if requested redemption amount is greater than value of credits on account, throw error if ($_SESSION['cot_gv'] > $currencies->value($this->user_has_gv_account($_SESSION['customer_id']))) { $messageStack->add_session('checkout_payment', TEXT_INVALID_REDEEM_AMOUNT, error); zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); } $od_amount = $this->calculate_deductions($order_total); $order->info['total'] = $order->info['total'] - $od_amount['total']; if (DISPLAY_PRICE_WITH_TAX != 'true') { $order->info['total'] -= $tax; } return $od_amount['total'] + $od_amount['tax']; } return 0; }
[ "function", "pre_confirmation_check", "(", "$", "order_total", ")", "{", "global", "$", "order", ",", "$", "currencies", ",", "$", "messageStack", ";", "// clean out negative values and strip common currency symbols", "$", "_SESSION", "[", "'cot_gv'", "]", "=", "preg_replace", "(", "'/[^0-9.%]/'", ",", "''", ",", "$", "_SESSION", "[", "'cot_gv'", "]", ")", ";", "$", "_SESSION", "[", "'cot_gv'", "]", "=", "abs", "(", "$", "_SESSION", "[", "'cot_gv'", "]", ")", ";", "if", "(", "$", "_SESSION", "[", "'cot_gv'", "]", ">", "0", ")", "{", "// if cot_gv value contains any nonvalid characters, throw error", "if", "(", "preg_match", "(", "'/[^0-9\\.]/'", ",", "trim", "(", "$", "_SESSION", "[", "'cot_gv'", "]", ")", ")", ")", "{", "$", "messageStack", "->", "add_session", "(", "'checkout_payment'", ",", "TEXT_INVALID_REDEEM_AMOUNT", ",", "error", ")", ";", "zen_redirect", "(", "zen_href_link", "(", "FILENAME_CHECKOUT_PAYMENT", ",", "''", ",", "'SSL'", ")", ")", ";", "}", "// if requested redemption amount is greater than value of credits on account, throw error", "if", "(", "$", "_SESSION", "[", "'cot_gv'", "]", ">", "$", "currencies", "->", "value", "(", "$", "this", "->", "user_has_gv_account", "(", "$", "_SESSION", "[", "'customer_id'", "]", ")", ")", ")", "{", "$", "messageStack", "->", "add_session", "(", "'checkout_payment'", ",", "TEXT_INVALID_REDEEM_AMOUNT", ",", "error", ")", ";", "zen_redirect", "(", "zen_href_link", "(", "FILENAME_CHECKOUT_PAYMENT", ",", "''", ",", "'SSL'", ")", ")", ";", "}", "$", "od_amount", "=", "$", "this", "->", "calculate_deductions", "(", "$", "order_total", ")", ";", "$", "order", "->", "info", "[", "'total'", "]", "=", "$", "order", "->", "info", "[", "'total'", "]", "-", "$", "od_amount", "[", "'total'", "]", ";", "if", "(", "DISPLAY_PRICE_WITH_TAX", "!=", "'true'", ")", "{", "$", "order", "->", "info", "[", "'total'", "]", "-=", "$", "tax", ";", "}", "return", "$", "od_amount", "[", "'total'", "]", "+", "$", "od_amount", "[", "'tax'", "]", ";", "}", "return", "0", ";", "}" ]
Check for validity of redemption amounts and recalculate order totals to include proposed GV redemption deductions
[ "Check", "for", "validity", "of", "redemption", "amounts", "and", "recalculate", "order", "totals", "to", "include", "proposed", "GV", "redemption", "deductions" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/order_total/ot_gv.php#L105-L130
229,803
ZenMagick/ZenCart
includes/modules/order_total/ot_gv.php
ot_gv.update_credit_account
function update_credit_account($i) { global $db, $order, $insert_id; // only act on newly-purchased gift certificates if (preg_match('/^GIFT/', addslashes($order->products[$i]['model']))) { // determine how much GV was purchased $gv_order_amount = ($order->products[$i]['final_price'] * $order->products[$i]['qty']); // if tax is to be calculated on purchased GVs, calculate it if ($this->credit_tax=='true') $gv_order_amount = $gv_order_amount * (100 + $order->products[$i]['tax']) / 100; $gv_order_amount = $gv_order_amount * 100 / 100; if (MODULE_ORDER_TOTAL_GV_QUEUE == 'false') { // GV_QUEUE is false so release amount to account immediately $gv_result = $this->user_has_gv_account($_SESSION['customer_id']); $customer_gv = false; $total_gv_amount = 0; if ($gv_result) { $total_gv_amount = $gv_result; $customer_gv = true; } $total_gv_amount = $total_gv_amount + $gv_order_amount; if ($customer_gv) { $db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $total_gv_amount . "' where customer_id = '" . (int)$_SESSION['customer_id'] . "'"); } else { $db->Execute("insert into " . TABLE_COUPON_GV_CUSTOMER . " (customer_id, amount) values ('" . (int)$_SESSION['customer_id'] . "', '" . $total_gv_amount . "')"); } } else { // GV_QUEUE is true - so queue the gv for release by store owner $db->Execute("insert into " . TABLE_COUPON_GV_QUEUE . " (customer_id, order_id, amount, date_created, ipaddr) values ('" . (int)$_SESSION['customer_id'] . "', '" . (int)$insert_id . "', '" . $gv_order_amount . "', NOW(), '" . $_SERVER['REMOTE_ADDR'] . "')"); } } }
php
function update_credit_account($i) { global $db, $order, $insert_id; // only act on newly-purchased gift certificates if (preg_match('/^GIFT/', addslashes($order->products[$i]['model']))) { // determine how much GV was purchased $gv_order_amount = ($order->products[$i]['final_price'] * $order->products[$i]['qty']); // if tax is to be calculated on purchased GVs, calculate it if ($this->credit_tax=='true') $gv_order_amount = $gv_order_amount * (100 + $order->products[$i]['tax']) / 100; $gv_order_amount = $gv_order_amount * 100 / 100; if (MODULE_ORDER_TOTAL_GV_QUEUE == 'false') { // GV_QUEUE is false so release amount to account immediately $gv_result = $this->user_has_gv_account($_SESSION['customer_id']); $customer_gv = false; $total_gv_amount = 0; if ($gv_result) { $total_gv_amount = $gv_result; $customer_gv = true; } $total_gv_amount = $total_gv_amount + $gv_order_amount; if ($customer_gv) { $db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $total_gv_amount . "' where customer_id = '" . (int)$_SESSION['customer_id'] . "'"); } else { $db->Execute("insert into " . TABLE_COUPON_GV_CUSTOMER . " (customer_id, amount) values ('" . (int)$_SESSION['customer_id'] . "', '" . $total_gv_amount . "')"); } } else { // GV_QUEUE is true - so queue the gv for release by store owner $db->Execute("insert into " . TABLE_COUPON_GV_QUEUE . " (customer_id, order_id, amount, date_created, ipaddr) values ('" . (int)$_SESSION['customer_id'] . "', '" . (int)$insert_id . "', '" . $gv_order_amount . "', NOW(), '" . $_SERVER['REMOTE_ADDR'] . "')"); } } }
[ "function", "update_credit_account", "(", "$", "i", ")", "{", "global", "$", "db", ",", "$", "order", ",", "$", "insert_id", ";", "// only act on newly-purchased gift certificates", "if", "(", "preg_match", "(", "'/^GIFT/'", ",", "addslashes", "(", "$", "order", "->", "products", "[", "$", "i", "]", "[", "'model'", "]", ")", ")", ")", "{", "// determine how much GV was purchased", "$", "gv_order_amount", "=", "(", "$", "order", "->", "products", "[", "$", "i", "]", "[", "'final_price'", "]", "*", "$", "order", "->", "products", "[", "$", "i", "]", "[", "'qty'", "]", ")", ";", "// if tax is to be calculated on purchased GVs, calculate it", "if", "(", "$", "this", "->", "credit_tax", "==", "'true'", ")", "$", "gv_order_amount", "=", "$", "gv_order_amount", "*", "(", "100", "+", "$", "order", "->", "products", "[", "$", "i", "]", "[", "'tax'", "]", ")", "/", "100", ";", "$", "gv_order_amount", "=", "$", "gv_order_amount", "*", "100", "/", "100", ";", "if", "(", "MODULE_ORDER_TOTAL_GV_QUEUE", "==", "'false'", ")", "{", "// GV_QUEUE is false so release amount to account immediately", "$", "gv_result", "=", "$", "this", "->", "user_has_gv_account", "(", "$", "_SESSION", "[", "'customer_id'", "]", ")", ";", "$", "customer_gv", "=", "false", ";", "$", "total_gv_amount", "=", "0", ";", "if", "(", "$", "gv_result", ")", "{", "$", "total_gv_amount", "=", "$", "gv_result", ";", "$", "customer_gv", "=", "true", ";", "}", "$", "total_gv_amount", "=", "$", "total_gv_amount", "+", "$", "gv_order_amount", ";", "if", "(", "$", "customer_gv", ")", "{", "$", "db", "->", "Execute", "(", "\"update \"", ".", "TABLE_COUPON_GV_CUSTOMER", ".", "\" set amount = '\"", ".", "$", "total_gv_amount", ".", "\"' where customer_id = '\"", ".", "(", "int", ")", "$", "_SESSION", "[", "'customer_id'", "]", ".", "\"'\"", ")", ";", "}", "else", "{", "$", "db", "->", "Execute", "(", "\"insert into \"", ".", "TABLE_COUPON_GV_CUSTOMER", ".", "\" (customer_id, amount) values ('\"", ".", "(", "int", ")", "$", "_SESSION", "[", "'customer_id'", "]", ".", "\"', '\"", ".", "$", "total_gv_amount", ".", "\"')\"", ")", ";", "}", "}", "else", "{", "// GV_QUEUE is true - so queue the gv for release by store owner", "$", "db", "->", "Execute", "(", "\"insert into \"", ".", "TABLE_COUPON_GV_QUEUE", ".", "\" (customer_id, order_id, amount, date_created, ipaddr) values ('\"", ".", "(", "int", ")", "$", "_SESSION", "[", "'customer_id'", "]", ".", "\"', '\"", ".", "(", "int", ")", "$", "insert_id", ".", "\"', '\"", ".", "$", "gv_order_amount", ".", "\"', NOW(), '\"", ".", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ".", "\"')\"", ")", ";", "}", "}", "}" ]
queue or release newly-purchased GV's
[ "queue", "or", "release", "newly", "-", "purchased", "GV", "s" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/order_total/ot_gv.php#L143-L173
229,804
ZenMagick/ZenCart
includes/modules/order_total/ot_gv.php
ot_gv.credit_selection
function credit_selection() { global $db, $currencies; $gv_query = $db->Execute("select coupon_id from " . TABLE_COUPONS . " where coupon_type = 'G' and coupon_active='Y'"); // checks to see if any GVs are in the system and active or if the current customer has any GV balance if ($gv_query->RecordCount() > 0 || $this->use_credit_amount()) { $selection = array('id' => $this->code, 'module' => $this->title, 'redeem_instructions' => MODULE_ORDER_TOTAL_GV_REDEEM_INSTRUCTIONS, 'checkbox' => $this->use_credit_amount(), 'fields' => array(array('title' => MODULE_ORDER_TOTAL_GV_TEXT_ENTER_CODE, 'field' => zen_draw_input_field('gv_redeem_code', '', 'id="disc-'.$this->code.'" onkeyup="submitFunction(0,0)"'), 'tag' => 'disc-'.$this->code ))); } return $selection; }
php
function credit_selection() { global $db, $currencies; $gv_query = $db->Execute("select coupon_id from " . TABLE_COUPONS . " where coupon_type = 'G' and coupon_active='Y'"); // checks to see if any GVs are in the system and active or if the current customer has any GV balance if ($gv_query->RecordCount() > 0 || $this->use_credit_amount()) { $selection = array('id' => $this->code, 'module' => $this->title, 'redeem_instructions' => MODULE_ORDER_TOTAL_GV_REDEEM_INSTRUCTIONS, 'checkbox' => $this->use_credit_amount(), 'fields' => array(array('title' => MODULE_ORDER_TOTAL_GV_TEXT_ENTER_CODE, 'field' => zen_draw_input_field('gv_redeem_code', '', 'id="disc-'.$this->code.'" onkeyup="submitFunction(0,0)"'), 'tag' => 'disc-'.$this->code ))); } return $selection; }
[ "function", "credit_selection", "(", ")", "{", "global", "$", "db", ",", "$", "currencies", ";", "$", "gv_query", "=", "$", "db", "->", "Execute", "(", "\"select coupon_id from \"", ".", "TABLE_COUPONS", ".", "\" where coupon_type = 'G' and coupon_active='Y'\"", ")", ";", "// checks to see if any GVs are in the system and active or if the current customer has any GV balance", "if", "(", "$", "gv_query", "->", "RecordCount", "(", ")", ">", "0", "||", "$", "this", "->", "use_credit_amount", "(", ")", ")", "{", "$", "selection", "=", "array", "(", "'id'", "=>", "$", "this", "->", "code", ",", "'module'", "=>", "$", "this", "->", "title", ",", "'redeem_instructions'", "=>", "MODULE_ORDER_TOTAL_GV_REDEEM_INSTRUCTIONS", ",", "'checkbox'", "=>", "$", "this", "->", "use_credit_amount", "(", ")", ",", "'fields'", "=>", "array", "(", "array", "(", "'title'", "=>", "MODULE_ORDER_TOTAL_GV_TEXT_ENTER_CODE", ",", "'field'", "=>", "zen_draw_input_field", "(", "'gv_redeem_code'", ",", "''", ",", "'id=\"disc-'", ".", "$", "this", "->", "code", ".", "'\" onkeyup=\"submitFunction(0,0)\"'", ")", ",", "'tag'", "=>", "'disc-'", ".", "$", "this", "->", "code", ")", ")", ")", ";", "}", "return", "$", "selection", ";", "}" ]
check system to see if GVs should be made available or not. If true, then supply GV-selection fields on checkout pages
[ "check", "system", "to", "see", "if", "GVs", "should", "be", "made", "available", "or", "not", ".", "If", "true", "then", "supply", "GV", "-", "selection", "fields", "on", "checkout", "pages" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/order_total/ot_gv.php#L177-L193
229,805
ZenMagick/ZenCart
includes/modules/order_total/ot_gv.php
ot_gv.apply_credit
function apply_credit() { global $db, $order, $messageStack; // check for valid redemption amount vs available credit for current customer if ($_SESSION['cot_gv'] != 0) { $gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$_SESSION['customer_id'] . "'"); // obtain final "deduction" amount $gv_payment_amount = $this->deduction; // determine amount of GV to redeem based on available balance minus qualified/calculated deduction suitable to this order $gv_amount = $gv_result->fields['amount'] - $gv_payment_amount; // reduce customer's GV balance by the amount redeemed $db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $gv_amount . "' where customer_id = '" . (int)$_SESSION['customer_id'] . "'"); } // clear GV redemption flag since it's already been claimed and deducted $_SESSION['cot_gv'] = false; // send back the amount of GV used for payment on this order return $gv_payment_amount; }
php
function apply_credit() { global $db, $order, $messageStack; // check for valid redemption amount vs available credit for current customer if ($_SESSION['cot_gv'] != 0) { $gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$_SESSION['customer_id'] . "'"); // obtain final "deduction" amount $gv_payment_amount = $this->deduction; // determine amount of GV to redeem based on available balance minus qualified/calculated deduction suitable to this order $gv_amount = $gv_result->fields['amount'] - $gv_payment_amount; // reduce customer's GV balance by the amount redeemed $db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $gv_amount . "' where customer_id = '" . (int)$_SESSION['customer_id'] . "'"); } // clear GV redemption flag since it's already been claimed and deducted $_SESSION['cot_gv'] = false; // send back the amount of GV used for payment on this order return $gv_payment_amount; }
[ "function", "apply_credit", "(", ")", "{", "global", "$", "db", ",", "$", "order", ",", "$", "messageStack", ";", "// check for valid redemption amount vs available credit for current customer", "if", "(", "$", "_SESSION", "[", "'cot_gv'", "]", "!=", "0", ")", "{", "$", "gv_result", "=", "$", "db", "->", "Execute", "(", "\"select amount from \"", ".", "TABLE_COUPON_GV_CUSTOMER", ".", "\" where customer_id = '\"", ".", "(", "int", ")", "$", "_SESSION", "[", "'customer_id'", "]", ".", "\"'\"", ")", ";", "// obtain final \"deduction\" amount", "$", "gv_payment_amount", "=", "$", "this", "->", "deduction", ";", "// determine amount of GV to redeem based on available balance minus qualified/calculated deduction suitable to this order", "$", "gv_amount", "=", "$", "gv_result", "->", "fields", "[", "'amount'", "]", "-", "$", "gv_payment_amount", ";", "// reduce customer's GV balance by the amount redeemed", "$", "db", "->", "Execute", "(", "\"update \"", ".", "TABLE_COUPON_GV_CUSTOMER", ".", "\" set amount = '\"", ".", "$", "gv_amount", ".", "\"' where customer_id = '\"", ".", "(", "int", ")", "$", "_SESSION", "[", "'customer_id'", "]", ".", "\"'\"", ")", ";", "}", "// clear GV redemption flag since it's already been claimed and deducted", "$", "_SESSION", "[", "'cot_gv'", "]", "=", "false", ";", "// send back the amount of GV used for payment on this order", "return", "$", "gv_payment_amount", ";", "}" ]
Verify that the customer has entered a valid redemption amount, and return the amount that can be applied to this order
[ "Verify", "that", "the", "customer", "has", "entered", "a", "valid", "redemption", "amount", "and", "return", "the", "amount", "that", "can", "be", "applied", "to", "this", "order" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/order_total/ot_gv.php#L197-L213
229,806
ZenMagick/ZenCart
includes/modules/order_total/ot_gv.php
ot_gv.user_has_gv_account
function user_has_gv_account($c_id) { global $db; $gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$c_id . "'"); if ($gv_result->RecordCount() > 0) { return $gv_result->fields['amount']; } return 0; // use 0 because 'false' was preventing checkout_payment from continuing }
php
function user_has_gv_account($c_id) { global $db; $gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$c_id . "'"); if ($gv_result->RecordCount() > 0) { return $gv_result->fields['amount']; } return 0; // use 0 because 'false' was preventing checkout_payment from continuing }
[ "function", "user_has_gv_account", "(", "$", "c_id", ")", "{", "global", "$", "db", ";", "$", "gv_result", "=", "$", "db", "->", "Execute", "(", "\"select amount from \"", ".", "TABLE_COUPON_GV_CUSTOMER", ".", "\" where customer_id = '\"", ".", "(", "int", ")", "$", "c_id", ".", "\"'\"", ")", ";", "if", "(", "$", "gv_result", "->", "RecordCount", "(", ")", ">", "0", ")", "{", "return", "$", "gv_result", "->", "fields", "[", "'amount'", "]", ";", "}", "return", "0", ";", "// use 0 because 'false' was preventing checkout_payment from continuing", "}" ]
Check to see whether current customer has a GV balance available Returns amount of GV balance on account
[ "Check", "to", "see", "whether", "current", "customer", "has", "a", "GV", "balance", "available", "Returns", "amount", "of", "GV", "balance", "on", "account" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/order_total/ot_gv.php#L340-L347
229,807
ZenMagick/ZenCart
includes/modules/order_total/ot_gv.php
ot_gv.get_order_total
function get_order_total() { global $order; $order_total = $order->info['total']; // if we are not supposed to include tax in credit calculations, subtract it out if ($this->include_tax != 'true') $order_total -= $order->info['tax']; // if we are not supposed to include shipping amount in credit calcs, subtract it out if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost']; $order_total = $order->info['total']; return $order_total; }
php
function get_order_total() { global $order; $order_total = $order->info['total']; // if we are not supposed to include tax in credit calculations, subtract it out if ($this->include_tax != 'true') $order_total -= $order->info['tax']; // if we are not supposed to include shipping amount in credit calcs, subtract it out if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost']; $order_total = $order->info['total']; return $order_total; }
[ "function", "get_order_total", "(", ")", "{", "global", "$", "order", ";", "$", "order_total", "=", "$", "order", "->", "info", "[", "'total'", "]", ";", "// if we are not supposed to include tax in credit calculations, subtract it out", "if", "(", "$", "this", "->", "include_tax", "!=", "'true'", ")", "$", "order_total", "-=", "$", "order", "->", "info", "[", "'tax'", "]", ";", "// if we are not supposed to include shipping amount in credit calcs, subtract it out", "if", "(", "$", "this", "->", "include_shipping", "!=", "'true'", ")", "$", "order_total", "-=", "$", "order", "->", "info", "[", "'shipping_cost'", "]", ";", "$", "order_total", "=", "$", "order", "->", "info", "[", "'total'", "]", ";", "return", "$", "order_total", ";", "}" ]
Recalculates base order-total amount for use in deduction calculations
[ "Recalculates", "base", "order", "-", "total", "amount", "for", "use", "in", "deduction", "calculations" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/order_total/ot_gv.php#L351-L360
229,808
Webiny/Framework
src/Webiny/Component/Rest/Compiler/Compiler.php
Compiler.writeCacheFiles
public function writeCacheFiles(ParsedApi $parsedApi) { $writtenCacheFiles = []; // first delete the cache foreach ($parsedApi->versions as $v => $parsedClass) { $this->cache->deleteCache($this->api, $parsedApi->apiClass); } // then build the cache foreach ($parsedApi->versions as $v => $parsedClass) { $compileArray = $this->compileCacheFile($parsedClass, $v); $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, $v, $compileArray); $writtenCacheFiles[$v] = $compileArray; } // write current and latest versions (just include return a specific version) $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, 'latest', $writtenCacheFiles[$parsedApi->latestVersion]); $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, 'current', $writtenCacheFiles[$parsedApi->currentVersion]); }
php
public function writeCacheFiles(ParsedApi $parsedApi) { $writtenCacheFiles = []; // first delete the cache foreach ($parsedApi->versions as $v => $parsedClass) { $this->cache->deleteCache($this->api, $parsedApi->apiClass); } // then build the cache foreach ($parsedApi->versions as $v => $parsedClass) { $compileArray = $this->compileCacheFile($parsedClass, $v); $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, $v, $compileArray); $writtenCacheFiles[$v] = $compileArray; } // write current and latest versions (just include return a specific version) $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, 'latest', $writtenCacheFiles[$parsedApi->latestVersion]); $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, 'current', $writtenCacheFiles[$parsedApi->currentVersion]); }
[ "public", "function", "writeCacheFiles", "(", "ParsedApi", "$", "parsedApi", ")", "{", "$", "writtenCacheFiles", "=", "[", "]", ";", "// first delete the cache", "foreach", "(", "$", "parsedApi", "->", "versions", "as", "$", "v", "=>", "$", "parsedClass", ")", "{", "$", "this", "->", "cache", "->", "deleteCache", "(", "$", "this", "->", "api", ",", "$", "parsedApi", "->", "apiClass", ")", ";", "}", "// then build the cache", "foreach", "(", "$", "parsedApi", "->", "versions", "as", "$", "v", "=>", "$", "parsedClass", ")", "{", "$", "compileArray", "=", "$", "this", "->", "compileCacheFile", "(", "$", "parsedClass", ",", "$", "v", ")", ";", "$", "this", "->", "cache", "->", "writeCacheFile", "(", "$", "this", "->", "api", ",", "$", "parsedApi", "->", "apiClass", ",", "$", "v", ",", "$", "compileArray", ")", ";", "$", "writtenCacheFiles", "[", "$", "v", "]", "=", "$", "compileArray", ";", "}", "// write current and latest versions (just include return a specific version)", "$", "this", "->", "cache", "->", "writeCacheFile", "(", "$", "this", "->", "api", ",", "$", "parsedApi", "->", "apiClass", ",", "'latest'", ",", "$", "writtenCacheFiles", "[", "$", "parsedApi", "->", "latestVersion", "]", ")", ";", "$", "this", "->", "cache", "->", "writeCacheFile", "(", "$", "this", "->", "api", ",", "$", "parsedApi", "->", "apiClass", ",", "'current'", ",", "$", "writtenCacheFiles", "[", "$", "parsedApi", "->", "currentVersion", "]", ")", ";", "}" ]
Based on the given ParsedApi instance, the method will create several cache file and update the cache index. @param ParsedApi $parsedApi
[ "Based", "on", "the", "given", "ParsedApi", "instance", "the", "method", "will", "create", "several", "cache", "file", "and", "update", "the", "cache", "index", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Compiler/Compiler.php#L57-L80
229,809
Webiny/Framework
src/Webiny/Component/Rest/Compiler/Compiler.php
Compiler.compileCacheFile
private function compileCacheFile(ParsedClass $parsedClass, $version) { $compileArray = []; $compileArray['class'] = $parsedClass->class; $compileArray['cacheKeyInterface'] = $parsedClass->cacheKeyInterface; $compileArray['accessInterface'] = $parsedClass->accessInterface; $compileArray['version'] = $version; foreach ($parsedClass->parsedMethods as $m) { $compileArray[$m->method][$m->urlPattern] = [ 'default' => $m->default, 'role' => ($m->role) ? $m->role : false, 'method' => $m->name, 'urlPattern' => $m->urlPattern, 'resourceNaming' => $m->resourceNaming, 'cache' => $m->cache, 'header' => $m->header, 'rateControl' => $m->rateControl, 'params' => [] ]; foreach ($m->params as $p) { $compileArray[$m->method][$m->urlPattern]['params'][$p->name] = [ 'required' => $p->required, 'type' => $p->type, 'default' => $p->default, 'pattern' => $p->matchPattern ]; } } return $compileArray; }
php
private function compileCacheFile(ParsedClass $parsedClass, $version) { $compileArray = []; $compileArray['class'] = $parsedClass->class; $compileArray['cacheKeyInterface'] = $parsedClass->cacheKeyInterface; $compileArray['accessInterface'] = $parsedClass->accessInterface; $compileArray['version'] = $version; foreach ($parsedClass->parsedMethods as $m) { $compileArray[$m->method][$m->urlPattern] = [ 'default' => $m->default, 'role' => ($m->role) ? $m->role : false, 'method' => $m->name, 'urlPattern' => $m->urlPattern, 'resourceNaming' => $m->resourceNaming, 'cache' => $m->cache, 'header' => $m->header, 'rateControl' => $m->rateControl, 'params' => [] ]; foreach ($m->params as $p) { $compileArray[$m->method][$m->urlPattern]['params'][$p->name] = [ 'required' => $p->required, 'type' => $p->type, 'default' => $p->default, 'pattern' => $p->matchPattern ]; } } return $compileArray; }
[ "private", "function", "compileCacheFile", "(", "ParsedClass", "$", "parsedClass", ",", "$", "version", ")", "{", "$", "compileArray", "=", "[", "]", ";", "$", "compileArray", "[", "'class'", "]", "=", "$", "parsedClass", "->", "class", ";", "$", "compileArray", "[", "'cacheKeyInterface'", "]", "=", "$", "parsedClass", "->", "cacheKeyInterface", ";", "$", "compileArray", "[", "'accessInterface'", "]", "=", "$", "parsedClass", "->", "accessInterface", ";", "$", "compileArray", "[", "'version'", "]", "=", "$", "version", ";", "foreach", "(", "$", "parsedClass", "->", "parsedMethods", "as", "$", "m", ")", "{", "$", "compileArray", "[", "$", "m", "->", "method", "]", "[", "$", "m", "->", "urlPattern", "]", "=", "[", "'default'", "=>", "$", "m", "->", "default", ",", "'role'", "=>", "(", "$", "m", "->", "role", ")", "?", "$", "m", "->", "role", ":", "false", ",", "'method'", "=>", "$", "m", "->", "name", ",", "'urlPattern'", "=>", "$", "m", "->", "urlPattern", ",", "'resourceNaming'", "=>", "$", "m", "->", "resourceNaming", ",", "'cache'", "=>", "$", "m", "->", "cache", ",", "'header'", "=>", "$", "m", "->", "header", ",", "'rateControl'", "=>", "$", "m", "->", "rateControl", ",", "'params'", "=>", "[", "]", "]", ";", "foreach", "(", "$", "m", "->", "params", "as", "$", "p", ")", "{", "$", "compileArray", "[", "$", "m", "->", "method", "]", "[", "$", "m", "->", "urlPattern", "]", "[", "'params'", "]", "[", "$", "p", "->", "name", "]", "=", "[", "'required'", "=>", "$", "p", "->", "required", ",", "'type'", "=>", "$", "p", "->", "type", ",", "'default'", "=>", "$", "p", "->", "default", ",", "'pattern'", "=>", "$", "p", "->", "matchPattern", "]", ";", "}", "}", "return", "$", "compileArray", ";", "}" ]
This method does the actual processing of ParsedClass instance into a compiled array that is later written into a cache file. @param ParsedClass $parsedClass ParsedClass instance that will be compiled into an array. @param string $version Version of the API. @return array The compiled array.
[ "This", "method", "does", "the", "actual", "processing", "of", "ParsedClass", "instance", "into", "a", "compiled", "array", "that", "is", "later", "written", "into", "a", "cache", "file", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Compiler/Compiler.php#L91-L124
229,810
Webiny/Framework
src/Webiny/Component/TemplateEngine/Bridge/TemplateEngine.php
TemplateEngine.getLibrary
private static function getLibrary($engineName) { $bridges = \Webiny\Component\TemplateEngine\TemplateEngine::getConfig()->get('Bridges', false); if (!$bridges) { if (!isset(self::$library[$engineName])) { return false; } return self::$library[$engineName]; } return $bridges->get($engineName, false); }
php
private static function getLibrary($engineName) { $bridges = \Webiny\Component\TemplateEngine\TemplateEngine::getConfig()->get('Bridges', false); if (!$bridges) { if (!isset(self::$library[$engineName])) { return false; } return self::$library[$engineName]; } return $bridges->get($engineName, false); }
[ "private", "static", "function", "getLibrary", "(", "$", "engineName", ")", "{", "$", "bridges", "=", "\\", "Webiny", "\\", "Component", "\\", "TemplateEngine", "\\", "TemplateEngine", "::", "getConfig", "(", ")", "->", "get", "(", "'Bridges'", ",", "false", ")", ";", "if", "(", "!", "$", "bridges", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "library", "[", "$", "engineName", "]", ")", ")", "{", "return", "false", ";", "}", "return", "self", "::", "$", "library", "[", "$", "engineName", "]", ";", "}", "return", "$", "bridges", "->", "get", "(", "$", "engineName", ",", "false", ")", ";", "}" ]
Get the name of bridge library which will be used as the driver. @param string $engineName Name of the template engine for which you wish to get the @return string
[ "Get", "the", "name", "of", "bridge", "library", "which", "will", "be", "used", "as", "the", "driver", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TemplateEngine/Bridge/TemplateEngine.php#L35-L47
229,811
Webiny/Framework
src/Webiny/Component/TemplateEngine/Bridge/TemplateEngine.php
TemplateEngine.getInstance
public static function getInstance($engineName, ConfigObject $config) { $driver = static::getLibrary($engineName); if (!self::isString($driver)) { throw new TemplateEngineException('Invalid driver returned for ' . $engineName . ' engine'); } try { $instance = new $driver($config); } catch (\Exception $e) { throw $e; } if (!self::isInstanceOf($instance, TemplateEngineInterface::class)) { throw new TemplateEngineException(TemplateEngineException::MSG_INVALID_ARG, ['driver', TemplateEngineInterface::class]); } return $instance; }
php
public static function getInstance($engineName, ConfigObject $config) { $driver = static::getLibrary($engineName); if (!self::isString($driver)) { throw new TemplateEngineException('Invalid driver returned for ' . $engineName . ' engine'); } try { $instance = new $driver($config); } catch (\Exception $e) { throw $e; } if (!self::isInstanceOf($instance, TemplateEngineInterface::class)) { throw new TemplateEngineException(TemplateEngineException::MSG_INVALID_ARG, ['driver', TemplateEngineInterface::class]); } return $instance; }
[ "public", "static", "function", "getInstance", "(", "$", "engineName", ",", "ConfigObject", "$", "config", ")", "{", "$", "driver", "=", "static", "::", "getLibrary", "(", "$", "engineName", ")", ";", "if", "(", "!", "self", "::", "isString", "(", "$", "driver", ")", ")", "{", "throw", "new", "TemplateEngineException", "(", "'Invalid driver returned for '", ".", "$", "engineName", ".", "' engine'", ")", ";", "}", "try", "{", "$", "instance", "=", "new", "$", "driver", "(", "$", "config", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "if", "(", "!", "self", "::", "isInstanceOf", "(", "$", "instance", ",", "TemplateEngineInterface", "::", "class", ")", ")", "{", "throw", "new", "TemplateEngineException", "(", "TemplateEngineException", "::", "MSG_INVALID_ARG", ",", "[", "'driver'", ",", "TemplateEngineInterface", "::", "class", "]", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Create an instance of an TemplateEngine driver. @param string $engineName Name of the template engine for which to load the instance. @param ConfigObject $config Template engine config. @throws TemplateEngineException @throws \Exception @return TemplateEngineInterface
[ "Create", "an", "instance", "of", "an", "TemplateEngine", "driver", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TemplateEngine/Bridge/TemplateEngine.php#L70-L89
229,812
milesj/admin
Console/Command/InstallShell.php
InstallShell.main
public function main() { $this->setSteps(array( 'Check Database Configuration' => 'checkDbConfig', 'Set Table Prefix' => 'checkTablePrefix', 'Set Users Table' => 'checkUsersTable', 'Check Table Status' => 'checkRequiredTables', 'Create Database Tables' => 'createTables', 'Setup ACL' => 'setupAcl', 'Finish Installation' => 'finish' )) ->setDbConfig(ADMIN_DATABASE) ->setTablePrefix(ADMIN_PREFIX) ->setRequiredTables(array('aros', 'acos', 'aros_acos')); $this->out('Plugin: Admin v' . Configure::read('Admin.version')); $this->out('Copyright: Miles Johnson, 2010-' . date('Y')); $this->out('Help: http://milesj.me/code/cakephp/admin'); parent::main(); }
php
public function main() { $this->setSteps(array( 'Check Database Configuration' => 'checkDbConfig', 'Set Table Prefix' => 'checkTablePrefix', 'Set Users Table' => 'checkUsersTable', 'Check Table Status' => 'checkRequiredTables', 'Create Database Tables' => 'createTables', 'Setup ACL' => 'setupAcl', 'Finish Installation' => 'finish' )) ->setDbConfig(ADMIN_DATABASE) ->setTablePrefix(ADMIN_PREFIX) ->setRequiredTables(array('aros', 'acos', 'aros_acos')); $this->out('Plugin: Admin v' . Configure::read('Admin.version')); $this->out('Copyright: Miles Johnson, 2010-' . date('Y')); $this->out('Help: http://milesj.me/code/cakephp/admin'); parent::main(); }
[ "public", "function", "main", "(", ")", "{", "$", "this", "->", "setSteps", "(", "array", "(", "'Check Database Configuration'", "=>", "'checkDbConfig'", ",", "'Set Table Prefix'", "=>", "'checkTablePrefix'", ",", "'Set Users Table'", "=>", "'checkUsersTable'", ",", "'Check Table Status'", "=>", "'checkRequiredTables'", ",", "'Create Database Tables'", "=>", "'createTables'", ",", "'Setup ACL'", "=>", "'setupAcl'", ",", "'Finish Installation'", "=>", "'finish'", ")", ")", "->", "setDbConfig", "(", "ADMIN_DATABASE", ")", "->", "setTablePrefix", "(", "ADMIN_PREFIX", ")", "->", "setRequiredTables", "(", "array", "(", "'aros'", ",", "'acos'", ",", "'aros_acos'", ")", ")", ";", "$", "this", "->", "out", "(", "'Plugin: Admin v'", ".", "Configure", "::", "read", "(", "'Admin.version'", ")", ")", ";", "$", "this", "->", "out", "(", "'Copyright: Miles Johnson, 2010-'", ".", "date", "(", "'Y'", ")", ")", ";", "$", "this", "->", "out", "(", "'Help: http://milesj.me/code/cakephp/admin'", ")", ";", "parent", "::", "main", "(", ")", ";", "}" ]
Trigger install.
[ "Trigger", "install", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Console/Command/InstallShell.php#L28-L47
229,813
milesj/admin
Console/Command/InstallShell.php
InstallShell.setupAcl
public function setupAcl() { $adminAlias = Configure::read('Admin.aliases.administrator'); $this->out(sprintf('Administrator Role: <info>%s</info>', $adminAlias)); $answer = mb_strtoupper($this->in('Is this correct?', array('Y', 'N'))); if ($answer === 'N') { $this->out('<warning>Configure the role through Admin.aliases.administrator</warning>'); return false; } $admin = $this->RequestObject->addObject($adminAlias); $userModel = ClassRegistry::init($this->usersModel, true); // Fetch user $this->out('What user would you like to give admin access?'); $user_id = $this->findUser(); // Give access $result = $this->RequestObject->addChildObject( $this->user[$userModel->alias][$userModel->displayField], $admin['RequestObject']['id'], $this->usersModel, $user_id); if (!$result) { $this->err('<error>Failed to give user admin access</error>'); return false; } $this->out('<success>Access granted, proceeding...</success>'); $this->plugin('Admin'); $this->plugin(Configure::read('Admin.coreName')); return true; }
php
public function setupAcl() { $adminAlias = Configure::read('Admin.aliases.administrator'); $this->out(sprintf('Administrator Role: <info>%s</info>', $adminAlias)); $answer = mb_strtoupper($this->in('Is this correct?', array('Y', 'N'))); if ($answer === 'N') { $this->out('<warning>Configure the role through Admin.aliases.administrator</warning>'); return false; } $admin = $this->RequestObject->addObject($adminAlias); $userModel = ClassRegistry::init($this->usersModel, true); // Fetch user $this->out('What user would you like to give admin access?'); $user_id = $this->findUser(); // Give access $result = $this->RequestObject->addChildObject( $this->user[$userModel->alias][$userModel->displayField], $admin['RequestObject']['id'], $this->usersModel, $user_id); if (!$result) { $this->err('<error>Failed to give user admin access</error>'); return false; } $this->out('<success>Access granted, proceeding...</success>'); $this->plugin('Admin'); $this->plugin(Configure::read('Admin.coreName')); return true; }
[ "public", "function", "setupAcl", "(", ")", "{", "$", "adminAlias", "=", "Configure", "::", "read", "(", "'Admin.aliases.administrator'", ")", ";", "$", "this", "->", "out", "(", "sprintf", "(", "'Administrator Role: <info>%s</info>'", ",", "$", "adminAlias", ")", ")", ";", "$", "answer", "=", "mb_strtoupper", "(", "$", "this", "->", "in", "(", "'Is this correct?'", ",", "array", "(", "'Y'", ",", "'N'", ")", ")", ")", ";", "if", "(", "$", "answer", "===", "'N'", ")", "{", "$", "this", "->", "out", "(", "'<warning>Configure the role through Admin.aliases.administrator</warning>'", ")", ";", "return", "false", ";", "}", "$", "admin", "=", "$", "this", "->", "RequestObject", "->", "addObject", "(", "$", "adminAlias", ")", ";", "$", "userModel", "=", "ClassRegistry", "::", "init", "(", "$", "this", "->", "usersModel", ",", "true", ")", ";", "// Fetch user", "$", "this", "->", "out", "(", "'What user would you like to give admin access?'", ")", ";", "$", "user_id", "=", "$", "this", "->", "findUser", "(", ")", ";", "// Give access", "$", "result", "=", "$", "this", "->", "RequestObject", "->", "addChildObject", "(", "$", "this", "->", "user", "[", "$", "userModel", "->", "alias", "]", "[", "$", "userModel", "->", "displayField", "]", ",", "$", "admin", "[", "'RequestObject'", "]", "[", "'id'", "]", ",", "$", "this", "->", "usersModel", ",", "$", "user_id", ")", ";", "if", "(", "!", "$", "result", ")", "{", "$", "this", "->", "err", "(", "'<error>Failed to give user admin access</error>'", ")", ";", "return", "false", ";", "}", "$", "this", "->", "out", "(", "'<success>Access granted, proceeding...</success>'", ")", ";", "$", "this", "->", "plugin", "(", "'Admin'", ")", ";", "$", "this", "->", "plugin", "(", "Configure", "::", "read", "(", "'Admin.coreName'", ")", ")", ";", "return", "true", ";", "}" ]
Setup all the ACL records. @return bool
[ "Setup", "all", "the", "ACL", "records", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Console/Command/InstallShell.php#L54-L90
229,814
milesj/admin
Console/Command/InstallShell.php
InstallShell.finish
public function finish() { $this->hr(1); $this->out('Admin installation complete!'); $this->out('Please read the documentation for further instructions:'); $this->out('http://milesj.me/code/cakephp/admin'); $this->hr(1); return true; }
php
public function finish() { $this->hr(1); $this->out('Admin installation complete!'); $this->out('Please read the documentation for further instructions:'); $this->out('http://milesj.me/code/cakephp/admin'); $this->hr(1); return true; }
[ "public", "function", "finish", "(", ")", "{", "$", "this", "->", "hr", "(", "1", ")", ";", "$", "this", "->", "out", "(", "'Admin installation complete!'", ")", ";", "$", "this", "->", "out", "(", "'Please read the documentation for further instructions:'", ")", ";", "$", "this", "->", "out", "(", "'http://milesj.me/code/cakephp/admin'", ")", ";", "$", "this", "->", "hr", "(", "1", ")", ";", "return", "true", ";", "}" ]
Finalize the installation. @return bool
[ "Finalize", "the", "installation", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Console/Command/InstallShell.php#L97-L105
229,815
milesj/admin
Console/Command/InstallShell.php
InstallShell.plugin
public function plugin($name = null) { $this->out(); $pluginName = $name ?: $this->args[0]; $plugin = Admin::getPlugin($pluginName); if (!$plugin) { $this->err(sprintf('<error>%s plugin does not exist</error>', $pluginName)); return; } $this->out(sprintf('<success>Installing %s...</success>', $pluginName)); // Create parent object $parent_id = $this->ControlObject->addObject($pluginName); $adminAlias = Configure::read('Admin.aliases.administrator'); // Create children objects foreach ($plugin['models'] as $model) { $this->out($model['title']); $this->ControlObject->addObject($model['id'], $parent_id); // Give admin access $this->Permission->allow($adminAlias, $pluginName . '/' . $model['id']); } $this->out(sprintf('<success>%s model ACOs installed</success>', $pluginName)); }
php
public function plugin($name = null) { $this->out(); $pluginName = $name ?: $this->args[0]; $plugin = Admin::getPlugin($pluginName); if (!$plugin) { $this->err(sprintf('<error>%s plugin does not exist</error>', $pluginName)); return; } $this->out(sprintf('<success>Installing %s...</success>', $pluginName)); // Create parent object $parent_id = $this->ControlObject->addObject($pluginName); $adminAlias = Configure::read('Admin.aliases.administrator'); // Create children objects foreach ($plugin['models'] as $model) { $this->out($model['title']); $this->ControlObject->addObject($model['id'], $parent_id); // Give admin access $this->Permission->allow($adminAlias, $pluginName . '/' . $model['id']); } $this->out(sprintf('<success>%s model ACOs installed</success>', $pluginName)); }
[ "public", "function", "plugin", "(", "$", "name", "=", "null", ")", "{", "$", "this", "->", "out", "(", ")", ";", "$", "pluginName", "=", "$", "name", "?", ":", "$", "this", "->", "args", "[", "0", "]", ";", "$", "plugin", "=", "Admin", "::", "getPlugin", "(", "$", "pluginName", ")", ";", "if", "(", "!", "$", "plugin", ")", "{", "$", "this", "->", "err", "(", "sprintf", "(", "'<error>%s plugin does not exist</error>'", ",", "$", "pluginName", ")", ")", ";", "return", ";", "}", "$", "this", "->", "out", "(", "sprintf", "(", "'<success>Installing %s...</success>'", ",", "$", "pluginName", ")", ")", ";", "// Create parent object", "$", "parent_id", "=", "$", "this", "->", "ControlObject", "->", "addObject", "(", "$", "pluginName", ")", ";", "$", "adminAlias", "=", "Configure", "::", "read", "(", "'Admin.aliases.administrator'", ")", ";", "// Create children objects", "foreach", "(", "$", "plugin", "[", "'models'", "]", "as", "$", "model", ")", "{", "$", "this", "->", "out", "(", "$", "model", "[", "'title'", "]", ")", ";", "$", "this", "->", "ControlObject", "->", "addObject", "(", "$", "model", "[", "'id'", "]", ",", "$", "parent_id", ")", ";", "// Give admin access", "$", "this", "->", "Permission", "->", "allow", "(", "$", "adminAlias", ",", "$", "pluginName", ".", "'/'", ".", "$", "model", "[", "'id'", "]", ")", ";", "}", "$", "this", "->", "out", "(", "sprintf", "(", "'<success>%s model ACOs installed</success>'", ",", "$", "pluginName", ")", ")", ";", "}" ]
Install ACOs for all plugin models. @param string $name
[ "Install", "ACOs", "for", "all", "plugin", "models", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Console/Command/InstallShell.php#L112-L140
229,816
milesj/admin
Console/Command/InstallShell.php
InstallShell.model
public function model($name = null) { $this->out(); $modelName = Inflector::classify($name ?: $this->args[0]); $model = ClassRegistry::init($modelName, true); if (get_class($model) === 'AppModel') { $this->err(sprintf('<error>%s model does not exist</error>', $modelName)); return; } list($plugin, $modelName) = pluginSplit($modelName); if (!$plugin) { $plugin = Configure::read('Admin.coreName'); } $this->out(sprintf('<success>Installing %s...</success>', $modelName)); // Create parent object $parent_id = $this->ControlObject->addObject($plugin); // Create children object $alias = $plugin . '.' . $modelName; $this->ControlObject->addObject($alias, $parent_id); // Give admin access $this->Permission->allow(Configure::read('Admin.aliases.administrator'), $plugin . '/' . $alias); $this->out(sprintf('<success>%s ACOs installed</success>', $modelName)); }
php
public function model($name = null) { $this->out(); $modelName = Inflector::classify($name ?: $this->args[0]); $model = ClassRegistry::init($modelName, true); if (get_class($model) === 'AppModel') { $this->err(sprintf('<error>%s model does not exist</error>', $modelName)); return; } list($plugin, $modelName) = pluginSplit($modelName); if (!$plugin) { $plugin = Configure::read('Admin.coreName'); } $this->out(sprintf('<success>Installing %s...</success>', $modelName)); // Create parent object $parent_id = $this->ControlObject->addObject($plugin); // Create children object $alias = $plugin . '.' . $modelName; $this->ControlObject->addObject($alias, $parent_id); // Give admin access $this->Permission->allow(Configure::read('Admin.aliases.administrator'), $plugin . '/' . $alias); $this->out(sprintf('<success>%s ACOs installed</success>', $modelName)); }
[ "public", "function", "model", "(", "$", "name", "=", "null", ")", "{", "$", "this", "->", "out", "(", ")", ";", "$", "modelName", "=", "Inflector", "::", "classify", "(", "$", "name", "?", ":", "$", "this", "->", "args", "[", "0", "]", ")", ";", "$", "model", "=", "ClassRegistry", "::", "init", "(", "$", "modelName", ",", "true", ")", ";", "if", "(", "get_class", "(", "$", "model", ")", "===", "'AppModel'", ")", "{", "$", "this", "->", "err", "(", "sprintf", "(", "'<error>%s model does not exist</error>'", ",", "$", "modelName", ")", ")", ";", "return", ";", "}", "list", "(", "$", "plugin", ",", "$", "modelName", ")", "=", "pluginSplit", "(", "$", "modelName", ")", ";", "if", "(", "!", "$", "plugin", ")", "{", "$", "plugin", "=", "Configure", "::", "read", "(", "'Admin.coreName'", ")", ";", "}", "$", "this", "->", "out", "(", "sprintf", "(", "'<success>Installing %s...</success>'", ",", "$", "modelName", ")", ")", ";", "// Create parent object", "$", "parent_id", "=", "$", "this", "->", "ControlObject", "->", "addObject", "(", "$", "plugin", ")", ";", "// Create children object", "$", "alias", "=", "$", "plugin", ".", "'.'", ".", "$", "modelName", ";", "$", "this", "->", "ControlObject", "->", "addObject", "(", "$", "alias", ",", "$", "parent_id", ")", ";", "// Give admin access", "$", "this", "->", "Permission", "->", "allow", "(", "Configure", "::", "read", "(", "'Admin.aliases.administrator'", ")", ",", "$", "plugin", ".", "'/'", ".", "$", "alias", ")", ";", "$", "this", "->", "out", "(", "sprintf", "(", "'<success>%s ACOs installed</success>'", ",", "$", "modelName", ")", ")", ";", "}" ]
Install ACOs for a single model. @param string $name
[ "Install", "ACOs", "for", "a", "single", "model", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Console/Command/InstallShell.php#L147-L177
229,817
Webiny/Framework
src/Webiny/Component/Entity/Attribute/AbstractDateAttribute.php
AbstractDateAttribute.setDefaultValueInternal
private function setDefaultValueInternal() { $defaultValue = $this->getDefaultValue(); if ($defaultValue == 'now') { $defaultValue = new DateTimeObject('now'); } $this->setValue($defaultValue); }
php
private function setDefaultValueInternal() { $defaultValue = $this->getDefaultValue(); if ($defaultValue == 'now') { $defaultValue = new DateTimeObject('now'); } $this->setValue($defaultValue); }
[ "private", "function", "setDefaultValueInternal", "(", ")", "{", "$", "defaultValue", "=", "$", "this", "->", "getDefaultValue", "(", ")", ";", "if", "(", "$", "defaultValue", "==", "'now'", ")", "{", "$", "defaultValue", "=", "new", "DateTimeObject", "(", "'now'", ")", ";", "}", "$", "this", "->", "setValue", "(", "$", "defaultValue", ")", ";", "}" ]
Set default attribute value
[ "Set", "default", "attribute", "value" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/Attribute/AbstractDateAttribute.php#L118-L125
229,818
Webiny/Framework
src/Webiny/Component/Image/Bridge/AbstractImage.php
AbstractImage.setFormat
public function setFormat($format) { if (!in_array($format, self::$formats)) { throw new ImageException('Invalid image format provided. Supported formats are [jpg, jpeg, png, gif].'); } $this->format = $format; }
php
public function setFormat($format) { if (!in_array($format, self::$formats)) { throw new ImageException('Invalid image format provided. Supported formats are [jpg, jpeg, png, gif].'); } $this->format = $format; }
[ "public", "function", "setFormat", "(", "$", "format", ")", "{", "if", "(", "!", "in_array", "(", "$", "format", ",", "self", "::", "$", "formats", ")", ")", "{", "throw", "new", "ImageException", "(", "'Invalid image format provided. Supported formats are [jpg, jpeg, png, gif].'", ")", ";", "}", "$", "this", "->", "format", "=", "$", "format", ";", "}" ]
Sets image mime-type format. @param string $format Format name. Supported formats are [jpg, jpeg, png, gif] @throws ImageException
[ "Sets", "image", "mime", "-", "type", "format", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/AbstractImage.php#L63-L70
229,819
Webiny/Framework
src/Webiny/Component/Image/Bridge/AbstractImage.php
AbstractImage.save
public function save(File $file = null, $options = []) { if ($this->isNull($file)) { if ($this->isNull($this->destination)) { throw new ImageException('Unable to save the image. Destination storage is not defined.'); } $file = $this->destination; } // extract the type try { $format = $this->str($file->getKey())->explode('.')->last()->caseLower()->val(); $this->setFormat($format); } catch (ImageException $e) { throw $e; } // check quality parameter $options['quality'] = isset($options['Quality']) ? $options['Quality'] : Image::getConfig()->get('Quality', 90); return $file->setContents($this->getBinary($options)); }
php
public function save(File $file = null, $options = []) { if ($this->isNull($file)) { if ($this->isNull($this->destination)) { throw new ImageException('Unable to save the image. Destination storage is not defined.'); } $file = $this->destination; } // extract the type try { $format = $this->str($file->getKey())->explode('.')->last()->caseLower()->val(); $this->setFormat($format); } catch (ImageException $e) { throw $e; } // check quality parameter $options['quality'] = isset($options['Quality']) ? $options['Quality'] : Image::getConfig()->get('Quality', 90); return $file->setContents($this->getBinary($options)); }
[ "public", "function", "save", "(", "File", "$", "file", "=", "null", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "isNull", "(", "$", "file", ")", ")", "{", "if", "(", "$", "this", "->", "isNull", "(", "$", "this", "->", "destination", ")", ")", "{", "throw", "new", "ImageException", "(", "'Unable to save the image. Destination storage is not defined.'", ")", ";", "}", "$", "file", "=", "$", "this", "->", "destination", ";", "}", "// extract the type", "try", "{", "$", "format", "=", "$", "this", "->", "str", "(", "$", "file", "->", "getKey", "(", ")", ")", "->", "explode", "(", "'.'", ")", "->", "last", "(", ")", "->", "caseLower", "(", ")", "->", "val", "(", ")", ";", "$", "this", "->", "setFormat", "(", "$", "format", ")", ";", "}", "catch", "(", "ImageException", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "// check quality parameter", "$", "options", "[", "'quality'", "]", "=", "isset", "(", "$", "options", "[", "'Quality'", "]", ")", "?", "$", "options", "[", "'Quality'", "]", ":", "Image", "::", "getConfig", "(", ")", "->", "get", "(", "'Quality'", ",", "90", ")", ";", "return", "$", "file", "->", "setContents", "(", "$", "this", "->", "getBinary", "(", "$", "options", ")", ")", ";", "}" ]
Saves the image in the defined storage. @param File $file Where to save the image. @param array $options An array of options. Possible keys are [quality, filters]. @return bool True if image is save successfully, otherwise false. @throws \Exception|ImageException
[ "Saves", "the", "image", "in", "the", "defined", "storage", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/AbstractImage.php#L92-L114
229,820
Webiny/Framework
src/Webiny/Component/Entity/EntityCollection.php
EntityCollection.filter
public function filter(\Closure $callback) { $result = []; foreach ($this->value as $entity) { if ($callback($entity)) { $result[] = $entity; } } return $result; }
php
public function filter(\Closure $callback) { $result = []; foreach ($this->value as $entity) { if ($callback($entity)) { $result[] = $entity; } } return $result; }
[ "public", "function", "filter", "(", "\\", "Closure", "$", "callback", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "value", "as", "$", "entity", ")", "{", "if", "(", "$", "callback", "(", "$", "entity", ")", ")", "{", "$", "result", "[", "]", "=", "$", "entity", ";", "}", "}", "return", "$", "result", ";", "}" ]
Filter current EntityCollection using the given \Closure and return a new array @param \Closure $callback @return array
[ "Filter", "current", "EntityCollection", "using", "the", "given", "\\", "Closure", "and", "return", "a", "new", "array" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/EntityCollection.php#L115-L125
229,821
Webiny/Framework
src/Webiny/Component/Entity/EntityCollection.php
EntityCollection.map
public function map(\Closure $callback) { $result = []; foreach ($this->value as $entity) { $result[] = $callback($entity); } return $result; }
php
public function map(\Closure $callback) { $result = []; foreach ($this->value as $entity) { $result[] = $callback($entity); } return $result; }
[ "public", "function", "map", "(", "\\", "Closure", "$", "callback", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "value", "as", "$", "entity", ")", "{", "$", "result", "[", "]", "=", "$", "callback", "(", "$", "entity", ")", ";", "}", "return", "$", "result", ";", "}" ]
Apply the callback to each entity in the current EntityCollection Returns a new array containing the return values of each callback execution. @param \Closure $callback @return array
[ "Apply", "the", "callback", "to", "each", "entity", "in", "the", "current", "EntityCollection" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/EntityCollection.php#L136-L144
229,822
Webiny/Framework
src/Webiny/Component/Entity/EntityCollection.php
EntityCollection.totalCount
public function totalCount() { if (!isset($this->parameters['conditions'])) { return count($this->value); } if (!$this->totalCount) { if (is_callable($this->totalCountCalculation)) { $this->totalCount = ($this->totalCountCalculation)(); } else { $mongo = Entity::getInstance()->getDatabase(); $entity = $this->entityClass; $this->totalCount = $mongo->count($entity::getCollection(), $this->parameters['conditions']); } } return $this->totalCount; }
php
public function totalCount() { if (!isset($this->parameters['conditions'])) { return count($this->value); } if (!$this->totalCount) { if (is_callable($this->totalCountCalculation)) { $this->totalCount = ($this->totalCountCalculation)(); } else { $mongo = Entity::getInstance()->getDatabase(); $entity = $this->entityClass; $this->totalCount = $mongo->count($entity::getCollection(), $this->parameters['conditions']); } } return $this->totalCount; }
[ "public", "function", "totalCount", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "parameters", "[", "'conditions'", "]", ")", ")", "{", "return", "count", "(", "$", "this", "->", "value", ")", ";", "}", "if", "(", "!", "$", "this", "->", "totalCount", ")", "{", "if", "(", "is_callable", "(", "$", "this", "->", "totalCountCalculation", ")", ")", "{", "$", "this", "->", "totalCount", "=", "(", "$", "this", "->", "totalCountCalculation", ")", "(", ")", ";", "}", "else", "{", "$", "mongo", "=", "Entity", "::", "getInstance", "(", ")", "->", "getDatabase", "(", ")", ";", "$", "entity", "=", "$", "this", "->", "entityClass", ";", "$", "this", "->", "totalCount", "=", "$", "mongo", "->", "count", "(", "$", "entity", "::", "getCollection", "(", ")", ",", "$", "this", "->", "parameters", "[", "'conditions'", "]", ")", ";", "}", "}", "return", "$", "this", "->", "totalCount", ";", "}" ]
Count total number of items in collection @return mixed
[ "Count", "total", "number", "of", "items", "in", "collection" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/EntityCollection.php#L151-L168
229,823
Webiny/Framework
src/Webiny/Component/Entity/EntityCollection.php
EntityCollection.removeItem
public function removeItem($item) { if ($item instanceof AbstractEntity) { $item = $item->id; } foreach ($this->value as $index => $entity) { if ($entity->id == $item) { unset($this->value[$index]); return; } } }
php
public function removeItem($item) { if ($item instanceof AbstractEntity) { $item = $item->id; } foreach ($this->value as $index => $entity) { if ($entity->id == $item) { unset($this->value[$index]); return; } } }
[ "public", "function", "removeItem", "(", "$", "item", ")", "{", "if", "(", "$", "item", "instanceof", "AbstractEntity", ")", "{", "$", "item", "=", "$", "item", "->", "id", ";", "}", "foreach", "(", "$", "this", "->", "value", "as", "$", "index", "=>", "$", "entity", ")", "{", "if", "(", "$", "entity", "->", "id", "==", "$", "item", ")", "{", "unset", "(", "$", "this", "->", "value", "[", "$", "index", "]", ")", ";", "return", ";", "}", "}", "}" ]
Remove item from data set @param $item
[ "Remove", "item", "from", "data", "set" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/EntityCollection.php#L237-L249
229,824
Webiny/Framework
src/Webiny/Component/Entity/EntityCollection.php
EntityCollection.normalizeValue
protected function normalizeValue($item, $fromDb = false) { $entityClass = $this->entityClass; $itemEntity = null; // $item can be an array of data or AbstractEntity if ($this->isInstanceOf($item, $entityClass)) { return $item; } if ($this->isArray($item) || $this->isArrayObject($item)) { if (isset($item['id'])) { // Try getting the instance from cache $itemEntity = Entity::getInstance()->get($entityClass, $item['id']); if ($itemEntity) { return $itemEntity; } // If not found in cache, load from database $itemEntity = $entityClass::findById($item['id']); } } // If instance was not found, create a new entity instance if (!$itemEntity) { $itemEntity = new $entityClass; } // If $item is an array - use it to populate the entity instance if ($this->isArray($item) || $this->isArrayObject($item)) { if ($fromDb) { $item['__webiny_db__'] = true; } $itemEntity->populate($item); } return $itemEntity; }
php
protected function normalizeValue($item, $fromDb = false) { $entityClass = $this->entityClass; $itemEntity = null; // $item can be an array of data or AbstractEntity if ($this->isInstanceOf($item, $entityClass)) { return $item; } if ($this->isArray($item) || $this->isArrayObject($item)) { if (isset($item['id'])) { // Try getting the instance from cache $itemEntity = Entity::getInstance()->get($entityClass, $item['id']); if ($itemEntity) { return $itemEntity; } // If not found in cache, load from database $itemEntity = $entityClass::findById($item['id']); } } // If instance was not found, create a new entity instance if (!$itemEntity) { $itemEntity = new $entityClass; } // If $item is an array - use it to populate the entity instance if ($this->isArray($item) || $this->isArrayObject($item)) { if ($fromDb) { $item['__webiny_db__'] = true; } $itemEntity->populate($item); } return $itemEntity; }
[ "protected", "function", "normalizeValue", "(", "$", "item", ",", "$", "fromDb", "=", "false", ")", "{", "$", "entityClass", "=", "$", "this", "->", "entityClass", ";", "$", "itemEntity", "=", "null", ";", "// $item can be an array of data or AbstractEntity", "if", "(", "$", "this", "->", "isInstanceOf", "(", "$", "item", ",", "$", "entityClass", ")", ")", "{", "return", "$", "item", ";", "}", "if", "(", "$", "this", "->", "isArray", "(", "$", "item", ")", "||", "$", "this", "->", "isArrayObject", "(", "$", "item", ")", ")", "{", "if", "(", "isset", "(", "$", "item", "[", "'id'", "]", ")", ")", "{", "// Try getting the instance from cache", "$", "itemEntity", "=", "Entity", "::", "getInstance", "(", ")", "->", "get", "(", "$", "entityClass", ",", "$", "item", "[", "'id'", "]", ")", ";", "if", "(", "$", "itemEntity", ")", "{", "return", "$", "itemEntity", ";", "}", "// If not found in cache, load from database", "$", "itemEntity", "=", "$", "entityClass", "::", "findById", "(", "$", "item", "[", "'id'", "]", ")", ";", "}", "}", "// If instance was not found, create a new entity instance", "if", "(", "!", "$", "itemEntity", ")", "{", "$", "itemEntity", "=", "new", "$", "entityClass", ";", "}", "// If $item is an array - use it to populate the entity instance", "if", "(", "$", "this", "->", "isArray", "(", "$", "item", ")", "||", "$", "this", "->", "isArrayObject", "(", "$", "item", ")", ")", "{", "if", "(", "$", "fromDb", ")", "{", "$", "item", "[", "'__webiny_db__'", "]", "=", "true", ";", "}", "$", "itemEntity", "->", "populate", "(", "$", "item", ")", ";", "}", "return", "$", "itemEntity", ";", "}" ]
Normalize value to always be an instance of AbstractEntity @param array|AbstractEntity $item @param bool $fromDb Is $item coming from DB @return AbstractEntity @throws EntityException
[ "Normalize", "value", "to", "always", "be", "an", "instance", "of", "AbstractEntity" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/EntityCollection.php#L328-L366
229,825
themsaid/katana-core
src/SiteBuilder.php
SiteBuilder.build
public function build() { $this->readConfigs(); $files = $this->getSiteFiles(); $otherFiles = array_filter($files, function ($file) { return ! str_contains($file->getRelativePath(), '_blog'); }); if (@$this->configs['enableBlog']) { $blogPostsFiles = array_filter($files, function ($file) { return str_contains($file->getRelativePath(), '_blog'); }); $this->readBlogPostsData($blogPostsFiles); } $this->buildViewsData(); $this->filesystem->cleanDirectory(KATANA_PUBLIC_DIR); if ($this->forceBuild) { $this->filesystem->cleanDirectory(KATANA_CACHE_DIR); } $this->handleSiteFiles($otherFiles); if (@$this->configs['enableBlog']) { $this->handleBlogPostsFiles($blogPostsFiles); $this->buildBlogPagination(); $this->buildRSSFeed(); } }
php
public function build() { $this->readConfigs(); $files = $this->getSiteFiles(); $otherFiles = array_filter($files, function ($file) { return ! str_contains($file->getRelativePath(), '_blog'); }); if (@$this->configs['enableBlog']) { $blogPostsFiles = array_filter($files, function ($file) { return str_contains($file->getRelativePath(), '_blog'); }); $this->readBlogPostsData($blogPostsFiles); } $this->buildViewsData(); $this->filesystem->cleanDirectory(KATANA_PUBLIC_DIR); if ($this->forceBuild) { $this->filesystem->cleanDirectory(KATANA_CACHE_DIR); } $this->handleSiteFiles($otherFiles); if (@$this->configs['enableBlog']) { $this->handleBlogPostsFiles($blogPostsFiles); $this->buildBlogPagination(); $this->buildRSSFeed(); } }
[ "public", "function", "build", "(", ")", "{", "$", "this", "->", "readConfigs", "(", ")", ";", "$", "files", "=", "$", "this", "->", "getSiteFiles", "(", ")", ";", "$", "otherFiles", "=", "array_filter", "(", "$", "files", ",", "function", "(", "$", "file", ")", "{", "return", "!", "str_contains", "(", "$", "file", "->", "getRelativePath", "(", ")", ",", "'_blog'", ")", ";", "}", ")", ";", "if", "(", "@", "$", "this", "->", "configs", "[", "'enableBlog'", "]", ")", "{", "$", "blogPostsFiles", "=", "array_filter", "(", "$", "files", ",", "function", "(", "$", "file", ")", "{", "return", "str_contains", "(", "$", "file", "->", "getRelativePath", "(", ")", ",", "'_blog'", ")", ";", "}", ")", ";", "$", "this", "->", "readBlogPostsData", "(", "$", "blogPostsFiles", ")", ";", "}", "$", "this", "->", "buildViewsData", "(", ")", ";", "$", "this", "->", "filesystem", "->", "cleanDirectory", "(", "KATANA_PUBLIC_DIR", ")", ";", "if", "(", "$", "this", "->", "forceBuild", ")", "{", "$", "this", "->", "filesystem", "->", "cleanDirectory", "(", "KATANA_CACHE_DIR", ")", ";", "}", "$", "this", "->", "handleSiteFiles", "(", "$", "otherFiles", ")", ";", "if", "(", "@", "$", "this", "->", "configs", "[", "'enableBlog'", "]", ")", "{", "$", "this", "->", "handleBlogPostsFiles", "(", "$", "blogPostsFiles", ")", ";", "$", "this", "->", "buildBlogPagination", "(", ")", ";", "$", "this", "->", "buildRSSFeed", "(", ")", ";", "}", "}" ]
Build the site from blade views. @return void
[ "Build", "the", "site", "from", "blade", "views", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/SiteBuilder.php#L95-L128
229,826
themsaid/katana-core
src/SiteBuilder.php
SiteBuilder.readConfigs
protected function readConfigs() { $configs = include getcwd().'/config.php'; if ( $this->environment != 'default' && $this->filesystem->exists(getcwd().'/'.$fileName = "config-{$this->environment}.php") ) { $configs = array_merge($configs, include getcwd().'/'.$fileName); } $this->configs = array_merge($configs, (array) $this->configs); }
php
protected function readConfigs() { $configs = include getcwd().'/config.php'; if ( $this->environment != 'default' && $this->filesystem->exists(getcwd().'/'.$fileName = "config-{$this->environment}.php") ) { $configs = array_merge($configs, include getcwd().'/'.$fileName); } $this->configs = array_merge($configs, (array) $this->configs); }
[ "protected", "function", "readConfigs", "(", ")", "{", "$", "configs", "=", "include", "getcwd", "(", ")", ".", "'/config.php'", ";", "if", "(", "$", "this", "->", "environment", "!=", "'default'", "&&", "$", "this", "->", "filesystem", "->", "exists", "(", "getcwd", "(", ")", ".", "'/'", ".", "$", "fileName", "=", "\"config-{$this->environment}.php\"", ")", ")", "{", "$", "configs", "=", "array_merge", "(", "$", "configs", ",", "include", "getcwd", "(", ")", ".", "'/'", ".", "$", "fileName", ")", ";", "}", "$", "this", "->", "configs", "=", "array_merge", "(", "$", "configs", ",", "(", "array", ")", "$", "this", "->", "configs", ")", ";", "}" ]
Read site configurations based on the current environment. It loads the default config file, then the environment specific config file, if found, and finally merges any other configs. @return void
[ "Read", "site", "configurations", "based", "on", "the", "current", "environment", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/SiteBuilder.php#L151-L163
229,827
themsaid/katana-core
src/SiteBuilder.php
SiteBuilder.getSiteFiles
protected function getSiteFiles() { $files = array_filter($this->filesystem->allFiles(KATANA_CONTENT_DIR), function (SplFileInfo $file) { return $this->filterFile($file); }); $this->appendFiles($files); return $files; }
php
protected function getSiteFiles() { $files = array_filter($this->filesystem->allFiles(KATANA_CONTENT_DIR), function (SplFileInfo $file) { return $this->filterFile($file); }); $this->appendFiles($files); return $files; }
[ "protected", "function", "getSiteFiles", "(", ")", "{", "$", "files", "=", "array_filter", "(", "$", "this", "->", "filesystem", "->", "allFiles", "(", "KATANA_CONTENT_DIR", ")", ",", "function", "(", "SplFileInfo", "$", "file", ")", "{", "return", "$", "this", "->", "filterFile", "(", "$", "file", ")", ";", "}", ")", ";", "$", "this", "->", "appendFiles", "(", "$", "files", ")", ";", "return", "$", "files", ";", "}" ]
Get the site files that will be converted into pages. @return SplFileInfo[]
[ "Get", "the", "site", "files", "that", "will", "be", "converted", "into", "pages", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/SiteBuilder.php#L198-L207
229,828
themsaid/katana-core
src/SiteBuilder.php
SiteBuilder.readBlogPostsData
protected function readBlogPostsData($files) { foreach ($files as $file) { $this->postsData[] = $this->blogPostHandler->getPostData($file); } }
php
protected function readBlogPostsData($files) { foreach ($files as $file) { $this->postsData[] = $this->blogPostHandler->getPostData($file); } }
[ "protected", "function", "readBlogPostsData", "(", "$", "files", ")", "{", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "this", "->", "postsData", "[", "]", "=", "$", "this", "->", "blogPostHandler", "->", "getPostData", "(", "$", "file", ")", ";", "}", "}" ]
Read the data of every blog post. @param array $files @return void
[ "Read", "the", "data", "of", "every", "blog", "post", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/SiteBuilder.php#L239-L244
229,829
themsaid/katana-core
src/SiteBuilder.php
SiteBuilder.buildViewsData
protected function buildViewsData() { $this->viewsData = $this->configs + ['blogPosts' => array_reverse((array) $this->postsData)]; $this->fileHandler->viewsData = $this->viewsData; $this->blogPostHandler->viewsData = $this->viewsData; }
php
protected function buildViewsData() { $this->viewsData = $this->configs + ['blogPosts' => array_reverse((array) $this->postsData)]; $this->fileHandler->viewsData = $this->viewsData; $this->blogPostHandler->viewsData = $this->viewsData; }
[ "protected", "function", "buildViewsData", "(", ")", "{", "$", "this", "->", "viewsData", "=", "$", "this", "->", "configs", "+", "[", "'blogPosts'", "=>", "array_reverse", "(", "(", "array", ")", "$", "this", "->", "postsData", ")", "]", ";", "$", "this", "->", "fileHandler", "->", "viewsData", "=", "$", "this", "->", "viewsData", ";", "$", "this", "->", "blogPostHandler", "->", "viewsData", "=", "$", "this", "->", "viewsData", ";", "}" ]
Build array of data to be passed to every view. @return void
[ "Build", "array", "of", "data", "to", "be", "passed", "to", "every", "view", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/SiteBuilder.php#L251-L258
229,830
themsaid/katana-core
src/SiteBuilder.php
SiteBuilder.buildBlogPagination
protected function buildBlogPagination() { $builder = new BlogPaginationBuilder( $this->filesystem, $this->viewFactory, $this->viewsData ); $builder->build(); }
php
protected function buildBlogPagination() { $builder = new BlogPaginationBuilder( $this->filesystem, $this->viewFactory, $this->viewsData ); $builder->build(); }
[ "protected", "function", "buildBlogPagination", "(", ")", "{", "$", "builder", "=", "new", "BlogPaginationBuilder", "(", "$", "this", "->", "filesystem", ",", "$", "this", "->", "viewFactory", ",", "$", "this", "->", "viewsData", ")", ";", "$", "builder", "->", "build", "(", ")", ";", "}" ]
Build the blog pagination files. @return void
[ "Build", "the", "blog", "pagination", "files", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/SiteBuilder.php#L265-L274
229,831
themsaid/katana-core
src/SiteBuilder.php
SiteBuilder.buildRSSFeed
protected function buildRSSFeed() { $builder = new RSSFeedBuilder( $this->filesystem, $this->viewFactory, $this->viewsData ); $builder->build(); }
php
protected function buildRSSFeed() { $builder = new RSSFeedBuilder( $this->filesystem, $this->viewFactory, $this->viewsData ); $builder->build(); }
[ "protected", "function", "buildRSSFeed", "(", ")", "{", "$", "builder", "=", "new", "RSSFeedBuilder", "(", "$", "this", "->", "filesystem", ",", "$", "this", "->", "viewFactory", ",", "$", "this", "->", "viewsData", ")", ";", "$", "builder", "->", "build", "(", ")", ";", "}" ]
Build the blog RSS feed. @return void
[ "Build", "the", "blog", "RSS", "feed", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/SiteBuilder.php#L281-L290
229,832
ZenMagick/ZenCart
includes/classes/split_page_results.php
splitPageResults.display_count
function display_count($text_output) { $to_num = ($this->number_of_rows_per_page * $this->current_page_number); if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows; $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1)); if ($to_num == 0) { $from_num = 0; } else { $from_num++; } if ($to_num <= 1) { // don't show count when 1 return ''; } else { return sprintf($text_output, $from_num, $to_num, $this->number_of_rows); } }
php
function display_count($text_output) { $to_num = ($this->number_of_rows_per_page * $this->current_page_number); if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows; $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1)); if ($to_num == 0) { $from_num = 0; } else { $from_num++; } if ($to_num <= 1) { // don't show count when 1 return ''; } else { return sprintf($text_output, $from_num, $to_num, $this->number_of_rows); } }
[ "function", "display_count", "(", "$", "text_output", ")", "{", "$", "to_num", "=", "(", "$", "this", "->", "number_of_rows_per_page", "*", "$", "this", "->", "current_page_number", ")", ";", "if", "(", "$", "to_num", ">", "$", "this", "->", "number_of_rows", ")", "$", "to_num", "=", "$", "this", "->", "number_of_rows", ";", "$", "from_num", "=", "(", "$", "this", "->", "number_of_rows_per_page", "*", "(", "$", "this", "->", "current_page_number", "-", "1", ")", ")", ";", "if", "(", "$", "to_num", "==", "0", ")", "{", "$", "from_num", "=", "0", ";", "}", "else", "{", "$", "from_num", "++", ";", "}", "if", "(", "$", "to_num", "<=", "1", ")", "{", "// don't show count when 1", "return", "''", ";", "}", "else", "{", "return", "sprintf", "(", "$", "text_output", ",", "$", "from_num", ",", "$", "to_num", ",", "$", "this", "->", "number_of_rows", ")", ";", "}", "}" ]
display number of total products found
[ "display", "number", "of", "total", "products", "found" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/classes/split_page_results.php#L145-L163
229,833
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.processLogin
public function processLogin($authProvider = '') { try { // if we are on login page, first try to get the instance of Login object from current auth provider $login = $this->getAuthProvider($authProvider)->getLoginObject($this->getConfig()); if (!$this->isInstanceOf($login, Login::class)) { throw new FirewallException('Authentication provider method getLoginObject() must return an instance of "' . Login::class . '".'); } $login->setAuthProviderName($this->authProviderName); } catch (\Exception $e) { throw new FirewallException($e->getMessage()); } // forward the login object to user providers and validate the credentials $this->user = $this->authenticate($login); if (!$this->user) { // login failed $this->getAuthProvider($authProvider)->invalidLoginProvidedCallback(); $this->eventManager()->fire(SecurityEvent::LOGIN_INVALID, new SecurityEvent(new AnonymousUser())); return false; } else { $this->getAuthProvider($authProvider)->loginSuccessfulCallback($this->user); $this->eventManager()->fire(SecurityEvent::LOGIN_VALID, new SecurityEvent($this->user)); $this->setUserRoles(); $this->userAuthenticated = true; return true; } }
php
public function processLogin($authProvider = '') { try { // if we are on login page, first try to get the instance of Login object from current auth provider $login = $this->getAuthProvider($authProvider)->getLoginObject($this->getConfig()); if (!$this->isInstanceOf($login, Login::class)) { throw new FirewallException('Authentication provider method getLoginObject() must return an instance of "' . Login::class . '".'); } $login->setAuthProviderName($this->authProviderName); } catch (\Exception $e) { throw new FirewallException($e->getMessage()); } // forward the login object to user providers and validate the credentials $this->user = $this->authenticate($login); if (!$this->user) { // login failed $this->getAuthProvider($authProvider)->invalidLoginProvidedCallback(); $this->eventManager()->fire(SecurityEvent::LOGIN_INVALID, new SecurityEvent(new AnonymousUser())); return false; } else { $this->getAuthProvider($authProvider)->loginSuccessfulCallback($this->user); $this->eventManager()->fire(SecurityEvent::LOGIN_VALID, new SecurityEvent($this->user)); $this->setUserRoles(); $this->userAuthenticated = true; return true; } }
[ "public", "function", "processLogin", "(", "$", "authProvider", "=", "''", ")", "{", "try", "{", "// if we are on login page, first try to get the instance of Login object from current auth provider", "$", "login", "=", "$", "this", "->", "getAuthProvider", "(", "$", "authProvider", ")", "->", "getLoginObject", "(", "$", "this", "->", "getConfig", "(", ")", ")", ";", "if", "(", "!", "$", "this", "->", "isInstanceOf", "(", "$", "login", ",", "Login", "::", "class", ")", ")", "{", "throw", "new", "FirewallException", "(", "'Authentication provider method getLoginObject() must return an instance of \"'", ".", "Login", "::", "class", ".", "'\".'", ")", ";", "}", "$", "login", "->", "setAuthProviderName", "(", "$", "this", "->", "authProviderName", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "FirewallException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "// forward the login object to user providers and validate the credentials", "$", "this", "->", "user", "=", "$", "this", "->", "authenticate", "(", "$", "login", ")", ";", "if", "(", "!", "$", "this", "->", "user", ")", "{", "// login failed", "$", "this", "->", "getAuthProvider", "(", "$", "authProvider", ")", "->", "invalidLoginProvidedCallback", "(", ")", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "SecurityEvent", "::", "LOGIN_INVALID", ",", "new", "SecurityEvent", "(", "new", "AnonymousUser", "(", ")", ")", ")", ";", "return", "false", ";", "}", "else", "{", "$", "this", "->", "getAuthProvider", "(", "$", "authProvider", ")", "->", "loginSuccessfulCallback", "(", "$", "this", "->", "user", ")", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "SecurityEvent", "::", "LOGIN_VALID", ",", "new", "SecurityEvent", "(", "$", "this", "->", "user", ")", ")", ";", "$", "this", "->", "setUserRoles", "(", ")", ";", "$", "this", "->", "userAuthenticated", "=", "true", ";", "return", "true", ";", "}", "}" ]
Call this method on your login submit page, it will trigger the authentication provider and validate the provided credentials. @param string $authProvider Name of the auth provider you wish to use to process the login. If you don't set it, the first registered provider will be used. @return bool True if login is valid, false if login has failed. @throws FirewallException
[ "Call", "this", "method", "on", "your", "login", "submit", "page", "it", "will", "trigger", "the", "authentication", "provider", "and", "validate", "the", "provided", "credentials", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L159-L188
229,834
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.processLogout
public function processLogout() { $this->getToken()->deleteUserToken(); if ($this->getUser()->isAuthenticated()) { $this->getAuthProvider($this->user->getAuthProviderName())->logoutCallback(); } $this->user = new AnonymousUser(); $this->userAuthenticated = false; $this->eventManager()->fire(SecurityEvent::LOGOUT); return true; }
php
public function processLogout() { $this->getToken()->deleteUserToken(); if ($this->getUser()->isAuthenticated()) { $this->getAuthProvider($this->user->getAuthProviderName())->logoutCallback(); } $this->user = new AnonymousUser(); $this->userAuthenticated = false; $this->eventManager()->fire(SecurityEvent::LOGOUT); return true; }
[ "public", "function", "processLogout", "(", ")", "{", "$", "this", "->", "getToken", "(", ")", "->", "deleteUserToken", "(", ")", ";", "if", "(", "$", "this", "->", "getUser", "(", ")", "->", "isAuthenticated", "(", ")", ")", "{", "$", "this", "->", "getAuthProvider", "(", "$", "this", "->", "user", "->", "getAuthProviderName", "(", ")", ")", "->", "logoutCallback", "(", ")", ";", "}", "$", "this", "->", "user", "=", "new", "AnonymousUser", "(", ")", ";", "$", "this", "->", "userAuthenticated", "=", "false", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "SecurityEvent", "::", "LOGOUT", ")", ";", "return", "true", ";", "}" ]
This method deletes user auth token and calls the logoutCallback on current login provider. After that, it replaces the current user instance with an instance of AnonymousUser and redirects the request to the logout.target.
[ "This", "method", "deletes", "user", "auth", "token", "and", "calls", "the", "logoutCallback", "on", "current", "login", "provider", ".", "After", "that", "it", "replaces", "the", "current", "user", "instance", "with", "an", "instance", "of", "AnonymousUser", "and", "redirects", "the", "request", "to", "the", "logout", ".", "target", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L195-L207
229,835
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.getUser
public function getUser() { if ($this->userAuthenticated) { return $this->user; } try { // get token $this->user = new AnonymousUser(); $tokenData = $this->getToken()->getUserFromToken(); if (!$tokenData) { $this->eventManager()->fire(SecurityEvent::NOT_AUTHENTICATED, new SecurityEvent($this->user)); $this->userAuthenticated = false; return $this->user; } else { $this->user->populate($tokenData->getUsername(), '', $tokenData->getRoles(), true); $this->user->setAuthProviderName($tokenData->getAuthProviderName()); $this->user->setUserProviderName($tokenData->getUserProviderName()); $this->eventManager()->fire(SecurityEvent::AUTHENTICATED, new SecurityEvent($this->user)); $this->setUserRoles(); $this->userAuthenticated = true; return $this->user; } } catch (TokenException $e) { throw $e; } catch (\Exception $e) { $this->userAuthenticated = true; throw new FirewallException($e->getMessage()); } }
php
public function getUser() { if ($this->userAuthenticated) { return $this->user; } try { // get token $this->user = new AnonymousUser(); $tokenData = $this->getToken()->getUserFromToken(); if (!$tokenData) { $this->eventManager()->fire(SecurityEvent::NOT_AUTHENTICATED, new SecurityEvent($this->user)); $this->userAuthenticated = false; return $this->user; } else { $this->user->populate($tokenData->getUsername(), '', $tokenData->getRoles(), true); $this->user->setAuthProviderName($tokenData->getAuthProviderName()); $this->user->setUserProviderName($tokenData->getUserProviderName()); $this->eventManager()->fire(SecurityEvent::AUTHENTICATED, new SecurityEvent($this->user)); $this->setUserRoles(); $this->userAuthenticated = true; return $this->user; } } catch (TokenException $e) { throw $e; } catch (\Exception $e) { $this->userAuthenticated = true; throw new FirewallException($e->getMessage()); } }
[ "public", "function", "getUser", "(", ")", "{", "if", "(", "$", "this", "->", "userAuthenticated", ")", "{", "return", "$", "this", "->", "user", ";", "}", "try", "{", "// get token", "$", "this", "->", "user", "=", "new", "AnonymousUser", "(", ")", ";", "$", "tokenData", "=", "$", "this", "->", "getToken", "(", ")", "->", "getUserFromToken", "(", ")", ";", "if", "(", "!", "$", "tokenData", ")", "{", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "SecurityEvent", "::", "NOT_AUTHENTICATED", ",", "new", "SecurityEvent", "(", "$", "this", "->", "user", ")", ")", ";", "$", "this", "->", "userAuthenticated", "=", "false", ";", "return", "$", "this", "->", "user", ";", "}", "else", "{", "$", "this", "->", "user", "->", "populate", "(", "$", "tokenData", "->", "getUsername", "(", ")", ",", "''", ",", "$", "tokenData", "->", "getRoles", "(", ")", ",", "true", ")", ";", "$", "this", "->", "user", "->", "setAuthProviderName", "(", "$", "tokenData", "->", "getAuthProviderName", "(", ")", ")", ";", "$", "this", "->", "user", "->", "setUserProviderName", "(", "$", "tokenData", "->", "getUserProviderName", "(", ")", ")", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "SecurityEvent", "::", "AUTHENTICATED", ",", "new", "SecurityEvent", "(", "$", "this", "->", "user", ")", ")", ";", "$", "this", "->", "setUserRoles", "(", ")", ";", "$", "this", "->", "userAuthenticated", "=", "true", ";", "return", "$", "this", "->", "user", ";", "}", "}", "catch", "(", "TokenException", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "userAuthenticated", "=", "true", ";", "throw", "new", "FirewallException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Tries to retrieve the user from current token. If the token does not exist, AnonymousUser is returned. @return bool|AbstractUser @throws FirewallException @throws TokenException
[ "Tries", "to", "retrieve", "the", "user", "from", "current", "token", ".", "If", "the", "token", "does", "not", "exist", "AnonymousUser", "is", "returned", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L216-L250
229,836
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.isUserAllowedAccess
public function isUserAllowedAccess() { if (!is_object($this->accessControl)) { $this->accessControl = new AccessControl($this->user, $this->config->get('AccessControl', false)); } $isAccessAllowed = $this->accessControl->isUserAllowedAccess(); if (!$isAccessAllowed) { $this->eventManager()->fire(SecurityEvent::ROLE_INVALID, new SecurityEvent($this->user)); } return $isAccessAllowed; }
php
public function isUserAllowedAccess() { if (!is_object($this->accessControl)) { $this->accessControl = new AccessControl($this->user, $this->config->get('AccessControl', false)); } $isAccessAllowed = $this->accessControl->isUserAllowedAccess(); if (!$isAccessAllowed) { $this->eventManager()->fire(SecurityEvent::ROLE_INVALID, new SecurityEvent($this->user)); } return $isAccessAllowed; }
[ "public", "function", "isUserAllowedAccess", "(", ")", "{", "if", "(", "!", "is_object", "(", "$", "this", "->", "accessControl", ")", ")", "{", "$", "this", "->", "accessControl", "=", "new", "AccessControl", "(", "$", "this", "->", "user", ",", "$", "this", "->", "config", "->", "get", "(", "'AccessControl'", ",", "false", ")", ")", ";", "}", "$", "isAccessAllowed", "=", "$", "this", "->", "accessControl", "->", "isUserAllowedAccess", "(", ")", ";", "if", "(", "!", "$", "isAccessAllowed", ")", "{", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "SecurityEvent", "::", "ROLE_INVALID", ",", "new", "SecurityEvent", "(", "$", "this", "->", "user", ")", ")", ";", "}", "return", "$", "isAccessAllowed", ";", "}" ]
Checks if current user has access to current area based by access rules. @return bool
[ "Checks", "if", "current", "user", "has", "access", "to", "current", "area", "based", "by", "access", "rules", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L257-L269
229,837
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.getAuthProviderConfig
private function getAuthProviderConfig($authProvider) { // have we already fetched the auth config if ($this->authProviderConfig) { return $this->authProviderConfig; } if ($authProvider == '') { // get the first auth provider from the list $providers = $this->getConfig()->get('AuthenticationProviders', []); $authProvider = $providers[0]; } $this->authProviderConfig = Security::getConfig()->get('AuthenticationProviders.' . $authProvider, new ConfigObject()); // merge the internal driver // merge only if driver is not set and it matches the internal auth provider name if (!$this->authProviderConfig->get('Driver', false) && isset(self::$authProviders[$authProvider])) { $this->authProviderConfig->mergeWith(['Driver' => self::$authProviders[$authProvider]]); } // make sure the requested auth provider is assigned to the current firewall if (!in_array($authProvider, $this->getConfig()->get('AuthenticationProviders', [])->toArray())) { throw new FirewallException('Authentication provider "' . $authProvider . '" is not defined on "' . $this->getFirewallKey() . '" firewall.'); } // check that we have the driver if (!$this->authProviderConfig->get('Driver', false)) { throw new FirewallException('Unable to detect configuration for authentication provider "' . $authProvider . '".'); } $this->authProviderName = $authProvider; return $this->authProviderConfig; }
php
private function getAuthProviderConfig($authProvider) { // have we already fetched the auth config if ($this->authProviderConfig) { return $this->authProviderConfig; } if ($authProvider == '') { // get the first auth provider from the list $providers = $this->getConfig()->get('AuthenticationProviders', []); $authProvider = $providers[0]; } $this->authProviderConfig = Security::getConfig()->get('AuthenticationProviders.' . $authProvider, new ConfigObject()); // merge the internal driver // merge only if driver is not set and it matches the internal auth provider name if (!$this->authProviderConfig->get('Driver', false) && isset(self::$authProviders[$authProvider])) { $this->authProviderConfig->mergeWith(['Driver' => self::$authProviders[$authProvider]]); } // make sure the requested auth provider is assigned to the current firewall if (!in_array($authProvider, $this->getConfig()->get('AuthenticationProviders', [])->toArray())) { throw new FirewallException('Authentication provider "' . $authProvider . '" is not defined on "' . $this->getFirewallKey() . '" firewall.'); } // check that we have the driver if (!$this->authProviderConfig->get('Driver', false)) { throw new FirewallException('Unable to detect configuration for authentication provider "' . $authProvider . '".'); } $this->authProviderName = $authProvider; return $this->authProviderConfig; }
[ "private", "function", "getAuthProviderConfig", "(", "$", "authProvider", ")", "{", "// have we already fetched the auth config", "if", "(", "$", "this", "->", "authProviderConfig", ")", "{", "return", "$", "this", "->", "authProviderConfig", ";", "}", "if", "(", "$", "authProvider", "==", "''", ")", "{", "// get the first auth provider from the list", "$", "providers", "=", "$", "this", "->", "getConfig", "(", ")", "->", "get", "(", "'AuthenticationProviders'", ",", "[", "]", ")", ";", "$", "authProvider", "=", "$", "providers", "[", "0", "]", ";", "}", "$", "this", "->", "authProviderConfig", "=", "Security", "::", "getConfig", "(", ")", "->", "get", "(", "'AuthenticationProviders.'", ".", "$", "authProvider", ",", "new", "ConfigObject", "(", ")", ")", ";", "// merge the internal driver", "// merge only if driver is not set and it matches the internal auth provider name", "if", "(", "!", "$", "this", "->", "authProviderConfig", "->", "get", "(", "'Driver'", ",", "false", ")", "&&", "isset", "(", "self", "::", "$", "authProviders", "[", "$", "authProvider", "]", ")", ")", "{", "$", "this", "->", "authProviderConfig", "->", "mergeWith", "(", "[", "'Driver'", "=>", "self", "::", "$", "authProviders", "[", "$", "authProvider", "]", "]", ")", ";", "}", "// make sure the requested auth provider is assigned to the current firewall", "if", "(", "!", "in_array", "(", "$", "authProvider", ",", "$", "this", "->", "getConfig", "(", ")", "->", "get", "(", "'AuthenticationProviders'", ",", "[", "]", ")", "->", "toArray", "(", ")", ")", ")", "{", "throw", "new", "FirewallException", "(", "'Authentication provider \"'", ".", "$", "authProvider", ".", "'\" is not defined on \"'", ".", "$", "this", "->", "getFirewallKey", "(", ")", ".", "'\" firewall.'", ")", ";", "}", "// check that we have the driver", "if", "(", "!", "$", "this", "->", "authProviderConfig", "->", "get", "(", "'Driver'", ",", "false", ")", ")", "{", "throw", "new", "FirewallException", "(", "'Unable to detect configuration for authentication provider \"'", ".", "$", "authProvider", ".", "'\".'", ")", ";", "}", "$", "this", "->", "authProviderName", "=", "$", "authProvider", ";", "return", "$", "this", "->", "authProviderConfig", ";", "}" ]
Returns the config of current auth provider. @param string $authProvider Name of the auth provider you wish to use to process the login. If you don't set it, the first registered provider will be used. @throws FirewallException @return ConfigObject
[ "Returns", "the", "config", "of", "current", "auth", "provider", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L355-L389
229,838
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.authenticate
private function authenticate(Login $login) { foreach ($this->userProviders as $name => $provider) { try { /* @var AbstractUser $user */ $user = $provider->getUser($login); if ($user && $user->authenticate($login, $this)) { $user->setUserProviderName($name); $user->setAuthProviderName($login->getAuthProviderName()); $this->getToken()->setRememberMe($login->getRememberMe())->saveUser($user); return $user; } } catch (\Exception $e) { // next user provider } } return false; }
php
private function authenticate(Login $login) { foreach ($this->userProviders as $name => $provider) { try { /* @var AbstractUser $user */ $user = $provider->getUser($login); if ($user && $user->authenticate($login, $this)) { $user->setUserProviderName($name); $user->setAuthProviderName($login->getAuthProviderName()); $this->getToken()->setRememberMe($login->getRememberMe())->saveUser($user); return $user; } } catch (\Exception $e) { // next user provider } } return false; }
[ "private", "function", "authenticate", "(", "Login", "$", "login", ")", "{", "foreach", "(", "$", "this", "->", "userProviders", "as", "$", "name", "=>", "$", "provider", ")", "{", "try", "{", "/* @var AbstractUser $user */", "$", "user", "=", "$", "provider", "->", "getUser", "(", "$", "login", ")", ";", "if", "(", "$", "user", "&&", "$", "user", "->", "authenticate", "(", "$", "login", ",", "$", "this", ")", ")", "{", "$", "user", "->", "setUserProviderName", "(", "$", "name", ")", ";", "$", "user", "->", "setAuthProviderName", "(", "$", "login", "->", "getAuthProviderName", "(", ")", ")", ";", "$", "this", "->", "getToken", "(", ")", "->", "setRememberMe", "(", "$", "login", "->", "getRememberMe", "(", ")", ")", "->", "saveUser", "(", "$", "user", ")", ";", "return", "$", "user", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// next user provider", "}", "}", "return", "false", ";", "}" ]
Method that validates the submitted credentials with defined firewall user providers. If authentication is valid, a user object is created and a token is stored. This method just calls the 'authenticate' method on current user object, and if auth method returns true, we create a token and return the user instance. @param Login $login @return bool|AbstractUser @throws FirewallException
[ "Method", "that", "validates", "the", "submitted", "credentials", "with", "defined", "firewall", "user", "providers", ".", "If", "authentication", "is", "valid", "a", "user", "object", "is", "created", "and", "a", "token", "is", "stored", ".", "This", "method", "just", "calls", "the", "authenticate", "method", "on", "current", "user", "object", "and", "if", "auth", "method", "returns", "true", "we", "create", "a", "token", "and", "return", "the", "user", "instance", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L402-L421
229,839
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.initToken
private function initToken() { $tokenName = $this->getConfig()->get('Token', false); $rememberMe = $this->getConfig()->get('RememberMe', false); if (!$tokenName) { // fallback to the default token $securityKey = $this->getConfig()->get('TokenKey', false); if (!$securityKey) { throw new FirewallException('Missing TokenKey for "' . $this->getRealmName() . '" firewall.'); } } else { $securityKey = Security::getConfig()->get('Tokens.' . $tokenName . '.SecurityKey', false); if (!$securityKey) { throw new FirewallException('Missing security key for "' . $tokenName . '" token.'); } } $tokenCryptDriver = Security::getConfig()->get('Tokens.' . $tokenName . '.Driver', $this->defaultCryptDriver); $tokenCryptParams = Security::getConfig()->get('Tokens.' . $tokenName . '.Params', [], true); try { $tokenCrypt = $this->factory($tokenCryptDriver, $this->cryptDriverInterface, $tokenCryptParams); } catch (\Exception $e) { throw new FirewallException($e->getMessage()); } $storageClass = Security::getConfig()->get('Tokens.' . $tokenName . '.StorageDriver'); $this->token = new Token($this->getTokenName(), $rememberMe, $securityKey, $tokenCrypt, $storageClass); }
php
private function initToken() { $tokenName = $this->getConfig()->get('Token', false); $rememberMe = $this->getConfig()->get('RememberMe', false); if (!$tokenName) { // fallback to the default token $securityKey = $this->getConfig()->get('TokenKey', false); if (!$securityKey) { throw new FirewallException('Missing TokenKey for "' . $this->getRealmName() . '" firewall.'); } } else { $securityKey = Security::getConfig()->get('Tokens.' . $tokenName . '.SecurityKey', false); if (!$securityKey) { throw new FirewallException('Missing security key for "' . $tokenName . '" token.'); } } $tokenCryptDriver = Security::getConfig()->get('Tokens.' . $tokenName . '.Driver', $this->defaultCryptDriver); $tokenCryptParams = Security::getConfig()->get('Tokens.' . $tokenName . '.Params', [], true); try { $tokenCrypt = $this->factory($tokenCryptDriver, $this->cryptDriverInterface, $tokenCryptParams); } catch (\Exception $e) { throw new FirewallException($e->getMessage()); } $storageClass = Security::getConfig()->get('Tokens.' . $tokenName . '.StorageDriver'); $this->token = new Token($this->getTokenName(), $rememberMe, $securityKey, $tokenCrypt, $storageClass); }
[ "private", "function", "initToken", "(", ")", "{", "$", "tokenName", "=", "$", "this", "->", "getConfig", "(", ")", "->", "get", "(", "'Token'", ",", "false", ")", ";", "$", "rememberMe", "=", "$", "this", "->", "getConfig", "(", ")", "->", "get", "(", "'RememberMe'", ",", "false", ")", ";", "if", "(", "!", "$", "tokenName", ")", "{", "// fallback to the default token", "$", "securityKey", "=", "$", "this", "->", "getConfig", "(", ")", "->", "get", "(", "'TokenKey'", ",", "false", ")", ";", "if", "(", "!", "$", "securityKey", ")", "{", "throw", "new", "FirewallException", "(", "'Missing TokenKey for \"'", ".", "$", "this", "->", "getRealmName", "(", ")", ".", "'\" firewall.'", ")", ";", "}", "}", "else", "{", "$", "securityKey", "=", "Security", "::", "getConfig", "(", ")", "->", "get", "(", "'Tokens.'", ".", "$", "tokenName", ".", "'.SecurityKey'", ",", "false", ")", ";", "if", "(", "!", "$", "securityKey", ")", "{", "throw", "new", "FirewallException", "(", "'Missing security key for \"'", ".", "$", "tokenName", ".", "'\" token.'", ")", ";", "}", "}", "$", "tokenCryptDriver", "=", "Security", "::", "getConfig", "(", ")", "->", "get", "(", "'Tokens.'", ".", "$", "tokenName", ".", "'.Driver'", ",", "$", "this", "->", "defaultCryptDriver", ")", ";", "$", "tokenCryptParams", "=", "Security", "::", "getConfig", "(", ")", "->", "get", "(", "'Tokens.'", ".", "$", "tokenName", ".", "'.Params'", ",", "[", "]", ",", "true", ")", ";", "try", "{", "$", "tokenCrypt", "=", "$", "this", "->", "factory", "(", "$", "tokenCryptDriver", ",", "$", "this", "->", "cryptDriverInterface", ",", "$", "tokenCryptParams", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "FirewallException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "$", "storageClass", "=", "Security", "::", "getConfig", "(", ")", "->", "get", "(", "'Tokens.'", ".", "$", "tokenName", ".", "'.StorageDriver'", ")", ";", "$", "this", "->", "token", "=", "new", "Token", "(", "$", "this", "->", "getTokenName", "(", ")", ",", "$", "rememberMe", ",", "$", "securityKey", ",", "$", "tokenCrypt", ",", "$", "storageClass", ")", ";", "}" ]
Initializes the Token.
[ "Initializes", "the", "Token", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L426-L457
229,840
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.getAuthProvider
private function getAuthProvider($authProvider) { if (is_null($this->authProvider)) { // auth provider config $authProviderConfig = $this->getAuthProviderConfig($authProvider); // optional params that will be passed to auth provider constructor $params = $authProviderConfig->get('Params', [], true); try { $this->authProvider = $this->factory($authProviderConfig->Driver, $this->authenticationInterface, $params); } catch (Exception $e) { throw new FirewallException($e->getMessage()); } } return $this->authProvider; }
php
private function getAuthProvider($authProvider) { if (is_null($this->authProvider)) { // auth provider config $authProviderConfig = $this->getAuthProviderConfig($authProvider); // optional params that will be passed to auth provider constructor $params = $authProviderConfig->get('Params', [], true); try { $this->authProvider = $this->factory($authProviderConfig->Driver, $this->authenticationInterface, $params); } catch (Exception $e) { throw new FirewallException($e->getMessage()); } } return $this->authProvider; }
[ "private", "function", "getAuthProvider", "(", "$", "authProvider", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "authProvider", ")", ")", "{", "// auth provider config", "$", "authProviderConfig", "=", "$", "this", "->", "getAuthProviderConfig", "(", "$", "authProvider", ")", ";", "// optional params that will be passed to auth provider constructor", "$", "params", "=", "$", "authProviderConfig", "->", "get", "(", "'Params'", ",", "[", "]", ",", "true", ")", ";", "try", "{", "$", "this", "->", "authProvider", "=", "$", "this", "->", "factory", "(", "$", "authProviderConfig", "->", "Driver", ",", "$", "this", "->", "authenticationInterface", ",", "$", "params", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "FirewallException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "return", "$", "this", "->", "authProvider", ";", "}" ]
Get the authentication provider. @param string $authProvider Name of the auth provider you wish to use to process the login. If you don't set it, the first registered provider will be used. @return AuthenticationInterface @throws FirewallException
[ "Get", "the", "authentication", "provider", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L479-L496
229,841
Webiny/Framework
src/Webiny/Component/Security/Authentication/Firewall.php
Firewall.setUserRoles
private function setUserRoles() { $this->initRoleHierarchy(); $this->user->setRoles($this->roleHierarchy->getAccessibleRoles($this->user->getRoles())); }
php
private function setUserRoles() { $this->initRoleHierarchy(); $this->user->setRoles($this->roleHierarchy->getAccessibleRoles($this->user->getRoles())); }
[ "private", "function", "setUserRoles", "(", ")", "{", "$", "this", "->", "initRoleHierarchy", "(", ")", ";", "$", "this", "->", "user", "->", "setRoles", "(", "$", "this", "->", "roleHierarchy", "->", "getAccessibleRoles", "(", "$", "this", "->", "user", "->", "getRoles", "(", ")", ")", ")", ";", "}" ]
Sets roles for current user.
[ "Sets", "roles", "for", "current", "user", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authentication/Firewall.php#L509-L513
229,842
Webiny/Framework
src/Webiny/Component/Rest/Parser/PathTransformations.php
PathTransformations.methodNameToUrl
public static function methodNameToUrl($methodName) { $url = preg_replace('/([A-Z])/', ' $1', $methodName); $url = self::str($url)->trim()->replace(' ', '-')->caseLower()->val(); return $url; }
php
public static function methodNameToUrl($methodName) { $url = preg_replace('/([A-Z])/', ' $1', $methodName); $url = self::str($url)->trim()->replace(' ', '-')->caseLower()->val(); return $url; }
[ "public", "static", "function", "methodNameToUrl", "(", "$", "methodName", ")", "{", "$", "url", "=", "preg_replace", "(", "'/([A-Z])/'", ",", "' $1'", ",", "$", "methodName", ")", ";", "$", "url", "=", "self", "::", "str", "(", "$", "url", ")", "->", "trim", "(", ")", "->", "replace", "(", "' '", ",", "'-'", ")", "->", "caseLower", "(", ")", "->", "val", "(", ")", ";", "return", "$", "url", ";", "}" ]
Transforms method name to a url path. @param string $methodName Method name. @return string
[ "Transforms", "method", "name", "to", "a", "url", "path", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/PathTransformations.php#L28-L34
229,843
Webiny/Framework
src/Webiny/Component/Rest/Parser/PathTransformations.php
PathTransformations.classNameToUrl
public static function classNameToUrl($className, $normalize) { $className = self::str($className)->explode('\\')->last()->val(); if(!$normalize){ return $className; } $url = preg_replace('/([A-Z])/', ' $1', $className); $url = self::str($url)->trim()->replace(' ', '-')->caseLower()->val(); return $url; }
php
public static function classNameToUrl($className, $normalize) { $className = self::str($className)->explode('\\')->last()->val(); if(!$normalize){ return $className; } $url = preg_replace('/([A-Z])/', ' $1', $className); $url = self::str($url)->trim()->replace(' ', '-')->caseLower()->val(); return $url; }
[ "public", "static", "function", "classNameToUrl", "(", "$", "className", ",", "$", "normalize", ")", "{", "$", "className", "=", "self", "::", "str", "(", "$", "className", ")", "->", "explode", "(", "'\\\\'", ")", "->", "last", "(", ")", "->", "val", "(", ")", ";", "if", "(", "!", "$", "normalize", ")", "{", "return", "$", "className", ";", "}", "$", "url", "=", "preg_replace", "(", "'/([A-Z])/'", ",", "' $1'", ",", "$", "className", ")", ";", "$", "url", "=", "self", "::", "str", "(", "$", "url", ")", "->", "trim", "(", ")", "->", "replace", "(", "' '", ",", "'-'", ")", "->", "caseLower", "(", ")", "->", "val", "(", ")", ";", "return", "$", "url", ";", "}" ]
Transforms the class name to url path. @param string $className Class name. @param bool $normalize Should the name be normalized or not @return string
[ "Transforms", "the", "class", "name", "to", "url", "path", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/PathTransformations.php#L44-L54
229,844
alexandresalome/php-webdriver
src/WebDriver/By.php
By.linkText
static public function linkText($value, $isPartial = false) { return new By($isPartial ? self::PARTIAL_LINK_TEXT : self::LINK_TEXT, $value); }
php
static public function linkText($value, $isPartial = false) { return new By($isPartial ? self::PARTIAL_LINK_TEXT : self::LINK_TEXT, $value); }
[ "static", "public", "function", "linkText", "(", "$", "value", ",", "$", "isPartial", "=", "false", ")", "{", "return", "new", "By", "(", "$", "isPartial", "?", "self", "::", "PARTIAL_LINK_TEXT", ":", "self", "::", "LINK_TEXT", ",", "$", "value", ")", ";", "}" ]
Returns an anchor element whose visible text matches the search value. Browser will search for exact text if you don't specify $isPartial argument to true. @param string $value Exact text to search in a link @param boolean $isPartial Set to true to enable partial text search @return By
[ "Returns", "an", "anchor", "element", "whose", "visible", "text", "matches", "the", "search", "value", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/By.php#L160-L163
229,845
Webiny/Framework
src/Webiny/Component/EventManager/EventManager.php
EventManager.listen
public function listen($eventName, EventListener $eventListener = null) { if (!$this->isString($eventName) || $this->str($eventName)->length() == 0) { throw new EventManagerException(EventManagerException::INVALID_EVENT_NAME); } if ($this->isNull($eventListener)) { $eventListener = new EventListener(); } $eventListeners = $this->events->key($eventName, [], true); $eventListeners[] = $eventListener; $this->events->key($eventName, $eventListeners); return $eventListener; }
php
public function listen($eventName, EventListener $eventListener = null) { if (!$this->isString($eventName) || $this->str($eventName)->length() == 0) { throw new EventManagerException(EventManagerException::INVALID_EVENT_NAME); } if ($this->isNull($eventListener)) { $eventListener = new EventListener(); } $eventListeners = $this->events->key($eventName, [], true); $eventListeners[] = $eventListener; $this->events->key($eventName, $eventListeners); return $eventListener; }
[ "public", "function", "listen", "(", "$", "eventName", ",", "EventListener", "$", "eventListener", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "isString", "(", "$", "eventName", ")", "||", "$", "this", "->", "str", "(", "$", "eventName", ")", "->", "length", "(", ")", "==", "0", ")", "{", "throw", "new", "EventManagerException", "(", "EventManagerException", "::", "INVALID_EVENT_NAME", ")", ";", "}", "if", "(", "$", "this", "->", "isNull", "(", "$", "eventListener", ")", ")", "{", "$", "eventListener", "=", "new", "EventListener", "(", ")", ";", "}", "$", "eventListeners", "=", "$", "this", "->", "events", "->", "key", "(", "$", "eventName", ",", "[", "]", ",", "true", ")", ";", "$", "eventListeners", "[", "]", "=", "$", "eventListener", ";", "$", "this", "->", "events", "->", "key", "(", "$", "eventName", ",", "$", "eventListeners", ")", ";", "return", "$", "eventListener", ";", "}" ]
Subscribe to event @param string $eventName Event name you want to listen @param EventListener $eventListener (Optional) If specified, given EventListener will be used for this event @throws EventManagerException @return EventListener Return instance of EventListener
[ "Subscribe", "to", "event" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/EventManager/EventManager.php#L50-L66
229,846
ZenMagick/ZenCart
includes/classes/query_cache.php
QueryCache.cache
function cache($query, $result) { if ($this->isSelectStatement($query) === TRUE) $this->queries[$query] = $result; else return(FALSE); return(TRUE); }
php
function cache($query, $result) { if ($this->isSelectStatement($query) === TRUE) $this->queries[$query] = $result; else return(FALSE); return(TRUE); }
[ "function", "cache", "(", "$", "query", ",", "$", "result", ")", "{", "if", "(", "$", "this", "->", "isSelectStatement", "(", "$", "query", ")", "===", "TRUE", ")", "$", "this", "->", "queries", "[", "$", "query", "]", "=", "$", "result", ";", "else", "return", "(", "FALSE", ")", ";", "return", "(", "TRUE", ")", ";", "}" ]
FALSE - otherwise
[ "FALSE", "-", "otherwise" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/classes/query_cache.php#L26-L30
229,847
Webiny/Framework
src/Webiny/Component/Config/ConfigObject.php
ConfigObject.getAsYaml
public function getAsYaml($indent = 4) { $driver = new YamlDriver($this->toArray()); return $driver->setIndent($indent)->getString(); }
php
public function getAsYaml($indent = 4) { $driver = new YamlDriver($this->toArray()); return $driver->setIndent($indent)->getString(); }
[ "public", "function", "getAsYaml", "(", "$", "indent", "=", "4", ")", "{", "$", "driver", "=", "new", "YamlDriver", "(", "$", "this", "->", "toArray", "(", ")", ")", ";", "return", "$", "driver", "->", "setIndent", "(", "$", "indent", ")", "->", "getString", "(", ")", ";", "}" ]
Get config as Yaml string @param int $indent @return string
[ "Get", "config", "as", "Yaml", "string" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/ConfigObject.php#L53-L58
229,848
Webiny/Framework
src/Webiny/Component/Config/ConfigObject.php
ConfigObject.toArray
public function toArray($asArrayObject = false) { $data = []; foreach ($this->data as $k => $v) { $data[$k] = $this->isInstanceOf($v, $this) ? $v->toArray() : $v; } return $asArrayObject ? $this->arr($data) : $data; }
php
public function toArray($asArrayObject = false) { $data = []; foreach ($this->data as $k => $v) { $data[$k] = $this->isInstanceOf($v, $this) ? $v->toArray() : $v; } return $asArrayObject ? $this->arr($data) : $data; }
[ "public", "function", "toArray", "(", "$", "asArrayObject", "=", "false", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "data", "[", "$", "k", "]", "=", "$", "this", "->", "isInstanceOf", "(", "$", "v", ",", "$", "this", ")", "?", "$", "v", "->", "toArray", "(", ")", ":", "$", "v", ";", "}", "return", "$", "asArrayObject", "?", "$", "this", "->", "arr", "(", "$", "data", ")", ":", "$", "data", ";", "}" ]
Get Config data in form of an array or ArrayObject @param bool $asArrayObject (Optional) Defaults to false @return array|ArrayObject Config data array or ArrayObject
[ "Get", "Config", "data", "in", "form", "of", "an", "array", "or", "ArrayObject" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/ConfigObject.php#L183-L191
229,849
Webiny/Framework
src/Webiny/Component/Config/ConfigObject.php
ConfigObject.mergeWith
public function mergeWith($config) { if ($this->isArray($config) || $this->isArrayObject($config)) { $config = Config::getInstance()->php(StdObjectWrapper::toArray($config)); } foreach ($config as $key => $value) { if ($this->data->keyExists($key)) { if (is_numeric($key)) { $this->data[$key] = $value; continue; } elseif ($value instanceof ConfigObject && $this->data[$key] instanceof ConfigObject) { $this->data[$key]->mergeWith($value); continue; } } $this->data[$key] = $value instanceof ConfigObject ? new ConfigObject($value->toArray()) : $value; } return $this; }
php
public function mergeWith($config) { if ($this->isArray($config) || $this->isArrayObject($config)) { $config = Config::getInstance()->php(StdObjectWrapper::toArray($config)); } foreach ($config as $key => $value) { if ($this->data->keyExists($key)) { if (is_numeric($key)) { $this->data[$key] = $value; continue; } elseif ($value instanceof ConfigObject && $this->data[$key] instanceof ConfigObject) { $this->data[$key]->mergeWith($value); continue; } } $this->data[$key] = $value instanceof ConfigObject ? new ConfigObject($value->toArray()) : $value; } return $this; }
[ "public", "function", "mergeWith", "(", "$", "config", ")", "{", "if", "(", "$", "this", "->", "isArray", "(", "$", "config", ")", "||", "$", "this", "->", "isArrayObject", "(", "$", "config", ")", ")", "{", "$", "config", "=", "Config", "::", "getInstance", "(", ")", "->", "php", "(", "StdObjectWrapper", "::", "toArray", "(", "$", "config", ")", ")", ";", "}", "foreach", "(", "$", "config", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "this", "->", "data", "->", "keyExists", "(", "$", "key", ")", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "this", "->", "data", "[", "$", "key", "]", "=", "$", "value", ";", "continue", ";", "}", "elseif", "(", "$", "value", "instanceof", "ConfigObject", "&&", "$", "this", "->", "data", "[", "$", "key", "]", "instanceof", "ConfigObject", ")", "{", "$", "this", "->", "data", "[", "$", "key", "]", "->", "mergeWith", "(", "$", "value", ")", ";", "continue", ";", "}", "}", "$", "this", "->", "data", "[", "$", "key", "]", "=", "$", "value", "instanceof", "ConfigObject", "?", "new", "ConfigObject", "(", "$", "value", "->", "toArray", "(", ")", ")", ":", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Merge current config with given config @param array|ArrayObject|ConfigObject $config ConfigObject or array of ConfigObject to merge with @throws ConfigException @return $this
[ "Merge", "current", "config", "with", "given", "config" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/ConfigObject.php#L305-L325
229,850
Webiny/Framework
src/Webiny/Component/Rest/Compiler/Cache.php
Cache.isCacheValid
public function isCacheValid($api, $class) { // get the modified time of the $class try { $reflection = new \ReflectionClass($class); } catch (\Exception $e) { throw new RestException('Unable to validate the cache for ' . $class . '. ' . $e->getMessage()); } $classModTime = filemtime($reflection->getFileName()); return $this->cacheDriver->isFresh($api, $class, 'current', $classModTime); }
php
public function isCacheValid($api, $class) { // get the modified time of the $class try { $reflection = new \ReflectionClass($class); } catch (\Exception $e) { throw new RestException('Unable to validate the cache for ' . $class . '. ' . $e->getMessage()); } $classModTime = filemtime($reflection->getFileName()); return $this->cacheDriver->isFresh($api, $class, 'current', $classModTime); }
[ "public", "function", "isCacheValid", "(", "$", "api", ",", "$", "class", ")", "{", "// get the modified time of the $class", "try", "{", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "RestException", "(", "'Unable to validate the cache for '", ".", "$", "class", ".", "'. '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "$", "classModTime", "=", "filemtime", "(", "$", "reflection", "->", "getFileName", "(", ")", ")", ";", "return", "$", "this", "->", "cacheDriver", "->", "isFresh", "(", "$", "api", ",", "$", "class", ",", "'current'", ",", "$", "classModTime", ")", ";", "}" ]
Checks if a cache file is valid. A valid file is considered and existing cache file that has a newer creation time, than the modify time, of an api class that the cache file belongs to. @param string $api Name of the rest api configuration. @param string $class Fully qualified class name. @throws \Webiny\Component\Rest\RestException @return bool True if cache file is valid, otherwise false.
[ "Checks", "if", "a", "cache", "file", "is", "valid", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Compiler/Cache.php#L48-L60
229,851
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StdObjectWrapper.php
StdObjectWrapper.returnStdObject
public static function returnStdObject(&$var) { // check if $var is already a standard object if (self::isInstanceOf($var, AbstractStdObject::class)) { return $var; } // try to map $var to a standard object if (self::isString($var)) { return new StringObject($var); } else { if (self::isArray($var)) { return new ArrayObject($var); } } // return value as StdObjectWrapper return new self($var); }
php
public static function returnStdObject(&$var) { // check if $var is already a standard object if (self::isInstanceOf($var, AbstractStdObject::class)) { return $var; } // try to map $var to a standard object if (self::isString($var)) { return new StringObject($var); } else { if (self::isArray($var)) { return new ArrayObject($var); } } // return value as StdObjectWrapper return new self($var); }
[ "public", "static", "function", "returnStdObject", "(", "&", "$", "var", ")", "{", "// check if $var is already a standard object", "if", "(", "self", "::", "isInstanceOf", "(", "$", "var", ",", "AbstractStdObject", "::", "class", ")", ")", "{", "return", "$", "var", ";", "}", "// try to map $var to a standard object", "if", "(", "self", "::", "isString", "(", "$", "var", ")", ")", "{", "return", "new", "StringObject", "(", "$", "var", ")", ";", "}", "else", "{", "if", "(", "self", "::", "isArray", "(", "$", "var", ")", ")", "{", "return", "new", "ArrayObject", "(", "$", "var", ")", ";", "}", "}", "// return value as StdObjectWrapper", "return", "new", "self", "(", "$", "var", ")", ";", "}" ]
This function make sure you are returning a standard object. @param mixed $var @return ArrayObject|StdObjectWrapper|StringObject
[ "This", "function", "make", "sure", "you", "are", "returning", "a", "standard", "object", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StdObjectWrapper.php#L47-L65
229,852
khepin/KhepinYamlFixturesBundle
Fixture/MongoYamlFixture.php
MongoYamlFixture.createObject
public function createObject($class, $data, $metadata, $options = array()) { // options to state if a document is to be embedded or persisted on its own $embedded = isset($options['embedded']); $mapping = array_keys($metadata->fieldMappings); // Instantiate new object $object = $this->makeInstance($class, $data); unset($data['__construct']); foreach ($data as $field => $value) { // Add the fields defined in the fixtures file $method = Inflector::camelize('set_' . $field); // This is a standard field if (in_array($field, $mapping)) { // Dates need to be converted to DateTime objects $type = $metadata->fieldMappings[$field]['type']; if ($type == 'many') { $method = Inflector::camelize('add_'.$field); // EmbedMany if ( isset($metadata->fieldMappings[$field]['embedded']) && $metadata->fieldMappings[$field]['embedded']) { foreach ($value as $embedded_value) { $embed_class = $metadata->fieldMappings[$field]['targetDocument']; $embed_data = $embedded_value; $embed_meta = $this->getMetaDataForClass($embed_class); $value = $this->createObject($embed_class, $embed_data, $embed_meta, array( 'embedded' => true)); $object->$method($value); } //ReferenceMany } else { foreach ($value as $reference_object) { $object->$method($this->loader->getReference($reference_object)); } } } else { if ($type == 'datetime' || $type == 'date' || $type == 'time') { $value = new \DateTime($value); } if ($type == 'one') { // EmbedOne if ( isset($metadata->fieldMappings[$field]['embedded']) && $metadata->fieldMappings[$field]['embedded']) { $embed_class = $metadata->fieldMappings[$field]['targetDocument']; $embed_data = $value; $embed_meta = $this->getMetaDataForClass($embed_class); $value = $this->createObject($embed_class, $embed_data, $embed_meta, array( 'embedded' => true)); // ReferenceOne } else { $value = $this->loader->getReference($value); } } $object->$method($value); } } else { // The key is not a field's name but the name of a method to be called $object->$method($value); } } // Save a reference to the current object if (!$embedded) { $this->runServiceCalls($object); } return $object; }
php
public function createObject($class, $data, $metadata, $options = array()) { // options to state if a document is to be embedded or persisted on its own $embedded = isset($options['embedded']); $mapping = array_keys($metadata->fieldMappings); // Instantiate new object $object = $this->makeInstance($class, $data); unset($data['__construct']); foreach ($data as $field => $value) { // Add the fields defined in the fixtures file $method = Inflector::camelize('set_' . $field); // This is a standard field if (in_array($field, $mapping)) { // Dates need to be converted to DateTime objects $type = $metadata->fieldMappings[$field]['type']; if ($type == 'many') { $method = Inflector::camelize('add_'.$field); // EmbedMany if ( isset($metadata->fieldMappings[$field]['embedded']) && $metadata->fieldMappings[$field]['embedded']) { foreach ($value as $embedded_value) { $embed_class = $metadata->fieldMappings[$field]['targetDocument']; $embed_data = $embedded_value; $embed_meta = $this->getMetaDataForClass($embed_class); $value = $this->createObject($embed_class, $embed_data, $embed_meta, array( 'embedded' => true)); $object->$method($value); } //ReferenceMany } else { foreach ($value as $reference_object) { $object->$method($this->loader->getReference($reference_object)); } } } else { if ($type == 'datetime' || $type == 'date' || $type == 'time') { $value = new \DateTime($value); } if ($type == 'one') { // EmbedOne if ( isset($metadata->fieldMappings[$field]['embedded']) && $metadata->fieldMappings[$field]['embedded']) { $embed_class = $metadata->fieldMappings[$field]['targetDocument']; $embed_data = $value; $embed_meta = $this->getMetaDataForClass($embed_class); $value = $this->createObject($embed_class, $embed_data, $embed_meta, array( 'embedded' => true)); // ReferenceOne } else { $value = $this->loader->getReference($value); } } $object->$method($value); } } else { // The key is not a field's name but the name of a method to be called $object->$method($value); } } // Save a reference to the current object if (!$embedded) { $this->runServiceCalls($object); } return $object; }
[ "public", "function", "createObject", "(", "$", "class", ",", "$", "data", ",", "$", "metadata", ",", "$", "options", "=", "array", "(", ")", ")", "{", "// options to state if a document is to be embedded or persisted on its own", "$", "embedded", "=", "isset", "(", "$", "options", "[", "'embedded'", "]", ")", ";", "$", "mapping", "=", "array_keys", "(", "$", "metadata", "->", "fieldMappings", ")", ";", "// Instantiate new object", "$", "object", "=", "$", "this", "->", "makeInstance", "(", "$", "class", ",", "$", "data", ")", ";", "unset", "(", "$", "data", "[", "'__construct'", "]", ")", ";", "foreach", "(", "$", "data", "as", "$", "field", "=>", "$", "value", ")", "{", "// Add the fields defined in the fixtures file", "$", "method", "=", "Inflector", "::", "camelize", "(", "'set_'", ".", "$", "field", ")", ";", "// This is a standard field", "if", "(", "in_array", "(", "$", "field", ",", "$", "mapping", ")", ")", "{", "// Dates need to be converted to DateTime objects", "$", "type", "=", "$", "metadata", "->", "fieldMappings", "[", "$", "field", "]", "[", "'type'", "]", ";", "if", "(", "$", "type", "==", "'many'", ")", "{", "$", "method", "=", "Inflector", "::", "camelize", "(", "'add_'", ".", "$", "field", ")", ";", "// EmbedMany", "if", "(", "isset", "(", "$", "metadata", "->", "fieldMappings", "[", "$", "field", "]", "[", "'embedded'", "]", ")", "&&", "$", "metadata", "->", "fieldMappings", "[", "$", "field", "]", "[", "'embedded'", "]", ")", "{", "foreach", "(", "$", "value", "as", "$", "embedded_value", ")", "{", "$", "embed_class", "=", "$", "metadata", "->", "fieldMappings", "[", "$", "field", "]", "[", "'targetDocument'", "]", ";", "$", "embed_data", "=", "$", "embedded_value", ";", "$", "embed_meta", "=", "$", "this", "->", "getMetaDataForClass", "(", "$", "embed_class", ")", ";", "$", "value", "=", "$", "this", "->", "createObject", "(", "$", "embed_class", ",", "$", "embed_data", ",", "$", "embed_meta", ",", "array", "(", "'embedded'", "=>", "true", ")", ")", ";", "$", "object", "->", "$", "method", "(", "$", "value", ")", ";", "}", "//ReferenceMany", "}", "else", "{", "foreach", "(", "$", "value", "as", "$", "reference_object", ")", "{", "$", "object", "->", "$", "method", "(", "$", "this", "->", "loader", "->", "getReference", "(", "$", "reference_object", ")", ")", ";", "}", "}", "}", "else", "{", "if", "(", "$", "type", "==", "'datetime'", "||", "$", "type", "==", "'date'", "||", "$", "type", "==", "'time'", ")", "{", "$", "value", "=", "new", "\\", "DateTime", "(", "$", "value", ")", ";", "}", "if", "(", "$", "type", "==", "'one'", ")", "{", "// EmbedOne", "if", "(", "isset", "(", "$", "metadata", "->", "fieldMappings", "[", "$", "field", "]", "[", "'embedded'", "]", ")", "&&", "$", "metadata", "->", "fieldMappings", "[", "$", "field", "]", "[", "'embedded'", "]", ")", "{", "$", "embed_class", "=", "$", "metadata", "->", "fieldMappings", "[", "$", "field", "]", "[", "'targetDocument'", "]", ";", "$", "embed_data", "=", "$", "value", ";", "$", "embed_meta", "=", "$", "this", "->", "getMetaDataForClass", "(", "$", "embed_class", ")", ";", "$", "value", "=", "$", "this", "->", "createObject", "(", "$", "embed_class", ",", "$", "embed_data", ",", "$", "embed_meta", ",", "array", "(", "'embedded'", "=>", "true", ")", ")", ";", "// ReferenceOne", "}", "else", "{", "$", "value", "=", "$", "this", "->", "loader", "->", "getReference", "(", "$", "value", ")", ";", "}", "}", "$", "object", "->", "$", "method", "(", "$", "value", ")", ";", "}", "}", "else", "{", "// The key is not a field's name but the name of a method to be called", "$", "object", "->", "$", "method", "(", "$", "value", ")", ";", "}", "}", "// Save a reference to the current object", "if", "(", "!", "$", "embedded", ")", "{", "$", "this", "->", "runServiceCalls", "(", "$", "object", ")", ";", "}", "return", "$", "object", ";", "}" ]
Creates and returns one object based on the given data and metadata @param $class object's class name @param $data array of the object's fixture data @param $metadata the class metadata for doctrine @param $embedded true for embedded documents @return Object
[ "Creates", "and", "returns", "one", "object", "based", "on", "the", "given", "data", "and", "metadata" ]
4f1947b03809421057e7b8a3553ccaa93423d192
https://github.com/khepin/KhepinYamlFixturesBundle/blob/4f1947b03809421057e7b8a3553ccaa93423d192/Fixture/MongoYamlFixture.php#L18-L87
229,853
addiks/phpsql
src/Addiks/PHPSQL/Value/Text/Email.php
Email.validate
protected function validate($value) { parent::validate($value); $validator = new EmailValidator(); if (!$validator->isValid($value)) { throw new ErrorException("Email address '{$value}' is invalid!"); } }
php
protected function validate($value) { parent::validate($value); $validator = new EmailValidator(); if (!$validator->isValid($value)) { throw new ErrorException("Email address '{$value}' is invalid!"); } }
[ "protected", "function", "validate", "(", "$", "value", ")", "{", "parent", "::", "validate", "(", "$", "value", ")", ";", "$", "validator", "=", "new", "EmailValidator", "(", ")", ";", "if", "(", "!", "$", "validator", "->", "isValid", "(", "$", "value", ")", ")", "{", "throw", "new", "ErrorException", "(", "\"Email address '{$value}' is invalid!\"", ")", ";", "}", "}" ]
Validates the mail-address using Zend. @param string $value @throws InvalidArgumentException
[ "Validates", "the", "mail", "-", "address", "using", "Zend", "." ]
28dae64ffc2123f39f801a50ab53bfe29890cbd9
https://github.com/addiks/phpsql/blob/28dae64ffc2123f39f801a50ab53bfe29890cbd9/src/Addiks/PHPSQL/Value/Text/Email.php#L45-L55
229,854
Webiny/Framework
src/Webiny/Component/Mailer/MailerTrait.php
MailerTrait.mailer
protected static function mailer($key = 'Default') { if (isset(self::$mailerInstances[$key])) { return self::$mailerInstances[$key]; } else { self::$mailerInstances[$key] = new Mailer($key); return self::$mailerInstances[$key]; } }
php
protected static function mailer($key = 'Default') { if (isset(self::$mailerInstances[$key])) { return self::$mailerInstances[$key]; } else { self::$mailerInstances[$key] = new Mailer($key); return self::$mailerInstances[$key]; } }
[ "protected", "static", "function", "mailer", "(", "$", "key", "=", "'Default'", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "mailerInstances", "[", "$", "key", "]", ")", ")", "{", "return", "self", "::", "$", "mailerInstances", "[", "$", "key", "]", ";", "}", "else", "{", "self", "::", "$", "mailerInstances", "[", "$", "key", "]", "=", "new", "Mailer", "(", "$", "key", ")", ";", "return", "self", "::", "$", "mailerInstances", "[", "$", "key", "]", ";", "}", "}" ]
Returns an instance of Mailer. @param string $key Key that identifies which mailer configuration to load. @return Mailer
[ "Returns", "an", "instance", "of", "Mailer", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/MailerTrait.php#L28-L37
229,855
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/SwiftMailer/SwiftMailer.php
SwiftMailer.getMessage
public static function getMessage(ConfigObject $config) { $message = new Message($config); if ($config->get('Sender', false)) { $sender = new Email($config->get('Sender.Email', 'me@localhost'), $config->get('Sender.Name', null)); $message->setSender($sender); // Fix/Hack (wasn't in headers before) $message->setFrom($sender); } return $message; }
php
public static function getMessage(ConfigObject $config) { $message = new Message($config); if ($config->get('Sender', false)) { $sender = new Email($config->get('Sender.Email', 'me@localhost'), $config->get('Sender.Name', null)); $message->setSender($sender); // Fix/Hack (wasn't in headers before) $message->setFrom($sender); } return $message; }
[ "public", "static", "function", "getMessage", "(", "ConfigObject", "$", "config", ")", "{", "$", "message", "=", "new", "Message", "(", "$", "config", ")", ";", "if", "(", "$", "config", "->", "get", "(", "'Sender'", ",", "false", ")", ")", "{", "$", "sender", "=", "new", "Email", "(", "$", "config", "->", "get", "(", "'Sender.Email'", ",", "'me@localhost'", ")", ",", "$", "config", "->", "get", "(", "'Sender.Name'", ",", "null", ")", ")", ";", "$", "message", "->", "setSender", "(", "$", "sender", ")", ";", "// Fix/Hack (wasn't in headers before)", "$", "message", "->", "setFrom", "(", "$", "sender", ")", ";", "}", "return", "$", "message", ";", "}" ]
Returns an instance of MessageInterface. @param ConfigObject $config The configuration of current mailer @return MessageInterface
[ "Returns", "an", "instance", "of", "MessageInterface", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/SwiftMailer/SwiftMailer.php#L42-L55
229,856
Webiny/Framework
src/Webiny/Component/Config/Drivers/JsonDriver.php
JsonDriver.parseJsonString
private function parseJsonString($data) { try { return json_decode($data, true); } catch (Exception $e) { throw new ConfigException($e->getMessage()); } }
php
private function parseJsonString($data) { try { return json_decode($data, true); } catch (Exception $e) { throw new ConfigException($e->getMessage()); } }
[ "private", "function", "parseJsonString", "(", "$", "data", ")", "{", "try", "{", "return", "json_decode", "(", "$", "data", ",", "true", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "ConfigException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Parse JSON string and return config array @param array $data @throws ConfigException @return array
[ "Parse", "JSON", "string", "and", "return", "config", "array" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/Drivers/JsonDriver.php#L51-L58
229,857
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.getProfile
public function getProfile($id) { return $this->send($this->getHttp()->get($this->url.'profiles/'.$id.'.json')); }
php
public function getProfile($id) { return $this->send($this->getHttp()->get($this->url.'profiles/'.$id.'.json')); }
[ "public", "function", "getProfile", "(", "$", "id", ")", "{", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "get", "(", "$", "this", "->", "url", ".", "'profiles/'", ".", "$", "id", ".", "'.json'", ")", ")", ";", "}" ]
Returns details of the single specified social media profile. @param string $id @return array
[ "Returns", "details", "of", "the", "single", "specified", "social", "media", "profile", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L69-L72
229,858
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.getProfileSchedules
public function getProfileSchedules($id) { return $this->send($this->getHttp()->get($this->url.'profiles/'.$id.'/schedules.json')); }
php
public function getProfileSchedules($id) { return $this->send($this->getHttp()->get($this->url.'profiles/'.$id.'/schedules.json')); }
[ "public", "function", "getProfileSchedules", "(", "$", "id", ")", "{", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "get", "(", "$", "this", "->", "url", ".", "'profiles/'", ".", "$", "id", ".", "'/schedules.json'", ")", ")", ";", "}" ]
Returns details of the posting schedules associated with a social media profile. @param string $id @return array
[ "Returns", "details", "of", "the", "posting", "schedules", "associated", "with", "a", "social", "media", "profile", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L80-L83
229,859
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.updateProfileSchedules
public function updateProfileSchedules($id, $schedules) { $payload = $this->buildProfileSchedulesPayload($schedules); return $this->send($this->getHttp()->post($this->url.'profiles/'.$id.'/schedules/update.json', null, $payload)); }
php
public function updateProfileSchedules($id, $schedules) { $payload = $this->buildProfileSchedulesPayload($schedules); return $this->send($this->getHttp()->post($this->url.'profiles/'.$id.'/schedules/update.json', null, $payload)); }
[ "public", "function", "updateProfileSchedules", "(", "$", "id", ",", "$", "schedules", ")", "{", "$", "payload", "=", "$", "this", "->", "buildProfileSchedulesPayload", "(", "$", "schedules", ")", ";", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "post", "(", "$", "this", "->", "url", ".", "'profiles/'", ".", "$", "id", ".", "'/schedules/update.json'", ",", "null", ",", "$", "payload", ")", ")", ";", "}" ]
Set the posting schedules for the specified social media profile. @param string $id @param mixed $schedules @return array
[ "Set", "the", "posting", "schedules", "for", "the", "specified", "social", "media", "profile", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L92-L97
229,860
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.buildProfileSchedulesPayload
protected function buildProfileSchedulesPayload($schedules) { if (is_array($schedules)) { throw new Exception('Multiple schedules update are not implemented.'); } $payload = array('schedules' => array()); $payload['schedules'][] = array( 'days' => $schedules->getDays(), 'times' => $schedules->getTimes(), ); return $payload; }
php
protected function buildProfileSchedulesPayload($schedules) { if (is_array($schedules)) { throw new Exception('Multiple schedules update are not implemented.'); } $payload = array('schedules' => array()); $payload['schedules'][] = array( 'days' => $schedules->getDays(), 'times' => $schedules->getTimes(), ); return $payload; }
[ "protected", "function", "buildProfileSchedulesPayload", "(", "$", "schedules", ")", "{", "if", "(", "is_array", "(", "$", "schedules", ")", ")", "{", "throw", "new", "Exception", "(", "'Multiple schedules update are not implemented.'", ")", ";", "}", "$", "payload", "=", "array", "(", "'schedules'", "=>", "array", "(", ")", ")", ";", "$", "payload", "[", "'schedules'", "]", "[", "]", "=", "array", "(", "'days'", "=>", "$", "schedules", "->", "getDays", "(", ")", ",", "'times'", "=>", "$", "schedules", "->", "getTimes", "(", ")", ",", ")", ";", "return", "$", "payload", ";", "}" ]
Given an array of Schedule objects, build the necessary payload to update the profile schedules. @param mixed $schedules @return array
[ "Given", "an", "array", "of", "Schedule", "objects", "build", "the", "necessary", "payload", "to", "update", "the", "profile", "schedules", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L106-L120
229,861
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.getUpdate
public function getUpdate($id) { return $this->send($this->getHttp()->get($this->url.'updates/'.$id.'.json')); }
php
public function getUpdate($id) { return $this->send($this->getHttp()->get($this->url.'updates/'.$id.'.json')); }
[ "public", "function", "getUpdate", "(", "$", "id", ")", "{", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "get", "(", "$", "this", "->", "url", ".", "'updates/'", ".", "$", "id", ".", "'.json'", ")", ")", ";", "}" ]
Returns a single social media update. @param string $id @return array
[ "Returns", "a", "single", "social", "media", "update", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L128-L131
229,862
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.getProfilePendingUpdates
public function getProfilePendingUpdates($id, $page = null, $count = null, $since = null, $utc = false) { $payload = $this->buildProfileUpdatesPayload(compact('page', 'count', 'since', 'utc')); return $this->send($this->getHttp()->get($this->url.'profiles/'.$id.'/updates/pending.json?'.$payload)); }
php
public function getProfilePendingUpdates($id, $page = null, $count = null, $since = null, $utc = false) { $payload = $this->buildProfileUpdatesPayload(compact('page', 'count', 'since', 'utc')); return $this->send($this->getHttp()->get($this->url.'profiles/'.$id.'/updates/pending.json?'.$payload)); }
[ "public", "function", "getProfilePendingUpdates", "(", "$", "id", ",", "$", "page", "=", "null", ",", "$", "count", "=", "null", ",", "$", "since", "=", "null", ",", "$", "utc", "=", "false", ")", "{", "$", "payload", "=", "$", "this", "->", "buildProfileUpdatesPayload", "(", "compact", "(", "'page'", ",", "'count'", ",", "'since'", ",", "'utc'", ")", ")", ";", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "get", "(", "$", "this", "->", "url", ".", "'profiles/'", ".", "$", "id", ".", "'/updates/pending.json?'", ".", "$", "payload", ")", ")", ";", "}" ]
Returns an array of updates that are currently in the buffer for an individual social media profile. @param string $id @param integer $page @param integer $count @param integer $since @param bool $utc @return array
[ "Returns", "an", "array", "of", "updates", "that", "are", "currently", "in", "the", "buffer", "for", "an", "individual", "social", "media", "profile", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L144-L149
229,863
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.getUpdateInteractions
public function getUpdateInteractions($id, $page = null, $count = null, $event = null) { $payload = $this->buildProfileUpdatesPayload(compact('page', 'count', 'event')); return $this->send($this->getHttp()->get($this->url.'updates/'.$id.'/interactions.json?'.$payload)); }
php
public function getUpdateInteractions($id, $page = null, $count = null, $event = null) { $payload = $this->buildProfileUpdatesPayload(compact('page', 'count', 'event')); return $this->send($this->getHttp()->get($this->url.'updates/'.$id.'/interactions.json?'.$payload)); }
[ "public", "function", "getUpdateInteractions", "(", "$", "id", ",", "$", "page", "=", "null", ",", "$", "count", "=", "null", ",", "$", "event", "=", "null", ")", "{", "$", "payload", "=", "$", "this", "->", "buildProfileUpdatesPayload", "(", "compact", "(", "'page'", ",", "'count'", ",", "'event'", ")", ")", ";", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "get", "(", "$", "this", "->", "url", ".", "'updates/'", ".", "$", "id", ".", "'/interactions.json?'", ".", "$", "payload", ")", ")", ";", "}" ]
Returns the detailed information on individual interactions with the social media update such as favorites, retweets and likes. @param string $id @param integer $page @param integer $count @param string $event @return array
[ "Returns", "the", "detailed", "information", "on", "individual", "interactions", "with", "the", "social", "media", "update", "such", "as", "favorites", "retweets", "and", "likes", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L179-L184
229,864
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.buildProfileUpdatesPayload
protected function buildProfileUpdatesPayload($data) { $payload = array(); if (isset($data['page']) and is_numeric($data['page'])) { $payload['page'] = $data['page']; } if (isset($data['count']) and is_numeric($data['count'])) { $payload['count'] = $data['count']; } if (isset($data['since']) and is_numeric($data['since'])) { $payload['since'] = $data['since']; } if (isset($data['utc']) and $data['utc']) { $payload['utc'] = $data['utc']; } if (isset($data['event'])) { $available = array( 'retweet', 'retweets', 'favorite', 'favorites', 'like', 'likes', 'comment', 'comments', 'mention', 'mentions', 'share', 'shares', ); if (in_array($data['event'], $available)) { $payload['event'] = $data['event']; } } return (count($payload) > 0) ? http_build_query($payload) : ''; }
php
protected function buildProfileUpdatesPayload($data) { $payload = array(); if (isset($data['page']) and is_numeric($data['page'])) { $payload['page'] = $data['page']; } if (isset($data['count']) and is_numeric($data['count'])) { $payload['count'] = $data['count']; } if (isset($data['since']) and is_numeric($data['since'])) { $payload['since'] = $data['since']; } if (isset($data['utc']) and $data['utc']) { $payload['utc'] = $data['utc']; } if (isset($data['event'])) { $available = array( 'retweet', 'retweets', 'favorite', 'favorites', 'like', 'likes', 'comment', 'comments', 'mention', 'mentions', 'share', 'shares', ); if (in_array($data['event'], $available)) { $payload['event'] = $data['event']; } } return (count($payload) > 0) ? http_build_query($payload) : ''; }
[ "protected", "function", "buildProfileUpdatesPayload", "(", "$", "data", ")", "{", "$", "payload", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'page'", "]", ")", "and", "is_numeric", "(", "$", "data", "[", "'page'", "]", ")", ")", "{", "$", "payload", "[", "'page'", "]", "=", "$", "data", "[", "'page'", "]", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'count'", "]", ")", "and", "is_numeric", "(", "$", "data", "[", "'count'", "]", ")", ")", "{", "$", "payload", "[", "'count'", "]", "=", "$", "data", "[", "'count'", "]", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'since'", "]", ")", "and", "is_numeric", "(", "$", "data", "[", "'since'", "]", ")", ")", "{", "$", "payload", "[", "'since'", "]", "=", "$", "data", "[", "'since'", "]", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'utc'", "]", ")", "and", "$", "data", "[", "'utc'", "]", ")", "{", "$", "payload", "[", "'utc'", "]", "=", "$", "data", "[", "'utc'", "]", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'event'", "]", ")", ")", "{", "$", "available", "=", "array", "(", "'retweet'", ",", "'retweets'", ",", "'favorite'", ",", "'favorites'", ",", "'like'", ",", "'likes'", ",", "'comment'", ",", "'comments'", ",", "'mention'", ",", "'mentions'", ",", "'share'", ",", "'shares'", ",", ")", ";", "if", "(", "in_array", "(", "$", "data", "[", "'event'", "]", ",", "$", "available", ")", ")", "{", "$", "payload", "[", "'event'", "]", "=", "$", "data", "[", "'event'", "]", ";", "}", "}", "return", "(", "count", "(", "$", "payload", ")", ">", "0", ")", "?", "http_build_query", "(", "$", "payload", ")", ":", "''", ";", "}" ]
Generic querystring generator for some of the Updates methods. @param array $data @return string
[ "Generic", "querystring", "generator", "for", "some", "of", "the", "Updates", "methods", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L192-L224
229,865
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.reorderProfileUpdates
public function reorderProfileUpdates($id, $order, $offset = null, $utc = false) { $payload = $this->buildReorderProfileUpdatesPayload((array) $order, $offset, $utc); return $this->send($this->getHttp()->post($this->url.'profiles/'.$id.'/updates/reorder.json', null, $payload)); }
php
public function reorderProfileUpdates($id, $order, $offset = null, $utc = false) { $payload = $this->buildReorderProfileUpdatesPayload((array) $order, $offset, $utc); return $this->send($this->getHttp()->post($this->url.'profiles/'.$id.'/updates/reorder.json', null, $payload)); }
[ "public", "function", "reorderProfileUpdates", "(", "$", "id", ",", "$", "order", ",", "$", "offset", "=", "null", ",", "$", "utc", "=", "false", ")", "{", "$", "payload", "=", "$", "this", "->", "buildReorderProfileUpdatesPayload", "(", "(", "array", ")", "$", "order", ",", "$", "offset", ",", "$", "utc", ")", ";", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "post", "(", "$", "this", "->", "url", ".", "'profiles/'", ".", "$", "id", ".", "'/updates/reorder.json'", ",", "null", ",", "$", "payload", ")", ")", ";", "}" ]
Edit the order at which statuses for the specified social media profile will be sent out of the buffer. @param string $id @param array|string $order @param integer $offset @param boolean $utc @return array
[ "Edit", "the", "order", "at", "which", "statuses", "for", "the", "specified", "social", "media", "profile", "will", "be", "sent", "out", "of", "the", "buffer", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L236-L241
229,866
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.buildReorderProfileUpdatesPayload
protected function buildReorderProfileUpdatesPayload($order, $offset, $utc) { $payload = array(); $payload['order'] = $order; if (is_numeric($offset)) { $payload['offset'] = $offset; } if ($utc) { $payload['utc'] = true; } return $payload; }
php
protected function buildReorderProfileUpdatesPayload($order, $offset, $utc) { $payload = array(); $payload['order'] = $order; if (is_numeric($offset)) { $payload['offset'] = $offset; } if ($utc) { $payload['utc'] = true; } return $payload; }
[ "protected", "function", "buildReorderProfileUpdatesPayload", "(", "$", "order", ",", "$", "offset", ",", "$", "utc", ")", "{", "$", "payload", "=", "array", "(", ")", ";", "$", "payload", "[", "'order'", "]", "=", "$", "order", ";", "if", "(", "is_numeric", "(", "$", "offset", ")", ")", "{", "$", "payload", "[", "'offset'", "]", "=", "$", "offset", ";", "}", "if", "(", "$", "utc", ")", "{", "$", "payload", "[", "'utc'", "]", "=", "true", ";", "}", "return", "$", "payload", ";", "}" ]
Build the payload for reorderProfileUpdates. @param array $order @param integer $offset @param boolean $utc @return array
[ "Build", "the", "payload", "for", "reorderProfileUpdates", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L251-L266
229,867
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.shuffleProfileUpdates
public function shuffleProfileUpdates($id, $count = null, $utc = false) { $payload = $this->buildShuffleProfileUpdatesPayload($count, $utc); return $this->send($this->getHttp()->post($this->url.'profiles/'.$id.'/updates/shuffle.json', null, $payload)); }
php
public function shuffleProfileUpdates($id, $count = null, $utc = false) { $payload = $this->buildShuffleProfileUpdatesPayload($count, $utc); return $this->send($this->getHttp()->post($this->url.'profiles/'.$id.'/updates/shuffle.json', null, $payload)); }
[ "public", "function", "shuffleProfileUpdates", "(", "$", "id", ",", "$", "count", "=", "null", ",", "$", "utc", "=", "false", ")", "{", "$", "payload", "=", "$", "this", "->", "buildShuffleProfileUpdatesPayload", "(", "$", "count", ",", "$", "utc", ")", ";", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "post", "(", "$", "this", "->", "url", ".", "'profiles/'", ".", "$", "id", ".", "'/updates/shuffle.json'", ",", "null", ",", "$", "payload", ")", ")", ";", "}" ]
Randomize the order at which statuses for the specified social media profile will be sent out of the buffer. @param string $id @param integer $count @param boolean $utc @return array
[ "Randomize", "the", "order", "at", "which", "statuses", "for", "the", "specified", "social", "media", "profile", "will", "be", "sent", "out", "of", "the", "buffer", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L277-L282
229,868
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.buildShuffleProfileUpdatesPayload
protected function buildShuffleProfileUpdatesPayload($count, $utc) { $payload = array(); if (is_numeric($count)) { $payload['count'] = $count; } if ($utc) { $payload['utc'] = true; } return $payload; }
php
protected function buildShuffleProfileUpdatesPayload($count, $utc) { $payload = array(); if (is_numeric($count)) { $payload['count'] = $count; } if ($utc) { $payload['utc'] = true; } return $payload; }
[ "protected", "function", "buildShuffleProfileUpdatesPayload", "(", "$", "count", ",", "$", "utc", ")", "{", "$", "payload", "=", "array", "(", ")", ";", "if", "(", "is_numeric", "(", "$", "count", ")", ")", "{", "$", "payload", "[", "'count'", "]", "=", "$", "count", ";", "}", "if", "(", "$", "utc", ")", "{", "$", "payload", "[", "'utc'", "]", "=", "true", ";", "}", "return", "$", "payload", ";", "}" ]
Build the payload for shuffleProfileUpdates. @param integer $count @param boolean $utc @return array
[ "Build", "the", "payload", "for", "shuffleProfileUpdates", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L291-L304
229,869
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.createUpdate
public function createUpdate(Update $update) { $payload = $this->buildCreateUpdatePayload($update); return $this->send($this->getHttp()->post($this->url.'updates/create.json', null, $payload)); }
php
public function createUpdate(Update $update) { $payload = $this->buildCreateUpdatePayload($update); return $this->send($this->getHttp()->post($this->url.'updates/create.json', null, $payload)); }
[ "public", "function", "createUpdate", "(", "Update", "$", "update", ")", "{", "$", "payload", "=", "$", "this", "->", "buildCreateUpdatePayload", "(", "$", "update", ")", ";", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "post", "(", "$", "this", "->", "url", ".", "'updates/create.json'", ",", "null", ",", "$", "payload", ")", ")", ";", "}" ]
Create one or more new status updates. @param \Ipalaus\Buffer\Update $update @return array
[ "Create", "one", "or", "more", "new", "status", "updates", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L312-L317
229,870
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.buildCreateUpdatePayload
protected function buildCreateUpdatePayload(Update $update) { $payload = array( 'text' => $update->text, 'profile_ids' => $update->profiles, 'shorten' => $update->shorten, 'now' => $update->now, 'top' => $update->top, 'attachment' => $update->attachment ); if ( ! empty($update->media)) { $payload['media'] = $update->media; } if ( ! is_null($update->scheduled_at)) { $payload['scheduled_at'] = $update->scheduled_at; } return $payload; }
php
protected function buildCreateUpdatePayload(Update $update) { $payload = array( 'text' => $update->text, 'profile_ids' => $update->profiles, 'shorten' => $update->shorten, 'now' => $update->now, 'top' => $update->top, 'attachment' => $update->attachment ); if ( ! empty($update->media)) { $payload['media'] = $update->media; } if ( ! is_null($update->scheduled_at)) { $payload['scheduled_at'] = $update->scheduled_at; } return $payload; }
[ "protected", "function", "buildCreateUpdatePayload", "(", "Update", "$", "update", ")", "{", "$", "payload", "=", "array", "(", "'text'", "=>", "$", "update", "->", "text", ",", "'profile_ids'", "=>", "$", "update", "->", "profiles", ",", "'shorten'", "=>", "$", "update", "->", "shorten", ",", "'now'", "=>", "$", "update", "->", "now", ",", "'top'", "=>", "$", "update", "->", "top", ",", "'attachment'", "=>", "$", "update", "->", "attachment", ")", ";", "if", "(", "!", "empty", "(", "$", "update", "->", "media", ")", ")", "{", "$", "payload", "[", "'media'", "]", "=", "$", "update", "->", "media", ";", "}", "if", "(", "!", "is_null", "(", "$", "update", "->", "scheduled_at", ")", ")", "{", "$", "payload", "[", "'scheduled_at'", "]", "=", "$", "update", "->", "scheduled_at", ";", "}", "return", "$", "payload", ";", "}" ]
Build the payload for createUpdate. @param \Ipalaus\Buffer\Update $update @return array
[ "Build", "the", "payload", "for", "createUpdate", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L325-L345
229,871
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.updateUpdate
public function updateUpdate($id, Update $update) { $payload = $this->buildUpdateUpdatePayload($update); return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/update.json', null, $payload)); }
php
public function updateUpdate($id, Update $update) { $payload = $this->buildUpdateUpdatePayload($update); return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/update.json', null, $payload)); }
[ "public", "function", "updateUpdate", "(", "$", "id", ",", "Update", "$", "update", ")", "{", "$", "payload", "=", "$", "this", "->", "buildUpdateUpdatePayload", "(", "$", "update", ")", ";", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "post", "(", "$", "this", "->", "url", ".", "'updates/'", ".", "$", "id", ".", "'/update.json'", ",", "null", ",", "$", "payload", ")", ")", ";", "}" ]
Edit an existing, individual status update. @param string $id @param \Ipalaus\Buffer\Update $update @return array
[ "Edit", "an", "existing", "individual", "status", "update", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L354-L359
229,872
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.buildUpdateUpdatePayload
protected function buildUpdateUpdatePayload(Update $update) { $payload = array( 'text' => $update->text, 'now' => $update->now, ); if ( ! empty($update->media)) { $payload['media'] = $update->media; } if ( ! is_null($update->scheduled_at)) { $payload['scheduled_at'] = $update->scheduled_at; } return $payload; }
php
protected function buildUpdateUpdatePayload(Update $update) { $payload = array( 'text' => $update->text, 'now' => $update->now, ); if ( ! empty($update->media)) { $payload['media'] = $update->media; } if ( ! is_null($update->scheduled_at)) { $payload['scheduled_at'] = $update->scheduled_at; } return $payload; }
[ "protected", "function", "buildUpdateUpdatePayload", "(", "Update", "$", "update", ")", "{", "$", "payload", "=", "array", "(", "'text'", "=>", "$", "update", "->", "text", ",", "'now'", "=>", "$", "update", "->", "now", ",", ")", ";", "if", "(", "!", "empty", "(", "$", "update", "->", "media", ")", ")", "{", "$", "payload", "[", "'media'", "]", "=", "$", "update", "->", "media", ";", "}", "if", "(", "!", "is_null", "(", "$", "update", "->", "scheduled_at", ")", ")", "{", "$", "payload", "[", "'scheduled_at'", "]", "=", "$", "update", "->", "scheduled_at", ";", "}", "return", "$", "payload", ";", "}" ]
Build the payload for updateUpdate. @param \Ipalaus\Buffer\Update $update @return array
[ "Build", "the", "payload", "for", "updateUpdate", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L367-L383
229,873
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.shareUpdate
public function shareUpdate($id) { return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/share.json')); }
php
public function shareUpdate($id) { return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/share.json')); }
[ "public", "function", "shareUpdate", "(", "$", "id", ")", "{", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "post", "(", "$", "this", "->", "url", ".", "'updates/'", ".", "$", "id", ".", "'/share.json'", ")", ")", ";", "}" ]
Immediately shares a single pending update and recalculates times for updates remaining in the queue. @param string $id @return array
[ "Immediately", "shares", "a", "single", "pending", "update", "and", "recalculates", "times", "for", "updates", "remaining", "in", "the", "queue", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L392-L395
229,874
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.destroyUpdate
public function destroyUpdate($id) { return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/destroy.json')); }
php
public function destroyUpdate($id) { return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/destroy.json')); }
[ "public", "function", "destroyUpdate", "(", "$", "id", ")", "{", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "post", "(", "$", "this", "->", "url", ".", "'updates/'", ".", "$", "id", ".", "'/destroy.json'", ")", ")", ";", "}" ]
Permanently delete an existing status update. @param string $id @return array
[ "Permanently", "delete", "an", "existing", "status", "update", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L403-L406
229,875
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.moveUpdateToTop
public function moveUpdateToTop($id) { return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/move_to_top.json')); }
php
public function moveUpdateToTop($id) { return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/move_to_top.json')); }
[ "public", "function", "moveUpdateToTop", "(", "$", "id", ")", "{", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "post", "(", "$", "this", "->", "url", ".", "'updates/'", ".", "$", "id", ".", "'/move_to_top.json'", ")", ")", ";", "}" ]
Move an existing status update to the top of the queue and recalculate times for all updates in the queue. Returns the update with its new posting time. @param string $id @return array
[ "Move", "an", "existing", "status", "update", "to", "the", "top", "of", "the", "queue", "and", "recalculate", "times", "for", "all", "updates", "in", "the", "queue", ".", "Returns", "the", "update", "with", "its", "new", "posting", "time", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L416-L419
229,876
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.getLinkShares
public function getLinkShares($url) { $payload = http_build_query(array('url' => $url)); return $this->send($this->getHttp()->get($this->url.'links/shares.json?'.$payload)); }
php
public function getLinkShares($url) { $payload = http_build_query(array('url' => $url)); return $this->send($this->getHttp()->get($this->url.'links/shares.json?'.$payload)); }
[ "public", "function", "getLinkShares", "(", "$", "url", ")", "{", "$", "payload", "=", "http_build_query", "(", "array", "(", "'url'", "=>", "$", "url", ")", ")", ";", "return", "$", "this", "->", "send", "(", "$", "this", "->", "getHttp", "(", ")", "->", "get", "(", "$", "this", "->", "url", ".", "'links/shares.json?'", ".", "$", "payload", ")", ")", ";", "}" ]
Returns an object with a the numbers of shares a link has had using Buffer. @param string $url @return array
[ "Returns", "an", "object", "with", "a", "the", "numbers", "of", "shares", "a", "link", "has", "had", "using", "Buffer", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L428-L433
229,877
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Client.php
Client.send
protected function send(Request $request) { $request = $this->auth->addCredentialsToRequest($request); return $request->send()->json(); }
php
protected function send(Request $request) { $request = $this->auth->addCredentialsToRequest($request); return $request->send()->json(); }
[ "protected", "function", "send", "(", "Request", "$", "request", ")", "{", "$", "request", "=", "$", "this", "->", "auth", "->", "addCredentialsToRequest", "(", "$", "request", ")", ";", "return", "$", "request", "->", "send", "(", ")", "->", "json", "(", ")", ";", "}" ]
Send an authorized request and the response as an array. @param \Guzzle\Http\Message\Request $request @return array
[ "Send", "an", "authorized", "request", "and", "the", "response", "as", "an", "array", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Client.php#L457-L462
229,878
Webiny/Framework
src/Webiny/Component/Rest/Parser/ParameterParser.php
ParameterParser.parse
public function parse() { if (!is_array($this->paramList)) { return []; } $parsedParams = []; foreach ($this->paramList as $p) { $param = new ParsedParameter(); $param->name = $p->name; $param->type = $this->getType($p->name, $this->paramAnnotations); $param->matchPattern = $this->getParamMatchType($param->type); try { $param->default = $p->getDefaultValue(); if (is_bool($param->default)) { $param->default = ($param->default===false) ? '0' : '1'; } $param->required = false; } catch (\Exception $e) { $param->default = null; $param->required = true; } $parsedParams[] = $param; } return $parsedParams; }
php
public function parse() { if (!is_array($this->paramList)) { return []; } $parsedParams = []; foreach ($this->paramList as $p) { $param = new ParsedParameter(); $param->name = $p->name; $param->type = $this->getType($p->name, $this->paramAnnotations); $param->matchPattern = $this->getParamMatchType($param->type); try { $param->default = $p->getDefaultValue(); if (is_bool($param->default)) { $param->default = ($param->default===false) ? '0' : '1'; } $param->required = false; } catch (\Exception $e) { $param->default = null; $param->required = true; } $parsedParams[] = $param; } return $parsedParams; }
[ "public", "function", "parse", "(", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "paramList", ")", ")", "{", "return", "[", "]", ";", "}", "$", "parsedParams", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "paramList", "as", "$", "p", ")", "{", "$", "param", "=", "new", "ParsedParameter", "(", ")", ";", "$", "param", "->", "name", "=", "$", "p", "->", "name", ";", "$", "param", "->", "type", "=", "$", "this", "->", "getType", "(", "$", "p", "->", "name", ",", "$", "this", "->", "paramAnnotations", ")", ";", "$", "param", "->", "matchPattern", "=", "$", "this", "->", "getParamMatchType", "(", "$", "param", "->", "type", ")", ";", "try", "{", "$", "param", "->", "default", "=", "$", "p", "->", "getDefaultValue", "(", ")", ";", "if", "(", "is_bool", "(", "$", "param", "->", "default", ")", ")", "{", "$", "param", "->", "default", "=", "(", "$", "param", "->", "default", "===", "false", ")", "?", "'0'", ":", "'1'", ";", "}", "$", "param", "->", "required", "=", "false", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "param", "->", "default", "=", "null", ";", "$", "param", "->", "required", "=", "true", ";", "}", "$", "parsedParams", "[", "]", "=", "$", "param", ";", "}", "return", "$", "parsedParams", ";", "}" ]
Parses all the parameters and return an array of ParsedParameter instances. @return array Array of ParsedParameter instances.
[ "Parses", "all", "the", "parameters", "and", "return", "an", "array", "of", "ParsedParameter", "instances", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/ParameterParser.php#L72-L99
229,879
Webiny/Framework
src/Webiny/Component/Rest/Parser/ParameterParser.php
ParameterParser.getType
private function getType($pName, $annotations) { $type = 'string'; foreach ($annotations as $a) { if (strpos($a, '$' . $pName)) { foreach (self::$paramTypes as $typeKey => $typeList) { foreach ($typeList as $t) { if (strpos(trim($a), $t) === 0) { $type = $typeKey; } } } } } return $type; }
php
private function getType($pName, $annotations) { $type = 'string'; foreach ($annotations as $a) { if (strpos($a, '$' . $pName)) { foreach (self::$paramTypes as $typeKey => $typeList) { foreach ($typeList as $t) { if (strpos(trim($a), $t) === 0) { $type = $typeKey; } } } } } return $type; }
[ "private", "function", "getType", "(", "$", "pName", ",", "$", "annotations", ")", "{", "$", "type", "=", "'string'", ";", "foreach", "(", "$", "annotations", "as", "$", "a", ")", "{", "if", "(", "strpos", "(", "$", "a", ",", "'$'", ".", "$", "pName", ")", ")", "{", "foreach", "(", "self", "::", "$", "paramTypes", "as", "$", "typeKey", "=>", "$", "typeList", ")", "{", "foreach", "(", "$", "typeList", "as", "$", "t", ")", "{", "if", "(", "strpos", "(", "trim", "(", "$", "a", ")", ",", "$", "t", ")", "===", "0", ")", "{", "$", "type", "=", "$", "typeKey", ";", "}", "}", "}", "}", "}", "return", "$", "type", ";", "}" ]
Tries to detect the type of a parameter based on its phpDoc block. If type is not detected, "string" is returned as the default type. @param string $pName Name of the parameter. @param ConfigObject $annotations Parameter annotations. @return string Name of the parameter type, based on keys in static::$paramTypes.
[ "Tries", "to", "detect", "the", "type", "of", "a", "parameter", "based", "on", "its", "phpDoc", "block", ".", "If", "type", "is", "not", "detected", "string", "is", "returned", "as", "the", "default", "type", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/ParameterParser.php#L110-L126
229,880
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Schedule.php
Schedule.addDay
public function addDay($day) { $available = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'); foreach ((array) $day as $value) { // only accept valid values if ( ! in_array($value, $available)) { throw new InvalidArgumentException('Day must be a valid value: '.implode(', ', $available)); } $this->days[] = $value; } return $this; }
php
public function addDay($day) { $available = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'); foreach ((array) $day as $value) { // only accept valid values if ( ! in_array($value, $available)) { throw new InvalidArgumentException('Day must be a valid value: '.implode(', ', $available)); } $this->days[] = $value; } return $this; }
[ "public", "function", "addDay", "(", "$", "day", ")", "{", "$", "available", "=", "array", "(", "'mon'", ",", "'tue'", ",", "'wed'", ",", "'thu'", ",", "'fri'", ",", "'sat'", ",", "'sun'", ")", ";", "foreach", "(", "(", "array", ")", "$", "day", "as", "$", "value", ")", "{", "// only accept valid values", "if", "(", "!", "in_array", "(", "$", "value", ",", "$", "available", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Day must be a valid value: '", ".", "implode", "(", "', '", ",", "$", "available", ")", ")", ";", "}", "$", "this", "->", "days", "[", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Schedule a new day. @param string|array $day @return \Ipalaus\Buffer\Schedule
[ "Schedule", "a", "new", "day", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Schedule.php#L48-L62
229,881
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Schedule.php
Schedule.addTime
public function addTime($time) { foreach ((array) $time as $value) { // only accept valid times (HH:mm) if ( ! preg_match('#([01][0-9]|2[0-3]):[0-5][0-9]#', $value)) { throw new InvalidArgumentException('Time must be valid: HH:mm.'); } $this->times[] = $value; } return $this; }
php
public function addTime($time) { foreach ((array) $time as $value) { // only accept valid times (HH:mm) if ( ! preg_match('#([01][0-9]|2[0-3]):[0-5][0-9]#', $value)) { throw new InvalidArgumentException('Time must be valid: HH:mm.'); } $this->times[] = $value; } return $this; }
[ "public", "function", "addTime", "(", "$", "time", ")", "{", "foreach", "(", "(", "array", ")", "$", "time", "as", "$", "value", ")", "{", "// only accept valid times (HH:mm)", "if", "(", "!", "preg_match", "(", "'#([01][0-9]|2[0-3]):[0-5][0-9]#'", ",", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Time must be valid: HH:mm.'", ")", ";", "}", "$", "this", "->", "times", "[", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Schedule a time. @param string|array $time @return \Ipalaus\Buffer\Schedule
[ "Schedule", "a", "time", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Schedule.php#L70-L82
229,882
Webiny/Framework
src/Webiny/Component/OAuth2/Server/Facebook.php
Facebook.processAuthResponse
public function processAuthResponse($response) { if (!$this->isArray($response)) { throw new OAuth2Exception('Invalid response while trying to get the access token.'); } if (isset($response['result']['error'])) { throw new OAuth2Exception($this->jsonEncode($response['result']['error']['message'])); } parse_str($response['result'], $info); return $info['access_token']; }
php
public function processAuthResponse($response) { if (!$this->isArray($response)) { throw new OAuth2Exception('Invalid response while trying to get the access token.'); } if (isset($response['result']['error'])) { throw new OAuth2Exception($this->jsonEncode($response['result']['error']['message'])); } parse_str($response['result'], $info); return $info['access_token']; }
[ "public", "function", "processAuthResponse", "(", "$", "response", ")", "{", "if", "(", "!", "$", "this", "->", "isArray", "(", "$", "response", ")", ")", "{", "throw", "new", "OAuth2Exception", "(", "'Invalid response while trying to get the access token.'", ")", ";", "}", "if", "(", "isset", "(", "$", "response", "[", "'result'", "]", "[", "'error'", "]", ")", ")", "{", "throw", "new", "OAuth2Exception", "(", "$", "this", "->", "jsonEncode", "(", "$", "response", "[", "'result'", "]", "[", "'error'", "]", "[", "'message'", "]", ")", ")", ";", "}", "parse_str", "(", "$", "response", "[", "'result'", "]", ",", "$", "info", ")", ";", "return", "$", "info", "[", "'access_token'", "]", ";", "}" ]
This method is called when user is redirected to the redirect_uri from the authorization step. Here you should process the response from OAuth2 server and extract the access token if possible. If you cannot get the access token, throw an exception. @param array $response Response from the OAuth2 server. @throws \Webiny\Component\OAuth2\OAuth2Exception @return string Access token.
[ "This", "method", "is", "called", "when", "user", "is", "redirected", "to", "the", "redirect_uri", "from", "the", "authorization", "step", ".", "Here", "you", "should", "process", "the", "response", "from", "OAuth2", "server", "and", "extract", "the", "access", "token", "if", "possible", ".", "If", "you", "cannot", "get", "the", "access", "token", "throw", "an", "exception", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/OAuth2/Server/Facebook.php#L75-L88
229,883
Fanamurov/larrock-core
src/Traits/GetLink.php
GetLink.linkQuery
public function linkQuery($childModel) { return $this->hasMany(Link::class, 'id_parent')->whereModelParent($this->config->model)->whereModelChild($childModel); }
php
public function linkQuery($childModel) { return $this->hasMany(Link::class, 'id_parent')->whereModelParent($this->config->model)->whereModelChild($childModel); }
[ "public", "function", "linkQuery", "(", "$", "childModel", ")", "{", "return", "$", "this", "->", "hasMany", "(", "Link", "::", "class", ",", "'id_parent'", ")", "->", "whereModelParent", "(", "$", "this", "->", "config", "->", "model", ")", "->", "whereModelChild", "(", "$", "childModel", ")", ";", "}" ]
Get link query builder. @param $childModel @return mixed
[ "Get", "link", "query", "builder", "." ]
bce1d297182a829453f411d29371ec2a78d62960
https://github.com/Fanamurov/larrock-core/blob/bce1d297182a829453f411d29371ec2a78d62960/src/Traits/GetLink.php#L15-L18
229,884
Fanamurov/larrock-core
src/Traits/GetLink.php
GetLink.link
public function link($childModel) { return $this->hasMany(Link::class, 'id_parent')->whereModelParent($this->config->model)->whereModelChild($childModel)->get(); }
php
public function link($childModel) { return $this->hasMany(Link::class, 'id_parent')->whereModelParent($this->config->model)->whereModelChild($childModel)->get(); }
[ "public", "function", "link", "(", "$", "childModel", ")", "{", "return", "$", "this", "->", "hasMany", "(", "Link", "::", "class", ",", "'id_parent'", ")", "->", "whereModelParent", "(", "$", "this", "->", "config", "->", "model", ")", "->", "whereModelChild", "(", "$", "childModel", ")", "->", "get", "(", ")", ";", "}" ]
Get link data. @param $childModel @return mixed
[ "Get", "link", "data", "." ]
bce1d297182a829453f411d29371ec2a78d62960
https://github.com/Fanamurov/larrock-core/blob/bce1d297182a829453f411d29371ec2a78d62960/src/Traits/GetLink.php#L25-L28
229,885
Fanamurov/larrock-core
src/Traits/GetLink.php
GetLink.linkAttribute
public function linkAttribute($childModel) { $this->{$childModel} = $this->hasMany(Link::class, 'id_parent')->whereModelParent($this->config->model)->whereModelChild($childModel)->get(); return $this; }
php
public function linkAttribute($childModel) { $this->{$childModel} = $this->hasMany(Link::class, 'id_parent')->whereModelParent($this->config->model)->whereModelChild($childModel)->get(); return $this; }
[ "public", "function", "linkAttribute", "(", "$", "childModel", ")", "{", "$", "this", "->", "{", "$", "childModel", "}", "=", "$", "this", "->", "hasMany", "(", "Link", "::", "class", ",", "'id_parent'", ")", "->", "whereModelParent", "(", "$", "this", "->", "config", "->", "model", ")", "->", "whereModelChild", "(", "$", "childModel", ")", "->", "get", "(", ")", ";", "return", "$", "this", ";", "}" ]
Get Model Component + link in attrubute. @param $childModel @return $this
[ "Get", "Model", "Component", "+", "link", "in", "attrubute", "." ]
bce1d297182a829453f411d29371ec2a78d62960
https://github.com/Fanamurov/larrock-core/blob/bce1d297182a829453f411d29371ec2a78d62960/src/Traits/GetLink.php#L45-L50
229,886
Webiny/Framework
src/Webiny/Component/Entity/EntityAttributeContainer.php
EntityAttributeContainer.attr
public function attr($attribute) { if (strpos($attribute, '_') !== false) { throw new EntityException('Underscore is not allowed in attribute names (found in \'' . $attribute . '\')'); } $this->attribute = $attribute; return $this; }
php
public function attr($attribute) { if (strpos($attribute, '_') !== false) { throw new EntityException('Underscore is not allowed in attribute names (found in \'' . $attribute . '\')'); } $this->attribute = $attribute; return $this; }
[ "public", "function", "attr", "(", "$", "attribute", ")", "{", "if", "(", "strpos", "(", "$", "attribute", ",", "'_'", ")", "!==", "false", ")", "{", "throw", "new", "EntityException", "(", "'Underscore is not allowed in attribute names (found in \\''", ".", "$", "attribute", ".", "'\\')'", ")", ";", "}", "$", "this", "->", "attribute", "=", "$", "attribute", ";", "return", "$", "this", ";", "}" ]
Create a new attribute @param $attribute @return $this @throws EntityException
[ "Create", "a", "new", "attribute" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/EntityAttributeContainer.php#L70-L79
229,887
Webiny/Framework
src/Webiny/Component/Entity/EntityAttributeContainer.php
EntityAttributeContainer.smart
public function smart(AbstractAttribute $attribute) { $attribute->setName($this->attribute)->setParent($this->entity); return $this->attributes[$this->attribute] = $attribute; }
php
public function smart(AbstractAttribute $attribute) { $attribute->setName($this->attribute)->setParent($this->entity); return $this->attributes[$this->attribute] = $attribute; }
[ "public", "function", "smart", "(", "AbstractAttribute", "$", "attribute", ")", "{", "$", "attribute", "->", "setName", "(", "$", "this", "->", "attribute", ")", "->", "setParent", "(", "$", "this", "->", "entity", ")", ";", "return", "$", "this", "->", "attributes", "[", "$", "this", "->", "attribute", "]", "=", "$", "attribute", ";", "}" ]
Set attribute instance @param AbstractAttribute $attribute @return AbstractAttribute
[ "Set", "attribute", "instance" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/EntityAttributeContainer.php#L101-L106
229,888
Webiny/Framework
src/Webiny/Component/Http/Request/Files.php
Files.createFileObject
private function createFileObject($file, $arrayOffset = null) { if (!is_null($arrayOffset)) { $fileObject = new File($file['name'][$arrayOffset], $file['tmp_name'][$arrayOffset], $file['type'][$arrayOffset], $file['error'][$arrayOffset], $file['size'][$arrayOffset]); $this->fileObject[$file['name']][$arrayOffset] = $fileObject; } else { $fileObject = new File($file['name'], $file['tmp_name'], $file['type'], $file['error'], $file['size']); $this->fileObject[$file['name']] = $fileObject; } return $fileObject; }
php
private function createFileObject($file, $arrayOffset = null) { if (!is_null($arrayOffset)) { $fileObject = new File($file['name'][$arrayOffset], $file['tmp_name'][$arrayOffset], $file['type'][$arrayOffset], $file['error'][$arrayOffset], $file['size'][$arrayOffset]); $this->fileObject[$file['name']][$arrayOffset] = $fileObject; } else { $fileObject = new File($file['name'], $file['tmp_name'], $file['type'], $file['error'], $file['size']); $this->fileObject[$file['name']] = $fileObject; } return $fileObject; }
[ "private", "function", "createFileObject", "(", "$", "file", ",", "$", "arrayOffset", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "arrayOffset", ")", ")", "{", "$", "fileObject", "=", "new", "File", "(", "$", "file", "[", "'name'", "]", "[", "$", "arrayOffset", "]", ",", "$", "file", "[", "'tmp_name'", "]", "[", "$", "arrayOffset", "]", ",", "$", "file", "[", "'type'", "]", "[", "$", "arrayOffset", "]", ",", "$", "file", "[", "'error'", "]", "[", "$", "arrayOffset", "]", ",", "$", "file", "[", "'size'", "]", "[", "$", "arrayOffset", "]", ")", ";", "$", "this", "->", "fileObject", "[", "$", "file", "[", "'name'", "]", "]", "[", "$", "arrayOffset", "]", "=", "$", "fileObject", ";", "}", "else", "{", "$", "fileObject", "=", "new", "File", "(", "$", "file", "[", "'name'", "]", ",", "$", "file", "[", "'tmp_name'", "]", ",", "$", "file", "[", "'type'", "]", ",", "$", "file", "[", "'error'", "]", ",", "$", "file", "[", "'size'", "]", ")", ";", "$", "this", "->", "fileObject", "[", "$", "file", "[", "'name'", "]", "]", "=", "$", "fileObject", ";", "}", "return", "$", "fileObject", ";", "}" ]
Create the File object. @param array $file @param null $arrayOffset @return File
[ "Create", "the", "File", "object", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request/Files.php#L86-L98
229,889
deanblackborough/zf3-view-helpers
src/Bootstrap4Column.php
Bootstrap4Column.lg
public function lg(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->lg_size = $size; } return $this; }
php
public function lg(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->lg_size = $size; } return $this; }
[ "public", "function", "lg", "(", "int", "$", "size", ")", ":", "Bootstrap4Column", "{", "if", "(", "$", "this", "->", "validateColumnSize", "(", "$", "size", ")", "===", "true", ")", "{", "$", "this", "->", "lg_size", "=", "$", "size", ";", "}", "return", "$", "this", ";", "}" ]
Large 'lg' column @param integer $size Number of lg columns, a value between 1 and 12 @return Bootstrap4Column
[ "Large", "lg", "column" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Column.php#L69-L76
229,890
deanblackborough/zf3-view-helpers
src/Bootstrap4Column.php
Bootstrap4Column.md
public function md(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->md_size = $size; } return $this; }
php
public function md(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->md_size = $size; } return $this; }
[ "public", "function", "md", "(", "int", "$", "size", ")", ":", "Bootstrap4Column", "{", "if", "(", "$", "this", "->", "validateColumnSize", "(", "$", "size", ")", "===", "true", ")", "{", "$", "this", "->", "md_size", "=", "$", "size", ";", "}", "return", "$", "this", ";", "}" ]
Medium 'md' column @param integer $size Number of md columns, a value between 1 and 12 @return Bootstrap4Column
[ "Medium", "md", "column" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Column.php#L85-L92
229,891
deanblackborough/zf3-view-helpers
src/Bootstrap4Column.php
Bootstrap4Column.sm
public function sm(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->sm_size = $size; } return $this; }
php
public function sm(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->sm_size = $size; } return $this; }
[ "public", "function", "sm", "(", "int", "$", "size", ")", ":", "Bootstrap4Column", "{", "if", "(", "$", "this", "->", "validateColumnSize", "(", "$", "size", ")", "===", "true", ")", "{", "$", "this", "->", "sm_size", "=", "$", "size", ";", "}", "return", "$", "this", ";", "}" ]
Small 'sm' column @param integer $size Number of sm columns, a value between 1 and 12 @return Bootstrap4Column
[ "Small", "sm", "column" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Column.php#L131-L138
229,892
deanblackborough/zf3-view-helpers
src/Bootstrap4Column.php
Bootstrap4Column.xl
public function xl(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->xl_size = $size; } return $this; }
php
public function xl(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->xl_size = $size; } return $this; }
[ "public", "function", "xl", "(", "int", "$", "size", ")", ":", "Bootstrap4Column", "{", "if", "(", "$", "this", "->", "validateColumnSize", "(", "$", "size", ")", "===", "true", ")", "{", "$", "this", "->", "xl_size", "=", "$", "size", ";", "}", "return", "$", "this", ";", "}" ]
Extra large 'xl' column @param integer $size Number of xl columns, a value between 1 and 12 @return Bootstrap4Column
[ "Extra", "large", "xl", "column" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Column.php#L147-L154
229,893
deanblackborough/zf3-view-helpers
src/Bootstrap4Column.php
Bootstrap4Column.xs
public function xs(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->xs_size = $size; } return $this; }
php
public function xs(int $size): Bootstrap4Column { if ($this->validateColumnSize($size) === true) { $this->xs_size = $size; } return $this; }
[ "public", "function", "xs", "(", "int", "$", "size", ")", ":", "Bootstrap4Column", "{", "if", "(", "$", "this", "->", "validateColumnSize", "(", "$", "size", ")", "===", "true", ")", "{", "$", "this", "->", "xs_size", "=", "$", "size", ";", "}", "return", "$", "this", ";", "}" ]
Extra small column @param integer $size Number of xs columns, a value between 1 and 12 @return Bootstrap4Column
[ "Extra", "small", "column" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Column.php#L163-L170
229,894
deanblackborough/zf3-view-helpers
src/Bootstrap4Column.php
Bootstrap4Column.classes
private function classes() : string { $classes = ''; if ($this->xl_size !== null) { $classes .= ' col-xl-' . $this->xl_size; } if ($this->lg_size !== null) { $classes .= ' col-lg-' . $this->lg_size; } if ($this->md_size !== null) { $classes .= ' col-md-' . $this->md_size; } if ($this->sm_size !== null) { $classes .= ' col-sm-' . $this->sm_size; } if ($this->xs_size !== null) { $classes .= ' col-' . $this->xs_size; } if ($this->bg_color !== null) { $classes .= ' bg-' . $this->bg_color; } if ($this->text_color !== null) { $classes .= ' text-' . $this->text_color; } return trim($classes); }
php
private function classes() : string { $classes = ''; if ($this->xl_size !== null) { $classes .= ' col-xl-' . $this->xl_size; } if ($this->lg_size !== null) { $classes .= ' col-lg-' . $this->lg_size; } if ($this->md_size !== null) { $classes .= ' col-md-' . $this->md_size; } if ($this->sm_size !== null) { $classes .= ' col-sm-' . $this->sm_size; } if ($this->xs_size !== null) { $classes .= ' col-' . $this->xs_size; } if ($this->bg_color !== null) { $classes .= ' bg-' . $this->bg_color; } if ($this->text_color !== null) { $classes .= ' text-' . $this->text_color; } return trim($classes); }
[ "private", "function", "classes", "(", ")", ":", "string", "{", "$", "classes", "=", "''", ";", "if", "(", "$", "this", "->", "xl_size", "!==", "null", ")", "{", "$", "classes", ".=", "' col-xl-'", ".", "$", "this", "->", "xl_size", ";", "}", "if", "(", "$", "this", "->", "lg_size", "!==", "null", ")", "{", "$", "classes", ".=", "' col-lg-'", ".", "$", "this", "->", "lg_size", ";", "}", "if", "(", "$", "this", "->", "md_size", "!==", "null", ")", "{", "$", "classes", ".=", "' col-md-'", ".", "$", "this", "->", "md_size", ";", "}", "if", "(", "$", "this", "->", "sm_size", "!==", "null", ")", "{", "$", "classes", ".=", "' col-sm-'", ".", "$", "this", "->", "sm_size", ";", "}", "if", "(", "$", "this", "->", "xs_size", "!==", "null", ")", "{", "$", "classes", ".=", "' col-'", ".", "$", "this", "->", "xs_size", ";", "}", "if", "(", "$", "this", "->", "bg_color", "!==", "null", ")", "{", "$", "classes", ".=", "' bg-'", ".", "$", "this", "->", "bg_color", ";", "}", "if", "(", "$", "this", "->", "text_color", "!==", "null", ")", "{", "$", "classes", ".=", "' text-'", ".", "$", "this", "->", "text_color", ";", "}", "return", "trim", "(", "$", "classes", ")", ";", "}" ]
Generate the classes string for the row @return string
[ "Generate", "the", "classes", "string", "for", "the", "row" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Column.php#L177-L210
229,895
addiks/phpsql
src/Addiks/PHPSQL/Value/Text/Annotation.php
Annotation.parseData
protected function parseData() { if (is_null($this->dataCache)) { $patternNamespace = '(?P<namespace>[a-zA-Z0-9\\\\]+\\\\)?'; $patternName = '(?P<name>[a-zA-Z0-9]+)'; $patternString = '\"[^\"]*\"|\'[^\']*\''; $patternFloat = '[0-9]+\.[0-9]+'; $patternInt = '[0-9]+'; $patternBool = 'true|false'; $patternAttrValues = "({$patternString}|{$patternFloat}|{$patternInt}|{$patternBool})"; $patternAttributes = "(?P<attr>\(\s*([a-zA-Z0-9]+\={$patternAttrValues}\s*\,?\s*)+\s*\))?"; $pattern = "^\@{$patternNamespace}{$patternName}\s*{$patternAttributes}(?P<rawtext>.*)$"; if (preg_match("/{$pattern}/is", $this->getValue(), $matches)) { $this->dataCache = array( 'namespace' => $matches['namespace'], 'name' => $matches['name'], 'attributes' => array(), 'tags' => array(), ); if (preg_match_all("/(?P<key>[a-zA-Z0-9]+)\s*\=\s*(?P<value>{$patternAttrValues})/is", $matches['attr'], $attributeMatches, PREG_SET_ORDER)) { foreach ($attributeMatches as $attributeMatch) { $key = $attributeMatch['key']; $value = $attributeMatch['value']; switch(true){ case $value === 'true': $value = true; break; case $value === 'false': $value = false; break; case $value[0] === '"': case $value[0] === "'": $value = substr($value, 1, strlen($value)-2); break; case strpos($value, '.')>0: $value = (float)$value; break; case is_numeric($value): $value = (int)$value; break; } $this->dataCache['attributes'][$key] = $value; } } foreach (preg_split("/\s+/is", trim($matches['rawtext'])) as $attributeTag) { $this->dataCache['tags'][] = $attributeTag; } } } return $this->dataCache; }
php
protected function parseData() { if (is_null($this->dataCache)) { $patternNamespace = '(?P<namespace>[a-zA-Z0-9\\\\]+\\\\)?'; $patternName = '(?P<name>[a-zA-Z0-9]+)'; $patternString = '\"[^\"]*\"|\'[^\']*\''; $patternFloat = '[0-9]+\.[0-9]+'; $patternInt = '[0-9]+'; $patternBool = 'true|false'; $patternAttrValues = "({$patternString}|{$patternFloat}|{$patternInt}|{$patternBool})"; $patternAttributes = "(?P<attr>\(\s*([a-zA-Z0-9]+\={$patternAttrValues}\s*\,?\s*)+\s*\))?"; $pattern = "^\@{$patternNamespace}{$patternName}\s*{$patternAttributes}(?P<rawtext>.*)$"; if (preg_match("/{$pattern}/is", $this->getValue(), $matches)) { $this->dataCache = array( 'namespace' => $matches['namespace'], 'name' => $matches['name'], 'attributes' => array(), 'tags' => array(), ); if (preg_match_all("/(?P<key>[a-zA-Z0-9]+)\s*\=\s*(?P<value>{$patternAttrValues})/is", $matches['attr'], $attributeMatches, PREG_SET_ORDER)) { foreach ($attributeMatches as $attributeMatch) { $key = $attributeMatch['key']; $value = $attributeMatch['value']; switch(true){ case $value === 'true': $value = true; break; case $value === 'false': $value = false; break; case $value[0] === '"': case $value[0] === "'": $value = substr($value, 1, strlen($value)-2); break; case strpos($value, '.')>0: $value = (float)$value; break; case is_numeric($value): $value = (int)$value; break; } $this->dataCache['attributes'][$key] = $value; } } foreach (preg_split("/\s+/is", trim($matches['rawtext'])) as $attributeTag) { $this->dataCache['tags'][] = $attributeTag; } } } return $this->dataCache; }
[ "protected", "function", "parseData", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "dataCache", ")", ")", "{", "$", "patternNamespace", "=", "'(?P<namespace>[a-zA-Z0-9\\\\\\\\]+\\\\\\\\)?'", ";", "$", "patternName", "=", "'(?P<name>[a-zA-Z0-9]+)'", ";", "$", "patternString", "=", "'\\\"[^\\\"]*\\\"|\\'[^\\']*\\''", ";", "$", "patternFloat", "=", "'[0-9]+\\.[0-9]+'", ";", "$", "patternInt", "=", "'[0-9]+'", ";", "$", "patternBool", "=", "'true|false'", ";", "$", "patternAttrValues", "=", "\"({$patternString}|{$patternFloat}|{$patternInt}|{$patternBool})\"", ";", "$", "patternAttributes", "=", "\"(?P<attr>\\(\\s*([a-zA-Z0-9]+\\={$patternAttrValues}\\s*\\,?\\s*)+\\s*\\))?\"", ";", "$", "pattern", "=", "\"^\\@{$patternNamespace}{$patternName}\\s*{$patternAttributes}(?P<rawtext>.*)$\"", ";", "if", "(", "preg_match", "(", "\"/{$pattern}/is\"", ",", "$", "this", "->", "getValue", "(", ")", ",", "$", "matches", ")", ")", "{", "$", "this", "->", "dataCache", "=", "array", "(", "'namespace'", "=>", "$", "matches", "[", "'namespace'", "]", ",", "'name'", "=>", "$", "matches", "[", "'name'", "]", ",", "'attributes'", "=>", "array", "(", ")", ",", "'tags'", "=>", "array", "(", ")", ",", ")", ";", "if", "(", "preg_match_all", "(", "\"/(?P<key>[a-zA-Z0-9]+)\\s*\\=\\s*(?P<value>{$patternAttrValues})/is\"", ",", "$", "matches", "[", "'attr'", "]", ",", "$", "attributeMatches", ",", "PREG_SET_ORDER", ")", ")", "{", "foreach", "(", "$", "attributeMatches", "as", "$", "attributeMatch", ")", "{", "$", "key", "=", "$", "attributeMatch", "[", "'key'", "]", ";", "$", "value", "=", "$", "attributeMatch", "[", "'value'", "]", ";", "switch", "(", "true", ")", "{", "case", "$", "value", "===", "'true'", ":", "$", "value", "=", "true", ";", "break", ";", "case", "$", "value", "===", "'false'", ":", "$", "value", "=", "false", ";", "break", ";", "case", "$", "value", "[", "0", "]", "===", "'\"'", ":", "case", "$", "value", "[", "0", "]", "===", "\"'\"", ":", "$", "value", "=", "substr", "(", "$", "value", ",", "1", ",", "strlen", "(", "$", "value", ")", "-", "2", ")", ";", "break", ";", "case", "strpos", "(", "$", "value", ",", "'.'", ")", ">", "0", ":", "$", "value", "=", "(", "float", ")", "$", "value", ";", "break", ";", "case", "is_numeric", "(", "$", "value", ")", ":", "$", "value", "=", "(", "int", ")", "$", "value", ";", "break", ";", "}", "$", "this", "->", "dataCache", "[", "'attributes'", "]", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "foreach", "(", "preg_split", "(", "\"/\\s+/is\"", ",", "trim", "(", "$", "matches", "[", "'rawtext'", "]", ")", ")", "as", "$", "attributeTag", ")", "{", "$", "this", "->", "dataCache", "[", "'tags'", "]", "[", "]", "=", "$", "attributeTag", ";", "}", "}", "}", "return", "$", "this", "->", "dataCache", ";", "}" ]
Parses the annotation-line down to its components. array( 'namespace' => $namespace, 'name' => $name, 'attributes' => array( 'someKey' => 'someValue', 'otherKey' => 'otherValue', ), 'tags' => array( 'foo', 'bar', 'baz' ) ) @return array
[ "Parses", "the", "annotation", "-", "line", "down", "to", "its", "components", "." ]
28dae64ffc2123f39f801a50ab53bfe29890cbd9
https://github.com/addiks/phpsql/blob/28dae64ffc2123f39f801a50ab53bfe29890cbd9/src/Addiks/PHPSQL/Value/Text/Annotation.php#L84-L142
229,896
clickalicious/rng
src/Generator.php
Generator.generateSeed
public function generateSeed() { list($usec, $sec) = explode(' ', microtime()); return (int)($sec + strrev($usec * 1000000)) + 13; }
php
public function generateSeed() { list($usec, $sec) = explode(' ', microtime()); return (int)($sec + strrev($usec * 1000000)) + 13; }
[ "public", "function", "generateSeed", "(", ")", "{", "list", "(", "$", "usec", ",", "$", "sec", ")", "=", "explode", "(", "' '", ",", "microtime", "(", ")", ")", ";", "return", "(", "int", ")", "(", "$", "sec", "+", "strrev", "(", "$", "usec", "*", "1000000", ")", ")", "+", "13", ";", "}" ]
Generate the seed from microtime. @author Benjamin Carl <opensource@clickalicious.de> @return int The seed value
[ "Generate", "the", "seed", "from", "microtime", "." ]
9ee48ac4c5a9000e5776559715d027228a015bf9
https://github.com/clickalicious/rng/blob/9ee48ac4c5a9000e5776559715d027228a015bf9/src/Generator.php#L194-L199
229,897
clickalicious/rng
src/Generator.php
Generator.getRandomBytes
public function getRandomBytes( $numberOfBytes = PHP_INT_MAX, $source = null ) { switch ($source) { case self::MODE_OPEN_SSL: $randomBytes = $this->getRandomBytesFromOpenSSL($numberOfBytes); break; default: // http://php.net/manual/de/function.random-bytes.php - POLYFILL used for PHP < 7 $randomBytes = random_bytes($numberOfBytes); break; } return $randomBytes; }
php
public function getRandomBytes( $numberOfBytes = PHP_INT_MAX, $source = null ) { switch ($source) { case self::MODE_OPEN_SSL: $randomBytes = $this->getRandomBytesFromOpenSSL($numberOfBytes); break; default: // http://php.net/manual/de/function.random-bytes.php - POLYFILL used for PHP < 7 $randomBytes = random_bytes($numberOfBytes); break; } return $randomBytes; }
[ "public", "function", "getRandomBytes", "(", "$", "numberOfBytes", "=", "PHP_INT_MAX", ",", "$", "source", "=", "null", ")", "{", "switch", "(", "$", "source", ")", "{", "case", "self", "::", "MODE_OPEN_SSL", ":", "$", "randomBytes", "=", "$", "this", "->", "getRandomBytesFromOpenSSL", "(", "$", "numberOfBytes", ")", ";", "break", ";", "default", ":", "// http://php.net/manual/de/function.random-bytes.php - POLYFILL used for PHP < 7", "$", "randomBytes", "=", "random_bytes", "(", "$", "numberOfBytes", ")", ";", "break", ";", "}", "return", "$", "randomBytes", ";", "}" ]
Returns random bytes secure for cryptographic context. @param int $numberOfBytes Number of bytes to read and return. @param int|null $source Source of random bytes. @author Benjamin Carl <opensource@clickalicious.de> @return string Random bytes @throws \Clickalicious\Rng\Exception @throws \Clickalicious\Rng\CryptographicWeaknessException
[ "Returns", "random", "bytes", "secure", "for", "cryptographic", "context", "." ]
9ee48ac4c5a9000e5776559715d027228a015bf9
https://github.com/clickalicious/rng/blob/9ee48ac4c5a9000e5776559715d027228a015bf9/src/Generator.php#L214-L232
229,898
clickalicious/rng
src/Generator.php
Generator.genericRand
protected function genericRand( $rangeMinimum, $rangeMaximum, $source = self::MODE_OPEN_SSL ) { $diff = $rangeMaximum - ($rangeMinimum + 1); if ($diff > PHP_INT_MAX) { throw new Exception('Bad range'); } // The largest *multiple* of diff less than our sample $ceiling = floor(PHP_INT_MAX / $diff) * $diff; do { switch ($source) { case self::MODE_OPEN_SSL: default: $bytes = $this->getRandomBytesFromOpenSSL(PHP_INT_SIZE); break; } /* @codeCoverageIgnoreStart */ // Check for error if (false === $bytes || PHP_INT_SIZE !== strlen($bytes)) { throw new Exception( sprintf( 'Failed to read %s bytes from %s.', PHP_INT_SIZE, 'OpenSSL' ) ); } /* @codeCoverageIgnoreEnd */ if (PHP_INT_SIZE === 8) { // 64-bit versions list($higher, $lower) = array_values(unpack('N2', $bytes)); $val = $higher << 32 | $lower; } else { // 32-bit versions $val = unpack('Nint', $bytes); } $val = $val['int'] & PHP_INT_MAX; } while ($val > $ceiling); // In the unlikely case our sample is bigger than largest multiple, just do over until it’s not any more. // Perfectly even sampling in our 0<output<diff domain is mathematically impossible unless the total number of // *valid* inputs is an exact multiple of diff. return $val % $diff + $rangeMinimum; }
php
protected function genericRand( $rangeMinimum, $rangeMaximum, $source = self::MODE_OPEN_SSL ) { $diff = $rangeMaximum - ($rangeMinimum + 1); if ($diff > PHP_INT_MAX) { throw new Exception('Bad range'); } // The largest *multiple* of diff less than our sample $ceiling = floor(PHP_INT_MAX / $diff) * $diff; do { switch ($source) { case self::MODE_OPEN_SSL: default: $bytes = $this->getRandomBytesFromOpenSSL(PHP_INT_SIZE); break; } /* @codeCoverageIgnoreStart */ // Check for error if (false === $bytes || PHP_INT_SIZE !== strlen($bytes)) { throw new Exception( sprintf( 'Failed to read %s bytes from %s.', PHP_INT_SIZE, 'OpenSSL' ) ); } /* @codeCoverageIgnoreEnd */ if (PHP_INT_SIZE === 8) { // 64-bit versions list($higher, $lower) = array_values(unpack('N2', $bytes)); $val = $higher << 32 | $lower; } else { // 32-bit versions $val = unpack('Nint', $bytes); } $val = $val['int'] & PHP_INT_MAX; } while ($val > $ceiling); // In the unlikely case our sample is bigger than largest multiple, just do over until it’s not any more. // Perfectly even sampling in our 0<output<diff domain is mathematically impossible unless the total number of // *valid* inputs is an exact multiple of diff. return $val % $diff + $rangeMinimum; }
[ "protected", "function", "genericRand", "(", "$", "rangeMinimum", ",", "$", "rangeMaximum", ",", "$", "source", "=", "self", "::", "MODE_OPEN_SSL", ")", "{", "$", "diff", "=", "$", "rangeMaximum", "-", "(", "$", "rangeMinimum", "+", "1", ")", ";", "if", "(", "$", "diff", ">", "PHP_INT_MAX", ")", "{", "throw", "new", "Exception", "(", "'Bad range'", ")", ";", "}", "// The largest *multiple* of diff less than our sample", "$", "ceiling", "=", "floor", "(", "PHP_INT_MAX", "/", "$", "diff", ")", "*", "$", "diff", ";", "do", "{", "switch", "(", "$", "source", ")", "{", "case", "self", "::", "MODE_OPEN_SSL", ":", "default", ":", "$", "bytes", "=", "$", "this", "->", "getRandomBytesFromOpenSSL", "(", "PHP_INT_SIZE", ")", ";", "break", ";", "}", "/* @codeCoverageIgnoreStart */", "// Check for error", "if", "(", "false", "===", "$", "bytes", "||", "PHP_INT_SIZE", "!==", "strlen", "(", "$", "bytes", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Failed to read %s bytes from %s.'", ",", "PHP_INT_SIZE", ",", "'OpenSSL'", ")", ")", ";", "}", "/* @codeCoverageIgnoreEnd */", "if", "(", "PHP_INT_SIZE", "===", "8", ")", "{", "// 64-bit versions", "list", "(", "$", "higher", ",", "$", "lower", ")", "=", "array_values", "(", "unpack", "(", "'N2'", ",", "$", "bytes", ")", ")", ";", "$", "val", "=", "$", "higher", "<<", "32", "|", "$", "lower", ";", "}", "else", "{", "// 32-bit versions", "$", "val", "=", "unpack", "(", "'Nint'", ",", "$", "bytes", ")", ";", "}", "$", "val", "=", "$", "val", "[", "'int'", "]", "&", "PHP_INT_MAX", ";", "}", "while", "(", "$", "val", ">", "$", "ceiling", ")", ";", "// In the unlikely case our sample is bigger than largest multiple, just do over until it’s not any more.", "// Perfectly even sampling in our 0<output<diff domain is mathematically impossible unless the total number of", "// *valid* inputs is an exact multiple of diff.", "return", "$", "val", "%", "$", "diff", "+", "$", "rangeMinimum", ";", "}" ]
"OpenSSL" based equivalent to rand & mt_rand but better randomness. @param int $rangeMinimum The minimum range border for randomizer @param int $rangeMaximum The maximum range border for randomizer @param int $source The source of the random bytes (OpenSSL, ...) @author Benjamin Carl <opensource@clickalicious.de> @return int From *closed* interval [$min, $max] @throws \Clickalicious\Rng\Exception @throws \Clickalicious\Rng\CryptographicWeaknessException
[ "OpenSSL", "based", "equivalent", "to", "rand", "&", "mt_rand", "but", "better", "randomness", "." ]
9ee48ac4c5a9000e5776559715d027228a015bf9
https://github.com/clickalicious/rng/blob/9ee48ac4c5a9000e5776559715d027228a015bf9/src/Generator.php#L282-L334
229,899
clickalicious/rng
src/Generator.php
Generator.getRandomBytesFromOpenSSL
protected function getRandomBytesFromOpenSSL($numberOfBytes) { $randomBytes = openssl_random_pseudo_bytes($numberOfBytes, $cryptographicStrong); $this->setCryptographicStrong($cryptographicStrong); if (false === $randomBytes || '' === $randomBytes || false === $cryptographicStrong) { throw new CryptographicWeaknessException( 'Error fetching random bytes from OpenSSL.' ); } return $randomBytes; }
php
protected function getRandomBytesFromOpenSSL($numberOfBytes) { $randomBytes = openssl_random_pseudo_bytes($numberOfBytes, $cryptographicStrong); $this->setCryptographicStrong($cryptographicStrong); if (false === $randomBytes || '' === $randomBytes || false === $cryptographicStrong) { throw new CryptographicWeaknessException( 'Error fetching random bytes from OpenSSL.' ); } return $randomBytes; }
[ "protected", "function", "getRandomBytesFromOpenSSL", "(", "$", "numberOfBytes", ")", "{", "$", "randomBytes", "=", "openssl_random_pseudo_bytes", "(", "$", "numberOfBytes", ",", "$", "cryptographicStrong", ")", ";", "$", "this", "->", "setCryptographicStrong", "(", "$", "cryptographicStrong", ")", ";", "if", "(", "false", "===", "$", "randomBytes", "||", "''", "===", "$", "randomBytes", "||", "false", "===", "$", "cryptographicStrong", ")", "{", "throw", "new", "CryptographicWeaknessException", "(", "'Error fetching random bytes from OpenSSL.'", ")", ";", "}", "return", "$", "randomBytes", ";", "}" ]
Returns random bytes from OpenSSL. @param int $numberOfBytes Number of bytes to read and return @author Benjamin Carl <opensource@clickalicious.de> @return string The random bytes @throws \Clickalicious\Rng\CryptographicWeaknessException
[ "Returns", "random", "bytes", "from", "OpenSSL", "." ]
9ee48ac4c5a9000e5776559715d027228a015bf9
https://github.com/clickalicious/rng/blob/9ee48ac4c5a9000e5776559715d027228a015bf9/src/Generator.php#L347-L360