repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
laravel/cashier-braintree | src/Invoice.php | Invoice.discountAmount | public function discountAmount()
{
$totalDiscount = 0;
foreach ($this->transaction->discounts as $discount) {
$totalDiscount += $discount->amount;
}
return (float) $totalDiscount;
} | php | public function discountAmount()
{
$totalDiscount = 0;
foreach ($this->transaction->discounts as $discount) {
$totalDiscount += $discount->amount;
}
return (float) $totalDiscount;
} | [
"public",
"function",
"discountAmount",
"(",
")",
"{",
"$",
"totalDiscount",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"transaction",
"->",
"discounts",
"as",
"$",
"discount",
")",
"{",
"$",
"totalDiscount",
"+=",
"$",
"discount",
"->",
"amount",
... | Get the raw discount amount.
@return float | [
"Get",
"the",
"raw",
"discount",
"amount",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Invoice.php#L164-L173 |
laravel/cashier-braintree | src/Invoice.php | Invoice.coupons | public function coupons()
{
$coupons = [];
foreach ($this->transaction->discounts as $discount) {
$coupons[] = $discount->id;
}
return $coupons;
} | php | public function coupons()
{
$coupons = [];
foreach ($this->transaction->discounts as $discount) {
$coupons[] = $discount->id;
}
return $coupons;
} | [
"public",
"function",
"coupons",
"(",
")",
"{",
"$",
"coupons",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"transaction",
"->",
"discounts",
"as",
"$",
"discount",
")",
"{",
"$",
"coupons",
"[",
"]",
"=",
"$",
"discount",
"->",
"id",
";... | Get the coupon codes applied to the invoice.
@return array | [
"Get",
"the",
"coupon",
"codes",
"applied",
"to",
"the",
"invoice",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Invoice.php#L180-L189 |
laravel/cashier-braintree | src/Invoice.php | Invoice.view | public function view(array $data): ViewContract
{
return View::make('cashier::receipt', array_merge(
$data, ['invoice' => $this, 'owner' => $this->owner, 'user' => $this->owner]
));
} | php | public function view(array $data): ViewContract
{
return View::make('cashier::receipt', array_merge(
$data, ['invoice' => $this, 'owner' => $this->owner, 'user' => $this->owner]
));
} | [
"public",
"function",
"view",
"(",
"array",
"$",
"data",
")",
":",
"ViewContract",
"{",
"return",
"View",
"::",
"make",
"(",
"'cashier::receipt'",
",",
"array_merge",
"(",
"$",
"data",
",",
"[",
"'invoice'",
"=>",
"$",
"this",
",",
"'owner'",
"=>",
"$",
... | Get the View instance for the invoice.
@param array $data
@return \Illuminate\Contracts\View\View | [
"Get",
"the",
"View",
"instance",
"for",
"the",
"invoice",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Invoice.php#L218-L223 |
laravel/cashier-braintree | src/Invoice.php | Invoice.pdf | public function pdf(array $data)
{
if (! defined('DOMPDF_ENABLE_AUTOLOAD')) {
define('DOMPDF_ENABLE_AUTOLOAD', false);
}
if (file_exists($configPath = base_path().'/vendor/dompdf/dompdf/dompdf_config.inc.php')) {
require_once $configPath;
}
$dompdf = new Dompdf;
$dompdf->loadHtml($this->view($data)->render());
$dompdf->render();
return $dompdf->output();
} | php | public function pdf(array $data)
{
if (! defined('DOMPDF_ENABLE_AUTOLOAD')) {
define('DOMPDF_ENABLE_AUTOLOAD', false);
}
if (file_exists($configPath = base_path().'/vendor/dompdf/dompdf/dompdf_config.inc.php')) {
require_once $configPath;
}
$dompdf = new Dompdf;
$dompdf->loadHtml($this->view($data)->render());
$dompdf->render();
return $dompdf->output();
} | [
"public",
"function",
"pdf",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'DOMPDF_ENABLE_AUTOLOAD'",
")",
")",
"{",
"define",
"(",
"'DOMPDF_ENABLE_AUTOLOAD'",
",",
"false",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"conf... | Capture the invoice as a PDF and return the raw bytes.
@param array $data
@return string
@throws \Throwable | [
"Capture",
"the",
"invoice",
"as",
"a",
"PDF",
"and",
"return",
"the",
"raw",
"bytes",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Invoice.php#L232-L249 |
laravel/cashier-braintree | src/Invoice.php | Invoice.download | public function download(array $data): Response
{
$filename = $data['product'].'_'.$this->date()->month.'_'.$this->date()->year.'.pdf';
return new Response($this->pdf($data), 200, [
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
]);
} | php | public function download(array $data): Response
{
$filename = $data['product'].'_'.$this->date()->month.'_'.$this->date()->year.'.pdf';
return new Response($this->pdf($data), 200, [
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
]);
} | [
"public",
"function",
"download",
"(",
"array",
"$",
"data",
")",
":",
"Response",
"{",
"$",
"filename",
"=",
"$",
"data",
"[",
"'product'",
"]",
".",
"'_'",
".",
"$",
"this",
"->",
"date",
"(",
")",
"->",
"month",
".",
"'_'",
".",
"$",
"this",
"... | Create an invoice download response.
@param array $data
@return \Symfony\Component\HttpFoundation\Response
@throws \Throwable | [
"Create",
"an",
"invoice",
"download",
"response",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Invoice.php#L258-L268 |
laravel/cashier-braintree | src/BraintreeService.php | BraintreeService.findPlan | public static function findPlan($id): Plan
{
$plans = BraintreePlan::all();
foreach ($plans as $plan) {
if ($plan->id === $id) {
return $plan;
}
}
throw new Exception("Unable to find Braintree plan with ID [{$id}].");
} | php | public static function findPlan($id): Plan
{
$plans = BraintreePlan::all();
foreach ($plans as $plan) {
if ($plan->id === $id) {
return $plan;
}
}
throw new Exception("Unable to find Braintree plan with ID [{$id}].");
} | [
"public",
"static",
"function",
"findPlan",
"(",
"$",
"id",
")",
":",
"Plan",
"{",
"$",
"plans",
"=",
"BraintreePlan",
"::",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"plans",
"as",
"$",
"plan",
")",
"{",
"if",
"(",
"$",
"plan",
"->",
"id",
"===... | Get the Braintree plan that has the given ID.
@param string $id
@return \Braintree\Plan
@throws \Exception | [
"Get",
"the",
"Braintree",
"plan",
"that",
"has",
"the",
"given",
"ID",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/BraintreeService.php#L18-L29 |
laravel/cashier-braintree | src/Http/Controllers/WebhookController.php | WebhookController.handleWebhook | public function handleWebhook(Request $request)
{
try {
$webhook = $this->parseBraintreeNotification($request);
} catch (Exception $e) {
return;
}
$method = 'handle'.Str::studly(str_replace('.', '_', $webhook->kind));
if (method_exists($this, $method)) {
return $this->{$method}($webhook);
}
return $this->missingMethod();
} | php | public function handleWebhook(Request $request)
{
try {
$webhook = $this->parseBraintreeNotification($request);
} catch (Exception $e) {
return;
}
$method = 'handle'.Str::studly(str_replace('.', '_', $webhook->kind));
if (method_exists($this, $method)) {
return $this->{$method}($webhook);
}
return $this->missingMethod();
} | [
"public",
"function",
"handleWebhook",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"webhook",
"=",
"$",
"this",
"->",
"parseBraintreeNotification",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return"... | Handle a Braintree webhook call.
@param \Illuminate\Http\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"Handle",
"a",
"Braintree",
"webhook",
"call",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Http/Controllers/WebhookController.php#L21-L36 |
laravel/cashier-braintree | src/Http/Controllers/WebhookController.php | WebhookController.cancelSubscription | protected function cancelSubscription($subscriptionId)
{
$subscription = $this->getSubscriptionById($subscriptionId);
if ($subscription && (! $subscription->cancelled() || $subscription->onGracePeriod())) {
$subscription->markAsCancelled();
}
return new Response('Webhook Handled', 200);
} | php | protected function cancelSubscription($subscriptionId)
{
$subscription = $this->getSubscriptionById($subscriptionId);
if ($subscription && (! $subscription->cancelled() || $subscription->onGracePeriod())) {
$subscription->markAsCancelled();
}
return new Response('Webhook Handled', 200);
} | [
"protected",
"function",
"cancelSubscription",
"(",
"$",
"subscriptionId",
")",
"{",
"$",
"subscription",
"=",
"$",
"this",
"->",
"getSubscriptionById",
"(",
"$",
"subscriptionId",
")",
";",
"if",
"(",
"$",
"subscription",
"&&",
"(",
"!",
"$",
"subscription",
... | Handle a subscription cancellation notification from Braintree.
@param string $subscriptionId
@return \Symfony\Component\HttpFoundation\Response | [
"Handle",
"a",
"subscription",
"cancellation",
"notification",
"from",
"Braintree",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Http/Controllers/WebhookController.php#L77-L86 |
laravel/cashier-braintree | src/SubscriptionBuilder.php | SubscriptionBuilder.create | public function create($token = null, array $customerOptions = [], array $subscriptionOptions = []): Subscription
{
$payload = $this->getSubscriptionPayload(
$this->getBraintreeCustomer($token, $customerOptions), $subscriptionOptions
);
if ($this->coupon) {
$payload = $this->addCouponToPayload($payload);
}
$response = BraintreeSubscription::create($payload);
if (! $response->success) {
throw new Exception('Braintree failed to create subscription: '.$response->message);
}
if ($this->skipTrial) {
$trialEndsAt = null;
} else {
$trialEndsAt = $this->trialDays ? Carbon::now()->addDays($this->trialDays) : null;
}
return $this->owner->subscriptions()->create([
'name' => $this->name,
'braintree_id' => $response->subscription->id,
'braintree_plan' => $this->plan,
'quantity' => 1,
'trial_ends_at' => $trialEndsAt,
'ends_at' => null,
]);
} | php | public function create($token = null, array $customerOptions = [], array $subscriptionOptions = []): Subscription
{
$payload = $this->getSubscriptionPayload(
$this->getBraintreeCustomer($token, $customerOptions), $subscriptionOptions
);
if ($this->coupon) {
$payload = $this->addCouponToPayload($payload);
}
$response = BraintreeSubscription::create($payload);
if (! $response->success) {
throw new Exception('Braintree failed to create subscription: '.$response->message);
}
if ($this->skipTrial) {
$trialEndsAt = null;
} else {
$trialEndsAt = $this->trialDays ? Carbon::now()->addDays($this->trialDays) : null;
}
return $this->owner->subscriptions()->create([
'name' => $this->name,
'braintree_id' => $response->subscription->id,
'braintree_plan' => $this->plan,
'quantity' => 1,
'trial_ends_at' => $trialEndsAt,
'ends_at' => null,
]);
} | [
"public",
"function",
"create",
"(",
"$",
"token",
"=",
"null",
",",
"array",
"$",
"customerOptions",
"=",
"[",
"]",
",",
"array",
"$",
"subscriptionOptions",
"=",
"[",
"]",
")",
":",
"Subscription",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"getSub... | Create a new Braintree subscription.
@param string|null $token
@param array $customerOptions
@param array $subscriptionOptions
@return \Laravel\Cashier\Subscription
@throws \Exception | [
"Create",
"a",
"new",
"Braintree",
"subscription",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/SubscriptionBuilder.php#L128-L158 |
laravel/cashier-braintree | src/SubscriptionBuilder.php | SubscriptionBuilder.getSubscriptionPayload | protected function getSubscriptionPayload($customer, array $options = [])
{
$plan = BraintreeService::findPlan($this->plan);
if ($this->skipTrial) {
$trialDuration = 0;
} else {
$trialDuration = $this->trialDays ?: 0;
}
return array_merge([
'planId' => $this->plan,
'price' => number_format($plan->price * (1 + ($this->owner->taxPercentage() / 100)), 2, '.', ''),
'paymentMethodToken' => $this->owner->paymentMethod()->token,
'trialPeriod' => $this->trialDays && ! $this->skipTrial ? true : false,
'trialDurationUnit' => 'day',
'trialDuration' => $trialDuration,
], $options);
} | php | protected function getSubscriptionPayload($customer, array $options = [])
{
$plan = BraintreeService::findPlan($this->plan);
if ($this->skipTrial) {
$trialDuration = 0;
} else {
$trialDuration = $this->trialDays ?: 0;
}
return array_merge([
'planId' => $this->plan,
'price' => number_format($plan->price * (1 + ($this->owner->taxPercentage() / 100)), 2, '.', ''),
'paymentMethodToken' => $this->owner->paymentMethod()->token,
'trialPeriod' => $this->trialDays && ! $this->skipTrial ? true : false,
'trialDurationUnit' => 'day',
'trialDuration' => $trialDuration,
], $options);
} | [
"protected",
"function",
"getSubscriptionPayload",
"(",
"$",
"customer",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"plan",
"=",
"BraintreeService",
"::",
"findPlan",
"(",
"$",
"this",
"->",
"plan",
")",
";",
"if",
"(",
"$",
"this",
"-... | Get the base subscription payload for Braintree.
@param \Braintree\Customer $customer
@param array $options
@return array
@throws \Exception | [
"Get",
"the",
"base",
"subscription",
"payload",
"for",
"Braintree",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/SubscriptionBuilder.php#L168-L186 |
laravel/cashier-braintree | src/SubscriptionBuilder.php | SubscriptionBuilder.getBraintreeCustomer | protected function getBraintreeCustomer($token = null, array $options = []): Customer
{
if (! $this->owner->braintree_id) {
$customer = $this->owner->createAsBraintreeCustomer($token, $options);
} else {
$customer = $this->owner->asBraintreeCustomer();
if ($token) {
$this->owner->updateCard($token);
}
}
return $customer;
} | php | protected function getBraintreeCustomer($token = null, array $options = []): Customer
{
if (! $this->owner->braintree_id) {
$customer = $this->owner->createAsBraintreeCustomer($token, $options);
} else {
$customer = $this->owner->asBraintreeCustomer();
if ($token) {
$this->owner->updateCard($token);
}
}
return $customer;
} | [
"protected",
"function",
"getBraintreeCustomer",
"(",
"$",
"token",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"Customer",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"owner",
"->",
"braintree_id",
")",
"{",
"$",
"customer",
"=",
... | Get the Braintree customer instance for the current user and token.
@param string|null $token
@param array $options
@return \Braintree\Customer | [
"Get",
"the",
"Braintree",
"customer",
"instance",
"for",
"the",
"current",
"user",
"and",
"token",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/SubscriptionBuilder.php#L214-L227 |
laravel/cashier-braintree | src/Subscription.php | Subscription.owner | public function owner()
{
$model = getenv('BRAINTREE_MODEL') ?: config('services.braintree.model', 'App\\User');
$model = new $model;
return $this->belongsTo(get_class($model), $model->getForeignKey());
} | php | public function owner()
{
$model = getenv('BRAINTREE_MODEL') ?: config('services.braintree.model', 'App\\User');
$model = new $model;
return $this->belongsTo(get_class($model), $model->getForeignKey());
} | [
"public",
"function",
"owner",
"(",
")",
"{",
"$",
"model",
"=",
"getenv",
"(",
"'BRAINTREE_MODEL'",
")",
"?",
":",
"config",
"(",
"'services.braintree.model'",
",",
"'App\\\\User'",
")",
";",
"$",
"model",
"=",
"new",
"$",
"model",
";",
"return",
"$",
"... | Get the model related to the subscription. | [
"Get",
"the",
"model",
"related",
"to",
"the",
"subscription",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L50-L57 |
laravel/cashier-braintree | src/Subscription.php | Subscription.onTrial | public function onTrial()
{
if (! is_null($this->trial_ends_at)) {
return Carbon::today()->lt($this->trial_ends_at);
}
return false;
} | php | public function onTrial()
{
if (! is_null($this->trial_ends_at)) {
return Carbon::today()->lt($this->trial_ends_at);
}
return false;
} | [
"public",
"function",
"onTrial",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"trial_ends_at",
")",
")",
"{",
"return",
"Carbon",
"::",
"today",
"(",
")",
"->",
"lt",
"(",
"$",
"this",
"->",
"trial_ends_at",
")",
";",
"}",
"ret... | Determine if the subscription is within its trial period.
@return bool | [
"Determine",
"if",
"the",
"subscription",
"is",
"within",
"its",
"trial",
"period",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L94-L101 |
laravel/cashier-braintree | src/Subscription.php | Subscription.updateQuantity | public function updateQuantity($quantity)
{
$quantity = max(0, $quantity - 1);
$addonName = $this->braintree_plan.'-quantity';
$options = ['remove' => [$addonName]];
if ($quantity > 0) {
$options = $this->quantity > 1
? ['update' => [['existingId' => $addonName, 'quantity' => $quantity]]]
: ['add' => [['inheritedFromId' => $addonName, 'quantity' => $quantity]]];
}
BraintreeSubscription::update($this->braintree_id, ['addOns' => $options]);
$this->quantity = $quantity + 1;
$this->save();
return $this;
} | php | public function updateQuantity($quantity)
{
$quantity = max(0, $quantity - 1);
$addonName = $this->braintree_plan.'-quantity';
$options = ['remove' => [$addonName]];
if ($quantity > 0) {
$options = $this->quantity > 1
? ['update' => [['existingId' => $addonName, 'quantity' => $quantity]]]
: ['add' => [['inheritedFromId' => $addonName, 'quantity' => $quantity]]];
}
BraintreeSubscription::update($this->braintree_id, ['addOns' => $options]);
$this->quantity = $quantity + 1;
$this->save();
return $this;
} | [
"public",
"function",
"updateQuantity",
"(",
"$",
"quantity",
")",
"{",
"$",
"quantity",
"=",
"max",
"(",
"0",
",",
"$",
"quantity",
"-",
"1",
")",
";",
"$",
"addonName",
"=",
"$",
"this",
"->",
"braintree_plan",
".",
"'-quantity'",
";",
"$",
"options"... | Update the quantity of the subscription.
@param int $quantity
@return $this | [
"Update",
"the",
"quantity",
"of",
"the",
"subscription",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L149-L170 |
laravel/cashier-braintree | src/Subscription.php | Subscription.swap | public function swap($plan)
{
if ($this->onGracePeriod() && $this->braintree_plan === $plan) {
return $this->resume();
}
if (! $this->active()) {
return $this->owner->newSubscription($this->name, $plan)
->skipTrial()->create();
}
$plan = BraintreeService::findPlan($plan);
if ($this->wouldChangeBillingFrequency($plan) && $this->prorate) {
return $this->swapAcrossFrequencies($plan);
}
$subscription = $this->asBraintreeSubscription();
$response = BraintreeSubscription::update($subscription->id, [
'planId' => $plan->id,
'price' => number_format($plan->price * (1 + ($this->owner->taxPercentage() / 100)), 2, '.', ''),
'neverExpires' => true,
'numberOfBillingCycles' => null,
'options' => [
'prorateCharges' => $this->prorate,
],
]);
if ($response->success) {
$this->fill([
'braintree_plan' => $plan->id,
'ends_at' => null,
])->save();
} else {
throw new Exception('Braintree failed to swap plans: '.$response->message);
}
return $this;
} | php | public function swap($plan)
{
if ($this->onGracePeriod() && $this->braintree_plan === $plan) {
return $this->resume();
}
if (! $this->active()) {
return $this->owner->newSubscription($this->name, $plan)
->skipTrial()->create();
}
$plan = BraintreeService::findPlan($plan);
if ($this->wouldChangeBillingFrequency($plan) && $this->prorate) {
return $this->swapAcrossFrequencies($plan);
}
$subscription = $this->asBraintreeSubscription();
$response = BraintreeSubscription::update($subscription->id, [
'planId' => $plan->id,
'price' => number_format($plan->price * (1 + ($this->owner->taxPercentage() / 100)), 2, '.', ''),
'neverExpires' => true,
'numberOfBillingCycles' => null,
'options' => [
'prorateCharges' => $this->prorate,
],
]);
if ($response->success) {
$this->fill([
'braintree_plan' => $plan->id,
'ends_at' => null,
])->save();
} else {
throw new Exception('Braintree failed to swap plans: '.$response->message);
}
return $this;
} | [
"public",
"function",
"swap",
"(",
"$",
"plan",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"onGracePeriod",
"(",
")",
"&&",
"$",
"this",
"->",
"braintree_plan",
"===",
"$",
"plan",
")",
"{",
"return",
"$",
"this",
"->",
"resume",
"(",
")",
";",
"}",
... | Swap the subscription to a new Braintree plan.
@param string $plan
@return $this|\Laravel\Cashier\Subscription
@throws \Exception | [
"Swap",
"the",
"subscription",
"to",
"a",
"new",
"Braintree",
"plan",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L179-L218 |
laravel/cashier-braintree | src/Subscription.php | Subscription.swapAcrossFrequencies | protected function swapAcrossFrequencies($plan): self
{
$currentPlan = BraintreeService::findPlan($this->braintree_plan);
$discount = $this->switchingToMonthlyPlan($currentPlan, $plan)
? $this->getDiscountForSwitchToMonthly($currentPlan, $plan)
: $this->getDiscountForSwitchToYearly();
$options = [];
if ($discount->amount > 0 && $discount->numberOfBillingCycles > 0) {
$options = ['discounts' => ['add' => [
[
'inheritedFromId' => 'plan-credit',
'amount' => (float) $discount->amount,
'numberOfBillingCycles' => $discount->numberOfBillingCycles,
],
]]];
}
$this->cancelNow();
return $this->owner->newSubscription($this->name, $plan->id)
->skipTrial()
->create(null, [], $options);
} | php | protected function swapAcrossFrequencies($plan): self
{
$currentPlan = BraintreeService::findPlan($this->braintree_plan);
$discount = $this->switchingToMonthlyPlan($currentPlan, $plan)
? $this->getDiscountForSwitchToMonthly($currentPlan, $plan)
: $this->getDiscountForSwitchToYearly();
$options = [];
if ($discount->amount > 0 && $discount->numberOfBillingCycles > 0) {
$options = ['discounts' => ['add' => [
[
'inheritedFromId' => 'plan-credit',
'amount' => (float) $discount->amount,
'numberOfBillingCycles' => $discount->numberOfBillingCycles,
],
]]];
}
$this->cancelNow();
return $this->owner->newSubscription($this->name, $plan->id)
->skipTrial()
->create(null, [], $options);
} | [
"protected",
"function",
"swapAcrossFrequencies",
"(",
"$",
"plan",
")",
":",
"self",
"{",
"$",
"currentPlan",
"=",
"BraintreeService",
"::",
"findPlan",
"(",
"$",
"this",
"->",
"braintree_plan",
")",
";",
"$",
"discount",
"=",
"$",
"this",
"->",
"switchingT... | Swap the subscription to a new Braintree plan with a different frequency.
@param \Braintree\Plan $plan
@return \Laravel\Cashier\Subscription
@throws \Exception | [
"Swap",
"the",
"subscription",
"to",
"a",
"new",
"Braintree",
"plan",
"with",
"a",
"different",
"frequency",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L239-L264 |
laravel/cashier-braintree | src/Subscription.php | Subscription.getDiscountForSwitchToMonthly | protected function getDiscountForSwitchToMonthly(Plan $currentPlan, Plan $plan)
{
return (object) [
'amount' => $plan->price,
'numberOfBillingCycles' => floor(
$this->moneyRemainingOnYearlyPlan($currentPlan) / $plan->price
),
];
} | php | protected function getDiscountForSwitchToMonthly(Plan $currentPlan, Plan $plan)
{
return (object) [
'amount' => $plan->price,
'numberOfBillingCycles' => floor(
$this->moneyRemainingOnYearlyPlan($currentPlan) / $plan->price
),
];
} | [
"protected",
"function",
"getDiscountForSwitchToMonthly",
"(",
"Plan",
"$",
"currentPlan",
",",
"Plan",
"$",
"plan",
")",
"{",
"return",
"(",
"object",
")",
"[",
"'amount'",
"=>",
"$",
"plan",
"->",
"price",
",",
"'numberOfBillingCycles'",
"=>",
"floor",
"(",
... | Get the discount to apply when switching to a monthly plan.
@param \Braintree\Plan $currentPlan
@param \Braintree\Plan $plan
@return object | [
"Get",
"the",
"discount",
"to",
"apply",
"when",
"switching",
"to",
"a",
"monthly",
"plan",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L285-L293 |
laravel/cashier-braintree | src/Subscription.php | Subscription.moneyRemainingOnYearlyPlan | protected function moneyRemainingOnYearlyPlan(Plan $plan)
{
return ($plan->price / 365) * Carbon::today()->diffInDays(Carbon::instance(
$this->asBraintreeSubscription()->billingPeriodEndDate
), false);
} | php | protected function moneyRemainingOnYearlyPlan(Plan $plan)
{
return ($plan->price / 365) * Carbon::today()->diffInDays(Carbon::instance(
$this->asBraintreeSubscription()->billingPeriodEndDate
), false);
} | [
"protected",
"function",
"moneyRemainingOnYearlyPlan",
"(",
"Plan",
"$",
"plan",
")",
"{",
"return",
"(",
"$",
"plan",
"->",
"price",
"/",
"365",
")",
"*",
"Carbon",
"::",
"today",
"(",
")",
"->",
"diffInDays",
"(",
"Carbon",
"::",
"instance",
"(",
"$",
... | Calculate the amount of discount to apply to a swap to monthly billing.
@param \Braintree\Plan $plan
@return float | [
"Calculate",
"the",
"amount",
"of",
"discount",
"to",
"apply",
"to",
"a",
"swap",
"to",
"monthly",
"billing",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L301-L306 |
laravel/cashier-braintree | src/Subscription.php | Subscription.getDiscountForSwitchToYearly | protected function getDiscountForSwitchToYearly()
{
$amount = 0;
foreach ($this->asBraintreeSubscription()->discounts as $discount) {
if ($discount->id == 'plan-credit') {
$amount += (float) $discount->amount * $discount->numberOfBillingCycles;
}
}
return (object) [
'amount' => $amount,
'numberOfBillingCycles' => 1,
];
} | php | protected function getDiscountForSwitchToYearly()
{
$amount = 0;
foreach ($this->asBraintreeSubscription()->discounts as $discount) {
if ($discount->id == 'plan-credit') {
$amount += (float) $discount->amount * $discount->numberOfBillingCycles;
}
}
return (object) [
'amount' => $amount,
'numberOfBillingCycles' => 1,
];
} | [
"protected",
"function",
"getDiscountForSwitchToYearly",
"(",
")",
"{",
"$",
"amount",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"asBraintreeSubscription",
"(",
")",
"->",
"discounts",
"as",
"$",
"discount",
")",
"{",
"if",
"(",
"$",
"discount",
"-... | Get the discount to apply when switching to a yearly plan.
@return object | [
"Get",
"the",
"discount",
"to",
"apply",
"when",
"switching",
"to",
"a",
"yearly",
"plan",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L313-L327 |
laravel/cashier-braintree | src/Subscription.php | Subscription.applyCoupon | public function applyCoupon($coupon, $removeOthers = false)
{
if (! $this->active()) {
throw new InvalidArgumentException('Unable to apply coupon. Subscription not active.');
}
BraintreeSubscription::update($this->braintree_id, [
'discounts' => [
'add' => [[
'inheritedFromId' => $coupon,
]],
'remove' => $removeOthers ? $this->currentDiscounts() : [],
],
]);
} | php | public function applyCoupon($coupon, $removeOthers = false)
{
if (! $this->active()) {
throw new InvalidArgumentException('Unable to apply coupon. Subscription not active.');
}
BraintreeSubscription::update($this->braintree_id, [
'discounts' => [
'add' => [[
'inheritedFromId' => $coupon,
]],
'remove' => $removeOthers ? $this->currentDiscounts() : [],
],
]);
} | [
"public",
"function",
"applyCoupon",
"(",
"$",
"coupon",
",",
"$",
"removeOthers",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"active",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Unable to apply coupon. Subscription ... | Apply a coupon to the subscription.
@param string $coupon
@param bool $removeOthers
@return void | [
"Apply",
"a",
"coupon",
"to",
"the",
"subscription",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L336-L350 |
laravel/cashier-braintree | src/Subscription.php | Subscription.currentDiscounts | protected function currentDiscounts()
{
return collect($this->asBraintreeSubscription()->discounts)->map(function ($discount) {
return $discount->id;
})->all();
} | php | protected function currentDiscounts()
{
return collect($this->asBraintreeSubscription()->discounts)->map(function ($discount) {
return $discount->id;
})->all();
} | [
"protected",
"function",
"currentDiscounts",
"(",
")",
"{",
"return",
"collect",
"(",
"$",
"this",
"->",
"asBraintreeSubscription",
"(",
")",
"->",
"discounts",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"discount",
")",
"{",
"return",
"$",
"discount",
"... | Get the current discounts for the subscription.
@return array | [
"Get",
"the",
"current",
"discounts",
"for",
"the",
"subscription",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L357-L362 |
laravel/cashier-braintree | src/Subscription.php | Subscription.cancel | public function cancel()
{
$subscription = $this->asBraintreeSubscription();
if ($this->onTrial()) {
BraintreeSubscription::cancel($subscription->id);
$this->markAsCancelled();
} else {
BraintreeSubscription::update($subscription->id, [
'numberOfBillingCycles' => $subscription->currentBillingCycle,
]);
$this->ends_at = $subscription->billingPeriodEndDate;
$this->save();
}
return $this;
} | php | public function cancel()
{
$subscription = $this->asBraintreeSubscription();
if ($this->onTrial()) {
BraintreeSubscription::cancel($subscription->id);
$this->markAsCancelled();
} else {
BraintreeSubscription::update($subscription->id, [
'numberOfBillingCycles' => $subscription->currentBillingCycle,
]);
$this->ends_at = $subscription->billingPeriodEndDate;
$this->save();
}
return $this;
} | [
"public",
"function",
"cancel",
"(",
")",
"{",
"$",
"subscription",
"=",
"$",
"this",
"->",
"asBraintreeSubscription",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"onTrial",
"(",
")",
")",
"{",
"BraintreeSubscription",
"::",
"cancel",
"(",
"$",
"subscri... | Cancel the subscription.
@return $this | [
"Cancel",
"the",
"subscription",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L369-L388 |
laravel/cashier-braintree | src/Subscription.php | Subscription.cancelNow | public function cancelNow()
{
$subscription = $this->asBraintreeSubscription();
BraintreeSubscription::cancel($subscription->id);
$this->markAsCancelled();
return $this;
} | php | public function cancelNow()
{
$subscription = $this->asBraintreeSubscription();
BraintreeSubscription::cancel($subscription->id);
$this->markAsCancelled();
return $this;
} | [
"public",
"function",
"cancelNow",
"(",
")",
"{",
"$",
"subscription",
"=",
"$",
"this",
"->",
"asBraintreeSubscription",
"(",
")",
";",
"BraintreeSubscription",
"::",
"cancel",
"(",
"$",
"subscription",
"->",
"id",
")",
";",
"$",
"this",
"->",
"markAsCancel... | Cancel the subscription immediately.
@return $this | [
"Cancel",
"the",
"subscription",
"immediately",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L395-L404 |
laravel/cashier-braintree | src/Subscription.php | Subscription.resume | public function resume()
{
if (! $this->onGracePeriod()) {
throw new LogicException('Unable to resume subscription that is not within grace period.');
}
$subscription = $this->asBraintreeSubscription();
BraintreeSubscription::update($subscription->id, [
'neverExpires' => true,
'numberOfBillingCycles' => null,
]);
$this->fill(['ends_at' => null])->save();
return $this;
} | php | public function resume()
{
if (! $this->onGracePeriod()) {
throw new LogicException('Unable to resume subscription that is not within grace period.');
}
$subscription = $this->asBraintreeSubscription();
BraintreeSubscription::update($subscription->id, [
'neverExpires' => true,
'numberOfBillingCycles' => null,
]);
$this->fill(['ends_at' => null])->save();
return $this;
} | [
"public",
"function",
"resume",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"onGracePeriod",
"(",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Unable to resume subscription that is not within grace period.'",
")",
";",
"}",
"$",
"subscription",
... | Resume the cancelled subscription.
@return $this
@throws \LogicException | [
"Resume",
"the",
"cancelled",
"subscription",
"."
] | train | https://github.com/laravel/cashier-braintree/blob/6d315e2715710ad226c9f9433b15bf9a83a53d8c/src/Subscription.php#L422-L438 |
geocoder-php/php-common | Dumper/AbstractDumper.php | AbstractDumper.formatName | protected function formatName(Location $address): string
{
$name = [];
$array = $address->toArray();
foreach (['streetNumber', 'streetName', 'postalCode', 'locality'] as $attr) {
$name[] = $array[$attr];
}
if (isset($array['adminLevels'][2])) {
$name[] = $array['adminLevels'][2]['name'];
}
if (isset($array['adminLevels'][1])) {
$name[] = $array['adminLevels'][1]['name'];
}
$name[] = $array['country'];
return implode(', ', array_filter($name));
} | php | protected function formatName(Location $address): string
{
$name = [];
$array = $address->toArray();
foreach (['streetNumber', 'streetName', 'postalCode', 'locality'] as $attr) {
$name[] = $array[$attr];
}
if (isset($array['adminLevels'][2])) {
$name[] = $array['adminLevels'][2]['name'];
}
if (isset($array['adminLevels'][1])) {
$name[] = $array['adminLevels'][1]['name'];
}
$name[] = $array['country'];
return implode(', ', array_filter($name));
} | [
"protected",
"function",
"formatName",
"(",
"Location",
"$",
"address",
")",
":",
"string",
"{",
"$",
"name",
"=",
"[",
"]",
";",
"$",
"array",
"=",
"$",
"address",
"->",
"toArray",
"(",
")",
";",
"foreach",
"(",
"[",
"'streetNumber'",
",",
"'streetNam... | @param Location $address
@return string | [
"@param",
"Location",
"$address"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Dumper/AbstractDumper.php#L24-L44 |
geocoder-php/php-common | Dumper/Gpx.php | Gpx.dump | public function dump(Location $location): string
{
$gpx = sprintf(<<<'GPX'
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx
version="1.0"
creator="Geocoder" version="%s"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
GPX
, Geocoder::VERSION);
if (null !== $bounds = $location->getBounds()) {
$gpx .= sprintf(<<<'GPX'
<bounds minlat="%f" minlon="%f" maxlat="%f" maxlon="%f"/>
GPX
, $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
}
$lat = null;
$lon = null;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
$gpx .= sprintf(<<<'GPX'
<wpt lat="%.7f" lon="%.7f">
<name><![CDATA[%s]]></name>
<type><![CDATA[Address]]></type>
</wpt>
GPX
, $lat, $lon, $this->formatName($location));
$gpx .= <<<'GPX'
</gpx>
GPX;
return $gpx;
} | php | public function dump(Location $location): string
{
$gpx = sprintf(<<<'GPX'
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx
version="1.0"
creator="Geocoder" version="%s"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
GPX
, Geocoder::VERSION);
if (null !== $bounds = $location->getBounds()) {
$gpx .= sprintf(<<<'GPX'
<bounds minlat="%f" minlon="%f" maxlat="%f" maxlon="%f"/>
GPX
, $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
}
$lat = null;
$lon = null;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
$gpx .= sprintf(<<<'GPX'
<wpt lat="%.7f" lon="%.7f">
<name><![CDATA[%s]]></name>
<type><![CDATA[Address]]></type>
</wpt>
GPX
, $lat, $lon, $this->formatName($location));
$gpx .= <<<'GPX'
</gpx>
GPX;
return $gpx;
} | [
"public",
"function",
"dump",
"(",
"Location",
"$",
"location",
")",
":",
"string",
"{",
"$",
"gpx",
"=",
"sprintf",
"(",
"<<<'GPX'\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n<gpx\nversion=\"1.0\"\n creator=\"Geocoder\" version=\"%s\"\n xmlns:xsi=\"http://w... | @param Location $location
@return string | [
"@param",
"Location",
"$location"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Dumper/Gpx.php#L28-L71 |
geocoder-php/php-common | Model/Address.php | Address.createFromArray | public static function createFromArray(array $data)
{
$defaults = [
'providedBy' => 'n/a',
'latitude' => null,
'longitude' => null,
'bounds' => [
'south' => null,
'west' => null,
'north' => null,
'east' => null,
],
'streetNumber' => null,
'streetName' => null,
'locality' => null,
'postalCode' => null,
'subLocality' => null,
'adminLevels' => [],
'country' => null,
'countryCode' => null,
'timezone' => null,
];
$data = array_merge($defaults, $data);
$adminLevels = [];
foreach ($data['adminLevels'] as $adminLevel) {
if (empty($adminLevel['level'])) {
continue;
}
$name = $adminLevel['name'] ?? $adminLevel['code'] ?? null;
if (empty($name)) {
continue;
}
$adminLevels[] = new AdminLevel($adminLevel['level'], $name, $adminLevel['code'] ?? null);
}
return new static(
$data['providedBy'],
new AdminLevelCollection($adminLevels),
self::createCoordinates(
$data['latitude'],
$data['longitude']
),
self::createBounds(
$data['bounds']['south'],
$data['bounds']['west'],
$data['bounds']['north'],
$data['bounds']['east']
),
$data['streetNumber'],
$data['streetName'],
$data['postalCode'],
$data['locality'],
$data['subLocality'],
self::createCountry($data['country'], $data['countryCode']),
$data['timezone']
);
} | php | public static function createFromArray(array $data)
{
$defaults = [
'providedBy' => 'n/a',
'latitude' => null,
'longitude' => null,
'bounds' => [
'south' => null,
'west' => null,
'north' => null,
'east' => null,
],
'streetNumber' => null,
'streetName' => null,
'locality' => null,
'postalCode' => null,
'subLocality' => null,
'adminLevels' => [],
'country' => null,
'countryCode' => null,
'timezone' => null,
];
$data = array_merge($defaults, $data);
$adminLevels = [];
foreach ($data['adminLevels'] as $adminLevel) {
if (empty($adminLevel['level'])) {
continue;
}
$name = $adminLevel['name'] ?? $adminLevel['code'] ?? null;
if (empty($name)) {
continue;
}
$adminLevels[] = new AdminLevel($adminLevel['level'], $name, $adminLevel['code'] ?? null);
}
return new static(
$data['providedBy'],
new AdminLevelCollection($adminLevels),
self::createCoordinates(
$data['latitude'],
$data['longitude']
),
self::createBounds(
$data['bounds']['south'],
$data['bounds']['west'],
$data['bounds']['north'],
$data['bounds']['east']
),
$data['streetNumber'],
$data['streetName'],
$data['postalCode'],
$data['locality'],
$data['subLocality'],
self::createCountry($data['country'], $data['countryCode']),
$data['timezone']
);
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"defaults",
"=",
"[",
"'providedBy'",
"=>",
"'n/a'",
",",
"'latitude'",
"=>",
"null",
",",
"'longitude'",
"=>",
"null",
",",
"'bounds'",
"=>",
"[",
"'south'",
"=>"... | Create an Address with an array. Useful for testing.
@param array $data
@return static | [
"Create",
"an",
"Address",
"with",
"an",
"array",
".",
"Useful",
"for",
"testing",
"."
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/Address.php#L211-L271 |
geocoder-php/php-common | Model/Address.php | Address.createCoordinates | private static function createCoordinates($latitude, $longitude)
{
if (null === $latitude || null === $longitude) {
return null;
}
return new Coordinates($latitude, $longitude);
} | php | private static function createCoordinates($latitude, $longitude)
{
if (null === $latitude || null === $longitude) {
return null;
}
return new Coordinates($latitude, $longitude);
} | [
"private",
"static",
"function",
"createCoordinates",
"(",
"$",
"latitude",
",",
"$",
"longitude",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"latitude",
"||",
"null",
"===",
"$",
"longitude",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"Coordin... | @param float $latitude
@param float $longitude
@return Coordinates|null | [
"@param",
"float",
"$latitude",
"@param",
"float",
"$longitude"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/Address.php#L279-L286 |
geocoder-php/php-common | Model/Address.php | Address.createCountry | private static function createCountry($name, $code)
{
if (null === $name && null === $code) {
return null;
}
return new Country($name, $code);
} | php | private static function createCountry($name, $code)
{
if (null === $name && null === $code) {
return null;
}
return new Country($name, $code);
} | [
"private",
"static",
"function",
"createCountry",
"(",
"$",
"name",
",",
"$",
"code",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"name",
"&&",
"null",
"===",
"$",
"code",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"Country",
"(",
"$",
"na... | @param string|null $name
@param string|null $code
@return Country|null | [
"@param",
"string|null",
"$name",
"@param",
"string|null",
"$code"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/Address.php#L294-L301 |
geocoder-php/php-common | Model/Address.php | Address.createBounds | private static function createBounds($south, $west, $north, $east)
{
if (null === $south || null === $west || null === $north || null === $east) {
return null;
}
return new Bounds($south, $west, $north, $east);
} | php | private static function createBounds($south, $west, $north, $east)
{
if (null === $south || null === $west || null === $north || null === $east) {
return null;
}
return new Bounds($south, $west, $north, $east);
} | [
"private",
"static",
"function",
"createBounds",
"(",
"$",
"south",
",",
"$",
"west",
",",
"$",
"north",
",",
"$",
"east",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"south",
"||",
"null",
"===",
"$",
"west",
"||",
"null",
"===",
"$",
"north",
"||",
... | @param float $south
@param float $west
@param float $north
@return Bounds|null | [
"@param",
"float",
"$south",
"@param",
"float",
"$west",
"@param",
"float",
"$north"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/Address.php#L310-L317 |
geocoder-php/php-common | Model/Address.php | Address.toArray | public function toArray(): array
{
$adminLevels = [];
foreach ($this->adminLevels as $adminLevel) {
$adminLevels[$adminLevel->getLevel()] = [
'name' => $adminLevel->getName(),
'code' => $adminLevel->getCode(),
'level' => $adminLevel->getLevel(),
];
}
$lat = null;
$lon = null;
if (null !== $coordinates = $this->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
$countryName = null;
$countryCode = null;
if (null !== $country = $this->getCountry()) {
$countryName = $country->getName();
$countryCode = $country->getCode();
}
$noBounds = [
'south' => null,
'west' => null,
'north' => null,
'east' => null,
];
return [
'providedBy' => $this->providedBy,
'latitude' => $lat,
'longitude' => $lon,
'bounds' => null !== $this->bounds ? $this->bounds->toArray() : $noBounds,
'streetNumber' => $this->streetNumber,
'streetName' => $this->streetName,
'postalCode' => $this->postalCode,
'locality' => $this->locality,
'subLocality' => $this->subLocality,
'adminLevels' => $adminLevels,
'country' => $countryName,
'countryCode' => $countryCode,
'timezone' => $this->timezone,
];
} | php | public function toArray(): array
{
$adminLevels = [];
foreach ($this->adminLevels as $adminLevel) {
$adminLevels[$adminLevel->getLevel()] = [
'name' => $adminLevel->getName(),
'code' => $adminLevel->getCode(),
'level' => $adminLevel->getLevel(),
];
}
$lat = null;
$lon = null;
if (null !== $coordinates = $this->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
$countryName = null;
$countryCode = null;
if (null !== $country = $this->getCountry()) {
$countryName = $country->getName();
$countryCode = $country->getCode();
}
$noBounds = [
'south' => null,
'west' => null,
'north' => null,
'east' => null,
];
return [
'providedBy' => $this->providedBy,
'latitude' => $lat,
'longitude' => $lon,
'bounds' => null !== $this->bounds ? $this->bounds->toArray() : $noBounds,
'streetNumber' => $this->streetNumber,
'streetName' => $this->streetName,
'postalCode' => $this->postalCode,
'locality' => $this->locality,
'subLocality' => $this->subLocality,
'adminLevels' => $adminLevels,
'country' => $countryName,
'countryCode' => $countryCode,
'timezone' => $this->timezone,
];
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"$",
"adminLevels",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"adminLevels",
"as",
"$",
"adminLevel",
")",
"{",
"$",
"adminLevels",
"[",
"$",
"adminLevel",
"->",
"getLevel",
"("... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/Address.php#L322-L369 |
geocoder-php/php-common | ProviderAggregator.php | ProviderAggregator.geocodeQuery | public function geocodeQuery(GeocodeQuery $query): Collection
{
if (null === $query->getLimit()) {
$query = $query->withLimit($this->limit);
}
return call_user_func($this->decider, $query, $this->providers, $this->provider)->geocodeQuery($query);
} | php | public function geocodeQuery(GeocodeQuery $query): Collection
{
if (null === $query->getLimit()) {
$query = $query->withLimit($this->limit);
}
return call_user_func($this->decider, $query, $this->providers, $this->provider)->geocodeQuery($query);
} | [
"public",
"function",
"geocodeQuery",
"(",
"GeocodeQuery",
"$",
"query",
")",
":",
"Collection",
"{",
"if",
"(",
"null",
"===",
"$",
"query",
"->",
"getLimit",
"(",
")",
")",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"withLimit",
"(",
"$",
"this",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/ProviderAggregator.php#L61-L68 |
geocoder-php/php-common | ProviderAggregator.php | ProviderAggregator.reverseQuery | public function reverseQuery(ReverseQuery $query): Collection
{
if (null === $query->getLimit()) {
$query = $query->withLimit($this->limit);
}
return call_user_func($this->decider, $query, $this->providers, $this->provider)->reverseQuery($query);
} | php | public function reverseQuery(ReverseQuery $query): Collection
{
if (null === $query->getLimit()) {
$query = $query->withLimit($this->limit);
}
return call_user_func($this->decider, $query, $this->providers, $this->provider)->reverseQuery($query);
} | [
"public",
"function",
"reverseQuery",
"(",
"ReverseQuery",
"$",
"query",
")",
":",
"Collection",
"{",
"if",
"(",
"null",
"===",
"$",
"query",
"->",
"getLimit",
"(",
")",
")",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"withLimit",
"(",
"$",
"this",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/ProviderAggregator.php#L73-L80 |
geocoder-php/php-common | ProviderAggregator.php | ProviderAggregator.geocode | public function geocode(string $value): Collection
{
return $this->geocodeQuery(GeocodeQuery::create($value)
->withLimit($this->limit));
} | php | public function geocode(string $value): Collection
{
return $this->geocodeQuery(GeocodeQuery::create($value)
->withLimit($this->limit));
} | [
"public",
"function",
"geocode",
"(",
"string",
"$",
"value",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"geocodeQuery",
"(",
"GeocodeQuery",
"::",
"create",
"(",
"$",
"value",
")",
"->",
"withLimit",
"(",
"$",
"this",
"->",
"limit",
")",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/ProviderAggregator.php#L93-L97 |
geocoder-php/php-common | ProviderAggregator.php | ProviderAggregator.reverse | public function reverse(float $latitude, float $longitude): Collection
{
return $this->reverseQuery(ReverseQuery::create(new Coordinates($latitude, $longitude))
->withLimit($this->limit));
} | php | public function reverse(float $latitude, float $longitude): Collection
{
return $this->reverseQuery(ReverseQuery::create(new Coordinates($latitude, $longitude))
->withLimit($this->limit));
} | [
"public",
"function",
"reverse",
"(",
"float",
"$",
"latitude",
",",
"float",
"$",
"longitude",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"reverseQuery",
"(",
"ReverseQuery",
"::",
"create",
"(",
"new",
"Coordinates",
"(",
"$",
"latitude",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/ProviderAggregator.php#L102-L106 |
geocoder-php/php-common | ProviderAggregator.php | ProviderAggregator.registerProvider | public function registerProvider(Provider $provider): self
{
$this->providers[$provider->getName()] = $provider;
return $this;
} | php | public function registerProvider(Provider $provider): self
{
$this->providers[$provider->getName()] = $provider;
return $this;
} | [
"public",
"function",
"registerProvider",
"(",
"Provider",
"$",
"provider",
")",
":",
"self",
"{",
"$",
"this",
"->",
"providers",
"[",
"$",
"provider",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"provider",
";",
"return",
"$",
"this",
";",
"}"
] | Registers a new provider to the aggregator.
@param Provider $provider
@return ProviderAggregator | [
"Registers",
"a",
"new",
"provider",
"to",
"the",
"aggregator",
"."
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/ProviderAggregator.php#L115-L120 |
geocoder-php/php-common | ProviderAggregator.php | ProviderAggregator.registerProviders | public function registerProviders(array $providers = []): self
{
foreach ($providers as $provider) {
$this->registerProvider($provider);
}
return $this;
} | php | public function registerProviders(array $providers = []): self
{
foreach ($providers as $provider) {
$this->registerProvider($provider);
}
return $this;
} | [
"public",
"function",
"registerProviders",
"(",
"array",
"$",
"providers",
"=",
"[",
"]",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"providers",
"as",
"$",
"provider",
")",
"{",
"$",
"this",
"->",
"registerProvider",
"(",
"$",
"provider",
")",
";",
"... | Registers a set of providers.
@param Provider[] $providers
@return ProviderAggregator | [
"Registers",
"a",
"set",
"of",
"providers",
"."
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/ProviderAggregator.php#L129-L136 |
geocoder-php/php-common | ProviderAggregator.php | ProviderAggregator.using | public function using(string $name): self
{
if (!isset($this->providers[$name])) {
throw ProviderNotRegistered::create($name ?? '', $this->providers);
}
$this->provider = $this->providers[$name];
return $this;
} | php | public function using(string $name): self
{
if (!isset($this->providers[$name])) {
throw ProviderNotRegistered::create($name ?? '', $this->providers);
}
$this->provider = $this->providers[$name];
return $this;
} | [
"public",
"function",
"using",
"(",
"string",
"$",
"name",
")",
":",
"self",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"providers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"ProviderNotRegistered",
"::",
"create",
"(",
"$",
"name",
... | Sets the default provider to use.
@param string $name
@return ProviderAggregator | [
"Sets",
"the",
"default",
"provider",
"to",
"use",
"."
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/ProviderAggregator.php#L145-L154 |
geocoder-php/php-common | ProviderAggregator.php | ProviderAggregator.getProvider | private static function getProvider($query, array $providers, Provider $currentProvider = null): Provider
{
if (null !== $currentProvider) {
return $currentProvider;
}
if (0 === count($providers)) {
throw ProviderNotRegistered::noProviderRegistered();
}
// Take first
$key = key($providers);
return $providers[$key];
} | php | private static function getProvider($query, array $providers, Provider $currentProvider = null): Provider
{
if (null !== $currentProvider) {
return $currentProvider;
}
if (0 === count($providers)) {
throw ProviderNotRegistered::noProviderRegistered();
}
// Take first
$key = key($providers);
return $providers[$key];
} | [
"private",
"static",
"function",
"getProvider",
"(",
"$",
"query",
",",
"array",
"$",
"providers",
",",
"Provider",
"$",
"currentProvider",
"=",
"null",
")",
":",
"Provider",
"{",
"if",
"(",
"null",
"!==",
"$",
"currentProvider",
")",
"{",
"return",
"$",
... | Get a provider to use for this query.
@param GeocodeQuery|ReverseQuery $query
@param Provider[] $providers
@param Provider $currentProvider
@return Provider
@throws ProviderNotRegistered | [
"Get",
"a",
"provider",
"to",
"use",
"for",
"this",
"query",
"."
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/ProviderAggregator.php#L177-L191 |
geocoder-php/php-common | Model/AdminLevelCollection.php | AdminLevelCollection.get | public function get(int $level): AdminLevel
{
$this->checkLevel($level);
if (!isset($this->adminLevels[$level])) {
throw new InvalidArgument(sprintf('Administrative level %d is not set for this address', $level));
}
return $this->adminLevels[$level];
} | php | public function get(int $level): AdminLevel
{
$this->checkLevel($level);
if (!isset($this->adminLevels[$level])) {
throw new InvalidArgument(sprintf('Administrative level %d is not set for this address', $level));
}
return $this->adminLevels[$level];
} | [
"public",
"function",
"get",
"(",
"int",
"$",
"level",
")",
":",
"AdminLevel",
"{",
"$",
"this",
"->",
"checkLevel",
"(",
"$",
"level",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"adminLevels",
"[",
"$",
"level",
"]",
")",
")",
"{... | @return AdminLevel
@throws \OutOfBoundsException
@throws InvalidArgument | [
"@return",
"AdminLevel"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AdminLevelCollection.php#L108-L117 |
geocoder-php/php-common | Model/AdminLevelCollection.php | AdminLevelCollection.checkLevel | private function checkLevel(int $level)
{
if ($level <= 0 || $level > self::MAX_LEVEL_DEPTH) {
throw new OutOfBounds(
sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level)
);
}
} | php | private function checkLevel(int $level)
{
if ($level <= 0 || $level > self::MAX_LEVEL_DEPTH) {
throw new OutOfBounds(
sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level)
);
}
} | [
"private",
"function",
"checkLevel",
"(",
"int",
"$",
"level",
")",
"{",
"if",
"(",
"$",
"level",
"<=",
"0",
"||",
"$",
"level",
">",
"self",
"::",
"MAX_LEVEL_DEPTH",
")",
"{",
"throw",
"new",
"OutOfBounds",
"(",
"sprintf",
"(",
"'Administrative level shou... | @param int $level
@throws \OutOfBoundsException | [
"@param",
"int",
"$level"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AdminLevelCollection.php#L132-L139 |
geocoder-php/php-common | GeocoderTrait.php | GeocoderTrait.reverse | public function reverse(float $latitude, float $longitude): Collection
{
return $this->reverseQuery(ReverseQuery::fromCoordinates($latitude, $longitude));
} | php | public function reverse(float $latitude, float $longitude): Collection
{
return $this->reverseQuery(ReverseQuery::fromCoordinates($latitude, $longitude));
} | [
"public",
"function",
"reverse",
"(",
"float",
"$",
"latitude",
",",
"float",
"$",
"longitude",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"reverseQuery",
"(",
"ReverseQuery",
"::",
"fromCoordinates",
"(",
"$",
"latitude",
",",
"$",
"longitude... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/GeocoderTrait.php#L40-L43 |
geocoder-php/php-common | Dumper/Wkb.php | Wkb.dump | public function dump(Location $location): string
{
$lat = null;
$lon = null;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
return pack('cLdd', 1, 1, $lon, $lat);
} | php | public function dump(Location $location): string
{
$lat = null;
$lon = null;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
return pack('cLdd', 1, 1, $lon, $lat);
} | [
"public",
"function",
"dump",
"(",
"Location",
"$",
"location",
")",
":",
"string",
"{",
"$",
"lat",
"=",
"null",
";",
"$",
"lon",
"=",
"null",
";",
"if",
"(",
"null",
"!==",
"$",
"coordinates",
"=",
"$",
"location",
"->",
"getCoordinates",
"(",
")",... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Dumper/Wkb.php#L25-L35 |
geocoder-php/php-common | Model/AddressCollection.php | AddressCollection.get | public function get(int $index): Location
{
if (!isset($this->locations[$index])) {
throw new OutOfBounds(sprintf('The index "%s" does not exist in this collection.', $index));
}
return $this->locations[$index];
} | php | public function get(int $index): Location
{
if (!isset($this->locations[$index])) {
throw new OutOfBounds(sprintf('The index "%s" does not exist in this collection.', $index));
}
return $this->locations[$index];
} | [
"public",
"function",
"get",
"(",
"int",
"$",
"index",
")",
":",
"Location",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"locations",
"[",
"$",
"index",
"]",
")",
")",
"{",
"throw",
"new",
"OutOfBounds",
"(",
"sprintf",
"(",
"'The index \"%... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AddressCollection.php#L90-L97 |
geocoder-php/php-common | Formatter/StringFormatter.php | StringFormatter.format | public function format(Location $location, string $format): string
{
$countryName = null;
$code = null;
if (null !== $country = $location->getCountry()) {
$countryName = $country->getName();
if (null !== $code = $country->getCode()) {
$code = strtoupper($code);
}
}
$replace = [
self::STREET_NUMBER => $location->getStreetNumber(),
self::STREET_NAME => $location->getStreetName(),
self::LOCALITY => $location->getLocality(),
self::POSTAL_CODE => $location->getPostalCode(),
self::SUB_LOCALITY => $location->getSubLocality(),
self::COUNTRY => $countryName,
self::COUNTRY_CODE => $code,
self::TIMEZONE => $location->getTimezone(),
];
for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++$level) {
$replace[self::ADMIN_LEVEL.$level] = null;
$replace[self::ADMIN_LEVEL_CODE.$level] = null;
}
foreach ($location->getAdminLevels() as $level => $adminLevel) {
$replace[self::ADMIN_LEVEL.$level] = $adminLevel->getName();
$replace[self::ADMIN_LEVEL_CODE.$level] = $adminLevel->getCode();
}
return strtr($format, $replace);
} | php | public function format(Location $location, string $format): string
{
$countryName = null;
$code = null;
if (null !== $country = $location->getCountry()) {
$countryName = $country->getName();
if (null !== $code = $country->getCode()) {
$code = strtoupper($code);
}
}
$replace = [
self::STREET_NUMBER => $location->getStreetNumber(),
self::STREET_NAME => $location->getStreetName(),
self::LOCALITY => $location->getLocality(),
self::POSTAL_CODE => $location->getPostalCode(),
self::SUB_LOCALITY => $location->getSubLocality(),
self::COUNTRY => $countryName,
self::COUNTRY_CODE => $code,
self::TIMEZONE => $location->getTimezone(),
];
for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++$level) {
$replace[self::ADMIN_LEVEL.$level] = null;
$replace[self::ADMIN_LEVEL_CODE.$level] = null;
}
foreach ($location->getAdminLevels() as $level => $adminLevel) {
$replace[self::ADMIN_LEVEL.$level] = $adminLevel->getName();
$replace[self::ADMIN_LEVEL_CODE.$level] = $adminLevel->getCode();
}
return strtr($format, $replace);
} | [
"public",
"function",
"format",
"(",
"Location",
"$",
"location",
",",
"string",
"$",
"format",
")",
":",
"string",
"{",
"$",
"countryName",
"=",
"null",
";",
"$",
"code",
"=",
"null",
";",
"if",
"(",
"null",
"!==",
"$",
"country",
"=",
"$",
"locatio... | Transform an `Address` instance into a string representation.
@param Location $location
@param string $format
@return string | [
"Transform",
"an",
"Address",
"instance",
"into",
"a",
"string",
"representation",
"."
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Formatter/StringFormatter.php#L51-L84 |
geocoder-php/php-common | TimedGeocoder.php | TimedGeocoder.geocodeQuery | public function geocodeQuery(GeocodeQuery $query): Collection
{
$this->stopwatch->start('geocode', 'geocoder');
try {
$result = $this->delegate->geocodeQuery($query);
} catch (\Throwable $e) {
$this->stopwatch->stop('geocode');
throw $e;
}
$this->stopwatch->stop('geocode');
return $result;
} | php | public function geocodeQuery(GeocodeQuery $query): Collection
{
$this->stopwatch->start('geocode', 'geocoder');
try {
$result = $this->delegate->geocodeQuery($query);
} catch (\Throwable $e) {
$this->stopwatch->stop('geocode');
throw $e;
}
$this->stopwatch->stop('geocode');
return $result;
} | [
"public",
"function",
"geocodeQuery",
"(",
"GeocodeQuery",
"$",
"query",
")",
":",
"Collection",
"{",
"$",
"this",
"->",
"stopwatch",
"->",
"start",
"(",
"'geocode'",
",",
"'geocoder'",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"delega... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/TimedGeocoder.php#L48-L63 |
geocoder-php/php-common | TimedGeocoder.php | TimedGeocoder.reverseQuery | public function reverseQuery(ReverseQuery $query): Collection
{
$this->stopwatch->start('reverse', 'geocoder');
try {
$result = $this->delegate->reverseQuery($query);
} catch (\Throwable $e) {
$this->stopwatch->stop('reverse');
throw $e;
}
$this->stopwatch->stop('reverse');
return $result;
} | php | public function reverseQuery(ReverseQuery $query): Collection
{
$this->stopwatch->start('reverse', 'geocoder');
try {
$result = $this->delegate->reverseQuery($query);
} catch (\Throwable $e) {
$this->stopwatch->stop('reverse');
throw $e;
}
$this->stopwatch->stop('reverse');
return $result;
} | [
"public",
"function",
"reverseQuery",
"(",
"ReverseQuery",
"$",
"query",
")",
":",
"Collection",
"{",
"$",
"this",
"->",
"stopwatch",
"->",
"start",
"(",
"'reverse'",
",",
"'geocoder'",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"delega... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/TimedGeocoder.php#L68-L83 |
geocoder-php/php-common | Dumper/AbstractArrayDumper.php | AbstractArrayDumper.getArray | protected function getArray(Location $location): array
{
$properties = array_filter($location->toArray(), function ($value) {
return !empty($value);
});
unset(
$properties['latitude'],
$properties['longitude'],
$properties['bounds']
);
if (0 === count($properties)) {
$properties = null;
}
$lat = 0;
$lon = 0;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
$array = [
'type' => 'Feature',
'geometry' => [
'type' => 'Point',
'coordinates' => [$lon, $lat],
],
'properties' => $properties,
];
if (null !== $bounds = $location->getBounds()) {
$array['bounds'] = $bounds->toArray();
}
return $array;
} | php | protected function getArray(Location $location): array
{
$properties = array_filter($location->toArray(), function ($value) {
return !empty($value);
});
unset(
$properties['latitude'],
$properties['longitude'],
$properties['bounds']
);
if (0 === count($properties)) {
$properties = null;
}
$lat = 0;
$lon = 0;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
$array = [
'type' => 'Feature',
'geometry' => [
'type' => 'Point',
'coordinates' => [$lon, $lat],
],
'properties' => $properties,
];
if (null !== $bounds = $location->getBounds()) {
$array['bounds'] = $bounds->toArray();
}
return $array;
} | [
"protected",
"function",
"getArray",
"(",
"Location",
"$",
"location",
")",
":",
"array",
"{",
"$",
"properties",
"=",
"array_filter",
"(",
"$",
"location",
"->",
"toArray",
"(",
")",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"!",
"empty",
... | @param Location $location
@return array | [
"@param",
"Location",
"$location"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Dumper/AbstractArrayDumper.php#L27-L64 |
geocoder-php/php-common | StatefulGeocoder.php | StatefulGeocoder.geocode | public function geocode(string $value): Collection
{
$query = GeocodeQuery::create($value)
->withLimit($this->limit);
if (!empty($this->locale)) {
$query = $query->withLocale($this->locale);
}
if (!empty($this->bounds)) {
$query = $query->withBounds($this->bounds);
}
return $this->provider->geocodeQuery($query);
} | php | public function geocode(string $value): Collection
{
$query = GeocodeQuery::create($value)
->withLimit($this->limit);
if (!empty($this->locale)) {
$query = $query->withLocale($this->locale);
}
if (!empty($this->bounds)) {
$query = $query->withBounds($this->bounds);
}
return $this->provider->geocodeQuery($query);
} | [
"public",
"function",
"geocode",
"(",
"string",
"$",
"value",
")",
":",
"Collection",
"{",
"$",
"query",
"=",
"GeocodeQuery",
"::",
"create",
"(",
"$",
"value",
")",
"->",
"withLimit",
"(",
"$",
"this",
"->",
"limit",
")",
";",
"if",
"(",
"!",
"empty... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/StatefulGeocoder.php#L59-L73 |
geocoder-php/php-common | StatefulGeocoder.php | StatefulGeocoder.reverse | public function reverse(float $latitude, float $longitude): Collection
{
$query = ReverseQuery::fromCoordinates($latitude, $longitude)
->withLimit($this->limit);
if (!empty($this->locale)) {
$query = $query->withLocale($this->locale);
}
return $this->provider->reverseQuery($query);
} | php | public function reverse(float $latitude, float $longitude): Collection
{
$query = ReverseQuery::fromCoordinates($latitude, $longitude)
->withLimit($this->limit);
if (!empty($this->locale)) {
$query = $query->withLocale($this->locale);
}
return $this->provider->reverseQuery($query);
} | [
"public",
"function",
"reverse",
"(",
"float",
"$",
"latitude",
",",
"float",
"$",
"longitude",
")",
":",
"Collection",
"{",
"$",
"query",
"=",
"ReverseQuery",
"::",
"fromCoordinates",
"(",
"$",
"latitude",
",",
"$",
"longitude",
")",
"->",
"withLimit",
"(... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/StatefulGeocoder.php#L78-L88 |
geocoder-php/php-common | StatefulGeocoder.php | StatefulGeocoder.geocodeQuery | public function geocodeQuery(GeocodeQuery $query): Collection
{
$locale = $query->getLocale();
if (empty($locale) && null !== $this->locale) {
$query = $query->withLocale($this->locale);
}
$bounds = $query->getBounds();
if (empty($bounds) && null !== $this->bounds) {
$query = $query->withBounds($this->bounds);
}
return $this->provider->geocodeQuery($query);
} | php | public function geocodeQuery(GeocodeQuery $query): Collection
{
$locale = $query->getLocale();
if (empty($locale) && null !== $this->locale) {
$query = $query->withLocale($this->locale);
}
$bounds = $query->getBounds();
if (empty($bounds) && null !== $this->bounds) {
$query = $query->withBounds($this->bounds);
}
return $this->provider->geocodeQuery($query);
} | [
"public",
"function",
"geocodeQuery",
"(",
"GeocodeQuery",
"$",
"query",
")",
":",
"Collection",
"{",
"$",
"locale",
"=",
"$",
"query",
"->",
"getLocale",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"locale",
")",
"&&",
"null",
"!==",
"$",
"this",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/StatefulGeocoder.php#L93-L106 |
geocoder-php/php-common | StatefulGeocoder.php | StatefulGeocoder.reverseQuery | public function reverseQuery(ReverseQuery $query): Collection
{
$locale = $query->getLocale();
if (empty($locale) && null !== $this->locale) {
$query = $query->withLocale($this->locale);
}
return $this->provider->reverseQuery($query);
} | php | public function reverseQuery(ReverseQuery $query): Collection
{
$locale = $query->getLocale();
if (empty($locale) && null !== $this->locale) {
$query = $query->withLocale($this->locale);
}
return $this->provider->reverseQuery($query);
} | [
"public",
"function",
"reverseQuery",
"(",
"ReverseQuery",
"$",
"query",
")",
":",
"Collection",
"{",
"$",
"locale",
"=",
"$",
"query",
"->",
"getLocale",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"locale",
")",
"&&",
"null",
"!==",
"$",
"this",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/StatefulGeocoder.php#L111-L119 |
geocoder-php/php-common | Dumper/Kml.php | Kml.dump | public function dump(Location $location): string
{
$name = $this->formatName($location);
$kml = <<<'KML'
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name><![CDATA[%s]]></name>
<description><![CDATA[%s]]></description>
<Point>
<coordinates>%.7F,%.7F,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
KML;
$lat = null;
$lon = null;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
return sprintf($kml, $name, $name, $lon, $lat);
} | php | public function dump(Location $location): string
{
$name = $this->formatName($location);
$kml = <<<'KML'
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name><![CDATA[%s]]></name>
<description><![CDATA[%s]]></description>
<Point>
<coordinates>%.7F,%.7F,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
KML;
$lat = null;
$lon = null;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}
return sprintf($kml, $name, $name, $lon, $lat);
} | [
"public",
"function",
"dump",
"(",
"Location",
"$",
"location",
")",
":",
"string",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"formatName",
"(",
"$",
"location",
")",
";",
"$",
"kml",
"=",
" <<<'KML'\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http:/... | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Dumper/Kml.php#L25-L51 |
geocoder-php/php-common | Model/AddressBuilder.php | AddressBuilder.build | public function build(string $class = Address::class): Address
{
if (!is_a($class, Address::class, true)) {
throw new LogicException('First parameter to LocationBuilder::build must be a class name extending Geocoder\Model\Address');
}
$country = null;
if (!empty($this->country) || !empty($this->countryCode)) {
$country = new Country($this->country, $this->countryCode);
}
return new $class(
$this->providedBy,
new AdminLevelCollection($this->adminLevels),
$this->coordinates,
$this->bounds,
$this->streetNumber,
$this->streetName,
$this->postalCode,
$this->locality,
$this->subLocality,
$country,
$this->timezone
);
} | php | public function build(string $class = Address::class): Address
{
if (!is_a($class, Address::class, true)) {
throw new LogicException('First parameter to LocationBuilder::build must be a class name extending Geocoder\Model\Address');
}
$country = null;
if (!empty($this->country) || !empty($this->countryCode)) {
$country = new Country($this->country, $this->countryCode);
}
return new $class(
$this->providedBy,
new AdminLevelCollection($this->adminLevels),
$this->coordinates,
$this->bounds,
$this->streetNumber,
$this->streetName,
$this->postalCode,
$this->locality,
$this->subLocality,
$country,
$this->timezone
);
} | [
"public",
"function",
"build",
"(",
"string",
"$",
"class",
"=",
"Address",
"::",
"class",
")",
":",
"Address",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"class",
",",
"Address",
"::",
"class",
",",
"true",
")",
")",
"{",
"throw",
"new",
"LogicException... | @param string $class
@return Address | [
"@param",
"string",
"$class"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AddressBuilder.php#L105-L129 |
geocoder-php/php-common | Model/AddressBuilder.php | AddressBuilder.setBounds | public function setBounds($south, $west, $north, $east): self
{
try {
$this->bounds = new Bounds($south, $west, $north, $east);
} catch (InvalidArgument $e) {
$this->bounds = null;
}
return $this;
} | php | public function setBounds($south, $west, $north, $east): self
{
try {
$this->bounds = new Bounds($south, $west, $north, $east);
} catch (InvalidArgument $e) {
$this->bounds = null;
}
return $this;
} | [
"public",
"function",
"setBounds",
"(",
"$",
"south",
",",
"$",
"west",
",",
"$",
"north",
",",
"$",
"east",
")",
":",
"self",
"{",
"try",
"{",
"$",
"this",
"->",
"bounds",
"=",
"new",
"Bounds",
"(",
"$",
"south",
",",
"$",
"west",
",",
"$",
"n... | @param float $south
@param float $west
@param float $north
@param float $east
@return AddressBuilder | [
"@param",
"float",
"$south",
"@param",
"float",
"$west",
"@param",
"float",
"$north",
"@param",
"float",
"$east"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AddressBuilder.php#L139-L148 |
geocoder-php/php-common | Model/AddressBuilder.php | AddressBuilder.setCoordinates | public function setCoordinates($latitude, $longitude): self
{
try {
$this->coordinates = new Coordinates($latitude, $longitude);
} catch (InvalidArgument $e) {
$this->coordinates = null;
}
return $this;
} | php | public function setCoordinates($latitude, $longitude): self
{
try {
$this->coordinates = new Coordinates($latitude, $longitude);
} catch (InvalidArgument $e) {
$this->coordinates = null;
}
return $this;
} | [
"public",
"function",
"setCoordinates",
"(",
"$",
"latitude",
",",
"$",
"longitude",
")",
":",
"self",
"{",
"try",
"{",
"$",
"this",
"->",
"coordinates",
"=",
"new",
"Coordinates",
"(",
"$",
"latitude",
",",
"$",
"longitude",
")",
";",
"}",
"catch",
"(... | @param float $latitude
@param float $longitude
@return AddressBuilder | [
"@param",
"float",
"$latitude",
"@param",
"float",
"$longitude"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AddressBuilder.php#L156-L165 |
geocoder-php/php-common | Model/AddressBuilder.php | AddressBuilder.addAdminLevel | public function addAdminLevel(int $level, string $name, string $code = null): self
{
$this->adminLevels[] = new AdminLevel($level, $name, $code);
return $this;
} | php | public function addAdminLevel(int $level, string $name, string $code = null): self
{
$this->adminLevels[] = new AdminLevel($level, $name, $code);
return $this;
} | [
"public",
"function",
"addAdminLevel",
"(",
"int",
"$",
"level",
",",
"string",
"$",
"name",
",",
"string",
"$",
"code",
"=",
"null",
")",
":",
"self",
"{",
"$",
"this",
"->",
"adminLevels",
"[",
"]",
"=",
"new",
"AdminLevel",
"(",
"$",
"level",
",",... | @param int $level
@param string $name
@param string|null $code
@return AddressBuilder | [
"@param",
"int",
"$level",
"@param",
"string",
"$name",
"@param",
"string|null",
"$code"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AddressBuilder.php#L174-L179 |
geocoder-php/php-common | Model/AddressBuilder.php | AddressBuilder.setValue | public function setValue(string $name, $value): self
{
$this->data[$name] = $value;
return $this;
} | php | public function setValue(string $name, $value): self
{
$this->data[$name] = $value;
return $this;
} | [
"public",
"function",
"setValue",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | @param string $name
@param mixed $value
@return AddressBuilder | [
"@param",
"string",
"$name",
"@param",
"mixed",
"$value"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AddressBuilder.php#L295-L300 |
geocoder-php/php-common | Model/AddressBuilder.php | AddressBuilder.getValue | public function getValue(string $name, $default = null)
{
if ($this->hasValue($name)) {
return $this->data[$name];
}
return $default;
} | php | public function getValue(string $name, $default = null)
{
if ($this->hasValue($name)) {
return $this->data[$name];
}
return $default;
} | [
"public",
"function",
"getValue",
"(",
"string",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasValue",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
";",
... | @param string $name
@param mixed|null $default
@return mixed | [
"@param",
"string",
"$name",
"@param",
"mixed|null",
"$default"
] | train | https://github.com/geocoder-php/php-common/blob/a85267c6de0fdbb3cf649aca60c8bcce4fd74379/Model/AddressBuilder.php#L308-L315 |
sonata-project/SonataIntlBundle | src/SonataIntlBundle.php | SonataIntlBundle.getSymfonyVersion | public static function getSymfonyVersion($version)
{
return implode('.', \array_slice(array_map(static function ($val) {
return (int) $val;
}, explode('.', $version)), 0, 3));
} | php | public static function getSymfonyVersion($version)
{
return implode('.', \array_slice(array_map(static function ($val) {
return (int) $val;
}, explode('.', $version)), 0, 3));
} | [
"public",
"static",
"function",
"getSymfonyVersion",
"(",
"$",
"version",
")",
"{",
"return",
"implode",
"(",
"'.'",
",",
"\\",
"array_slice",
"(",
"array_map",
"(",
"static",
"function",
"(",
"$",
"val",
")",
"{",
"return",
"(",
"int",
")",
"$",
"val",
... | Returns a cleaned version number.
@static
@param $version
@return string | [
"Returns",
"a",
"cleaned",
"version",
"number",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/SonataIntlBundle.php#L31-L36 |
sonata-project/SonataIntlBundle | src/Locale/RequestDetector.php | RequestDetector.getLocale | public function getLocale()
{
if ($this->container->isScopeActive('request')) {
if ($request = $this->container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
return $request->getLocale();
}
}
return $this->defaultLocale;
} | php | public function getLocale()
{
if ($this->container->isScopeActive('request')) {
if ($request = $this->container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
return $request->getLocale();
}
}
return $this->defaultLocale;
} | [
"public",
"function",
"getLocale",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"isScopeActive",
"(",
"'request'",
")",
")",
"{",
"if",
"(",
"$",
"request",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'request'",
",",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Locale/RequestDetector.php#L43-L52 |
sonata-project/SonataIntlBundle | src/Templating/Helper/LocaleHelper.php | LocaleHelper.country | public function country($code, $locale = null)
{
$name = Intl::getRegionBundle()->getCountryName($code, $locale ?: $this->localeDetector->getLocale());
return $name ? $this->fixCharset($name) : '';
} | php | public function country($code, $locale = null)
{
$name = Intl::getRegionBundle()->getCountryName($code, $locale ?: $this->localeDetector->getLocale());
return $name ? $this->fixCharset($name) : '';
} | [
"public",
"function",
"country",
"(",
"$",
"code",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"Intl",
"::",
"getRegionBundle",
"(",
")",
"->",
"getCountryName",
"(",
"$",
"code",
",",
"$",
"locale",
"?",
":",
"$",
"this",
"->",
"l... | @param string $code
@param string|null $locale
@return string | [
"@param",
"string",
"$code",
"@param",
"string|null",
"$locale"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/LocaleHelper.php#L31-L36 |
sonata-project/SonataIntlBundle | src/Templating/Helper/LocaleHelper.php | LocaleHelper.language | public function language($code, $locale = null)
{
$codes = explode('_', $code);
$name = Intl::getLanguageBundle()->getLanguageName(
$codes[0],
$codes[1] ?? null,
$locale ?: $this->localeDetector->getLocale()
);
return $name ? $this->fixCharset($name) : '';
} | php | public function language($code, $locale = null)
{
$codes = explode('_', $code);
$name = Intl::getLanguageBundle()->getLanguageName(
$codes[0],
$codes[1] ?? null,
$locale ?: $this->localeDetector->getLocale()
);
return $name ? $this->fixCharset($name) : '';
} | [
"public",
"function",
"language",
"(",
"$",
"code",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"codes",
"=",
"explode",
"(",
"'_'",
",",
"$",
"code",
")",
";",
"$",
"name",
"=",
"Intl",
"::",
"getLanguageBundle",
"(",
")",
"->",
"getLanguageName... | @param string $code
@param string|null $locale
@return string | [
"@param",
"string",
"$code",
"@param",
"string|null",
"$locale"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/LocaleHelper.php#L44-L55 |
sonata-project/SonataIntlBundle | src/Templating/Helper/LocaleHelper.php | LocaleHelper.locale | public function locale($code, $locale = null)
{
$name = Intl::getLocaleBundle()->getLocaleName($code, $locale ?: $this->localeDetector->getLocale());
return $name ? $this->fixCharset($name) : '';
} | php | public function locale($code, $locale = null)
{
$name = Intl::getLocaleBundle()->getLocaleName($code, $locale ?: $this->localeDetector->getLocale());
return $name ? $this->fixCharset($name) : '';
} | [
"public",
"function",
"locale",
"(",
"$",
"code",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"Intl",
"::",
"getLocaleBundle",
"(",
")",
"->",
"getLocaleName",
"(",
"$",
"code",
",",
"$",
"locale",
"?",
":",
"$",
"this",
"->",
"loc... | @param string $code
@param string|null $locale
@return string | [
"@param",
"string",
"$code",
"@param",
"string|null",
"$locale"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/LocaleHelper.php#L63-L68 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.formatPercent | public function formatPercent($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::PERCENT, $attributes, $textAttributes, $symbols, $locale);
} | php | public function formatPercent($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::PERCENT, $attributes, $textAttributes, $symbols, $locale);
} | [
"public",
"function",
"formatPercent",
"(",
"$",
"number",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"array_pad",
"(",
"\\",
... | Formats a number as percent according to the specified locale and
\NumberFormatter attributes.
@param string|float|int $number The number to format
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string The formatted number | [
"Formats",
"a",
"number",
"as",
"percent",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L69-L76 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.formatDuration | public function formatDuration($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::DURATION, $attributes, $textAttributes, $symbols, $locale);
} | php | public function formatDuration($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::DURATION, $attributes, $textAttributes, $symbols, $locale);
} | [
"public",
"function",
"formatDuration",
"(",
"$",
"number",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"array_pad",
"(",
"\\",
... | Formats a number as duration according to the specified locale and
\NumberFormatter attributes.
@param string|float|int $number The number to format
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string The formatted number | [
"Formats",
"a",
"number",
"as",
"duration",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L90-L97 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.formatDecimal | public function formatDecimal($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::DECIMAL, $attributes, $textAttributes, $symbols, $locale);
} | php | public function formatDecimal($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::DECIMAL, $attributes, $textAttributes, $symbols, $locale);
} | [
"public",
"function",
"formatDecimal",
"(",
"$",
"number",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"array_pad",
"(",
"\\",
... | Formats a number as decimal according to the specified locale and
\NumberFormatter attributes.
@param string|float|int $number The number to format
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string The formatted number | [
"Formats",
"a",
"number",
"as",
"decimal",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L111-L118 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.formatSpellout | public function formatSpellout($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::SPELLOUT, $attributes, $textAttributes, $symbols, $locale);
} | php | public function formatSpellout($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::SPELLOUT, $attributes, $textAttributes, $symbols, $locale);
} | [
"public",
"function",
"formatSpellout",
"(",
"$",
"number",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"array_pad",
"(",
"\\",
... | Formats a number as spellout according to the specified locale and
\NumberFormatter attributes.
@param string|float|int $number The number to format
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string The formatted number | [
"Formats",
"a",
"number",
"as",
"spellout",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L132-L139 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.formatCurrency | public function formatCurrency($number, $currency, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 6, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
$formatter = $this->getFormatter($locale ?: $this->localeDetector->getLocale(), \NumberFormatter::CURRENCY, $attributes, $textAttributes, $symbols);
return $this->fixCharset($formatter->formatCurrency($number, $currency));
} | php | public function formatCurrency($number, $currency, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 6, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
$formatter = $this->getFormatter($locale ?: $this->localeDetector->getLocale(), \NumberFormatter::CURRENCY, $attributes, $textAttributes, $symbols);
return $this->fixCharset($formatter->formatCurrency($number, $currency));
} | [
"public",
"function",
"formatCurrency",
"(",
"$",
"number",
",",
"$",
"currency",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"... | Formats a number as currency according to the specified locale and
\NumberFormatter attributes.
@param string|float|int $number The number to format
@param string $currency The currency in which format the number
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string The formatted number | [
"Formats",
"a",
"number",
"as",
"currency",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L154-L163 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.formatScientific | public function formatScientific($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::SCIENTIFIC, $attributes, $textAttributes, $symbols, $locale);
} | php | public function formatScientific($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::SCIENTIFIC, $attributes, $textAttributes, $symbols, $locale);
} | [
"public",
"function",
"formatScientific",
"(",
"$",
"number",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"array_pad",
"(",
"\\",... | Formats a number in scientific notation according to the specified
locale and \NumberFormatter attributes.
@param string|float|int $number The number to format
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string The formatted number | [
"Formats",
"a",
"number",
"in",
"scientific",
"notation",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L177-L184 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.formatOrdinal | public function formatOrdinal($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::ORDINAL, $attributes, $textAttributes, $symbols, $locale);
} | php | public function formatOrdinal($number, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 5, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[3], $methodArgs[4]);
return $this->format($number, \NumberFormatter::ORDINAL, $attributes, $textAttributes, $symbols, $locale);
} | [
"public",
"function",
"formatOrdinal",
"(",
"$",
"number",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"array_pad",
"(",
"\\",
... | Formats a number as ordinal according to the specified locale and
\NumberFormatter attributes.
@param string|float|int $number The number to format
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string The formatted number | [
"Formats",
"a",
"number",
"as",
"ordinal",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L198-L205 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.format | public function format($number, $style, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 6, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
$formatter = $this->getFormatter($locale ?: $this->localeDetector->getLocale(), $style, $attributes, $textAttributes, $symbols);
return $this->fixCharset($formatter->format($number));
} | php | public function format($number, $style, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 6, null);
list($locale, $symbols) = $this->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
$formatter = $this->getFormatter($locale ?: $this->localeDetector->getLocale(), $style, $attributes, $textAttributes, $symbols);
return $this->fixCharset($formatter->format($number));
} | [
"public",
"function",
"format",
"(",
"$",
"number",
",",
"$",
"style",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"array_pad",... | Formats a number according to the specified locale and \NumberFormatter
attributes.
@param string|float|int $number The number to format
@param $style
@param array $attributes The attributes used by the formatter
@param array $textAttributes The text attributes used by the formatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string | [
"Formats",
"a",
"number",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L220-L229 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.normalizeMethodSignature | public function normalizeMethodSignature($symbols, $locale)
{
$oldSignature = (null === $symbols || \is_string($symbols)) && null === $locale;
$newSignature = \is_array($symbols) && (\is_string($locale) || null === $locale);
// Confirm possible signatures
if (!$oldSignature && !$newSignature) {
throw new \BadMethodCallException('Neither new nor old signature matches, please provide the correct arguments');
}
if ($oldSignature) {
// If the old signature matches, we pass an empty array as symbols
// argument and the symbols value as the locale argument.
return [$symbols, []];
}
return [$locale, $symbols];
} | php | public function normalizeMethodSignature($symbols, $locale)
{
$oldSignature = (null === $symbols || \is_string($symbols)) && null === $locale;
$newSignature = \is_array($symbols) && (\is_string($locale) || null === $locale);
// Confirm possible signatures
if (!$oldSignature && !$newSignature) {
throw new \BadMethodCallException('Neither new nor old signature matches, please provide the correct arguments');
}
if ($oldSignature) {
// If the old signature matches, we pass an empty array as symbols
// argument and the symbols value as the locale argument.
return [$symbols, []];
}
return [$locale, $symbols];
} | [
"public",
"function",
"normalizeMethodSignature",
"(",
"$",
"symbols",
",",
"$",
"locale",
")",
"{",
"$",
"oldSignature",
"=",
"(",
"null",
"===",
"$",
"symbols",
"||",
"\\",
"is_string",
"(",
"$",
"symbols",
")",
")",
"&&",
"null",
"===",
"$",
"locale",... | Normalizes the given arguments according to the new function signature.
It asserts if neither the new nor old signature matches. This function
is public just to prevent code duplication inside the Twig Extension.
@param mixed $symbols The symbols used by the formatter
@param mixed $locale The locale
@throws \BadMethodCallException If the arguments does not match any signature
@return array Arguments list normalized to the new method signature
@internal | [
"Normalizes",
"the",
"given",
"arguments",
"according",
"to",
"the",
"new",
"function",
"signature",
".",
"It",
"asserts",
"if",
"neither",
"the",
"new",
"nor",
"old",
"signature",
"matches",
".",
"This",
"function",
"is",
"public",
"just",
"to",
"prevent",
... | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L245-L262 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.getFormatter | protected function getFormatter($culture, $style, $attributes = [], $textAttributes = [], $symbols = [])
{
$attributes = $this->parseAttributes(array_merge($this->attributes, $attributes));
$textAttributes = $this->parseAttributes(array_merge($this->textAttributes, $textAttributes));
$symbols = $this->parseAttributes(array_merge($this->symbols, $symbols));
$formatter = new \NumberFormatter($culture, $style);
self::checkInternalClass($formatter, '\NumberFormatter', [
'culture' => $culture,
'style' => $style,
]);
foreach ($attributes as $attribute => $value) {
$formatter->setAttribute($attribute, $value);
}
foreach ($textAttributes as $attribute => $value) {
$formatter->setTextAttribute($attribute, $value);
}
foreach ($symbols as $attribute => $value) {
$formatter->setSymbol($attribute, $value);
}
return $formatter;
} | php | protected function getFormatter($culture, $style, $attributes = [], $textAttributes = [], $symbols = [])
{
$attributes = $this->parseAttributes(array_merge($this->attributes, $attributes));
$textAttributes = $this->parseAttributes(array_merge($this->textAttributes, $textAttributes));
$symbols = $this->parseAttributes(array_merge($this->symbols, $symbols));
$formatter = new \NumberFormatter($culture, $style);
self::checkInternalClass($formatter, '\NumberFormatter', [
'culture' => $culture,
'style' => $style,
]);
foreach ($attributes as $attribute => $value) {
$formatter->setAttribute($attribute, $value);
}
foreach ($textAttributes as $attribute => $value) {
$formatter->setTextAttribute($attribute, $value);
}
foreach ($symbols as $attribute => $value) {
$formatter->setSymbol($attribute, $value);
}
return $formatter;
} | [
"protected",
"function",
"getFormatter",
"(",
"$",
"culture",
",",
"$",
"style",
",",
"$",
"attributes",
"=",
"[",
"]",
",",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"symbols",
"=",
"[",
"]",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"-... | Gets an instance of \NumberFormatter set with the given attributes and
style.
@param string $culture The culture used by \NumberFormatter
@param string $style The style used by \NumberFormatter
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by \NumberFormatter
@return \NumberFormatter | [
"Gets",
"an",
"instance",
"of",
"\\",
"NumberFormatter",
"set",
"with",
"the",
"given",
"attributes",
"and",
"style",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L284-L309 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.parseAttributes | protected function parseAttributes(array $attributes)
{
$result = [];
foreach ($attributes as $attribute => $value) {
$result[$this->parseConstantValue($attribute)] = $value;
}
return $result;
} | php | protected function parseAttributes(array $attributes)
{
$result = [];
foreach ($attributes as $attribute => $value) {
$result[$this->parseConstantValue($attribute)] = $value;
}
return $result;
} | [
"protected",
"function",
"parseAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"$",
"result",
"[",
"$",
"this",
"->",
... | Converts keys of attributes array to values of \NumberFormatter constants.
@param array $attributes The list of attributes
@throws \InvalidArgumentException If any attribute does not match any constant
@return array List of \NumberFormatter constants | [
"Converts",
"keys",
"of",
"attributes",
"array",
"to",
"values",
"of",
"\\",
"NumberFormatter",
"constants",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L320-L329 |
sonata-project/SonataIntlBundle | src/Templating/Helper/NumberHelper.php | NumberHelper.parseConstantValue | protected function parseConstantValue($attribute)
{
$attribute = strtoupper($attribute);
$constantName = 'NumberFormatter::'.$attribute;
if (!\defined($constantName)) {
throw new \InvalidArgumentException(sprintf('NumberFormatter has no constant "%s".', $attribute));
}
return \constant($constantName);
} | php | protected function parseConstantValue($attribute)
{
$attribute = strtoupper($attribute);
$constantName = 'NumberFormatter::'.$attribute;
if (!\defined($constantName)) {
throw new \InvalidArgumentException(sprintf('NumberFormatter has no constant "%s".', $attribute));
}
return \constant($constantName);
} | [
"protected",
"function",
"parseConstantValue",
"(",
"$",
"attribute",
")",
"{",
"$",
"attribute",
"=",
"strtoupper",
"(",
"$",
"attribute",
")",
";",
"$",
"constantName",
"=",
"'NumberFormatter::'",
".",
"$",
"attribute",
";",
"if",
"(",
"!",
"\\",
"defined"... | Parse the given value trying to get a match with a \NumberFormatter constant.
@param string $attribute The constant's name
@throws \InvalidArgumentException If the value does not match any constant
@return mixed The \NumberFormatter constant | [
"Parse",
"the",
"given",
"value",
"trying",
"to",
"get",
"a",
"match",
"with",
"a",
"\\",
"NumberFormatter",
"constant",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/NumberHelper.php#L340-L350 |
sonata-project/SonataIntlBundle | src/DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('sonata_intl');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->root('sonata_intl');
} else {
$rootNode = $treeBuilder->getRootNode();
}
$rootNode
->children()
->scalarNode('locale')->defaultValue(false)->end()
->arrayNode('timezone')
->addDefaultsIfNotSet()
->children()
->scalarNode('service')->end()
->arrayNode('detectors')
->prototype('scalar')
->end()
->end()
->scalarNode('default')->defaultValue(date_default_timezone_get())->end()
->arrayNode('locales')
->defaultValue([])
->useAttributeAsKey('name')
->prototype('scalar')
->end()
->end()
->end()
->end();
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('sonata_intl');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->root('sonata_intl');
} else {
$rootNode = $treeBuilder->getRootNode();
}
$rootNode
->children()
->scalarNode('locale')->defaultValue(false)->end()
->arrayNode('timezone')
->addDefaultsIfNotSet()
->children()
->scalarNode('service')->end()
->arrayNode('detectors')
->prototype('scalar')
->end()
->end()
->scalarNode('default')->defaultValue(date_default_timezone_get())->end()
->arrayNode('locales')
->defaultValue([])
->useAttributeAsKey('name')
->prototype('scalar')
->end()
->end()
->end()
->end();
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
"'sonata_intl'",
")",
";",
"// Keep compatibility with symfony/config < 4.2",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"treeBuilder",
",",
"'getRootNode'... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/DependencyInjection/Configuration.php#L32-L65 |
sonata-project/SonataIntlBundle | src/Templating/Helper/DateTimeHelper.php | DateTimeHelper.formatDate | public function formatDate($date, $locale = null, $timezone = null, $dateType = null)
{
$date = $this->getDatetime($date, $timezone);
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => null === $dateType ? \IntlDateFormatter::MEDIUM : $dateType,
'timetype' => \IntlDateFormatter::NONE,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
]);
return $this->process($formatter, $date);
} | php | public function formatDate($date, $locale = null, $timezone = null, $dateType = null)
{
$date = $this->getDatetime($date, $timezone);
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => null === $dateType ? \IntlDateFormatter::MEDIUM : $dateType,
'timetype' => \IntlDateFormatter::NONE,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
]);
return $this->process($formatter, $date);
} | [
"public",
"function",
"formatDate",
"(",
"$",
"date",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
",",
"$",
"dateType",
"=",
"null",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"getDatetime",
"(",
"$",
"date",
",",
"$",
... | @param \DateTime|\DateTimeInterface|string|int $date
@param string|null $locale
@param string|null $timezone
@param int|null $dateType See \IntlDateFormatter::getDateType
@return string | [
"@param",
"\\",
"DateTime|",
"\\",
"DateTimeInterface|string|int",
"$date",
"@param",
"string|null",
"$locale",
"@param",
"string|null",
"$timezone",
"@param",
"int|null",
"$dateType",
"See",
"\\",
"IntlDateFormatter",
"::",
"getDateType"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/DateTimeHelper.php#L60-L73 |
sonata-project/SonataIntlBundle | src/Templating/Helper/DateTimeHelper.php | DateTimeHelper.formatDateTime | public function formatDateTime($datetime, $locale = null, $timezone = null, $dateType = null, $timeType = null)
{
$date = $this->getDatetime($datetime, $timezone);
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => null === $dateType ? \IntlDateFormatter::MEDIUM : $dateType,
'timetype' => null === $timeType ? \IntlDateFormatter::MEDIUM : $timeType,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
]);
return $this->process($formatter, $date);
} | php | public function formatDateTime($datetime, $locale = null, $timezone = null, $dateType = null, $timeType = null)
{
$date = $this->getDatetime($datetime, $timezone);
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => null === $dateType ? \IntlDateFormatter::MEDIUM : $dateType,
'timetype' => null === $timeType ? \IntlDateFormatter::MEDIUM : $timeType,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
]);
return $this->process($formatter, $date);
} | [
"public",
"function",
"formatDateTime",
"(",
"$",
"datetime",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
",",
"$",
"dateType",
"=",
"null",
",",
"$",
"timeType",
"=",
"null",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"... | @param \DateTime|\DateTimeInterface|string|int $datetime
@param string|null $locale
@param string|null $timezone
@param int|null $dateType See \IntlDateFormatter::getDateType
@param int|null $timeType See \IntlDateFormatter::getTimeType
@return string | [
"@param",
"\\",
"DateTime|",
"\\",
"DateTimeInterface|string|int",
"$datetime",
"@param",
"string|null",
"$locale",
"@param",
"string|null",
"$timezone",
"@param",
"int|null",
"$dateType",
"See",
"\\",
"IntlDateFormatter",
"::",
"getDateType",
"@param",
"int|null",
"$time... | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/DateTimeHelper.php#L84-L97 |
sonata-project/SonataIntlBundle | src/Templating/Helper/DateTimeHelper.php | DateTimeHelper.formatTime | public function formatTime($time, $locale = null, $timezone = null, $timeType = null)
{
$date = $this->getDatetime($time, $timezone);
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => \IntlDateFormatter::NONE,
'timetype' => null === $timeType ? \IntlDateFormatter::MEDIUM : $timeType,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
]);
return $this->process($formatter, $date);
} | php | public function formatTime($time, $locale = null, $timezone = null, $timeType = null)
{
$date = $this->getDatetime($time, $timezone);
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => \IntlDateFormatter::NONE,
'timetype' => null === $timeType ? \IntlDateFormatter::MEDIUM : $timeType,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
]);
return $this->process($formatter, $date);
} | [
"public",
"function",
"formatTime",
"(",
"$",
"time",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
",",
"$",
"timeType",
"=",
"null",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"getDatetime",
"(",
"$",
"time",
",",
"$",
... | @param \DateTime|\DateTimeInterface|string|int $time
@param string|null $locale
@param string|null $timezone
@param int|null $timeType See \IntlDateFormatter::getTimeType
@return string | [
"@param",
"\\",
"DateTime|",
"\\",
"DateTimeInterface|string|int",
"$time",
"@param",
"string|null",
"$locale",
"@param",
"string|null",
"$timezone",
"@param",
"int|null",
"$timeType",
"See",
"\\",
"IntlDateFormatter",
"::",
"getTimeType"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/DateTimeHelper.php#L107-L120 |
sonata-project/SonataIntlBundle | src/Templating/Helper/DateTimeHelper.php | DateTimeHelper.format | public function format($datetime, $pattern, $locale = null, $timezone = null)
{
$date = $this->getDatetime($datetime, $timezone);
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => \IntlDateFormatter::FULL,
'timetype' => \IntlDateFormatter::FULL,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
'pattern' => $pattern,
]);
return $this->process($formatter, $date);
} | php | public function format($datetime, $pattern, $locale = null, $timezone = null)
{
$date = $this->getDatetime($datetime, $timezone);
$formatter = self::createInstance([
'locale' => $locale ?: $this->localeDetector->getLocale(),
'datetype' => \IntlDateFormatter::FULL,
'timetype' => \IntlDateFormatter::FULL,
'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
'calendar' => \IntlDateFormatter::GREGORIAN,
'pattern' => $pattern,
]);
return $this->process($formatter, $date);
} | [
"public",
"function",
"format",
"(",
"$",
"datetime",
",",
"$",
"pattern",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"getDatetime",
"(",
"$",
"datetime",
",",
"$",
"timezone",
... | @param \DateTime|\DateTimeInterface|string|int $datetime
@param $pattern
@param string|null $locale
@param string|null $timezone
@return string | [
"@param",
"\\",
"DateTime|",
"\\",
"DateTimeInterface|string|int",
"$datetime",
"@param",
"$pattern",
"@param",
"string|null",
"$locale",
"@param",
"string|null",
"$timezone"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/DateTimeHelper.php#L130-L144 |
sonata-project/SonataIntlBundle | src/Templating/Helper/DateTimeHelper.php | DateTimeHelper.process | public function process(\IntlDateFormatter $formatter, \DateTime $date)
{
// strange bug with PHP 5.3.3-7+squeeze14 with Suhosin-Patch
// getTimestamp() method alters the object...
return $this->fixCharset($formatter->format((int) $date->format('U')));
} | php | public function process(\IntlDateFormatter $formatter, \DateTime $date)
{
// strange bug with PHP 5.3.3-7+squeeze14 with Suhosin-Patch
// getTimestamp() method alters the object...
return $this->fixCharset($formatter->format((int) $date->format('U')));
} | [
"public",
"function",
"process",
"(",
"\\",
"IntlDateFormatter",
"$",
"formatter",
",",
"\\",
"DateTime",
"$",
"date",
")",
"{",
"// strange bug with PHP 5.3.3-7+squeeze14 with Suhosin-Patch",
"// getTimestamp() method alters the object...",
"return",
"$",
"this",
"->",
"fi... | NEXT_MAJOR: Change to $date to \DateTimeInterface.
@param \IntlDateFormatter $formatter
@param \DateTime $date
@return string | [
"NEXT_MAJOR",
":",
"Change",
"to",
"$date",
"to",
"\\",
"DateTimeInterface",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/DateTimeHelper.php#L154-L159 |
sonata-project/SonataIntlBundle | src/Templating/Helper/DateTimeHelper.php | DateTimeHelper.getDatetime | public function getDatetime($data, $timezone = null)
{
if ($data instanceof \DateTime) {
return $data;
}
if ($data instanceof \DateTimeImmutable) {
return \DateTime::createFromFormat(\DateTime::ATOM, $data->format(\DateTime::ATOM));
}
// the format method accept array or integer
if (is_numeric($data)) {
$data = (int) $data;
}
if (\is_string($data)) {
$data = strtotime($data);
}
$date = new \DateTime();
$date->setTimestamp($data);
$date->setTimezone(new \DateTimeZone($timezone ?: $this->timezoneDetector->getTimezone()));
return $date;
} | php | public function getDatetime($data, $timezone = null)
{
if ($data instanceof \DateTime) {
return $data;
}
if ($data instanceof \DateTimeImmutable) {
return \DateTime::createFromFormat(\DateTime::ATOM, $data->format(\DateTime::ATOM));
}
// the format method accept array or integer
if (is_numeric($data)) {
$data = (int) $data;
}
if (\is_string($data)) {
$data = strtotime($data);
}
$date = new \DateTime();
$date->setTimestamp($data);
$date->setTimezone(new \DateTimeZone($timezone ?: $this->timezoneDetector->getTimezone()));
return $date;
} | [
"public",
"function",
"getDatetime",
"(",
"$",
"data",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"data",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"$",
"data",
";",
"}",
"if",
"(",
"$",
"data",
"instanceof",
"\\",
"DateTi... | Gets a date time instance by a given data and timezone.
@param \DateTime|\DateTimeInterface|string|int $data Value representing date
@param string|null $timezone Timezone of the date
@return \DateTime | [
"Gets",
"a",
"date",
"time",
"instance",
"by",
"a",
"given",
"data",
"and",
"timezone",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/DateTimeHelper.php#L169-L193 |
sonata-project/SonataIntlBundle | src/Templating/Helper/DateTimeHelper.php | DateTimeHelper.createInstance | protected static function createInstance(array $args = [])
{
if (!self::$reflection) {
self::$reflection = new \ReflectionClass('IntlDateFormatter');
}
$instance = self::$reflection->newInstanceArgs($args);
self::checkInternalClass($instance, '\IntlDateFormatter', $args);
return $instance;
} | php | protected static function createInstance(array $args = [])
{
if (!self::$reflection) {
self::$reflection = new \ReflectionClass('IntlDateFormatter');
}
$instance = self::$reflection->newInstanceArgs($args);
self::checkInternalClass($instance, '\IntlDateFormatter', $args);
return $instance;
} | [
"protected",
"static",
"function",
"createInstance",
"(",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"reflection",
")",
"{",
"self",
"::",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"'IntlDateForma... | @param array $args
@return \IntlDateFormatter | [
"@param",
"array",
"$args"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/DateTimeHelper.php#L208-L219 |
sonata-project/SonataIntlBundle | src/Timezone/UserBasedTimezoneDetector.php | UserBasedTimezoneDetector.getTimezone | public function getTimezone()
{
if (!$token = $this->securityContext->getToken()) {
return;
}
if (!$user = $token->getUser()) {
return;
}
if ($user instanceof User) {
return $user->getTimezone();
}
} | php | public function getTimezone()
{
if (!$token = $this->securityContext->getToken()) {
return;
}
if (!$user = $token->getUser()) {
return;
}
if ($user instanceof User) {
return $user->getTimezone();
}
} | [
"public",
"function",
"getTimezone",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"token",
"=",
"$",
"this",
"->",
"securityContext",
"->",
"getToken",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"=",
"$",
"token",
"->",
"getUser",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Timezone/UserBasedTimezoneDetector.php#L47-L60 |
sonata-project/SonataIntlBundle | src/DependencyInjection/SonataIntlExtension.php | SonataIntlExtension.validateTimezones | private function validateTimezones(array $timezones)
{
try {
foreach ($timezones as $timezone) {
$tz = new \DateTimeZone($timezone);
}
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Unknown timezone "%s". Please check your sonata_intl configuration.', $timezone));
}
} | php | private function validateTimezones(array $timezones)
{
try {
foreach ($timezones as $timezone) {
$tz = new \DateTimeZone($timezone);
}
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('Unknown timezone "%s". Please check your sonata_intl configuration.', $timezone));
}
} | [
"private",
"function",
"validateTimezones",
"(",
"array",
"$",
"timezones",
")",
"{",
"try",
"{",
"foreach",
"(",
"$",
"timezones",
"as",
"$",
"timezone",
")",
"{",
"$",
"tz",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"timezone",
")",
";",
"}",
"}",
... | Validate timezones.
@param array $timezones
@throws \RuntimeException If one of the locales is invalid | [
"Validate",
"timezones",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/DependencyInjection/SonataIntlExtension.php#L137-L146 |
sonata-project/SonataIntlBundle | src/DependencyInjection/Compiler/StrictPass.php | StrictPass.process | public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('sonata.intl.locale_detector.request')) {
return;
}
$requestDetector = $container->getDefinition('sonata.intl.locale_detector.request');
$requestDetector->replaceArgument(0, $this->changeReference($requestDetector->getArgument(0), 'service_container'));
if (!$container->hasDefinition('sonata.intl.locale_detector.session')) {
return;
}
$sessionDetector = $container->getDefinition('sonata.intl.locale_detector.session');
$sessionDetector->replaceArgument(0, $this->changeReference($sessionDetector->getArgument(0), 'session'));
} | php | public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('sonata.intl.locale_detector.request')) {
return;
}
$requestDetector = $container->getDefinition('sonata.intl.locale_detector.request');
$requestDetector->replaceArgument(0, $this->changeReference($requestDetector->getArgument(0), 'service_container'));
if (!$container->hasDefinition('sonata.intl.locale_detector.session')) {
return;
}
$sessionDetector = $container->getDefinition('sonata.intl.locale_detector.session');
$sessionDetector->replaceArgument(0, $this->changeReference($sessionDetector->getArgument(0), 'session'));
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"if",
"(",
"!",
"$",
"container",
"->",
"hasDefinition",
"(",
"'sonata.intl.locale_detector.request'",
")",
")",
"{",
"return",
";",
"}",
"$",
"requestDetector",
"=",
"$",
"c... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/DependencyInjection/Compiler/StrictPass.php#L25-L40 |
sonata-project/SonataIntlBundle | src/Templating/Helper/BaseHelper.php | BaseHelper.getICUDataVersion | public static function getICUDataVersion()
{
if (\defined('INTL_ICU_VERSION')) {
return INTL_ICU_VERSION;
}
ob_start();
phpinfo();
$content = ob_get_contents();
ob_end_clean();
$info = explode("\n", $content);
if ('cli' === \PHP_SAPI) {
foreach ($info as $line) {
$results = [];
if (preg_match('/(ICU Data version|ICU version) => (.*)/', $line, $results)) {
return $results[2];
}
}
} else {
foreach ($info as $line) {
$results = [];
if (preg_match('/(ICU Data version).*/', $line, $results)) {
return trim(strtolower(strip_tags($results[0])), 'ICU Data version');
}
if (preg_match('/(ICU version).*/', $line, $results)) {
return trim(strtolower(strip_tags($results[0])), 'icu version');
}
}
}
} | php | public static function getICUDataVersion()
{
if (\defined('INTL_ICU_VERSION')) {
return INTL_ICU_VERSION;
}
ob_start();
phpinfo();
$content = ob_get_contents();
ob_end_clean();
$info = explode("\n", $content);
if ('cli' === \PHP_SAPI) {
foreach ($info as $line) {
$results = [];
if (preg_match('/(ICU Data version|ICU version) => (.*)/', $line, $results)) {
return $results[2];
}
}
} else {
foreach ($info as $line) {
$results = [];
if (preg_match('/(ICU Data version).*/', $line, $results)) {
return trim(strtolower(strip_tags($results[0])), 'ICU Data version');
}
if (preg_match('/(ICU version).*/', $line, $results)) {
return trim(strtolower(strip_tags($results[0])), 'icu version');
}
}
}
} | [
"public",
"static",
"function",
"getICUDataVersion",
"(",
")",
"{",
"if",
"(",
"\\",
"defined",
"(",
"'INTL_ICU_VERSION'",
")",
")",
"{",
"return",
"INTL_ICU_VERSION",
";",
"}",
"ob_start",
"(",
")",
";",
"phpinfo",
"(",
")",
";",
"$",
"content",
"=",
"o... | @static
@return string | [
"@static"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/BaseHelper.php#L72-L106 |
sonata-project/SonataIntlBundle | src/Templating/Helper/BaseHelper.php | BaseHelper.fixCharset | protected function fixCharset($string)
{
if ('UTF-8' !== $this->getCharset()) {
$string = mb_convert_encoding($string, $this->getCharset(), 'UTF-8');
}
return $string;
} | php | protected function fixCharset($string)
{
if ('UTF-8' !== $this->getCharset()) {
$string = mb_convert_encoding($string, $this->getCharset(), 'UTF-8');
}
return $string;
} | [
"protected",
"function",
"fixCharset",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"'UTF-8'",
"!==",
"$",
"this",
"->",
"getCharset",
"(",
")",
")",
"{",
"$",
"string",
"=",
"mb_convert_encoding",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"getCharset",
... | Fixes the charset by converting a string from an UTF-8 charset to the
charset of the kernel.
Precondition: the kernel charset is not UTF-8
@param string $string The string to fix
@return string A string with the %kernel.charset% encoding | [
"Fixes",
"the",
"charset",
"by",
"converting",
"a",
"string",
"from",
"an",
"UTF",
"-",
"8",
"charset",
"to",
"the",
"charset",
"of",
"the",
"kernel",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/BaseHelper.php#L118-L125 |
sonata-project/SonataIntlBundle | src/Templating/Helper/BaseHelper.php | BaseHelper.checkInternalClass | protected static function checkInternalClass($instance, $class, array $args = [])
{
if (null !== $instance) {
return;
}
$messages = [];
foreach ($args as $name => $value) {
$messages[] = sprintf('%s => %s', $name, $value);
}
throw new \RuntimeException(sprintf(
'Unable to create internal class: %s, with params: %s',
$class,
implode(', ', $messages)
));
} | php | protected static function checkInternalClass($instance, $class, array $args = [])
{
if (null !== $instance) {
return;
}
$messages = [];
foreach ($args as $name => $value) {
$messages[] = sprintf('%s => %s', $name, $value);
}
throw new \RuntimeException(sprintf(
'Unable to create internal class: %s, with params: %s',
$class,
implode(', ', $messages)
));
} | [
"protected",
"static",
"function",
"checkInternalClass",
"(",
"$",
"instance",
",",
"$",
"class",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"instance",
")",
"{",
"return",
";",
"}",
"$",
"messages",
"=",
"[",
... | https://wiki.php.net/rfc/internal_constructor_behaviour.
@param mixed $instance
@param string $class
@param array $args | [
"https",
":",
"//",
"wiki",
".",
"php",
".",
"net",
"/",
"rfc",
"/",
"internal_constructor_behaviour",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Templating/Helper/BaseHelper.php#L134-L150 |
sonata-project/SonataIntlBundle | src/Twig/Extension/DateTimeExtension.php | DateTimeExtension.formatDate | public function formatDate($date, $pattern = null, $locale = null, $timezone = null, $dateType = null)
{
if ($pattern) {
return $this->helper->format($date, $pattern, $locale, $timezone);
}
return $this->helper->formatDate($date, $locale, $timezone, $dateType);
} | php | public function formatDate($date, $pattern = null, $locale = null, $timezone = null, $dateType = null)
{
if ($pattern) {
return $this->helper->format($date, $pattern, $locale, $timezone);
}
return $this->helper->formatDate($date, $locale, $timezone, $dateType);
} | [
"public",
"function",
"formatDate",
"(",
"$",
"date",
",",
"$",
"pattern",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
",",
"$",
"dateType",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"pattern",
")",
"{",
"return",
... | @param \Datetime|string|int $date
@param string|null $pattern
@param string|null $locale
@param string|null $timezone
@param string|null $dateType
@return string | [
"@param",
"\\",
"Datetime|string|int",
"$date",
"@param",
"string|null",
"$pattern",
"@param",
"string|null",
"$locale",
"@param",
"string|null",
"$timezone",
"@param",
"string|null",
"$dateType"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Twig/Extension/DateTimeExtension.php#L59-L66 |
sonata-project/SonataIntlBundle | src/Twig/Extension/DateTimeExtension.php | DateTimeExtension.formatTime | public function formatTime($time, $pattern = null, $locale = null, $timezone = null, $timeType = null)
{
if ($pattern) {
return $this->helper->format($time, $pattern, $locale, $timezone);
}
return $this->helper->formatTime($time, $locale, $timezone, $timeType);
} | php | public function formatTime($time, $pattern = null, $locale = null, $timezone = null, $timeType = null)
{
if ($pattern) {
return $this->helper->format($time, $pattern, $locale, $timezone);
}
return $this->helper->formatTime($time, $locale, $timezone, $timeType);
} | [
"public",
"function",
"formatTime",
"(",
"$",
"time",
",",
"$",
"pattern",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
",",
"$",
"timeType",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"pattern",
")",
"{",
"return",
... | @param \Datetime|string|int $time
@param string|null $pattern
@param string|null $locale
@param string|null $timezone
@param string|null $timeType
@return string | [
"@param",
"\\",
"Datetime|string|int",
"$time",
"@param",
"string|null",
"$pattern",
"@param",
"string|null",
"$locale",
"@param",
"string|null",
"$timezone",
"@param",
"string|null",
"$timeType"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Twig/Extension/DateTimeExtension.php#L77-L84 |
sonata-project/SonataIntlBundle | src/Twig/Extension/DateTimeExtension.php | DateTimeExtension.formatDatetime | public function formatDatetime($time, $pattern = null, $locale = null, $timezone = null, $dateType = null, $timeType = null)
{
if ($pattern) {
return $this->helper->format($time, $pattern, $locale, $timezone);
}
return $this->helper->formatDateTime($time, $locale, $timezone, $dateType, $timeType);
} | php | public function formatDatetime($time, $pattern = null, $locale = null, $timezone = null, $dateType = null, $timeType = null)
{
if ($pattern) {
return $this->helper->format($time, $pattern, $locale, $timezone);
}
return $this->helper->formatDateTime($time, $locale, $timezone, $dateType, $timeType);
} | [
"public",
"function",
"formatDatetime",
"(",
"$",
"time",
",",
"$",
"pattern",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
",",
"$",
"dateType",
"=",
"null",
",",
"$",
"timeType",
"=",
"null",
")",
"{",
"if",
"(... | @param \Datetime|string|int $time
@param string|null $pattern
@param string|null $locale
@param string|null $timezone
@param string|null $dateType
@param string|null $timeType
@return string | [
"@param",
"\\",
"Datetime|string|int",
"$time",
"@param",
"string|null",
"$pattern",
"@param",
"string|null",
"$locale",
"@param",
"string|null",
"$timezone",
"@param",
"string|null",
"$dateType",
"@param",
"string|null",
"$timeType"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Twig/Extension/DateTimeExtension.php#L96-L103 |
sonata-project/SonataIntlBundle | src/Timezone/LocaleBasedTimezoneDetector.php | LocaleBasedTimezoneDetector.getTimezone | public function getTimezone()
{
$locale = $this->localeDetector->getLocale();
return isset($this->timezoneMap[$locale]) ? $this->timezoneMap[$locale] : null;
} | php | public function getTimezone()
{
$locale = $this->localeDetector->getLocale();
return isset($this->timezoneMap[$locale]) ? $this->timezoneMap[$locale] : null;
} | [
"public",
"function",
"getTimezone",
"(",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"localeDetector",
"->",
"getLocale",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"timezoneMap",
"[",
"$",
"locale",
"]",
")",
"?",
"$",
"this",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Timezone/LocaleBasedTimezoneDetector.php#L48-L53 |
sonata-project/SonataIntlBundle | src/Twig/Extension/NumberExtension.php | NumberExtension.formatCurrency | public function formatCurrency($number, $currency, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 6, null);
list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
return $this->helper->formatCurrency($number, $currency, $attributes, $textAttributes, $symbols, $locale);
} | php | public function formatCurrency($number, $currency, array $attributes = [], array $textAttributes = [], $locale = null)
{
$methodArgs = array_pad(\func_get_args(), 6, null);
list($locale, $symbols) = $this->helper->normalizeMethodSignature($methodArgs[4], $methodArgs[5]);
return $this->helper->formatCurrency($number, $currency, $attributes, $textAttributes, $symbols, $locale);
} | [
"public",
"function",
"formatCurrency",
"(",
"$",
"number",
",",
"$",
"currency",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"textAttributes",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"methodArgs",
"=",
"... | Formats a number as currency according to the specified locale and
\NumberFormatter attributes.
@param string|float|int $number The number to format
@param string $currency The currency in which format the number
@param array $attributes The attributes used by \NumberFormatter
@param array $textAttributes The text attributes used by \NumberFormatter
@param array $symbols The symbols used by the formatter
@param string|null $locale The locale used to format the number
@return string The formatted number | [
"Formats",
"a",
"number",
"as",
"currency",
"according",
"to",
"the",
"specified",
"locale",
"and",
"\\",
"NumberFormatter",
"attributes",
"."
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Twig/Extension/NumberExtension.php#L77-L84 |
sonata-project/SonataIntlBundle | src/Timezone/ChainTimezoneDetector.php | ChainTimezoneDetector.getTimezone | public function getTimezone()
{
if (!$this->guessedTimezone) {
$availableTimezones = \DateTimeZone::listIdentifiers();
foreach ($this->timezoneDetectors as $timezoneDetector) {
if ($timezone = $timezoneDetector->getTimezone()) {
if (\in_array($timezone, $availableTimezones, true)) {
return $this->guessedTimezone = $timezone;
}
}
}
$this->guessedTimezone = $this->defaultTimezone;
}
return $this->guessedTimezone;
} | php | public function getTimezone()
{
if (!$this->guessedTimezone) {
$availableTimezones = \DateTimeZone::listIdentifiers();
foreach ($this->timezoneDetectors as $timezoneDetector) {
if ($timezone = $timezoneDetector->getTimezone()) {
if (\in_array($timezone, $availableTimezones, true)) {
return $this->guessedTimezone = $timezone;
}
}
}
$this->guessedTimezone = $this->defaultTimezone;
}
return $this->guessedTimezone;
} | [
"public",
"function",
"getTimezone",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"guessedTimezone",
")",
"{",
"$",
"availableTimezones",
"=",
"\\",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"timezoneDe... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataIntlBundle/blob/153971d93f9f3fa1a2e8a4268eb77da812675ae6/src/Timezone/ChainTimezoneDetector.php#L58-L75 |
laravel-auto-presenter/laravel-auto-presenter | src/BasePresenter.php | BasePresenter.resolveRouteBinding | public function resolveRouteBinding($routeKey)
{
if (method_exists($this->wrappedObject, 'resolveRouteBinding') && is_callable([$this->wrappedObject, 'resolveRouteBinding'])) {
return $this->wrappedObject->resolveRouteBinding($routeKey);
}
return $this->wrappedObject->where($this->wrappedObject->getRouteKeyName(), $routeKey)->first();
} | php | public function resolveRouteBinding($routeKey)
{
if (method_exists($this->wrappedObject, 'resolveRouteBinding') && is_callable([$this->wrappedObject, 'resolveRouteBinding'])) {
return $this->wrappedObject->resolveRouteBinding($routeKey);
}
return $this->wrappedObject->where($this->wrappedObject->getRouteKeyName(), $routeKey)->first();
} | [
"public",
"function",
"resolveRouteBinding",
"(",
"$",
"routeKey",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"wrappedObject",
",",
"'resolveRouteBinding'",
")",
"&&",
"is_callable",
"(",
"[",
"$",
"this",
"->",
"wrappedObject",
",",
"'resol... | Retrieve model for route model binding.
@param mixed $routeKey
@return mixed | [
"Retrieve",
"model",
"for",
"route",
"model",
"binding",
"."
] | train | https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/0df80883b7f772359d71f8400677e63a5aaa2487/src/BasePresenter.php#L80-L87 |
laravel-auto-presenter/laravel-auto-presenter | src/BasePresenter.php | BasePresenter.__isset | public function __isset(string $key)
{
if (method_exists($this, $key)) {
return true;
}
return isset($this->wrappedObject->$key);
} | php | public function __isset(string $key)
{
if (method_exists($this, $key)) {
return true;
}
return isset($this->wrappedObject->$key);
} | [
"public",
"function",
"__isset",
"(",
"string",
"$",
"key",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"wrappedObject",
"->",
"$",
"... | Is the key set on either the presenter or the wrapped object?
@param string $key
@return bool | [
"Is",
"the",
"key",
"set",
"on",
"either",
"the",
"presenter",
"or",
"the",
"wrapped",
"object?"
] | train | https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/0df80883b7f772359d71f8400677e63a5aaa2487/src/BasePresenter.php#L133-L140 |
laravel-auto-presenter/laravel-auto-presenter | src/Decorators/AtomDecorator.php | AtomDecorator.decorate | public function decorate($subject)
{
if (is_object($subject)) {
$subject = clone $subject;
}
if ($subject instanceof Model) {
foreach ($subject->getRelations() as $relationName => $model) {
$subject->setRelation($relationName, $this->autoPresenter->decorate($model));
}
}
if (!$subject instanceof HasPresenter) {
return $subject;
}
if (!class_exists($presenter = $subject->getPresenterClass())) {
throw new PresenterNotFoundException($presenter);
}
return $this->container->make($presenter)->setWrappedObject($subject);
} | php | public function decorate($subject)
{
if (is_object($subject)) {
$subject = clone $subject;
}
if ($subject instanceof Model) {
foreach ($subject->getRelations() as $relationName => $model) {
$subject->setRelation($relationName, $this->autoPresenter->decorate($model));
}
}
if (!$subject instanceof HasPresenter) {
return $subject;
}
if (!class_exists($presenter = $subject->getPresenterClass())) {
throw new PresenterNotFoundException($presenter);
}
return $this->container->make($presenter)->setWrappedObject($subject);
} | [
"public",
"function",
"decorate",
"(",
"$",
"subject",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"subject",
")",
")",
"{",
"$",
"subject",
"=",
"clone",
"$",
"subject",
";",
"}",
"if",
"(",
"$",
"subject",
"instanceof",
"Model",
")",
"{",
"foreach"... | Decorate a given subject.
@param object $subject
@return object | [
"Decorate",
"a",
"given",
"subject",
"."
] | train | https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/0df80883b7f772359d71f8400677e63a5aaa2487/src/Decorators/AtomDecorator.php#L73-L94 |
laravel-auto-presenter/laravel-auto-presenter | src/AutoPresenter.php | AutoPresenter.decorate | public function decorate($subject)
{
foreach ($this->decorators as $decorator) {
if ($decorator->canDecorate($subject)) {
return $decorator->decorate($subject);
}
}
return $subject;
} | php | public function decorate($subject)
{
foreach ($this->decorators as $decorator) {
if ($decorator->canDecorate($subject)) {
return $decorator->decorate($subject);
}
}
return $subject;
} | [
"public",
"function",
"decorate",
"(",
"$",
"subject",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"decorators",
"as",
"$",
"decorator",
")",
"{",
"if",
"(",
"$",
"decorator",
"->",
"canDecorate",
"(",
"$",
"subject",
")",
")",
"{",
"return",
"$",
"... | Things go in, get decorated (or not) and are returned.
@param mixed $subject
@return mixed | [
"Things",
"go",
"in",
"get",
"decorated",
"(",
"or",
"not",
")",
"and",
"are",
"returned",
"."
] | train | https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/0df80883b7f772359d71f8400677e63a5aaa2487/src/AutoPresenter.php#L47-L56 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.