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 |
|---|---|---|---|---|---|---|---|---|---|---|
Torann/laravel-currency | src/Middleware/CurrencyMiddleware.php | CurrencyMiddleware.setUserCurrency | private function setUserCurrency($currency, $request)
{
$currency = strtoupper($currency);
// Set user selection globally
currency()->setUserCurrency($currency);
// Save it for later too!
$request->getSession()->put(['currency' => $currency]);
return $currency;
} | php | private function setUserCurrency($currency, $request)
{
$currency = strtoupper($currency);
// Set user selection globally
currency()->setUserCurrency($currency);
// Save it for later too!
$request->getSession()->put(['currency' => $currency]);
return $currency;
} | [
"private",
"function",
"setUserCurrency",
"(",
"$",
"currency",
",",
"$",
"request",
")",
"{",
"$",
"currency",
"=",
"strtoupper",
"(",
"$",
"currency",
")",
";",
"// Set user selection globally",
"currency",
"(",
")",
"->",
"setUserCurrency",
"(",
"$",
"currency",
")",
";",
"// Save it for later too!",
"$",
"request",
"->",
"getSession",
"(",
")",
"->",
"put",
"(",
"[",
"'currency'",
"=>",
"$",
"currency",
"]",
")",
";",
"return",
"$",
"currency",
";",
"}"
] | Set the user currency.
@param string $currency
@param Request $request
@return string | [
"Set",
"the",
"user",
"currency",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Middleware/CurrencyMiddleware.php#L88-L99 |
Torann/laravel-currency | src/Console/Update.php | Update.handle | public function handle()
{
// Get Settings
$defaultCurrency = $this->currency->config('default');
if ($this->input->getOption('google')) {
// Get rates from google
return $this->updateFromGoogle($defaultCurrency);
}
if ($this->input->getOption('openexchangerates')) {
if (!$api = $this->currency->config('api_key')) {
$this->error('An API key is needed from OpenExchangeRates.org to continue.');
return;
}
// Get rates from OpenExchangeRates
return $this->updateFromOpenExchangeRates($defaultCurrency, $api);
}
} | php | public function handle()
{
// Get Settings
$defaultCurrency = $this->currency->config('default');
if ($this->input->getOption('google')) {
// Get rates from google
return $this->updateFromGoogle($defaultCurrency);
}
if ($this->input->getOption('openexchangerates')) {
if (!$api = $this->currency->config('api_key')) {
$this->error('An API key is needed from OpenExchangeRates.org to continue.');
return;
}
// Get rates from OpenExchangeRates
return $this->updateFromOpenExchangeRates($defaultCurrency, $api);
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"// Get Settings",
"$",
"defaultCurrency",
"=",
"$",
"this",
"->",
"currency",
"->",
"config",
"(",
"'default'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'google'",
")",
")",
"{",
"// Get rates from google",
"return",
"$",
"this",
"->",
"updateFromGoogle",
"(",
"$",
"defaultCurrency",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'openexchangerates'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"api",
"=",
"$",
"this",
"->",
"currency",
"->",
"config",
"(",
"'api_key'",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'An API key is needed from OpenExchangeRates.org to continue.'",
")",
";",
"return",
";",
"}",
"// Get rates from OpenExchangeRates",
"return",
"$",
"this",
"->",
"updateFromOpenExchangeRates",
"(",
"$",
"defaultCurrency",
",",
"$",
"api",
")",
";",
"}",
"}"
] | Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Update.php#L59-L79 |
Torann/laravel-currency | src/Console/Update.php | Update.updateFromOpenExchangeRates | private function updateFromOpenExchangeRates($defaultCurrency, $api)
{
$this->info('Updating currency exchange rates from OpenExchangeRates.org...');
// Make request
$content = json_decode($this->request("http://openexchangerates.org/api/latest.json?base={$defaultCurrency}&app_id={$api}&show_alternative=1"));
// Error getting content?
if (isset($content->error)) {
$this->error($content->description);
return;
}
// Parse timestamp for DB
$timestamp = (new DateTime())->setTimestamp($content->timestamp);
// Update each rate
foreach ($content->rates as $code => $value) {
$this->currency->getDriver()->update($code, [
'exchange_rate' => $value,
'updated_at' => $timestamp,
]);
}
$this->currency->clearCache();
$this->info('Update!');
} | php | private function updateFromOpenExchangeRates($defaultCurrency, $api)
{
$this->info('Updating currency exchange rates from OpenExchangeRates.org...');
// Make request
$content = json_decode($this->request("http://openexchangerates.org/api/latest.json?base={$defaultCurrency}&app_id={$api}&show_alternative=1"));
// Error getting content?
if (isset($content->error)) {
$this->error($content->description);
return;
}
// Parse timestamp for DB
$timestamp = (new DateTime())->setTimestamp($content->timestamp);
// Update each rate
foreach ($content->rates as $code => $value) {
$this->currency->getDriver()->update($code, [
'exchange_rate' => $value,
'updated_at' => $timestamp,
]);
}
$this->currency->clearCache();
$this->info('Update!');
} | [
"private",
"function",
"updateFromOpenExchangeRates",
"(",
"$",
"defaultCurrency",
",",
"$",
"api",
")",
"{",
"$",
"this",
"->",
"info",
"(",
"'Updating currency exchange rates from OpenExchangeRates.org...'",
")",
";",
"// Make request",
"$",
"content",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"request",
"(",
"\"http://openexchangerates.org/api/latest.json?base={$defaultCurrency}&app_id={$api}&show_alternative=1\"",
")",
")",
";",
"// Error getting content?",
"if",
"(",
"isset",
"(",
"$",
"content",
"->",
"error",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"content",
"->",
"description",
")",
";",
"return",
";",
"}",
"// Parse timestamp for DB",
"$",
"timestamp",
"=",
"(",
"new",
"DateTime",
"(",
")",
")",
"->",
"setTimestamp",
"(",
"$",
"content",
"->",
"timestamp",
")",
";",
"// Update each rate",
"foreach",
"(",
"$",
"content",
"->",
"rates",
"as",
"$",
"code",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"currency",
"->",
"getDriver",
"(",
")",
"->",
"update",
"(",
"$",
"code",
",",
"[",
"'exchange_rate'",
"=>",
"$",
"value",
",",
"'updated_at'",
"=>",
"$",
"timestamp",
",",
"]",
")",
";",
"}",
"$",
"this",
"->",
"currency",
"->",
"clearCache",
"(",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Update!'",
")",
";",
"}"
] | Fetch rates from the API
@param $defaultCurrency
@param $api | [
"Fetch",
"rates",
"from",
"the",
"API"
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Update.php#L87-L115 |
Torann/laravel-currency | src/Console/Update.php | Update.updateFromGoogle | private function updateFromGoogle($defaultCurrency)
{
$this->info('Updating currency exchange rates from finance.google.com...');
foreach ($this->currency->getDriver()->all() as $code => $value) {
// Don't update the default currency, the value is always 1
if ($code === $defaultCurrency) {
continue;
}
$response = $this->request('http://finance.google.com/finance/converter?a=1&from=' . $defaultCurrency . '&to=' . $code);
if (Str::contains($response, 'bld>')) {
$data = explode('bld>', $response);
$rate = explode($code, $data[1])[0];
$this->currency->getDriver()->update($code, [
'exchange_rate' => $rate,
]);
}
else {
$this->warn('Can\'t update rate for ' . $code);
continue;
}
}
} | php | private function updateFromGoogle($defaultCurrency)
{
$this->info('Updating currency exchange rates from finance.google.com...');
foreach ($this->currency->getDriver()->all() as $code => $value) {
// Don't update the default currency, the value is always 1
if ($code === $defaultCurrency) {
continue;
}
$response = $this->request('http://finance.google.com/finance/converter?a=1&from=' . $defaultCurrency . '&to=' . $code);
if (Str::contains($response, 'bld>')) {
$data = explode('bld>', $response);
$rate = explode($code, $data[1])[0];
$this->currency->getDriver()->update($code, [
'exchange_rate' => $rate,
]);
}
else {
$this->warn('Can\'t update rate for ' . $code);
continue;
}
}
} | [
"private",
"function",
"updateFromGoogle",
"(",
"$",
"defaultCurrency",
")",
"{",
"$",
"this",
"->",
"info",
"(",
"'Updating currency exchange rates from finance.google.com...'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"currency",
"->",
"getDriver",
"(",
")",
"->",
"all",
"(",
")",
"as",
"$",
"code",
"=>",
"$",
"value",
")",
"{",
"// Don't update the default currency, the value is always 1",
"if",
"(",
"$",
"code",
"===",
"$",
"defaultCurrency",
")",
"{",
"continue",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"request",
"(",
"'http://finance.google.com/finance/converter?a=1&from='",
".",
"$",
"defaultCurrency",
".",
"'&to='",
".",
"$",
"code",
")",
";",
"if",
"(",
"Str",
"::",
"contains",
"(",
"$",
"response",
",",
"'bld>'",
")",
")",
"{",
"$",
"data",
"=",
"explode",
"(",
"'bld>'",
",",
"$",
"response",
")",
";",
"$",
"rate",
"=",
"explode",
"(",
"$",
"code",
",",
"$",
"data",
"[",
"1",
"]",
")",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"currency",
"->",
"getDriver",
"(",
")",
"->",
"update",
"(",
"$",
"code",
",",
"[",
"'exchange_rate'",
"=>",
"$",
"rate",
",",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"warn",
"(",
"'Can\\'t update rate for '",
".",
"$",
"code",
")",
";",
"continue",
";",
"}",
"}",
"}"
] | Fetch rates from Google Finance
@param $defaultCurrency | [
"Fetch",
"rates",
"from",
"Google",
"Finance"
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Update.php#L122-L146 |
Torann/laravel-currency | src/Console/Cleanup.php | Cleanup.handle | public function handle()
{
// Clear cache
$this->currency->clearCache();
$this->comment('Currency cache cleaned.');
// Force the system to rebuild cache
$this->currency->getCurrencies();
$this->comment('Currency cache rebuilt.');
} | php | public function handle()
{
// Clear cache
$this->currency->clearCache();
$this->comment('Currency cache cleaned.');
// Force the system to rebuild cache
$this->currency->getCurrencies();
$this->comment('Currency cache rebuilt.');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"// Clear cache",
"$",
"this",
"->",
"currency",
"->",
"clearCache",
"(",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'Currency cache cleaned.'",
")",
";",
"// Force the system to rebuild cache",
"$",
"this",
"->",
"currency",
"->",
"getCurrencies",
"(",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'Currency cache rebuilt.'",
")",
";",
"}"
] | Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Cleanup.php#L55-L64 |
Torann/laravel-currency | src/Drivers/Database.php | Database.create | public function create(array $params)
{
// Ensure the currency doesn't already exist
if ($this->find($params['code'], null) !== null) {
return 'exists';
}
// Created at stamp
$created = new DateTime('now');
$params = array_merge([
'name' => '',
'code' => '',
'symbol' => '',
'format' => '',
'exchange_rate' => 1,
'active' => 0,
'created_at' => $created,
'updated_at' => $created,
], $params);
return $this->database->table($this->config('table'))->insert($params);
} | php | public function create(array $params)
{
// Ensure the currency doesn't already exist
if ($this->find($params['code'], null) !== null) {
return 'exists';
}
// Created at stamp
$created = new DateTime('now');
$params = array_merge([
'name' => '',
'code' => '',
'symbol' => '',
'format' => '',
'exchange_rate' => 1,
'active' => 0,
'created_at' => $created,
'updated_at' => $created,
], $params);
return $this->database->table($this->config('table'))->insert($params);
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"params",
")",
"{",
"// Ensure the currency doesn't already exist",
"if",
"(",
"$",
"this",
"->",
"find",
"(",
"$",
"params",
"[",
"'code'",
"]",
",",
"null",
")",
"!==",
"null",
")",
"{",
"return",
"'exists'",
";",
"}",
"// Created at stamp",
"$",
"created",
"=",
"new",
"DateTime",
"(",
"'now'",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"[",
"'name'",
"=>",
"''",
",",
"'code'",
"=>",
"''",
",",
"'symbol'",
"=>",
"''",
",",
"'format'",
"=>",
"''",
",",
"'exchange_rate'",
"=>",
"1",
",",
"'active'",
"=>",
"0",
",",
"'created_at'",
"=>",
"$",
"created",
",",
"'updated_at'",
"=>",
"$",
"created",
",",
"]",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"database",
"->",
"table",
"(",
"$",
"this",
"->",
"config",
"(",
"'table'",
")",
")",
"->",
"insert",
"(",
"$",
"params",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Drivers/Database.php#L33-L55 |
Torann/laravel-currency | src/Drivers/Database.php | Database.all | public function all()
{
$collection = new Collection($this->database->table($this->config('table'))->get());
return $collection->keyBy('code')
->map(function ($item) {
return [
'id' => $item->id,
'name' => $item->name,
'code' => strtoupper($item->code),
'symbol' => $item->symbol,
'format' => $item->format,
'exchange_rate' => $item->exchange_rate,
'active' => $item->active,
'created_at' => $item->updated_at,
'updated_at' => $item->updated_at,
];
})
->all();
} | php | public function all()
{
$collection = new Collection($this->database->table($this->config('table'))->get());
return $collection->keyBy('code')
->map(function ($item) {
return [
'id' => $item->id,
'name' => $item->name,
'code' => strtoupper($item->code),
'symbol' => $item->symbol,
'format' => $item->format,
'exchange_rate' => $item->exchange_rate,
'active' => $item->active,
'created_at' => $item->updated_at,
'updated_at' => $item->updated_at,
];
})
->all();
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"collection",
"=",
"new",
"Collection",
"(",
"$",
"this",
"->",
"database",
"->",
"table",
"(",
"$",
"this",
"->",
"config",
"(",
"'table'",
")",
")",
"->",
"get",
"(",
")",
")",
";",
"return",
"$",
"collection",
"->",
"keyBy",
"(",
"'code'",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"item",
"->",
"id",
",",
"'name'",
"=>",
"$",
"item",
"->",
"name",
",",
"'code'",
"=>",
"strtoupper",
"(",
"$",
"item",
"->",
"code",
")",
",",
"'symbol'",
"=>",
"$",
"item",
"->",
"symbol",
",",
"'format'",
"=>",
"$",
"item",
"->",
"format",
",",
"'exchange_rate'",
"=>",
"$",
"item",
"->",
"exchange_rate",
",",
"'active'",
"=>",
"$",
"item",
"->",
"active",
",",
"'created_at'",
"=>",
"$",
"item",
"->",
"updated_at",
",",
"'updated_at'",
"=>",
"$",
"item",
"->",
"updated_at",
",",
"]",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Drivers/Database.php#L60-L79 |
Torann/laravel-currency | src/Drivers/Database.php | Database.find | public function find($code, $active = 1)
{
$query = $this->database->table($this->config('table'))
->where('code', strtoupper($code));
// Make active optional
if (is_null($active) === false) {
$query->where('active', $active);
}
return $query->first();
} | php | public function find($code, $active = 1)
{
$query = $this->database->table($this->config('table'))
->where('code', strtoupper($code));
// Make active optional
if (is_null($active) === false) {
$query->where('active', $active);
}
return $query->first();
} | [
"public",
"function",
"find",
"(",
"$",
"code",
",",
"$",
"active",
"=",
"1",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"database",
"->",
"table",
"(",
"$",
"this",
"->",
"config",
"(",
"'table'",
")",
")",
"->",
"where",
"(",
"'code'",
",",
"strtoupper",
"(",
"$",
"code",
")",
")",
";",
"// Make active optional",
"if",
"(",
"is_null",
"(",
"$",
"active",
")",
"===",
"false",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'active'",
",",
"$",
"active",
")",
";",
"}",
"return",
"$",
"query",
"->",
"first",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Drivers/Database.php#L84-L95 |
Torann/laravel-currency | src/Drivers/Filesystem.php | Filesystem.create | public function create(array $params)
{
// Get blacklist path
$path = $this->config('path');
// Get all as an array
$currencies = $this->all();
// Verify the currency doesn't exists
if (isset($currencies[$params['code']]) === true) {
return 'exists';
}
// Created at stamp
$created = (new DateTime('now'))->format('Y-m-d H:i:s');
$currencies[$params['code']] = array_merge([
'name' => '',
'code' => '',
'symbol' => '',
'format' => '',
'exchange_rate' => 1,
'active' => 0,
'created_at' => $created,
'updated_at' => $created,
], $params);
return $this->filesystem->put($path, json_encode($currencies, JSON_PRETTY_PRINT));
} | php | public function create(array $params)
{
// Get blacklist path
$path = $this->config('path');
// Get all as an array
$currencies = $this->all();
// Verify the currency doesn't exists
if (isset($currencies[$params['code']]) === true) {
return 'exists';
}
// Created at stamp
$created = (new DateTime('now'))->format('Y-m-d H:i:s');
$currencies[$params['code']] = array_merge([
'name' => '',
'code' => '',
'symbol' => '',
'format' => '',
'exchange_rate' => 1,
'active' => 0,
'created_at' => $created,
'updated_at' => $created,
], $params);
return $this->filesystem->put($path, json_encode($currencies, JSON_PRETTY_PRINT));
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"params",
")",
"{",
"// Get blacklist path",
"$",
"path",
"=",
"$",
"this",
"->",
"config",
"(",
"'path'",
")",
";",
"// Get all as an array",
"$",
"currencies",
"=",
"$",
"this",
"->",
"all",
"(",
")",
";",
"// Verify the currency doesn't exists",
"if",
"(",
"isset",
"(",
"$",
"currencies",
"[",
"$",
"params",
"[",
"'code'",
"]",
"]",
")",
"===",
"true",
")",
"{",
"return",
"'exists'",
";",
"}",
"// Created at stamp",
"$",
"created",
"=",
"(",
"new",
"DateTime",
"(",
"'now'",
")",
")",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"currencies",
"[",
"$",
"params",
"[",
"'code'",
"]",
"]",
"=",
"array_merge",
"(",
"[",
"'name'",
"=>",
"''",
",",
"'code'",
"=>",
"''",
",",
"'symbol'",
"=>",
"''",
",",
"'format'",
"=>",
"''",
",",
"'exchange_rate'",
"=>",
"1",
",",
"'active'",
"=>",
"0",
",",
"'created_at'",
"=>",
"$",
"created",
",",
"'updated_at'",
"=>",
"$",
"created",
",",
"]",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"filesystem",
"->",
"put",
"(",
"$",
"path",
",",
"json_encode",
"(",
"$",
"currencies",
",",
"JSON_PRETTY_PRINT",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Drivers/Filesystem.php#L34-L62 |
Torann/laravel-currency | src/Drivers/Filesystem.php | Filesystem.update | public function update($code, array $attributes, DateTime $timestamp = null)
{
// Get blacklist path
$path = $this->config('path');
// Get all as an array
$currencies = $this->all();
// Verify the currency exists
if (isset($currencies[$code]) === false) {
return 'doesn\'t exists';
}
// Create timestamp
if (empty($attributes['updated_at']) === true) {
$attributes['updated_at'] = (new DateTime('now'))->format('Y-m-d H:i:s');
}
// Merge values
$currencies[$code] = array_merge($currencies[$code], $attributes);
return $this->filesystem->put($path, json_encode($currencies, JSON_PRETTY_PRINT));
} | php | public function update($code, array $attributes, DateTime $timestamp = null)
{
// Get blacklist path
$path = $this->config('path');
// Get all as an array
$currencies = $this->all();
// Verify the currency exists
if (isset($currencies[$code]) === false) {
return 'doesn\'t exists';
}
// Create timestamp
if (empty($attributes['updated_at']) === true) {
$attributes['updated_at'] = (new DateTime('now'))->format('Y-m-d H:i:s');
}
// Merge values
$currencies[$code] = array_merge($currencies[$code], $attributes);
return $this->filesystem->put($path, json_encode($currencies, JSON_PRETTY_PRINT));
} | [
"public",
"function",
"update",
"(",
"$",
"code",
",",
"array",
"$",
"attributes",
",",
"DateTime",
"$",
"timestamp",
"=",
"null",
")",
"{",
"// Get blacklist path",
"$",
"path",
"=",
"$",
"this",
"->",
"config",
"(",
"'path'",
")",
";",
"// Get all as an array",
"$",
"currencies",
"=",
"$",
"this",
"->",
"all",
"(",
")",
";",
"// Verify the currency exists",
"if",
"(",
"isset",
"(",
"$",
"currencies",
"[",
"$",
"code",
"]",
")",
"===",
"false",
")",
"{",
"return",
"'doesn\\'t exists'",
";",
"}",
"// Create timestamp",
"if",
"(",
"empty",
"(",
"$",
"attributes",
"[",
"'updated_at'",
"]",
")",
"===",
"true",
")",
"{",
"$",
"attributes",
"[",
"'updated_at'",
"]",
"=",
"(",
"new",
"DateTime",
"(",
"'now'",
")",
")",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"}",
"// Merge values",
"$",
"currencies",
"[",
"$",
"code",
"]",
"=",
"array_merge",
"(",
"$",
"currencies",
"[",
"$",
"code",
"]",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
"->",
"filesystem",
"->",
"put",
"(",
"$",
"path",
",",
"json_encode",
"(",
"$",
"currencies",
",",
"JSON_PRETTY_PRINT",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Drivers/Filesystem.php#L98-L120 |
Torann/laravel-currency | src/Drivers/Filesystem.php | Filesystem.delete | public function delete($code)
{
// Get blacklist path
$path = $this->config('path');
// Get all as an array
$currencies = $this->all();
// Verify the currency exists
if (isset($currencies[$code]) === false) {
return false;
}
unset($currencies[$code]);
return $this->filesystem->put($path, json_encode($currencies, JSON_PRETTY_PRINT));
} | php | public function delete($code)
{
// Get blacklist path
$path = $this->config('path');
// Get all as an array
$currencies = $this->all();
// Verify the currency exists
if (isset($currencies[$code]) === false) {
return false;
}
unset($currencies[$code]);
return $this->filesystem->put($path, json_encode($currencies, JSON_PRETTY_PRINT));
} | [
"public",
"function",
"delete",
"(",
"$",
"code",
")",
"{",
"// Get blacklist path",
"$",
"path",
"=",
"$",
"this",
"->",
"config",
"(",
"'path'",
")",
";",
"// Get all as an array",
"$",
"currencies",
"=",
"$",
"this",
"->",
"all",
"(",
")",
";",
"// Verify the currency exists",
"if",
"(",
"isset",
"(",
"$",
"currencies",
"[",
"$",
"code",
"]",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"unset",
"(",
"$",
"currencies",
"[",
"$",
"code",
"]",
")",
";",
"return",
"$",
"this",
"->",
"filesystem",
"->",
"put",
"(",
"$",
"path",
",",
"json_encode",
"(",
"$",
"currencies",
",",
"JSON_PRETTY_PRINT",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Drivers/Filesystem.php#L125-L141 |
Torann/laravel-currency | src/CurrencyServiceProvider.php | CurrencyServiceProvider.register | public function register()
{
$this->registerCurrency();
if ($this->app->runningInConsole()) {
$this->registerResources();
$this->registerCurrencyCommands();
}
} | php | public function register()
{
$this->registerCurrency();
if ($this->app->runningInConsole()) {
$this->registerResources();
$this->registerCurrencyCommands();
}
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"registerCurrency",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"runningInConsole",
"(",
")",
")",
"{",
"$",
"this",
"->",
"registerResources",
"(",
")",
";",
"$",
"this",
"->",
"registerCurrencyCommands",
"(",
")",
";",
"}",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/CurrencyServiceProvider.php#L14-L22 |
Torann/laravel-currency | src/CurrencyServiceProvider.php | CurrencyServiceProvider.registerResources | public function registerResources()
{
if ($this->isLumen() === false) {
$this->publishes([
__DIR__ . '/../config/currency.php' => config_path('currency.php'),
], 'config');
$this->mergeConfigFrom(
__DIR__ . '/../config/currency.php', 'currency'
);
}
$this->publishes([
__DIR__ . '/../database/migrations' => base_path('/database/migrations'),
], 'migrations');
} | php | public function registerResources()
{
if ($this->isLumen() === false) {
$this->publishes([
__DIR__ . '/../config/currency.php' => config_path('currency.php'),
], 'config');
$this->mergeConfigFrom(
__DIR__ . '/../config/currency.php', 'currency'
);
}
$this->publishes([
__DIR__ . '/../database/migrations' => base_path('/database/migrations'),
], 'migrations');
} | [
"public",
"function",
"registerResources",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isLumen",
"(",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../config/currency.php'",
"=>",
"config_path",
"(",
"'currency.php'",
")",
",",
"]",
",",
"'config'",
")",
";",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"__DIR__",
".",
"'/../config/currency.php'",
",",
"'currency'",
")",
";",
"}",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../database/migrations'",
"=>",
"base_path",
"(",
"'/database/migrations'",
")",
",",
"]",
",",
"'migrations'",
")",
";",
"}"
] | Register currency resources.
@return void | [
"Register",
"currency",
"resources",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/CurrencyServiceProvider.php#L44-L59 |
Torann/laravel-currency | src/Console/Manage.php | Manage.handle | public function handle()
{
$action = $this->getActionArgument(['add', 'update', 'delete']);
foreach ($this->getCurrencyArgument() as $currency) {
$this->$action(strtoupper($currency));
}
} | php | public function handle()
{
$action = $this->getActionArgument(['add', 'update', 'delete']);
foreach ($this->getCurrencyArgument() as $currency) {
$this->$action(strtoupper($currency));
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"getActionArgument",
"(",
"[",
"'add'",
",",
"'update'",
",",
"'delete'",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getCurrencyArgument",
"(",
")",
"as",
"$",
"currency",
")",
"{",
"$",
"this",
"->",
"$",
"action",
"(",
"strtoupper",
"(",
"$",
"currency",
")",
")",
";",
"}",
"}"
] | Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Manage.php#L66-L73 |
Torann/laravel-currency | src/Console/Manage.php | Manage.update | protected function update($currency)
{
if (($data = $this->getCurrency($currency)) === null) {
return $this->error("Currency \"{$currency}\" not found");
}
$this->output->write("Updating {$currency} currency...");
if (is_string($result = $this->storage->update($currency, $data))) {
$this->output->writeln('<error>' . ($result ?: 'Failed') . '</error>');
}
else {
$this->output->writeln("<info>success</info>");
}
} | php | protected function update($currency)
{
if (($data = $this->getCurrency($currency)) === null) {
return $this->error("Currency \"{$currency}\" not found");
}
$this->output->write("Updating {$currency} currency...");
if (is_string($result = $this->storage->update($currency, $data))) {
$this->output->writeln('<error>' . ($result ?: 'Failed') . '</error>');
}
else {
$this->output->writeln("<info>success</info>");
}
} | [
"protected",
"function",
"update",
"(",
"$",
"currency",
")",
"{",
"if",
"(",
"(",
"$",
"data",
"=",
"$",
"this",
"->",
"getCurrency",
"(",
"$",
"currency",
")",
")",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"\"Currency \\\"{$currency}\\\" not found\"",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"write",
"(",
"\"Updating {$currency} currency...\"",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"storage",
"->",
"update",
"(",
"$",
"currency",
",",
"$",
"data",
")",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'<error>'",
".",
"(",
"$",
"result",
"?",
":",
"'Failed'",
")",
".",
"'</error>'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<info>success</info>\"",
")",
";",
"}",
"}"
] | Update currency in storage.
@param string $currency
@return void | [
"Update",
"currency",
"in",
"storage",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Manage.php#L107-L121 |
Torann/laravel-currency | src/Console/Manage.php | Manage.delete | protected function delete($currency)
{
$this->output->write("Deleting {$currency} currency...");
if (is_string($result = $this->storage->delete($currency))) {
$this->output->writeln('<error>' . ($result ?: 'Failed') . '</error>');
}
else {
$this->output->writeln("<info>success</info>");
}
} | php | protected function delete($currency)
{
$this->output->write("Deleting {$currency} currency...");
if (is_string($result = $this->storage->delete($currency))) {
$this->output->writeln('<error>' . ($result ?: 'Failed') . '</error>');
}
else {
$this->output->writeln("<info>success</info>");
}
} | [
"protected",
"function",
"delete",
"(",
"$",
"currency",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"write",
"(",
"\"Deleting {$currency} currency...\"",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"storage",
"->",
"delete",
"(",
"$",
"currency",
")",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'<error>'",
".",
"(",
"$",
"result",
"?",
":",
"'Failed'",
")",
".",
"'</error>'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<info>success</info>\"",
")",
";",
"}",
"}"
] | Delete currency from storage.
@param string $currency
@return void | [
"Delete",
"currency",
"from",
"storage",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Manage.php#L130-L140 |
Torann/laravel-currency | src/Console/Manage.php | Manage.getCurrencyArgument | protected function getCurrencyArgument()
{
// Get the user entered value
$value = preg_replace('/\s+/', '', $this->argument('currency'));
// Return all currencies if requested
if ($value === 'all') {
return array_keys($this->currencies);
}
return explode(',', $value);
} | php | protected function getCurrencyArgument()
{
// Get the user entered value
$value = preg_replace('/\s+/', '', $this->argument('currency'));
// Return all currencies if requested
if ($value === 'all') {
return array_keys($this->currencies);
}
return explode(',', $value);
} | [
"protected",
"function",
"getCurrencyArgument",
"(",
")",
"{",
"// Get the user entered value",
"$",
"value",
"=",
"preg_replace",
"(",
"'/\\s+/'",
",",
"''",
",",
"$",
"this",
"->",
"argument",
"(",
"'currency'",
")",
")",
";",
"// Return all currencies if requested",
"if",
"(",
"$",
"value",
"===",
"'all'",
")",
"{",
"return",
"array_keys",
"(",
"$",
"this",
"->",
"currencies",
")",
";",
"}",
"return",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"}"
] | Get currency argument.
@return array | [
"Get",
"currency",
"argument",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Manage.php#L147-L158 |
Torann/laravel-currency | src/Console/Manage.php | Manage.getActionArgument | protected function getActionArgument($validActions = [])
{
$action = strtolower($this->argument('action'));
if (in_array($action, $validActions) === false) {
throw new \RuntimeException("The \"{$action}\" option does not exist.");
}
return $action;
} | php | protected function getActionArgument($validActions = [])
{
$action = strtolower($this->argument('action'));
if (in_array($action, $validActions) === false) {
throw new \RuntimeException("The \"{$action}\" option does not exist.");
}
return $action;
} | [
"protected",
"function",
"getActionArgument",
"(",
"$",
"validActions",
"=",
"[",
"]",
")",
"{",
"$",
"action",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"argument",
"(",
"'action'",
")",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"action",
",",
"$",
"validActions",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"The \\\"{$action}\\\" option does not exist.\"",
")",
";",
"}",
"return",
"$",
"action",
";",
"}"
] | Get action argument.
@param array $validActions
@return array | [
"Get",
"action",
"argument",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Console/Manage.php#L167-L176 |
Torann/laravel-currency | database/migrations/2013_11_26_161501_create_currency_table.php | CreateCurrencyTable.up | public function up()
{
Schema::create($this->table_name, function ($table) {
$table->increments('id')->unsigned();
$table->string('name');
$table->string('code', 10)->index();
$table->string('symbol', 25);
$table->string('format', 50);
$table->string('exchange_rate');
$table->boolean('active')->default(false);
$table->timestamps();
});
} | php | public function up()
{
Schema::create($this->table_name, function ($table) {
$table->increments('id')->unsigned();
$table->string('name');
$table->string('code', 10)->index();
$table->string('symbol', 25);
$table->string('format', 50);
$table->string('exchange_rate');
$table->boolean('active')->default(false);
$table->timestamps();
});
} | [
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"create",
"(",
"$",
"this",
"->",
"table_name",
",",
"function",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"increments",
"(",
"'id'",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'name'",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'code'",
",",
"10",
")",
"->",
"index",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'symbol'",
",",
"25",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'format'",
",",
"50",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'exchange_rate'",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'active'",
")",
"->",
"default",
"(",
"false",
")",
";",
"$",
"table",
"->",
"timestamps",
"(",
")",
";",
"}",
")",
";",
"}"
] | Run the migrations.
@return void | [
"Run",
"the",
"migrations",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/database/migrations/2013_11_26_161501_create_currency_table.php#L27-L39 |
Torann/laravel-currency | src/Currency.php | Currency.format | public function format($value, $code = null, $include_symbol = true)
{
// Get default currency if one is not set
$code = $code ?: $this->config('default');
// Remove unnecessary characters
$value = preg_replace('/[\s\',!]/', '', $value);
// Check for a custom formatter
if ($formatter = $this->getFormatter()) {
return $formatter->format($value, $code);
}
// Get the measurement format
$format = $this->getCurrencyProp($code, 'format');
// Value Regex
$valRegex = '/([0-9].*|)[0-9]/';
// Match decimal and thousand separators
preg_match_all('/[\s\',.!]/', $format, $separators);
if ($thousand = array_get($separators, '0.0', null)) {
if ($thousand == '!') {
$thousand = '';
}
}
$decimal = array_get($separators, '0.1', null);
// Match format for decimals count
preg_match($valRegex, $format, $valFormat);
$valFormat = array_get($valFormat, 0, 0);
// Count decimals length
$decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0;
// Do we have a negative value?
if ($negative = $value < 0 ? '-' : '') {
$value = $value * -1;
}
// Format the value
$value = number_format($value, $decimals, $decimal, $thousand);
// Apply the formatted measurement
if ($include_symbol) {
$value = preg_replace($valRegex, $value, $format);
}
// Return value
return $negative . $value;
} | php | public function format($value, $code = null, $include_symbol = true)
{
// Get default currency if one is not set
$code = $code ?: $this->config('default');
// Remove unnecessary characters
$value = preg_replace('/[\s\',!]/', '', $value);
// Check for a custom formatter
if ($formatter = $this->getFormatter()) {
return $formatter->format($value, $code);
}
// Get the measurement format
$format = $this->getCurrencyProp($code, 'format');
// Value Regex
$valRegex = '/([0-9].*|)[0-9]/';
// Match decimal and thousand separators
preg_match_all('/[\s\',.!]/', $format, $separators);
if ($thousand = array_get($separators, '0.0', null)) {
if ($thousand == '!') {
$thousand = '';
}
}
$decimal = array_get($separators, '0.1', null);
// Match format for decimals count
preg_match($valRegex, $format, $valFormat);
$valFormat = array_get($valFormat, 0, 0);
// Count decimals length
$decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0;
// Do we have a negative value?
if ($negative = $value < 0 ? '-' : '') {
$value = $value * -1;
}
// Format the value
$value = number_format($value, $decimals, $decimal, $thousand);
// Apply the formatted measurement
if ($include_symbol) {
$value = preg_replace($valRegex, $value, $format);
}
// Return value
return $negative . $value;
} | [
"public",
"function",
"format",
"(",
"$",
"value",
",",
"$",
"code",
"=",
"null",
",",
"$",
"include_symbol",
"=",
"true",
")",
"{",
"// Get default currency if one is not set\r",
"$",
"code",
"=",
"$",
"code",
"?",
":",
"$",
"this",
"->",
"config",
"(",
"'default'",
")",
";",
"// Remove unnecessary characters\r",
"$",
"value",
"=",
"preg_replace",
"(",
"'/[\\s\\',!]/'",
",",
"''",
",",
"$",
"value",
")",
";",
"// Check for a custom formatter\r",
"if",
"(",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
")",
")",
"{",
"return",
"$",
"formatter",
"->",
"format",
"(",
"$",
"value",
",",
"$",
"code",
")",
";",
"}",
"// Get the measurement format\r",
"$",
"format",
"=",
"$",
"this",
"->",
"getCurrencyProp",
"(",
"$",
"code",
",",
"'format'",
")",
";",
"// Value Regex\r",
"$",
"valRegex",
"=",
"'/([0-9].*|)[0-9]/'",
";",
"// Match decimal and thousand separators\r",
"preg_match_all",
"(",
"'/[\\s\\',.!]/'",
",",
"$",
"format",
",",
"$",
"separators",
")",
";",
"if",
"(",
"$",
"thousand",
"=",
"array_get",
"(",
"$",
"separators",
",",
"'0.0'",
",",
"null",
")",
")",
"{",
"if",
"(",
"$",
"thousand",
"==",
"'!'",
")",
"{",
"$",
"thousand",
"=",
"''",
";",
"}",
"}",
"$",
"decimal",
"=",
"array_get",
"(",
"$",
"separators",
",",
"'0.1'",
",",
"null",
")",
";",
"// Match format for decimals count\r",
"preg_match",
"(",
"$",
"valRegex",
",",
"$",
"format",
",",
"$",
"valFormat",
")",
";",
"$",
"valFormat",
"=",
"array_get",
"(",
"$",
"valFormat",
",",
"0",
",",
"0",
")",
";",
"// Count decimals length\r",
"$",
"decimals",
"=",
"$",
"decimal",
"?",
"strlen",
"(",
"substr",
"(",
"strrchr",
"(",
"$",
"valFormat",
",",
"$",
"decimal",
")",
",",
"1",
")",
")",
":",
"0",
";",
"// Do we have a negative value?\r",
"if",
"(",
"$",
"negative",
"=",
"$",
"value",
"<",
"0",
"?",
"'-'",
":",
"''",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"*",
"-",
"1",
";",
"}",
"// Format the value\r",
"$",
"value",
"=",
"number_format",
"(",
"$",
"value",
",",
"$",
"decimals",
",",
"$",
"decimal",
",",
"$",
"thousand",
")",
";",
"// Apply the formatted measurement\r",
"if",
"(",
"$",
"include_symbol",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"$",
"valRegex",
",",
"$",
"value",
",",
"$",
"format",
")",
";",
"}",
"// Return value\r",
"return",
"$",
"negative",
".",
"$",
"value",
";",
"}"
] | Format the value into the desired currency.
@param float $value
@param string $code
@param bool $include_symbol
@return string | [
"Format",
"the",
"value",
"into",
"the",
"desired",
"currency",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Currency.php#L115-L168 |
Torann/laravel-currency | src/Currency.php | Currency.isActive | public function isActive($code)
{
return $code && (bool) Arr::get($this->getCurrency($code), 'active', false);
} | php | public function isActive($code)
{
return $code && (bool) Arr::get($this->getCurrency($code), 'active', false);
} | [
"public",
"function",
"isActive",
"(",
"$",
"code",
")",
"{",
"return",
"$",
"code",
"&&",
"(",
"bool",
")",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"getCurrency",
"(",
"$",
"code",
")",
",",
"'active'",
",",
"false",
")",
";",
"}"
] | Determine if the provided currency is active.
@param string $code
@return bool | [
"Determine",
"if",
"the",
"provided",
"currency",
"is",
"active",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Currency.php#L209-L212 |
Torann/laravel-currency | src/Currency.php | Currency.getCurrency | public function getCurrency($code = null)
{
$code = $code ?: $this->getUserCurrency();
return Arr::get($this->getCurrencies(), strtoupper($code));
} | php | public function getCurrency($code = null)
{
$code = $code ?: $this->getUserCurrency();
return Arr::get($this->getCurrencies(), strtoupper($code));
} | [
"public",
"function",
"getCurrency",
"(",
"$",
"code",
"=",
"null",
")",
"{",
"$",
"code",
"=",
"$",
"code",
"?",
":",
"$",
"this",
"->",
"getUserCurrency",
"(",
")",
";",
"return",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"getCurrencies",
"(",
")",
",",
"strtoupper",
"(",
"$",
"code",
")",
")",
";",
"}"
] | Return the current currency if the
one supplied is not valid.
@param string $code
@return array|null | [
"Return",
"the",
"current",
"currency",
"if",
"the",
"one",
"supplied",
"is",
"not",
"valid",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Currency.php#L222-L227 |
Torann/laravel-currency | src/Currency.php | Currency.getCurrencies | public function getCurrencies()
{
if ($this->currencies_cache === null) {
if (config('app.debug', false) === true) {
$this->currencies_cache = $this->getDriver()->all();
}
else {
$this->currencies_cache = $this->cache->rememberForever('torann.currency', function () {
return $this->getDriver()->all();
});
}
}
return $this->currencies_cache;
} | php | public function getCurrencies()
{
if ($this->currencies_cache === null) {
if (config('app.debug', false) === true) {
$this->currencies_cache = $this->getDriver()->all();
}
else {
$this->currencies_cache = $this->cache->rememberForever('torann.currency', function () {
return $this->getDriver()->all();
});
}
}
return $this->currencies_cache;
} | [
"public",
"function",
"getCurrencies",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currencies_cache",
"===",
"null",
")",
"{",
"if",
"(",
"config",
"(",
"'app.debug'",
",",
"false",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"currencies_cache",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"all",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"currencies_cache",
"=",
"$",
"this",
"->",
"cache",
"->",
"rememberForever",
"(",
"'torann.currency'",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"all",
"(",
")",
";",
"}",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"currencies_cache",
";",
"}"
] | Return all currencies.
@return array | [
"Return",
"all",
"currencies",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Currency.php#L234-L248 |
Torann/laravel-currency | src/Currency.php | Currency.getDriver | public function getDriver()
{
if ($this->driver === null) {
// Get driver configuration
$config = $this->config('drivers.' . $this->config('driver'), []);
// Get driver class
$driver = Arr::pull($config, 'class');
// Create driver instance
$this->driver = new $driver($config);
}
return $this->driver;
} | php | public function getDriver()
{
if ($this->driver === null) {
// Get driver configuration
$config = $this->config('drivers.' . $this->config('driver'), []);
// Get driver class
$driver = Arr::pull($config, 'class');
// Create driver instance
$this->driver = new $driver($config);
}
return $this->driver;
} | [
"public",
"function",
"getDriver",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"driver",
"===",
"null",
")",
"{",
"// Get driver configuration\r",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"(",
"'drivers.'",
".",
"$",
"this",
"->",
"config",
"(",
"'driver'",
")",
",",
"[",
"]",
")",
";",
"// Get driver class\r",
"$",
"driver",
"=",
"Arr",
"::",
"pull",
"(",
"$",
"config",
",",
"'class'",
")",
";",
"// Create driver instance\r",
"$",
"this",
"->",
"driver",
"=",
"new",
"$",
"driver",
"(",
"$",
"config",
")",
";",
"}",
"return",
"$",
"this",
"->",
"driver",
";",
"}"
] | Get storage driver.
@return \Torann\Currency\Contracts\DriverInterface | [
"Get",
"storage",
"driver",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Currency.php#L267-L281 |
Torann/laravel-currency | src/Currency.php | Currency.getFormatter | public function getFormatter()
{
if ($this->formatter === null && $this->config('formatter') !== null) {
// Get formatter configuration
$config = $this->config('formatters.' . $this->config('formatter'), []);
// Get formatter class
$class = Arr::pull($config, 'class');
// Create formatter instance
$this->formatter = new $class(array_filter($config));
}
return $this->formatter;
} | php | public function getFormatter()
{
if ($this->formatter === null && $this->config('formatter') !== null) {
// Get formatter configuration
$config = $this->config('formatters.' . $this->config('formatter'), []);
// Get formatter class
$class = Arr::pull($config, 'class');
// Create formatter instance
$this->formatter = new $class(array_filter($config));
}
return $this->formatter;
} | [
"public",
"function",
"getFormatter",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"formatter",
"===",
"null",
"&&",
"$",
"this",
"->",
"config",
"(",
"'formatter'",
")",
"!==",
"null",
")",
"{",
"// Get formatter configuration\r",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"(",
"'formatters.'",
".",
"$",
"this",
"->",
"config",
"(",
"'formatter'",
")",
",",
"[",
"]",
")",
";",
"// Get formatter class\r",
"$",
"class",
"=",
"Arr",
"::",
"pull",
"(",
"$",
"config",
",",
"'class'",
")",
";",
"// Create formatter instance\r",
"$",
"this",
"->",
"formatter",
"=",
"new",
"$",
"class",
"(",
"array_filter",
"(",
"$",
"config",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatter",
";",
"}"
] | Get formatter driver.
@return \Torann\Currency\Contracts\FormatterInterface | [
"Get",
"formatter",
"driver",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Currency.php#L288-L302 |
Torann/laravel-currency | src/Currency.php | Currency.config | public function config($key = null, $default = null)
{
if ($key === null) {
return $this->config;
}
return Arr::get($this->config, $key, $default);
} | php | public function config($key = null, $default = null)
{
if ($key === null) {
return $this->config;
}
return Arr::get($this->config, $key, $default);
} | [
"public",
"function",
"config",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"config",
";",
"}",
"return",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] | Get configuration value.
@param string $key
@param mixed $default
@return mixed | [
"Get",
"configuration",
"value",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Currency.php#L321-L328 |
Torann/laravel-currency | src/Currency.php | Currency.getCurrencyProp | protected function getCurrencyProp($code, $key, $default = null)
{
return Arr::get($this->getCurrency($code), $key, $default);
} | php | protected function getCurrencyProp($code, $key, $default = null)
{
return Arr::get($this->getCurrency($code), $key, $default);
} | [
"protected",
"function",
"getCurrencyProp",
"(",
"$",
"code",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"return",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"getCurrency",
"(",
"$",
"code",
")",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] | Get the given property value from provided currency.
@param string $code
@param string $key
@param mixed $default
@return array | [
"Get",
"the",
"given",
"property",
"value",
"from",
"provided",
"currency",
"."
] | train | https://github.com/Torann/laravel-currency/blob/69841ec5390d9c45bfbbb6a26495ba09d7476c59/src/Currency.php#L339-L342 |
michaeldyrynda/laravel-make-user | src/MakeUserServiceProvider.php | MakeUserServiceProvider.register | public function register()
{
$this->app->singleton('dyrynda.artisan.make:user', function ($app) {
return $app->make(MakeUser::class);
});
$this->commands('dyrynda.artisan.make:user');
} | php | public function register()
{
$this->app->singleton('dyrynda.artisan.make:user', function ($app) {
return $app->make(MakeUser::class);
});
$this->commands('dyrynda.artisan.make:user');
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'dyrynda.artisan.make:user'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"->",
"make",
"(",
"MakeUser",
"::",
"class",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"commands",
"(",
"'dyrynda.artisan.make:user'",
")",
";",
"}"
] | Register the application services.
@return void | [
"Register",
"the",
"application",
"services",
"."
] | train | https://github.com/michaeldyrynda/laravel-make-user/blob/8d4cd8bef67c202419f9dcbc04d7dd03e473a146/src/MakeUserServiceProvider.php#L15-L22 |
michaeldyrynda/laravel-make-user | src/Console/Commands/MakeUser.php | MakeUser.handle | public function handle()
{
$email = $this->ask("What is the new user's email address?");
$name = $this->ask("What is the new user's name?") ?: '';
$password = bcrypt($this->secret("What is the new user's password? (blank generates a random one)", str_random(32)));
$sendReset = $this->confirm('Do you want to send a password reset email?');
while ($custom = $this->ask('Do you have any custom user fields to add? Field=Value (blank continues)', false)) {
list($key, $value) = explode('=', $custom);
$this->customFields[$key] = value($value);
}
try {
app('db')->beginTransaction();
$this->validateEmail($email);
app(config('auth.providers.users.model'))->create(array_merge(
compact('email', 'name', 'password'),
$this->customFields
));
if ($sendReset) {
Password::sendResetLink(compact('email'));
$this->info("Sent password reset email to {$email}");
}
$this->info("Created new user for email {$email}");
app('db')->commit();
} catch (Exception $e) {
$this->error($e->getMessage());
$this->error('The user was not created');
app('db')->rollBack();
}
} | php | public function handle()
{
$email = $this->ask("What is the new user's email address?");
$name = $this->ask("What is the new user's name?") ?: '';
$password = bcrypt($this->secret("What is the new user's password? (blank generates a random one)", str_random(32)));
$sendReset = $this->confirm('Do you want to send a password reset email?');
while ($custom = $this->ask('Do you have any custom user fields to add? Field=Value (blank continues)', false)) {
list($key, $value) = explode('=', $custom);
$this->customFields[$key] = value($value);
}
try {
app('db')->beginTransaction();
$this->validateEmail($email);
app(config('auth.providers.users.model'))->create(array_merge(
compact('email', 'name', 'password'),
$this->customFields
));
if ($sendReset) {
Password::sendResetLink(compact('email'));
$this->info("Sent password reset email to {$email}");
}
$this->info("Created new user for email {$email}");
app('db')->commit();
} catch (Exception $e) {
$this->error($e->getMessage());
$this->error('The user was not created');
app('db')->rollBack();
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"email",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"What is the new user's email address?\"",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"What is the new user's name?\"",
")",
"?",
":",
"''",
";",
"$",
"password",
"=",
"bcrypt",
"(",
"$",
"this",
"->",
"secret",
"(",
"\"What is the new user's password? (blank generates a random one)\"",
",",
"str_random",
"(",
"32",
")",
")",
")",
";",
"$",
"sendReset",
"=",
"$",
"this",
"->",
"confirm",
"(",
"'Do you want to send a password reset email?'",
")",
";",
"while",
"(",
"$",
"custom",
"=",
"$",
"this",
"->",
"ask",
"(",
"'Do you have any custom user fields to add? Field=Value (blank continues)'",
",",
"false",
")",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"custom",
")",
";",
"$",
"this",
"->",
"customFields",
"[",
"$",
"key",
"]",
"=",
"value",
"(",
"$",
"value",
")",
";",
"}",
"try",
"{",
"app",
"(",
"'db'",
")",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"this",
"->",
"validateEmail",
"(",
"$",
"email",
")",
";",
"app",
"(",
"config",
"(",
"'auth.providers.users.model'",
")",
")",
"->",
"create",
"(",
"array_merge",
"(",
"compact",
"(",
"'email'",
",",
"'name'",
",",
"'password'",
")",
",",
"$",
"this",
"->",
"customFields",
")",
")",
";",
"if",
"(",
"$",
"sendReset",
")",
"{",
"Password",
"::",
"sendResetLink",
"(",
"compact",
"(",
"'email'",
")",
")",
";",
"$",
"this",
"->",
"info",
"(",
"\"Sent password reset email to {$email}\"",
")",
";",
"}",
"$",
"this",
"->",
"info",
"(",
"\"Created new user for email {$email}\"",
")",
";",
"app",
"(",
"'db'",
")",
"->",
"commit",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"error",
"(",
"'The user was not created'",
")",
";",
"app",
"(",
"'db'",
")",
"->",
"rollBack",
"(",
")",
";",
"}",
"}"
] | Execute the console command.
Handle creation of the new application user.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/michaeldyrynda/laravel-make-user/blob/8d4cd8bef67c202419f9dcbc04d7dd03e473a146/src/Console/Commands/MakeUser.php#L40-L78 |
michaeldyrynda/laravel-make-user | src/Console/Commands/MakeUser.php | MakeUser.validateEmail | private function validateEmail($email)
{
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw MakeUserException::invalidEmail($email);
}
if (app(config('auth.providers.users.model'))->where('email', $email)->exists()) {
throw MakeUserException::emailExists($email);
}
} | php | private function validateEmail($email)
{
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw MakeUserException::invalidEmail($email);
}
if (app(config('auth.providers.users.model'))->where('email', $email)->exists()) {
throw MakeUserException::emailExists($email);
}
} | [
"private",
"function",
"validateEmail",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"email",
",",
"FILTER_VALIDATE_EMAIL",
")",
")",
"{",
"throw",
"MakeUserException",
"::",
"invalidEmail",
"(",
"$",
"email",
")",
";",
"}",
"if",
"(",
"app",
"(",
"config",
"(",
"'auth.providers.users.model'",
")",
")",
"->",
"where",
"(",
"'email'",
",",
"$",
"email",
")",
"->",
"exists",
"(",
")",
")",
"{",
"throw",
"MakeUserException",
"::",
"emailExists",
"(",
"$",
"email",
")",
";",
"}",
"}"
] | Determine if the given email address already exists.
@param string $email
@return void
@throws \Dyrynda\Artisan\Exceptions\MakeUserException | [
"Determine",
"if",
"the",
"given",
"email",
"address",
"already",
"exists",
"."
] | train | https://github.com/michaeldyrynda/laravel-make-user/blob/8d4cd8bef67c202419f9dcbc04d7dd03e473a146/src/Console/Commands/MakeUser.php#L88-L97 |
box-project/box2 | src/lib/KevinGH/Box/Command/AbstractCommand.php | AbstractCommand.putln | protected function putln($prefix, $message)
{
switch ($prefix) {
case '!':
$prefix = "<error>$prefix</error>";
break;
case '*':
$prefix = "<info>$prefix</info>";
break;
case '?':
$prefix = "<comment>$prefix</comment>";
break;
case '-':
case '+':
$prefix = " <comment>$prefix</comment>";
break;
case '>':
$prefix = " <comment>$prefix</comment>";
break;
}
$this->verboseln("$prefix $message");
} | php | protected function putln($prefix, $message)
{
switch ($prefix) {
case '!':
$prefix = "<error>$prefix</error>";
break;
case '*':
$prefix = "<info>$prefix</info>";
break;
case '?':
$prefix = "<comment>$prefix</comment>";
break;
case '-':
case '+':
$prefix = " <comment>$prefix</comment>";
break;
case '>':
$prefix = " <comment>$prefix</comment>";
break;
}
$this->verboseln("$prefix $message");
} | [
"protected",
"function",
"putln",
"(",
"$",
"prefix",
",",
"$",
"message",
")",
"{",
"switch",
"(",
"$",
"prefix",
")",
"{",
"case",
"'!'",
":",
"$",
"prefix",
"=",
"\"<error>$prefix</error>\"",
";",
"break",
";",
"case",
"'*'",
":",
"$",
"prefix",
"=",
"\"<info>$prefix</info>\"",
";",
"break",
";",
"case",
"'?'",
":",
"$",
"prefix",
"=",
"\"<comment>$prefix</comment>\"",
";",
"break",
";",
"case",
"'-'",
":",
"case",
"'+'",
":",
"$",
"prefix",
"=",
"\" <comment>$prefix</comment>\"",
";",
"break",
";",
"case",
"'>'",
":",
"$",
"prefix",
"=",
"\" <comment>$prefix</comment>\"",
";",
"break",
";",
"}",
"$",
"this",
"->",
"verboseln",
"(",
"\"$prefix $message\"",
")",
";",
"}"
] | Outputs a message with a colored prefix.
@param string $prefix The prefix.
@param string $message The message. | [
"Outputs",
"a",
"message",
"with",
"a",
"colored",
"prefix",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Command/AbstractCommand.php#L49-L71 |
box-project/box2 | src/lib/KevinGH/Box/Command/AbstractCommand.php | AbstractCommand.verbose | protected function verbose($message, $newline = false, $type = 0)
{
if ($this->isVerbose()) {
$this->output->write($message, $newline, $type);
}
} | php | protected function verbose($message, $newline = false, $type = 0)
{
if ($this->isVerbose()) {
$this->output->write($message, $newline, $type);
}
} | [
"protected",
"function",
"verbose",
"(",
"$",
"message",
",",
"$",
"newline",
"=",
"false",
",",
"$",
"type",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isVerbose",
"(",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"write",
"(",
"$",
"message",
",",
"$",
"newline",
",",
"$",
"type",
")",
";",
"}",
"}"
] | Writes the message only when verbosity is set to VERBOSITY_VERBOSE.
@see OutputInterface#write | [
"Writes",
"the",
"message",
"only",
"when",
"verbosity",
"is",
"set",
"to",
"VERBOSITY_VERBOSE",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Command/AbstractCommand.php#L78-L83 |
box-project/box2 | src/lib/KevinGH/Box/Helper/ConfigurationHelper.php | ConfigurationHelper.getDefaultPath | public function getDefaultPath()
{
if (false === file_exists(self::FILE_NAME)) {
if (false === file_exists(self::FILE_NAME . '.dist')) {
throw new RuntimeException(
sprintf('The configuration file could not be found.')
);
}
return realpath(self::FILE_NAME . '.dist');
}
return realpath(self::FILE_NAME);
} | php | public function getDefaultPath()
{
if (false === file_exists(self::FILE_NAME)) {
if (false === file_exists(self::FILE_NAME . '.dist')) {
throw new RuntimeException(
sprintf('The configuration file could not be found.')
);
}
return realpath(self::FILE_NAME . '.dist');
}
return realpath(self::FILE_NAME);
} | [
"public",
"function",
"getDefaultPath",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"self",
"::",
"FILE_NAME",
")",
")",
"{",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"self",
"::",
"FILE_NAME",
".",
"'.dist'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The configuration file could not be found.'",
")",
")",
";",
"}",
"return",
"realpath",
"(",
"self",
"::",
"FILE_NAME",
".",
"'.dist'",
")",
";",
"}",
"return",
"realpath",
"(",
"self",
"::",
"FILE_NAME",
")",
";",
"}"
] | Returns the file path to the default configuration file.
@return string The file path.
@throws RuntimeException If the default file does not exist. | [
"Returns",
"the",
"file",
"path",
"to",
"the",
"default",
"configuration",
"file",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Helper/ConfigurationHelper.php#L62-L75 |
box-project/box2 | src/lib/KevinGH/Box/Helper/ConfigurationHelper.php | ConfigurationHelper.loadFile | public function loadFile($file = null)
{
if (null === $file) {
$file = $this->getDefaultPath();
}
$json = $this->json->decodeFile($file);
if (isset($json->import)) {
if (!Path::isAbsolute($json->import)) {
$json->import = Path::join(
array(
dirname($file),
$json->import
)
);
}
$json = (object) array_merge(
(array) $this->json->decodeFile($json->import),
(array) $json
);
}
$this->json->validate(
$this->json->decodeFile(BOX_SCHEMA_FILE),
$json
);
return new Configuration($file, $json);
} | php | public function loadFile($file = null)
{
if (null === $file) {
$file = $this->getDefaultPath();
}
$json = $this->json->decodeFile($file);
if (isset($json->import)) {
if (!Path::isAbsolute($json->import)) {
$json->import = Path::join(
array(
dirname($file),
$json->import
)
);
}
$json = (object) array_merge(
(array) $this->json->decodeFile($json->import),
(array) $json
);
}
$this->json->validate(
$this->json->decodeFile(BOX_SCHEMA_FILE),
$json
);
return new Configuration($file, $json);
} | [
"public",
"function",
"loadFile",
"(",
"$",
"file",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getDefaultPath",
"(",
")",
";",
"}",
"$",
"json",
"=",
"$",
"this",
"->",
"json",
"->",
"decodeFile",
"(",
"$",
"file",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"json",
"->",
"import",
")",
")",
"{",
"if",
"(",
"!",
"Path",
"::",
"isAbsolute",
"(",
"$",
"json",
"->",
"import",
")",
")",
"{",
"$",
"json",
"->",
"import",
"=",
"Path",
"::",
"join",
"(",
"array",
"(",
"dirname",
"(",
"$",
"file",
")",
",",
"$",
"json",
"->",
"import",
")",
")",
";",
"}",
"$",
"json",
"=",
"(",
"object",
")",
"array_merge",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"json",
"->",
"decodeFile",
"(",
"$",
"json",
"->",
"import",
")",
",",
"(",
"array",
")",
"$",
"json",
")",
";",
"}",
"$",
"this",
"->",
"json",
"->",
"validate",
"(",
"$",
"this",
"->",
"json",
"->",
"decodeFile",
"(",
"BOX_SCHEMA_FILE",
")",
",",
"$",
"json",
")",
";",
"return",
"new",
"Configuration",
"(",
"$",
"file",
",",
"$",
"json",
")",
";",
"}"
] | Loads the configuration file and returns it.
@param string $file The configuration file path.
@return Configuration The configuration settings. | [
"Loads",
"the",
"configuration",
"file",
"and",
"returns",
"it",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Helper/ConfigurationHelper.php#L84-L114 |
box-project/box2 | src/lib/KevinGH/Box/Command/Configurable.php | Configurable.getConfig | protected function getConfig(InputInterface $input)
{
/** @var $helper ConfigurationHelper */
$helper = $this->getHelper('config');
return $helper->loadFile($input->getOption('configuration'));
} | php | protected function getConfig(InputInterface $input)
{
/** @var $helper ConfigurationHelper */
$helper = $this->getHelper('config');
return $helper->loadFile($input->getOption('configuration'));
} | [
"protected",
"function",
"getConfig",
"(",
"InputInterface",
"$",
"input",
")",
"{",
"/** @var $helper ConfigurationHelper */",
"$",
"helper",
"=",
"$",
"this",
"->",
"getHelper",
"(",
"'config'",
")",
";",
"return",
"$",
"helper",
"->",
"loadFile",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'configuration'",
")",
")",
";",
"}"
] | Returns the configuration settings.
@param InputInterface $input The input handler.
@return Configuration The configuration settings. | [
"Returns",
"the",
"configuration",
"settings",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Command/Configurable.php#L37-L43 |
box-project/box2 | src/lib/KevinGH/Box/Command/Info.php | Info.contents | private function contents(
OutputInterface $output,
Traversable $list,
$indent,
$base,
Phar $phar,
$root
) {
/** @var PharFileInfo $item */
foreach ($list as $item) {
$item = $phar[str_replace($root, '', $item->getPathname())];
if (false !== $indent) {
$output->write(str_repeat(' ', $indent));
$path = $item->getFilename();
if ($item->isDir()) {
$path .= '/';
}
} else {
$path = str_replace($base, '', $item->getPathname());
}
if ($item->isDir()) {
$output->writeln("<info>$path</info>");
} else {
$compression = '';
foreach (self::$fileAlgorithms as $code => $name) {
if ($item->isCompressed($code)) {
$compression = " <fg=cyan>[$name]</fg=cyan>";
}
}
$output->writeln($path . $compression);
}
if ($item->isDir()) {
$this->contents(
$output,
new DirectoryIterator($item->getPathname()),
(false === $indent) ? $indent : $indent + 2,
$base,
$phar,
$root
);
}
}
} | php | private function contents(
OutputInterface $output,
Traversable $list,
$indent,
$base,
Phar $phar,
$root
) {
/** @var PharFileInfo $item */
foreach ($list as $item) {
$item = $phar[str_replace($root, '', $item->getPathname())];
if (false !== $indent) {
$output->write(str_repeat(' ', $indent));
$path = $item->getFilename();
if ($item->isDir()) {
$path .= '/';
}
} else {
$path = str_replace($base, '', $item->getPathname());
}
if ($item->isDir()) {
$output->writeln("<info>$path</info>");
} else {
$compression = '';
foreach (self::$fileAlgorithms as $code => $name) {
if ($item->isCompressed($code)) {
$compression = " <fg=cyan>[$name]</fg=cyan>";
}
}
$output->writeln($path . $compression);
}
if ($item->isDir()) {
$this->contents(
$output,
new DirectoryIterator($item->getPathname()),
(false === $indent) ? $indent : $indent + 2,
$base,
$phar,
$root
);
}
}
} | [
"private",
"function",
"contents",
"(",
"OutputInterface",
"$",
"output",
",",
"Traversable",
"$",
"list",
",",
"$",
"indent",
",",
"$",
"base",
",",
"Phar",
"$",
"phar",
",",
"$",
"root",
")",
"{",
"/** @var PharFileInfo $item */",
"foreach",
"(",
"$",
"list",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"$",
"phar",
"[",
"str_replace",
"(",
"$",
"root",
",",
"''",
",",
"$",
"item",
"->",
"getPathname",
"(",
")",
")",
"]",
";",
"if",
"(",
"false",
"!==",
"$",
"indent",
")",
"{",
"$",
"output",
"->",
"write",
"(",
"str_repeat",
"(",
"' '",
",",
"$",
"indent",
")",
")",
";",
"$",
"path",
"=",
"$",
"item",
"->",
"getFilename",
"(",
")",
";",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"path",
".=",
"'/'",
";",
"}",
"}",
"else",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"$",
"base",
",",
"''",
",",
"$",
"item",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"\"<info>$path</info>\"",
")",
";",
"}",
"else",
"{",
"$",
"compression",
"=",
"''",
";",
"foreach",
"(",
"self",
"::",
"$",
"fileAlgorithms",
"as",
"$",
"code",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"isCompressed",
"(",
"$",
"code",
")",
")",
"{",
"$",
"compression",
"=",
"\" <fg=cyan>[$name]</fg=cyan>\"",
";",
"}",
"}",
"$",
"output",
"->",
"writeln",
"(",
"$",
"path",
".",
"$",
"compression",
")",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"this",
"->",
"contents",
"(",
"$",
"output",
",",
"new",
"DirectoryIterator",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
")",
",",
"(",
"false",
"===",
"$",
"indent",
")",
"?",
"$",
"indent",
":",
"$",
"indent",
"+",
"2",
",",
"$",
"base",
",",
"$",
"phar",
",",
"$",
"root",
")",
";",
"}",
"}",
"}"
] | Renders the contents of an iterator.
@param OutputInterface $output The output handler.
@param Traversable $list The traversable list.
@param boolean|integer $indent The indentation level.
@param string $base The base path.
@param Phar $phar The PHP archive.
@param string $root The root path to remove. | [
"Renders",
"the",
"contents",
"of",
"an",
"iterator",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Command/Info.php#L159-L208 |
box-project/box2 | src/lib/KevinGH/Box/Command/Info.php | Info.render | private function render(OutputInterface $output, array $attributes)
{
$out = false;
foreach ($attributes as $name => $value) {
if ($out) {
$output->writeln('');
}
$output->write("<comment>$name:</comment>");
if (is_array($value)) {
$output->writeln('');
foreach ($value as $v) {
$output->writeln(" - $v");
}
} else {
$output->writeln(" $value");
}
$out = true;
}
} | php | private function render(OutputInterface $output, array $attributes)
{
$out = false;
foreach ($attributes as $name => $value) {
if ($out) {
$output->writeln('');
}
$output->write("<comment>$name:</comment>");
if (is_array($value)) {
$output->writeln('');
foreach ($value as $v) {
$output->writeln(" - $v");
}
} else {
$output->writeln(" $value");
}
$out = true;
}
} | [
"private",
"function",
"render",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"out",
"=",
"false",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"out",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"}",
"$",
"output",
"->",
"write",
"(",
"\"<comment>$name:</comment>\"",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"v",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"\" - $v\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"output",
"->",
"writeln",
"(",
"\" $value\"",
")",
";",
"}",
"$",
"out",
"=",
"true",
";",
"}",
"}"
] | Renders the list of attributes.
@param OutputInterface $output The output.
@param array $attributes The list of attributes. | [
"Renders",
"the",
"list",
"of",
"attributes",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Command/Info.php#L216-L239 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getBasePath | public function getBasePath()
{
if (isset($this->raw->{'base-path'})) {
if (false === is_dir($this->raw->{'base-path'})) {
throw new InvalidArgumentException(
sprintf(
'The base path "%s" is not a directory or does not exist.',
$this->raw->{'base-path'}
)
);
}
return realpath($this->raw->{'base-path'});
}
return realpath(dirname($this->file));
} | php | public function getBasePath()
{
if (isset($this->raw->{'base-path'})) {
if (false === is_dir($this->raw->{'base-path'})) {
throw new InvalidArgumentException(
sprintf(
'The base path "%s" is not a directory or does not exist.',
$this->raw->{'base-path'}
)
);
}
return realpath($this->raw->{'base-path'});
}
return realpath(dirname($this->file));
} | [
"public",
"function",
"getBasePath",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"{",
"'base-path'",
"}",
")",
")",
"{",
"if",
"(",
"false",
"===",
"is_dir",
"(",
"$",
"this",
"->",
"raw",
"->",
"{",
"'base-path'",
"}",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The base path \"%s\" is not a directory or does not exist.'",
",",
"$",
"this",
"->",
"raw",
"->",
"{",
"'base-path'",
"}",
")",
")",
";",
"}",
"return",
"realpath",
"(",
"$",
"this",
"->",
"raw",
"->",
"{",
"'base-path'",
"}",
")",
";",
"}",
"return",
"realpath",
"(",
"dirname",
"(",
"$",
"this",
"->",
"file",
")",
")",
";",
"}"
] | Returns the base path.
@return string The base path.
@throws InvalidArgumentException If the base path is not valid. | [
"Returns",
"the",
"base",
"path",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L71-L87 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getBinaryDirectories | public function getBinaryDirectories()
{
if (isset($this->raw->{'directories-bin'})) {
$directories = (array) $this->raw->{'directories-bin'};
$base = $this->getBasePath();
array_walk(
$directories,
function (&$directory) use ($base) {
$directory = $base
. DIRECTORY_SEPARATOR
. Path::canonical($directory);
}
);
return $directories;
}
return array();
} | php | public function getBinaryDirectories()
{
if (isset($this->raw->{'directories-bin'})) {
$directories = (array) $this->raw->{'directories-bin'};
$base = $this->getBasePath();
array_walk(
$directories,
function (&$directory) use ($base) {
$directory = $base
. DIRECTORY_SEPARATOR
. Path::canonical($directory);
}
);
return $directories;
}
return array();
} | [
"public",
"function",
"getBinaryDirectories",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"{",
"'directories-bin'",
"}",
")",
")",
"{",
"$",
"directories",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"{",
"'directories-bin'",
"}",
";",
"$",
"base",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
";",
"array_walk",
"(",
"$",
"directories",
",",
"function",
"(",
"&",
"$",
"directory",
")",
"use",
"(",
"$",
"base",
")",
"{",
"$",
"directory",
"=",
"$",
"base",
".",
"DIRECTORY_SEPARATOR",
".",
"Path",
"::",
"canonical",
"(",
"$",
"directory",
")",
";",
"}",
")",
";",
"return",
"$",
"directories",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Returns the list of relative directory paths for binary files.
@return array The list of paths. | [
"Returns",
"the",
"list",
"of",
"relative",
"directory",
"paths",
"for",
"binary",
"files",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L106-L125 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getBinaryDirectoriesIterator | public function getBinaryDirectoriesIterator()
{
if (array() !== ($directories = $this->getBinaryDirectories())) {
return Finder::create()
->files()
->filter($this->getBlacklistFilter())
->ignoreVCS(true)
->in($directories);
}
return null;
} | php | public function getBinaryDirectoriesIterator()
{
if (array() !== ($directories = $this->getBinaryDirectories())) {
return Finder::create()
->files()
->filter($this->getBlacklistFilter())
->ignoreVCS(true)
->in($directories);
}
return null;
} | [
"public",
"function",
"getBinaryDirectoriesIterator",
"(",
")",
"{",
"if",
"(",
"array",
"(",
")",
"!==",
"(",
"$",
"directories",
"=",
"$",
"this",
"->",
"getBinaryDirectories",
"(",
")",
")",
")",
"{",
"return",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"filter",
"(",
"$",
"this",
"->",
"getBlacklistFilter",
"(",
")",
")",
"->",
"ignoreVCS",
"(",
"true",
")",
"->",
"in",
"(",
"$",
"directories",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the iterator for the binary directory paths.
@return Finder The iterator. | [
"Returns",
"the",
"iterator",
"for",
"the",
"binary",
"directory",
"paths",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L132-L143 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getBinaryFiles | public function getBinaryFiles()
{
if (isset($this->raw->{'files-bin'})) {
$base = $this->getBasePath();
$files = array();
foreach ((array) $this->raw->{'files-bin'} as $file) {
$files[] = new SplFileInfo(
$base . DIRECTORY_SEPARATOR . Path::canonical($file)
);
}
return $files;
}
return array();
} | php | public function getBinaryFiles()
{
if (isset($this->raw->{'files-bin'})) {
$base = $this->getBasePath();
$files = array();
foreach ((array) $this->raw->{'files-bin'} as $file) {
$files[] = new SplFileInfo(
$base . DIRECTORY_SEPARATOR . Path::canonical($file)
);
}
return $files;
}
return array();
} | [
"public",
"function",
"getBinaryFiles",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"{",
"'files-bin'",
"}",
")",
")",
"{",
"$",
"base",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
";",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"{",
"'files-bin'",
"}",
"as",
"$",
"file",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"new",
"SplFileInfo",
"(",
"$",
"base",
".",
"DIRECTORY_SEPARATOR",
".",
"Path",
"::",
"canonical",
"(",
"$",
"file",
")",
")",
";",
"}",
"return",
"$",
"files",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Returns the list of relative paths for binary files.
@return array The list of paths. | [
"Returns",
"the",
"list",
"of",
"relative",
"paths",
"for",
"binary",
"files",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L150-L166 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getBlacklist | public function getBlacklist()
{
if (isset($this->raw->blacklist)) {
$blacklist = (array) $this->raw->blacklist;
array_walk(
$blacklist,
function (&$file) {
$file = Path::canonical($file);
}
);
return $blacklist;
}
return array();
} | php | public function getBlacklist()
{
if (isset($this->raw->blacklist)) {
$blacklist = (array) $this->raw->blacklist;
array_walk(
$blacklist,
function (&$file) {
$file = Path::canonical($file);
}
);
return $blacklist;
}
return array();
} | [
"public",
"function",
"getBlacklist",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"blacklist",
")",
")",
"{",
"$",
"blacklist",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"blacklist",
";",
"array_walk",
"(",
"$",
"blacklist",
",",
"function",
"(",
"&",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"Path",
"::",
"canonical",
"(",
"$",
"file",
")",
";",
"}",
")",
";",
"return",
"$",
"blacklist",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Returns the list of blacklisted relative file paths.
@return array The list of paths. | [
"Returns",
"the",
"list",
"of",
"blacklisted",
"relative",
"file",
"paths",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L201-L217 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getBlacklistFilter | public function getBlacklistFilter()
{
$blacklist = $this->getBlacklist();
$base = '/^'
. preg_quote($this->getBasePath() . DIRECTORY_SEPARATOR, '/')
. '/';
return function (SplFileInfo $file) use ($base, $blacklist) {
$path = Path::canonical(
preg_replace($base, '', $file->getPathname())
);
if (in_array($path, $blacklist)) {
return false;
}
return null;
};
} | php | public function getBlacklistFilter()
{
$blacklist = $this->getBlacklist();
$base = '/^'
. preg_quote($this->getBasePath() . DIRECTORY_SEPARATOR, '/')
. '/';
return function (SplFileInfo $file) use ($base, $blacklist) {
$path = Path::canonical(
preg_replace($base, '', $file->getPathname())
);
if (in_array($path, $blacklist)) {
return false;
}
return null;
};
} | [
"public",
"function",
"getBlacklistFilter",
"(",
")",
"{",
"$",
"blacklist",
"=",
"$",
"this",
"->",
"getBlacklist",
"(",
")",
";",
"$",
"base",
"=",
"'/^'",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"getBasePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
",",
"'/'",
")",
".",
"'/'",
";",
"return",
"function",
"(",
"SplFileInfo",
"$",
"file",
")",
"use",
"(",
"$",
"base",
",",
"$",
"blacklist",
")",
"{",
"$",
"path",
"=",
"Path",
"::",
"canonical",
"(",
"preg_replace",
"(",
"$",
"base",
",",
"''",
",",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"path",
",",
"$",
"blacklist",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"null",
";",
"}",
";",
"}"
] | Returns a filter callable for the configured blacklist.
@return callable The callable. | [
"Returns",
"a",
"filter",
"callable",
"for",
"the",
"configured",
"blacklist",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L224-L242 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getBootstrapFile | public function getBootstrapFile()
{
if (isset($this->raw->bootstrap)) {
$path = $this->raw->bootstrap;
if (false === Path::isAbsolute($path)) {
$path = Path::canonical(
$this->getBasePath() . DIRECTORY_SEPARATOR . $path
);
}
return $path;
}
return null;
} | php | public function getBootstrapFile()
{
if (isset($this->raw->bootstrap)) {
$path = $this->raw->bootstrap;
if (false === Path::isAbsolute($path)) {
$path = Path::canonical(
$this->getBasePath() . DIRECTORY_SEPARATOR . $path
);
}
return $path;
}
return null;
} | [
"public",
"function",
"getBootstrapFile",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"bootstrap",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"raw",
"->",
"bootstrap",
";",
"if",
"(",
"false",
"===",
"Path",
"::",
"isAbsolute",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"Path",
"::",
"canonical",
"(",
"$",
"this",
"->",
"getBasePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
")",
";",
"}",
"return",
"$",
"path",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the bootstrap file path.
@return string The file path. | [
"Returns",
"the",
"bootstrap",
"file",
"path",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L249-L264 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getCompactors | public function getCompactors()
{
$compactors = array();
if (isset($this->raw->compactors)) {
foreach ((array) $this->raw->compactors as $class) {
if (false === class_exists($class)) {
throw new InvalidArgumentException(
sprintf(
'The compactor class "%s" does not exist.',
$class
)
);
}
$compactor = new $class();
if (false === ($compactor instanceof CompactorInterface)) {
throw new InvalidArgumentException(
sprintf(
'The class "%s" is not a compactor class.',
$class
)
);
}
if ($compactor instanceof Php) {
if (!empty($this->raw->annotations)) {
$tokenizer = new Tokenizer();
if (isset($this->raw->annotations->ignore)) {
$tokenizer->ignore(
(array) $this->raw->annotations->ignore
);
}
$compactor->setTokenizer($tokenizer);
}
}
$compactors[] = $compactor;
}
}
return $compactors;
} | php | public function getCompactors()
{
$compactors = array();
if (isset($this->raw->compactors)) {
foreach ((array) $this->raw->compactors as $class) {
if (false === class_exists($class)) {
throw new InvalidArgumentException(
sprintf(
'The compactor class "%s" does not exist.',
$class
)
);
}
$compactor = new $class();
if (false === ($compactor instanceof CompactorInterface)) {
throw new InvalidArgumentException(
sprintf(
'The class "%s" is not a compactor class.',
$class
)
);
}
if ($compactor instanceof Php) {
if (!empty($this->raw->annotations)) {
$tokenizer = new Tokenizer();
if (isset($this->raw->annotations->ignore)) {
$tokenizer->ignore(
(array) $this->raw->annotations->ignore
);
}
$compactor->setTokenizer($tokenizer);
}
}
$compactors[] = $compactor;
}
}
return $compactors;
} | [
"public",
"function",
"getCompactors",
"(",
")",
"{",
"$",
"compactors",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"compactors",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"compactors",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"false",
"===",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The compactor class \"%s\" does not exist.'",
",",
"$",
"class",
")",
")",
";",
"}",
"$",
"compactor",
"=",
"new",
"$",
"class",
"(",
")",
";",
"if",
"(",
"false",
"===",
"(",
"$",
"compactor",
"instanceof",
"CompactorInterface",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The class \"%s\" is not a compactor class.'",
",",
"$",
"class",
")",
")",
";",
"}",
"if",
"(",
"$",
"compactor",
"instanceof",
"Php",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"raw",
"->",
"annotations",
")",
")",
"{",
"$",
"tokenizer",
"=",
"new",
"Tokenizer",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"annotations",
"->",
"ignore",
")",
")",
"{",
"$",
"tokenizer",
"->",
"ignore",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"annotations",
"->",
"ignore",
")",
";",
"}",
"$",
"compactor",
"->",
"setTokenizer",
"(",
"$",
"tokenizer",
")",
";",
"}",
"}",
"$",
"compactors",
"[",
"]",
"=",
"$",
"compactor",
";",
"}",
"}",
"return",
"$",
"compactors",
";",
"}"
] | Returns the list of file contents compactors.
@return CompactorInterface[] The list of compactors.
@throws InvalidArgumentException If a class is not valid. | [
"Returns",
"the",
"list",
"of",
"file",
"contents",
"compactors",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L273-L318 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getCompressionAlgorithm | public function getCompressionAlgorithm()
{
if (isset($this->raw->compression)) {
if (is_string($this->raw->compression)) {
if (false === defined('Phar::' . $this->raw->compression)) {
throw new InvalidArgumentException(
sprintf(
'The compression algorithm "%s" is not supported.',
$this->raw->compression
)
);
}
$value = constant('Phar::' . $this->raw->compression);
// Phar::NONE is not valid for compressFiles()
if (Phar::NONE === $value) {
return null;
}
return $value;
}
return $this->raw->compression;
}
return null;
} | php | public function getCompressionAlgorithm()
{
if (isset($this->raw->compression)) {
if (is_string($this->raw->compression)) {
if (false === defined('Phar::' . $this->raw->compression)) {
throw new InvalidArgumentException(
sprintf(
'The compression algorithm "%s" is not supported.',
$this->raw->compression
)
);
}
$value = constant('Phar::' . $this->raw->compression);
// Phar::NONE is not valid for compressFiles()
if (Phar::NONE === $value) {
return null;
}
return $value;
}
return $this->raw->compression;
}
return null;
} | [
"public",
"function",
"getCompressionAlgorithm",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"compression",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"raw",
"->",
"compression",
")",
")",
"{",
"if",
"(",
"false",
"===",
"defined",
"(",
"'Phar::'",
".",
"$",
"this",
"->",
"raw",
"->",
"compression",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The compression algorithm \"%s\" is not supported.'",
",",
"$",
"this",
"->",
"raw",
"->",
"compression",
")",
")",
";",
"}",
"$",
"value",
"=",
"constant",
"(",
"'Phar::'",
".",
"$",
"this",
"->",
"raw",
"->",
"compression",
")",
";",
"// Phar::NONE is not valid for compressFiles()",
"if",
"(",
"Phar",
"::",
"NONE",
"===",
"$",
"value",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"raw",
"->",
"compression",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the Phar compression algorithm.
@return integer The compression algorithm.
@throws InvalidArgumentException If the algorithm is not valid. | [
"Returns",
"the",
"Phar",
"compression",
"algorithm",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L327-L354 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getDirectories | public function getDirectories()
{
if (isset($this->raw->directories)) {
$directories = (array) $this->raw->directories;
$base = $this->getBasePath();
array_walk(
$directories,
function (&$directory) use ($base) {
$directory = $base
. DIRECTORY_SEPARATOR
. rtrim(Path::canonical($directory), DIRECTORY_SEPARATOR);
}
);
return $directories;
}
return array();
} | php | public function getDirectories()
{
if (isset($this->raw->directories)) {
$directories = (array) $this->raw->directories;
$base = $this->getBasePath();
array_walk(
$directories,
function (&$directory) use ($base) {
$directory = $base
. DIRECTORY_SEPARATOR
. rtrim(Path::canonical($directory), DIRECTORY_SEPARATOR);
}
);
return $directories;
}
return array();
} | [
"public",
"function",
"getDirectories",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"directories",
")",
")",
"{",
"$",
"directories",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"directories",
";",
"$",
"base",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
";",
"array_walk",
"(",
"$",
"directories",
",",
"function",
"(",
"&",
"$",
"directory",
")",
"use",
"(",
"$",
"base",
")",
"{",
"$",
"directory",
"=",
"$",
"base",
".",
"DIRECTORY_SEPARATOR",
".",
"rtrim",
"(",
"Path",
"::",
"canonical",
"(",
"$",
"directory",
")",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
")",
";",
"return",
"$",
"directories",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Returns the list of relative directory paths.
@return array The list of paths. | [
"Returns",
"the",
"list",
"of",
"relative",
"directory",
"paths",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L361-L380 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getDirectoriesIterator | public function getDirectoriesIterator()
{
if (array() !== ($directories = $this->getDirectories())) {
return Finder::create()
->files()
->filter($this->getBlacklistFilter())
->ignoreVCS(true)
->in($directories);
}
return null;
} | php | public function getDirectoriesIterator()
{
if (array() !== ($directories = $this->getDirectories())) {
return Finder::create()
->files()
->filter($this->getBlacklistFilter())
->ignoreVCS(true)
->in($directories);
}
return null;
} | [
"public",
"function",
"getDirectoriesIterator",
"(",
")",
"{",
"if",
"(",
"array",
"(",
")",
"!==",
"(",
"$",
"directories",
"=",
"$",
"this",
"->",
"getDirectories",
"(",
")",
")",
")",
"{",
"return",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"filter",
"(",
"$",
"this",
"->",
"getBlacklistFilter",
"(",
")",
")",
"->",
"ignoreVCS",
"(",
"true",
")",
"->",
"in",
"(",
"$",
"directories",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the iterator for the directory paths.
@return Finder The iterator. | [
"Returns",
"the",
"iterator",
"for",
"the",
"directory",
"paths",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L387-L398 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getFileMode | public function getFileMode()
{
if (isset($this->raw->chmod)) {
return intval($this->raw->chmod, 8);
}
return null;
} | php | public function getFileMode()
{
if (isset($this->raw->chmod)) {
return intval($this->raw->chmod, 8);
}
return null;
} | [
"public",
"function",
"getFileMode",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"chmod",
")",
")",
"{",
"return",
"intval",
"(",
"$",
"this",
"->",
"raw",
"->",
"chmod",
",",
"8",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the file mode in octal form.
@return integer The file mode. | [
"Returns",
"the",
"file",
"mode",
"in",
"octal",
"form",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L405-L412 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getFiles | public function getFiles()
{
if (isset($this->raw->files)) {
$base = $this->getBasePath();
$files = array();
foreach ((array) $this->raw->files as $file) {
$file = new SplFileInfo(
$path = $base . DIRECTORY_SEPARATOR . Path::canonical($file)
);
if (false === $file->isFile()) {
throw new RuntimeException(
sprintf(
'The file "%s" does not exist or is not a file.',
$path
)
);
}
$files[] = $file;
}
return $files;
}
return array();
} | php | public function getFiles()
{
if (isset($this->raw->files)) {
$base = $this->getBasePath();
$files = array();
foreach ((array) $this->raw->files as $file) {
$file = new SplFileInfo(
$path = $base . DIRECTORY_SEPARATOR . Path::canonical($file)
);
if (false === $file->isFile()) {
throw new RuntimeException(
sprintf(
'The file "%s" does not exist or is not a file.',
$path
)
);
}
$files[] = $file;
}
return $files;
}
return array();
} | [
"public",
"function",
"getFiles",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"files",
")",
")",
"{",
"$",
"base",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
";",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"new",
"SplFileInfo",
"(",
"$",
"path",
"=",
"$",
"base",
".",
"DIRECTORY_SEPARATOR",
".",
"Path",
"::",
"canonical",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"false",
"===",
"$",
"file",
"->",
"isFile",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The file \"%s\" does not exist or is not a file.'",
",",
"$",
"path",
")",
")",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"files",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Returns the list of relative file paths.
@return array The list of paths.
@throws RuntimeException If one of the files does not exist. | [
"Returns",
"the",
"list",
"of",
"relative",
"file",
"paths",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L421-L448 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getFinders | public function getFinders()
{
if (isset($this->raw->finder)) {
return $this->processFinders($this->raw->finder);
}
return array();
} | php | public function getFinders()
{
if (isset($this->raw->finder)) {
return $this->processFinders($this->raw->finder);
}
return array();
} | [
"public",
"function",
"getFinders",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"finder",
")",
")",
"{",
"return",
"$",
"this",
"->",
"processFinders",
"(",
"$",
"this",
"->",
"raw",
"->",
"finder",
")",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Returns the list of configured Finder instances.
@return Finder[] The list of Finders. | [
"Returns",
"the",
"list",
"of",
"configured",
"Finder",
"instances",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L469-L476 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getGitVersion | public function getGitVersion()
{
try {
return $this->getGitTag();
} catch (RuntimeException $exception) {
try {
return $this->getGitHash(true);
} catch (RuntimeException $exception) {
throw new RuntimeException(
sprintf(
'The tag or commit hash could not be retrieved from "%s": %s',
dirname($this->file),
$exception->getMessage()
),
0,
$exception
);
}
}
} | php | public function getGitVersion()
{
try {
return $this->getGitTag();
} catch (RuntimeException $exception) {
try {
return $this->getGitHash(true);
} catch (RuntimeException $exception) {
throw new RuntimeException(
sprintf(
'The tag or commit hash could not be retrieved from "%s": %s',
dirname($this->file),
$exception->getMessage()
),
0,
$exception
);
}
}
} | [
"public",
"function",
"getGitVersion",
"(",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"getGitTag",
"(",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"exception",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"getGitHash",
"(",
"true",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"exception",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The tag or commit hash could not be retrieved from \"%s\": %s'",
",",
"dirname",
"(",
"$",
"this",
"->",
"file",
")",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
",",
"0",
",",
"$",
"exception",
")",
";",
"}",
"}",
"}"
] | Returns the Git tag name or short commit hash.
@return string The tag name or short commit hash.
@throws RuntimeException If the version could not be retrieved. | [
"Returns",
"the",
"Git",
"tag",
"name",
"or",
"short",
"commit",
"hash",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L584-L603 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getMainScriptContents | public function getMainScriptContents()
{
if (null !== ($path = $this->getMainScriptPath())) {
$path = $this->getBasePath() . DIRECTORY_SEPARATOR . $path;
if (false === ($contents = @file_get_contents($path))) {
$errors = error_get_last();
if ($errors === null) {
$errors = array('message' => 'failed to get contents of \''.$path.'\'');
}
throw new RuntimeException($errors['message']);
}
return preg_replace('/^#!.*\s*/', '', $contents);
}
return null;
} | php | public function getMainScriptContents()
{
if (null !== ($path = $this->getMainScriptPath())) {
$path = $this->getBasePath() . DIRECTORY_SEPARATOR . $path;
if (false === ($contents = @file_get_contents($path))) {
$errors = error_get_last();
if ($errors === null) {
$errors = array('message' => 'failed to get contents of \''.$path.'\'');
}
throw new RuntimeException($errors['message']);
}
return preg_replace('/^#!.*\s*/', '', $contents);
}
return null;
} | [
"public",
"function",
"getMainScriptContents",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"path",
"=",
"$",
"this",
"->",
"getMainScriptPath",
"(",
")",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
";",
"if",
"(",
"false",
"===",
"(",
"$",
"contents",
"=",
"@",
"file_get_contents",
"(",
"$",
"path",
")",
")",
")",
"{",
"$",
"errors",
"=",
"error_get_last",
"(",
")",
";",
"if",
"(",
"$",
"errors",
"===",
"null",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
"'message'",
"=>",
"'failed to get contents of \\''",
".",
"$",
"path",
".",
"'\\''",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"$",
"errors",
"[",
"'message'",
"]",
")",
";",
"}",
"return",
"preg_replace",
"(",
"'/^#!.*\\s*/'",
",",
"''",
",",
"$",
"contents",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the processed contents of the main script file.
@return string The contents.
@throws RuntimeException If the file could not be read. | [
"Returns",
"the",
"processed",
"contents",
"of",
"the",
"main",
"script",
"file",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L626-L644 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getMainScriptPath | public function getMainScriptPath()
{
if (isset($this->raw->main)) {
return Path::canonical($this->raw->main);
}
return null;
} | php | public function getMainScriptPath()
{
if (isset($this->raw->main)) {
return Path::canonical($this->raw->main);
}
return null;
} | [
"public",
"function",
"getMainScriptPath",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"main",
")",
")",
"{",
"return",
"Path",
"::",
"canonical",
"(",
"$",
"this",
"->",
"raw",
"->",
"main",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the main script file path.
@return string The file path. | [
"Returns",
"the",
"main",
"script",
"file",
"path",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L651-L658 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getMap | public function getMap()
{
if (isset($this->raw->map)) {
$map = array();
foreach ((array) $this->raw->map as $item) {
$processed = array();
foreach ($item as $match => $replace) {
$processed[Path::canonical($match)] = Path::canonical($replace);
}
if (isset($processed['_empty_'])) {
$processed[''] = $processed['_empty_'];
unset($processed['_empty_']);
}
$map[] = $processed;
}
return $map;
}
return array();
} | php | public function getMap()
{
if (isset($this->raw->map)) {
$map = array();
foreach ((array) $this->raw->map as $item) {
$processed = array();
foreach ($item as $match => $replace) {
$processed[Path::canonical($match)] = Path::canonical($replace);
}
if (isset($processed['_empty_'])) {
$processed[''] = $processed['_empty_'];
unset($processed['_empty_']);
}
$map[] = $processed;
}
return $map;
}
return array();
} | [
"public",
"function",
"getMap",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"map",
")",
")",
"{",
"$",
"map",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"map",
"as",
"$",
"item",
")",
"{",
"$",
"processed",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"item",
"as",
"$",
"match",
"=>",
"$",
"replace",
")",
"{",
"$",
"processed",
"[",
"Path",
"::",
"canonical",
"(",
"$",
"match",
")",
"]",
"=",
"Path",
"::",
"canonical",
"(",
"$",
"replace",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"processed",
"[",
"'_empty_'",
"]",
")",
")",
"{",
"$",
"processed",
"[",
"''",
"]",
"=",
"$",
"processed",
"[",
"'_empty_'",
"]",
";",
"unset",
"(",
"$",
"processed",
"[",
"'_empty_'",
"]",
")",
";",
"}",
"$",
"map",
"[",
"]",
"=",
"$",
"processed",
";",
"}",
"return",
"$",
"map",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Returns the internal file path mapping.
@return array The mapping. | [
"Returns",
"the",
"internal",
"file",
"path",
"mapping",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L665-L690 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getMapper | public function getMapper()
{
$map = $this->getMap();
return function ($path) use ($map) {
foreach ($map as $item) {
foreach ($item as $match => $replace) {
if (empty($match)) {
return $replace . $path;
} elseif (0 === strpos($path, $match)) {
return preg_replace(
'/^' . preg_quote($match, '/') . '/',
$replace,
$path
);
}
}
}
return null;
};
} | php | public function getMapper()
{
$map = $this->getMap();
return function ($path) use ($map) {
foreach ($map as $item) {
foreach ($item as $match => $replace) {
if (empty($match)) {
return $replace . $path;
} elseif (0 === strpos($path, $match)) {
return preg_replace(
'/^' . preg_quote($match, '/') . '/',
$replace,
$path
);
}
}
}
return null;
};
} | [
"public",
"function",
"getMapper",
"(",
")",
"{",
"$",
"map",
"=",
"$",
"this",
"->",
"getMap",
"(",
")",
";",
"return",
"function",
"(",
"$",
"path",
")",
"use",
"(",
"$",
"map",
")",
"{",
"foreach",
"(",
"$",
"map",
"as",
"$",
"item",
")",
"{",
"foreach",
"(",
"$",
"item",
"as",
"$",
"match",
"=>",
"$",
"replace",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"match",
")",
")",
"{",
"return",
"$",
"replace",
".",
"$",
"path",
";",
"}",
"elseif",
"(",
"0",
"===",
"strpos",
"(",
"$",
"path",
",",
"$",
"match",
")",
")",
"{",
"return",
"preg_replace",
"(",
"'/^'",
".",
"preg_quote",
"(",
"$",
"match",
",",
"'/'",
")",
".",
"'/'",
",",
"$",
"replace",
",",
"$",
"path",
")",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}",
";",
"}"
] | Returns a mapping callable for the configured map.
@return callable The mapping callable. | [
"Returns",
"a",
"mapping",
"callable",
"for",
"the",
"configured",
"map",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L697-L718 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getMetadata | public function getMetadata()
{
if (isset($this->raw->metadata)) {
if (is_object($this->raw->metadata)) {
return (array) $this->raw->metadata;
}
return $this->raw->metadata;
}
return null;
} | php | public function getMetadata()
{
if (isset($this->raw->metadata)) {
if (is_object($this->raw->metadata)) {
return (array) $this->raw->metadata;
}
return $this->raw->metadata;
}
return null;
} | [
"public",
"function",
"getMetadata",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"metadata",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"raw",
"->",
"metadata",
")",
")",
"{",
"return",
"(",
"array",
")",
"$",
"this",
"->",
"raw",
"->",
"metadata",
";",
"}",
"return",
"$",
"this",
"->",
"raw",
"->",
"metadata",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the Phar metadata.
@return mixed The metadata. | [
"Returns",
"the",
"Phar",
"metadata",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L725-L736 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getOutputPath | public function getOutputPath()
{
$base = getcwd() . DIRECTORY_SEPARATOR;
if (isset($this->raw->output)) {
$path = $this->raw->output;
if (false === Path::isAbsolute($path)) {
$path = Path::canonical($base . $path);
}
} else {
$path = $base . 'default.phar';
}
if (false !== strpos($path, '@' . 'git-version@')) {
$path = str_replace('@' . 'git-version@', $this->getGitVersion(), $path);
}
return $path;
} | php | public function getOutputPath()
{
$base = getcwd() . DIRECTORY_SEPARATOR;
if (isset($this->raw->output)) {
$path = $this->raw->output;
if (false === Path::isAbsolute($path)) {
$path = Path::canonical($base . $path);
}
} else {
$path = $base . 'default.phar';
}
if (false !== strpos($path, '@' . 'git-version@')) {
$path = str_replace('@' . 'git-version@', $this->getGitVersion(), $path);
}
return $path;
} | [
"public",
"function",
"getOutputPath",
"(",
")",
"{",
"$",
"base",
"=",
"getcwd",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"output",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"raw",
"->",
"output",
";",
"if",
"(",
"false",
"===",
"Path",
"::",
"isAbsolute",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"Path",
"::",
"canonical",
"(",
"$",
"base",
".",
"$",
"path",
")",
";",
"}",
"}",
"else",
"{",
"$",
"path",
"=",
"$",
"base",
".",
"'default.phar'",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"path",
",",
"'@'",
".",
"'git-version@'",
")",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'@'",
".",
"'git-version@'",
",",
"$",
"this",
"->",
"getGitVersion",
"(",
")",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Returns the output file path.
@return string The file path. | [
"Returns",
"the",
"output",
"file",
"path",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L785-L804 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getPrivateKeyPassphrase | public function getPrivateKeyPassphrase()
{
if (isset($this->raw->{'key-pass'})
&& is_string($this->raw->{'key-pass'})) {
return $this->raw->{'key-pass'};
}
return null;
} | php | public function getPrivateKeyPassphrase()
{
if (isset($this->raw->{'key-pass'})
&& is_string($this->raw->{'key-pass'})) {
return $this->raw->{'key-pass'};
}
return null;
} | [
"public",
"function",
"getPrivateKeyPassphrase",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"{",
"'key-pass'",
"}",
")",
"&&",
"is_string",
"(",
"$",
"this",
"->",
"raw",
"->",
"{",
"'key-pass'",
"}",
")",
")",
"{",
"return",
"$",
"this",
"->",
"raw",
"->",
"{",
"'key-pass'",
"}",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the private key passphrase.
@return string The passphrase. | [
"Returns",
"the",
"private",
"key",
"passphrase",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L811-L819 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getProcessedReplacements | public function getProcessedReplacements()
{
$values = $this->getReplacements();
if (null !== ($git = $this->getGitHashPlaceholder())) {
$values[$git] = $this->getGitHash();
}
if (null !== ($git = $this->getGitShortHashPlaceholder())) {
$values[$git] = $this->getGitHash(true);
}
if (null !== ($git = $this->getGitTagPlaceholder())) {
$values[$git] = $this->getGitTag();
}
if (null !== ($git = $this->getGitVersionPlaceholder())) {
$values[$git] = $this->getGitVersion();
}
if (null !== ($date = $this->getDatetimeNowPlaceHolder())) {
$values[$date] = $this->getDatetimeNow($this->getDatetimeFormat());
}
$sigil = $this->getReplacementSigil();
foreach ($values as $key => $value) {
unset($values[$key]);
$values["$sigil$key$sigil"] = $value;
}
return $values;
} | php | public function getProcessedReplacements()
{
$values = $this->getReplacements();
if (null !== ($git = $this->getGitHashPlaceholder())) {
$values[$git] = $this->getGitHash();
}
if (null !== ($git = $this->getGitShortHashPlaceholder())) {
$values[$git] = $this->getGitHash(true);
}
if (null !== ($git = $this->getGitTagPlaceholder())) {
$values[$git] = $this->getGitTag();
}
if (null !== ($git = $this->getGitVersionPlaceholder())) {
$values[$git] = $this->getGitVersion();
}
if (null !== ($date = $this->getDatetimeNowPlaceHolder())) {
$values[$date] = $this->getDatetimeNow($this->getDatetimeFormat());
}
$sigil = $this->getReplacementSigil();
foreach ($values as $key => $value) {
unset($values[$key]);
$values["$sigil$key$sigil"] = $value;
}
return $values;
} | [
"public",
"function",
"getProcessedReplacements",
"(",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"getReplacements",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"(",
"$",
"git",
"=",
"$",
"this",
"->",
"getGitHashPlaceholder",
"(",
")",
")",
")",
"{",
"$",
"values",
"[",
"$",
"git",
"]",
"=",
"$",
"this",
"->",
"getGitHash",
"(",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"git",
"=",
"$",
"this",
"->",
"getGitShortHashPlaceholder",
"(",
")",
")",
")",
"{",
"$",
"values",
"[",
"$",
"git",
"]",
"=",
"$",
"this",
"->",
"getGitHash",
"(",
"true",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"git",
"=",
"$",
"this",
"->",
"getGitTagPlaceholder",
"(",
")",
")",
")",
"{",
"$",
"values",
"[",
"$",
"git",
"]",
"=",
"$",
"this",
"->",
"getGitTag",
"(",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"git",
"=",
"$",
"this",
"->",
"getGitVersionPlaceholder",
"(",
")",
")",
")",
"{",
"$",
"values",
"[",
"$",
"git",
"]",
"=",
"$",
"this",
"->",
"getGitVersion",
"(",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"date",
"=",
"$",
"this",
"->",
"getDatetimeNowPlaceHolder",
"(",
")",
")",
")",
"{",
"$",
"values",
"[",
"$",
"date",
"]",
"=",
"$",
"this",
"->",
"getDatetimeNow",
"(",
"$",
"this",
"->",
"getDatetimeFormat",
"(",
")",
")",
";",
"}",
"$",
"sigil",
"=",
"$",
"this",
"->",
"getReplacementSigil",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"unset",
"(",
"$",
"values",
"[",
"$",
"key",
"]",
")",
";",
"$",
"values",
"[",
"\"$sigil$key$sigil\"",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Returns the processed list of replacement placeholders and their values.
@return array The list of replacements. | [
"Returns",
"the",
"processed",
"list",
"of",
"replacement",
"placeholders",
"and",
"their",
"values",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L840-L873 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getShebang | public function getShebang()
{
if (isset($this->raw->shebang)) {
if (('' === $this->raw->shebang) || (false === $this->raw->shebang)) {
return '';
}
$shebang = trim($this->raw->shebang);
if ('#!' !== substr($shebang, 0, 2)) {
throw new InvalidArgumentException(
sprintf(
'The shebang line must start with "#!": %s',
$shebang
)
);
}
return $shebang;
}
return null;
} | php | public function getShebang()
{
if (isset($this->raw->shebang)) {
if (('' === $this->raw->shebang) || (false === $this->raw->shebang)) {
return '';
}
$shebang = trim($this->raw->shebang);
if ('#!' !== substr($shebang, 0, 2)) {
throw new InvalidArgumentException(
sprintf(
'The shebang line must start with "#!": %s',
$shebang
)
);
}
return $shebang;
}
return null;
} | [
"public",
"function",
"getShebang",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"shebang",
")",
")",
"{",
"if",
"(",
"(",
"''",
"===",
"$",
"this",
"->",
"raw",
"->",
"shebang",
")",
"||",
"(",
"false",
"===",
"$",
"this",
"->",
"raw",
"->",
"shebang",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"shebang",
"=",
"trim",
"(",
"$",
"this",
"->",
"raw",
"->",
"shebang",
")",
";",
"if",
"(",
"'#!'",
"!==",
"substr",
"(",
"$",
"shebang",
",",
"0",
",",
"2",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The shebang line must start with \"#!\": %s'",
",",
"$",
"shebang",
")",
")",
";",
"}",
"return",
"$",
"shebang",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the shebang line.
@return string The shebang line.
@throws InvalidArgumentException If the shebang line is no valid. | [
"Returns",
"the",
"shebang",
"line",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L910-L932 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getSigningAlgorithm | public function getSigningAlgorithm()
{
if (isset($this->raw->algorithm)) {
if (is_string($this->raw->algorithm)) {
if (false === defined('Phar::' . $this->raw->algorithm)) {
throw new InvalidArgumentException(
sprintf(
'The signing algorithm "%s" is not supported.',
$this->raw->algorithm
)
);
}
return constant('Phar::' . $this->raw->algorithm);
}
return $this->raw->algorithm;
}
return Phar::SHA1;
} | php | public function getSigningAlgorithm()
{
if (isset($this->raw->algorithm)) {
if (is_string($this->raw->algorithm)) {
if (false === defined('Phar::' . $this->raw->algorithm)) {
throw new InvalidArgumentException(
sprintf(
'The signing algorithm "%s" is not supported.',
$this->raw->algorithm
)
);
}
return constant('Phar::' . $this->raw->algorithm);
}
return $this->raw->algorithm;
}
return Phar::SHA1;
} | [
"public",
"function",
"getSigningAlgorithm",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"algorithm",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"raw",
"->",
"algorithm",
")",
")",
"{",
"if",
"(",
"false",
"===",
"defined",
"(",
"'Phar::'",
".",
"$",
"this",
"->",
"raw",
"->",
"algorithm",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The signing algorithm \"%s\" is not supported.'",
",",
"$",
"this",
"->",
"raw",
"->",
"algorithm",
")",
")",
";",
"}",
"return",
"constant",
"(",
"'Phar::'",
".",
"$",
"this",
"->",
"raw",
"->",
"algorithm",
")",
";",
"}",
"return",
"$",
"this",
"->",
"raw",
"->",
"algorithm",
";",
"}",
"return",
"Phar",
"::",
"SHA1",
";",
"}"
] | Returns the Phar signing algorithm.
@return integer The signing algorithm.
@throws InvalidArgumentException If the algorithm is not valid. | [
"Returns",
"the",
"Phar",
"signing",
"algorithm",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L941-L961 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getStubBannerFromFile | public function getStubBannerFromFile()
{
if (null !== ($path = $this->getStubBannerPath())) {
$path = $this->getBasePath() . DIRECTORY_SEPARATOR . $path;
if (false === ($contents = @file_get_contents($path))) {
$errors = error_get_last();
if ($errors === null) {
$errors = array('message' => 'failed to get contents of \''.$path.'\'');
}
throw new RuntimeException($errors['message']);
}
return $contents;
}
return null;
} | php | public function getStubBannerFromFile()
{
if (null !== ($path = $this->getStubBannerPath())) {
$path = $this->getBasePath() . DIRECTORY_SEPARATOR . $path;
if (false === ($contents = @file_get_contents($path))) {
$errors = error_get_last();
if ($errors === null) {
$errors = array('message' => 'failed to get contents of \''.$path.'\'');
}
throw new RuntimeException($errors['message']);
}
return $contents;
}
return null;
} | [
"public",
"function",
"getStubBannerFromFile",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"path",
"=",
"$",
"this",
"->",
"getStubBannerPath",
"(",
")",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
";",
"if",
"(",
"false",
"===",
"(",
"$",
"contents",
"=",
"@",
"file_get_contents",
"(",
"$",
"path",
")",
")",
")",
"{",
"$",
"errors",
"=",
"error_get_last",
"(",
")",
";",
"if",
"(",
"$",
"errors",
"===",
"null",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
"'message'",
"=>",
"'failed to get contents of \\''",
".",
"$",
"path",
".",
"'\\''",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"$",
"errors",
"[",
"'message'",
"]",
")",
";",
"}",
"return",
"$",
"contents",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the stub banner comment from the file.
@return string The stub banner comment.
@throws RuntimeException If the comment file could not be read. | [
"Returns",
"the",
"stub",
"banner",
"comment",
"from",
"the",
"file",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L984-L1002 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.getStubPath | public function getStubPath()
{
if (isset($this->raw->stub) && is_string($this->raw->stub)) {
return $this->raw->stub;
}
return null;
} | php | public function getStubPath()
{
if (isset($this->raw->stub) && is_string($this->raw->stub)) {
return $this->raw->stub;
}
return null;
} | [
"public",
"function",
"getStubPath",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"stub",
")",
"&&",
"is_string",
"(",
"$",
"this",
"->",
"raw",
"->",
"stub",
")",
")",
"{",
"return",
"$",
"this",
"->",
"raw",
"->",
"stub",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the Phar stub file path.
@return string The file path. | [
"Returns",
"the",
"Phar",
"stub",
"file",
"path",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L1022-L1029 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.isStubGenerated | public function isStubGenerated()
{
if (isset($this->raw->stub) && (true === $this->raw->stub)) {
return true;
}
return false;
} | php | public function isStubGenerated()
{
if (isset($this->raw->stub) && (true === $this->raw->stub)) {
return true;
}
return false;
} | [
"public",
"function",
"isStubGenerated",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"->",
"stub",
")",
"&&",
"(",
"true",
"===",
"$",
"this",
"->",
"raw",
"->",
"stub",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if the Phar stub should be generated.
@return boolean TRUE if it should be generated, FALSE if not. | [
"Checks",
"if",
"the",
"Phar",
"stub",
"should",
"be",
"generated",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L1079-L1086 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.loadBootstrap | public function loadBootstrap()
{
if (null !== ($file = $this->getBootstrapFile())) {
if (false === file_exists($file)) {
throw new InvalidArgumentException(
sprintf(
'The bootstrap path "%s" is not a file or does not exist.',
$file
)
);
}
/** @noinspection PhpIncludeInspection */
include $file;
}
} | php | public function loadBootstrap()
{
if (null !== ($file = $this->getBootstrapFile())) {
if (false === file_exists($file)) {
throw new InvalidArgumentException(
sprintf(
'The bootstrap path "%s" is not a file or does not exist.',
$file
)
);
}
/** @noinspection PhpIncludeInspection */
include $file;
}
} | [
"public",
"function",
"loadBootstrap",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getBootstrapFile",
"(",
")",
")",
")",
"{",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The bootstrap path \"%s\" is not a file or does not exist.'",
",",
"$",
"file",
")",
")",
";",
"}",
"/** @noinspection PhpIncludeInspection */",
"include",
"$",
"file",
";",
"}",
"}"
] | Loads the configured bootstrap file if available. | [
"Loads",
"the",
"configured",
"bootstrap",
"file",
"if",
"available",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L1105-L1120 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.processFinders | private function processFinders(array $config)
{
$finders = array();
$filter = $this->getBlacklistFilter();
foreach ($config as $methods) {
$finder = Finder::create()
->files()
->filter($filter)
->ignoreVCS(true);
if (isset($methods->in)) {
$base = $this->getBasePath();
$methods->in = (array) $methods->in;
array_walk(
$methods->in,
function (&$directory) use ($base) {
$directory = Path::canonical(
$base . DIRECTORY_SEPARATOR . $directory
);
}
);
}
foreach ($methods as $method => $arguments) {
if (false === method_exists($finder, $method)) {
throw new InvalidArgumentException(
sprintf(
'The method "Finder::%s" does not exist.',
$method
)
);
}
$arguments = (array) $arguments;
foreach ($arguments as $argument) {
$finder->$method($argument);
}
}
$finders[] = $finder;
}
return $finders;
} | php | private function processFinders(array $config)
{
$finders = array();
$filter = $this->getBlacklistFilter();
foreach ($config as $methods) {
$finder = Finder::create()
->files()
->filter($filter)
->ignoreVCS(true);
if (isset($methods->in)) {
$base = $this->getBasePath();
$methods->in = (array) $methods->in;
array_walk(
$methods->in,
function (&$directory) use ($base) {
$directory = Path::canonical(
$base . DIRECTORY_SEPARATOR . $directory
);
}
);
}
foreach ($methods as $method => $arguments) {
if (false === method_exists($finder, $method)) {
throw new InvalidArgumentException(
sprintf(
'The method "Finder::%s" does not exist.',
$method
)
);
}
$arguments = (array) $arguments;
foreach ($arguments as $argument) {
$finder->$method($argument);
}
}
$finders[] = $finder;
}
return $finders;
} | [
"private",
"function",
"processFinders",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"finders",
"=",
"array",
"(",
")",
";",
"$",
"filter",
"=",
"$",
"this",
"->",
"getBlacklistFilter",
"(",
")",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"methods",
")",
"{",
"$",
"finder",
"=",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"filter",
"(",
"$",
"filter",
")",
"->",
"ignoreVCS",
"(",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"methods",
"->",
"in",
")",
")",
"{",
"$",
"base",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
";",
"$",
"methods",
"->",
"in",
"=",
"(",
"array",
")",
"$",
"methods",
"->",
"in",
";",
"array_walk",
"(",
"$",
"methods",
"->",
"in",
",",
"function",
"(",
"&",
"$",
"directory",
")",
"use",
"(",
"$",
"base",
")",
"{",
"$",
"directory",
"=",
"Path",
"::",
"canonical",
"(",
"$",
"base",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"directory",
")",
";",
"}",
")",
";",
"}",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
"=>",
"$",
"arguments",
")",
"{",
"if",
"(",
"false",
"===",
"method_exists",
"(",
"$",
"finder",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The method \"Finder::%s\" does not exist.'",
",",
"$",
"method",
")",
")",
";",
"}",
"$",
"arguments",
"=",
"(",
"array",
")",
"$",
"arguments",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"argument",
")",
"{",
"$",
"finder",
"->",
"$",
"method",
"(",
"$",
"argument",
")",
";",
"}",
"}",
"$",
"finders",
"[",
"]",
"=",
"$",
"finder",
";",
"}",
"return",
"$",
"finders",
";",
"}"
] | Processes the Finders configuration list.
@param array $config The configuration.
@return Finder[] The list of Finders.
@throws InvalidArgumentException If the configured method does not exist. | [
"Processes",
"the",
"Finders",
"configuration",
"list",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L1131-L1177 |
box-project/box2 | src/lib/KevinGH/Box/Configuration.php | Configuration.runGitCommand | private function runGitCommand($command)
{
$path = dirname($this->file);
$process = new Process($command, $path);
if (0 === $process->run()) {
return trim($process->getOutput());
}
throw new RuntimeException(
sprintf(
'The tag or commit hash could not be retrieved from "%s": %s',
$path,
$process->getErrorOutput()
)
);
} | php | private function runGitCommand($command)
{
$path = dirname($this->file);
$process = new Process($command, $path);
if (0 === $process->run()) {
return trim($process->getOutput());
}
throw new RuntimeException(
sprintf(
'The tag or commit hash could not be retrieved from "%s": %s',
$path,
$process->getErrorOutput()
)
);
} | [
"private",
"function",
"runGitCommand",
"(",
"$",
"command",
")",
"{",
"$",
"path",
"=",
"dirname",
"(",
"$",
"this",
"->",
"file",
")",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"command",
",",
"$",
"path",
")",
";",
"if",
"(",
"0",
"===",
"$",
"process",
"->",
"run",
"(",
")",
")",
"{",
"return",
"trim",
"(",
"$",
"process",
"->",
"getOutput",
"(",
")",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The tag or commit hash could not be retrieved from \"%s\": %s'",
",",
"$",
"path",
",",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
")",
";",
"}"
] | Runs a Git command on the repository.
@param string $command The command.
@return string The trimmed output from the command.
@throws RuntimeException If the command failed. | [
"Runs",
"a",
"Git",
"command",
"on",
"the",
"repository",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Configuration.php#L1188-L1204 |
box-project/box2 | src/lib/KevinGH/Box/Command/Build.php | Build.add | private function add(
Traversable $iterator = null,
$message = null,
$binary = false
) {
static $count = 0;
if ($iterator) {
if ($message) {
$this->putln('?', $message);
}
$box = $binary ? $this->box->getPhar() : $this->box;
$baseRegex = $this->config->getBasePathRegex();
$mapper = $this->config->getMapper();
/** @var $file SplFileInfo */
foreach ($iterator as $file) {
if (0 === (++$count % 100)) {
gc_collect_cycles();
}
$relative = preg_replace($baseRegex, '', $file->getPathname());
if (null !== ($mapped = $mapper($relative))) {
$relative = $mapped;
}
if ($this->isVerbose()) {
if (false === $file->isReadable()) {
throw new RuntimeException(
sprintf(
'The file "%s" is not readable.',
$file->getPathname()
)
);
}
$this->putln('+', $file);
if (null !== $mapped) {
$this->putln('>', $relative);
}
}
$box->addFile($file, $relative);
}
}
} | php | private function add(
Traversable $iterator = null,
$message = null,
$binary = false
) {
static $count = 0;
if ($iterator) {
if ($message) {
$this->putln('?', $message);
}
$box = $binary ? $this->box->getPhar() : $this->box;
$baseRegex = $this->config->getBasePathRegex();
$mapper = $this->config->getMapper();
/** @var $file SplFileInfo */
foreach ($iterator as $file) {
if (0 === (++$count % 100)) {
gc_collect_cycles();
}
$relative = preg_replace($baseRegex, '', $file->getPathname());
if (null !== ($mapped = $mapper($relative))) {
$relative = $mapped;
}
if ($this->isVerbose()) {
if (false === $file->isReadable()) {
throw new RuntimeException(
sprintf(
'The file "%s" is not readable.',
$file->getPathname()
)
);
}
$this->putln('+', $file);
if (null !== $mapped) {
$this->putln('>', $relative);
}
}
$box->addFile($file, $relative);
}
}
} | [
"private",
"function",
"add",
"(",
"Traversable",
"$",
"iterator",
"=",
"null",
",",
"$",
"message",
"=",
"null",
",",
"$",
"binary",
"=",
"false",
")",
"{",
"static",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"$",
"iterator",
")",
"{",
"if",
"(",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"putln",
"(",
"'?'",
",",
"$",
"message",
")",
";",
"}",
"$",
"box",
"=",
"$",
"binary",
"?",
"$",
"this",
"->",
"box",
"->",
"getPhar",
"(",
")",
":",
"$",
"this",
"->",
"box",
";",
"$",
"baseRegex",
"=",
"$",
"this",
"->",
"config",
"->",
"getBasePathRegex",
"(",
")",
";",
"$",
"mapper",
"=",
"$",
"this",
"->",
"config",
"->",
"getMapper",
"(",
")",
";",
"/** @var $file SplFileInfo */",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"0",
"===",
"(",
"++",
"$",
"count",
"%",
"100",
")",
")",
"{",
"gc_collect_cycles",
"(",
")",
";",
"}",
"$",
"relative",
"=",
"preg_replace",
"(",
"$",
"baseRegex",
",",
"''",
",",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"if",
"(",
"null",
"!==",
"(",
"$",
"mapped",
"=",
"$",
"mapper",
"(",
"$",
"relative",
")",
")",
")",
"{",
"$",
"relative",
"=",
"$",
"mapped",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isVerbose",
"(",
")",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"file",
"->",
"isReadable",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The file \"%s\" is not readable.'",
",",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"putln",
"(",
"'+'",
",",
"$",
"file",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"mapped",
")",
"{",
"$",
"this",
"->",
"putln",
"(",
"'>'",
",",
"$",
"relative",
")",
";",
"}",
"}",
"$",
"box",
"->",
"addFile",
"(",
"$",
"file",
",",
"$",
"relative",
")",
";",
"}",
"}",
"}"
] | Adds files using an iterator.
@param Traversable $iterator The iterator.
@param string $message The message to announce.
@param boolean $binary Should the adding be binary-safe?
@throws RuntimeException If a file is not readable. | [
"Adds",
"files",
"using",
"an",
"iterator",
"."
] | train | https://github.com/box-project/box2/blob/740f8ce7742f523056e38cb2cb077f2edb32e5af/src/lib/KevinGH/Box/Command/Build.php#L651-L699 |
spatie/laravel-googletagmanager | src/GoogleTagManagerMiddleware.php | GoogleTagManagerMiddleware.handle | public function handle($request, Closure $next)
{
if ($this->session->has($this->sessionKey)) {
$this->googleTagManager->set($this->session->get($this->sessionKey));
}
$response = $next($request);
$this->session->flash($this->sessionKey, $this->googleTagManager->getFlashData());
return $response;
} | php | public function handle($request, Closure $next)
{
if ($this->session->has($this->sessionKey)) {
$this->googleTagManager->set($this->session->get($this->sessionKey));
}
$response = $next($request);
$this->session->flash($this->sessionKey, $this->googleTagManager->getFlashData());
return $response;
} | [
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"session",
"->",
"has",
"(",
"$",
"this",
"->",
"sessionKey",
")",
")",
"{",
"$",
"this",
"->",
"googleTagManager",
"->",
"set",
"(",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"$",
"this",
"->",
"sessionKey",
")",
")",
";",
"}",
"$",
"response",
"=",
"$",
"next",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"session",
"->",
"flash",
"(",
"$",
"this",
"->",
"sessionKey",
",",
"$",
"this",
"->",
"googleTagManager",
"->",
"getFlashData",
"(",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@return mixed | [
"Handle",
"an",
"incoming",
"request",
"."
] | train | https://github.com/spatie/laravel-googletagmanager/blob/8e58e47767df0484055b415ec49dc7ef42bc3a9c/src/GoogleTagManagerMiddleware.php#L46-L57 |
spatie/laravel-googletagmanager | src/GoogleTagManager.php | GoogleTagManager.push | public function push($key, $value = null)
{
$pushItem = new DataLayer();
$pushItem->set($key, $value);
$this->pushDataLayer->push($pushItem);
} | php | public function push($key, $value = null)
{
$pushItem = new DataLayer();
$pushItem->set($key, $value);
$this->pushDataLayer->push($pushItem);
} | [
"public",
"function",
"push",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"pushItem",
"=",
"new",
"DataLayer",
"(",
")",
";",
"$",
"pushItem",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"pushDataLayer",
"->",
"push",
"(",
"$",
"pushItem",
")",
";",
"}"
] | Add data to be pushed to the data layer.
@param array|string $key
@param mixed $value | [
"Add",
"data",
"to",
"be",
"pushed",
"to",
"the",
"data",
"layer",
"."
] | train | https://github.com/spatie/laravel-googletagmanager/blob/8e58e47767df0484055b415ec49dc7ef42bc3a9c/src/GoogleTagManager.php#L140-L145 |
spatie/laravel-googletagmanager | src/GoogleTagManagerServiceProvider.php | GoogleTagManagerServiceProvider.boot | public function boot()
{
$this->loadViewsFrom(__DIR__.'/../resources/views', 'googletagmanager');
$this->publishes([
__DIR__.'/../resources/config/config.php' => config_path('googletagmanager.php'),
], 'config');
$this->publishes([
__DIR__.'/../resources/views' => base_path('resources/views/vendor/googletagmanager'),
], 'views');
$this->app['view']->creator(
['googletagmanager::head', 'googletagmanager::body', 'googletagmanager::script'],
'Spatie\GoogleTagManager\ScriptViewCreator'
);
} | php | public function boot()
{
$this->loadViewsFrom(__DIR__.'/../resources/views', 'googletagmanager');
$this->publishes([
__DIR__.'/../resources/config/config.php' => config_path('googletagmanager.php'),
], 'config');
$this->publishes([
__DIR__.'/../resources/views' => base_path('resources/views/vendor/googletagmanager'),
], 'views');
$this->app['view']->creator(
['googletagmanager::head', 'googletagmanager::body', 'googletagmanager::script'],
'Spatie\GoogleTagManager\ScriptViewCreator'
);
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"__DIR__",
".",
"'/../resources/views'",
",",
"'googletagmanager'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../resources/config/config.php'",
"=>",
"config_path",
"(",
"'googletagmanager.php'",
")",
",",
"]",
",",
"'config'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../resources/views'",
"=>",
"base_path",
"(",
"'resources/views/vendor/googletagmanager'",
")",
",",
"]",
",",
"'views'",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'view'",
"]",
"->",
"creator",
"(",
"[",
"'googletagmanager::head'",
",",
"'googletagmanager::body'",
",",
"'googletagmanager::script'",
"]",
",",
"'Spatie\\GoogleTagManager\\ScriptViewCreator'",
")",
";",
"}"
] | Bootstrap the application services. | [
"Bootstrap",
"the",
"application",
"services",
"."
] | train | https://github.com/spatie/laravel-googletagmanager/blob/8e58e47767df0484055b415ec49dc7ef42bc3a9c/src/GoogleTagManagerServiceProvider.php#L13-L29 |
spatie/laravel-googletagmanager | src/GoogleTagManagerServiceProvider.php | GoogleTagManagerServiceProvider.register | public function register()
{
$this->mergeConfigFrom(__DIR__.'/../resources/config/config.php', 'googletagmanager');
$googleTagManager = new GoogleTagManager(config('googletagmanager.id'));
if (config('googletagmanager.enabled') === false) {
$googleTagManager->disable();
}
$this->app->instance('Spatie\GoogleTagManager\GoogleTagManager', $googleTagManager);
$this->app->alias('Spatie\GoogleTagManager\GoogleTagManager', 'googletagmanager');
if (is_file(config('googletagmanager.macroPath'))) {
include config('googletagmanager.macroPath');
}
} | php | public function register()
{
$this->mergeConfigFrom(__DIR__.'/../resources/config/config.php', 'googletagmanager');
$googleTagManager = new GoogleTagManager(config('googletagmanager.id'));
if (config('googletagmanager.enabled') === false) {
$googleTagManager->disable();
}
$this->app->instance('Spatie\GoogleTagManager\GoogleTagManager', $googleTagManager);
$this->app->alias('Spatie\GoogleTagManager\GoogleTagManager', 'googletagmanager');
if (is_file(config('googletagmanager.macroPath'))) {
include config('googletagmanager.macroPath');
}
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"__DIR__",
".",
"'/../resources/config/config.php'",
",",
"'googletagmanager'",
")",
";",
"$",
"googleTagManager",
"=",
"new",
"GoogleTagManager",
"(",
"config",
"(",
"'googletagmanager.id'",
")",
")",
";",
"if",
"(",
"config",
"(",
"'googletagmanager.enabled'",
")",
"===",
"false",
")",
"{",
"$",
"googleTagManager",
"->",
"disable",
"(",
")",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"instance",
"(",
"'Spatie\\GoogleTagManager\\GoogleTagManager'",
",",
"$",
"googleTagManager",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"'Spatie\\GoogleTagManager\\GoogleTagManager'",
",",
"'googletagmanager'",
")",
";",
"if",
"(",
"is_file",
"(",
"config",
"(",
"'googletagmanager.macroPath'",
")",
")",
")",
"{",
"include",
"config",
"(",
"'googletagmanager.macroPath'",
")",
";",
"}",
"}"
] | Register the application services. | [
"Register",
"the",
"application",
"services",
"."
] | train | https://github.com/spatie/laravel-googletagmanager/blob/8e58e47767df0484055b415ec49dc7ef42bc3a9c/src/GoogleTagManagerServiceProvider.php#L34-L50 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean8.php | CINean8.draw | public function draw($im) {
// Checksum
$this->calculateChecksum();
$temp_text = $this->text . $this->keys[$this->checksumValue];
// Starting Code
$this->drawChar($im, '000', true);
// Draw First 4 Chars (Left-Hand)
for ($i = 0; $i < 4; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), false);
}
// Draw Center Guard Bar
$this->drawChar($im, '00000', false);
// Draw Last 4 Chars (Right-Hand)
for ($i = 4; $i < 8; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Draw Right Guard Bar
$this->drawChar($im, '000', true);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
if ($this->isDefaultEanLabelEnabled()) {
$dimension = $this->labelRight->getDimension();
$this->drawExtendedBars($im, $dimension[1] - 2);
}
} | php | public function draw($im) {
// Checksum
$this->calculateChecksum();
$temp_text = $this->text . $this->keys[$this->checksumValue];
// Starting Code
$this->drawChar($im, '000', true);
// Draw First 4 Chars (Left-Hand)
for ($i = 0; $i < 4; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), false);
}
// Draw Center Guard Bar
$this->drawChar($im, '00000', false);
// Draw Last 4 Chars (Right-Hand)
for ($i = 4; $i < 8; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Draw Right Guard Bar
$this->drawChar($im, '000', true);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
if ($this->isDefaultEanLabelEnabled()) {
$dimension = $this->labelRight->getDimension();
$this->drawExtendedBars($im, $dimension[1] - 2);
}
} | [
"public",
"function",
"draw",
"(",
"$",
"im",
")",
"{",
"// Checksum\r",
"$",
"this",
"->",
"calculateChecksum",
"(",
")",
";",
"$",
"temp_text",
"=",
"$",
"this",
"->",
"text",
".",
"$",
"this",
"->",
"keys",
"[",
"$",
"this",
"->",
"checksumValue",
"]",
";",
"// Starting Code\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'000'",
",",
"true",
")",
";",
"// Draw First 4 Chars (Left-Hand)\r",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"4",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"findCode",
"(",
"$",
"temp_text",
"[",
"$",
"i",
"]",
")",
",",
"false",
")",
";",
"}",
"// Draw Center Guard Bar\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'00000'",
",",
"false",
")",
";",
"// Draw Last 4 Chars (Right-Hand)\r",
"for",
"(",
"$",
"i",
"=",
"4",
";",
"$",
"i",
"<",
"8",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"findCode",
"(",
"$",
"temp_text",
"[",
"$",
"i",
"]",
")",
",",
"true",
")",
";",
"}",
"// Draw Right Guard Bar\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'000'",
",",
"true",
")",
";",
"$",
"this",
"->",
"drawText",
"(",
"$",
"im",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"positionX",
",",
"$",
"this",
"->",
"thickness",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isDefaultEanLabelEnabled",
"(",
")",
")",
"{",
"$",
"dimension",
"=",
"$",
"this",
"->",
"labelRight",
"->",
"getDimension",
"(",
")",
";",
"$",
"this",
"->",
"drawExtendedBars",
"(",
"$",
"im",
",",
"$",
"dimension",
"[",
"1",
"]",
"-",
"2",
")",
";",
"}",
"}"
] | Draws the barcode.
@param resource $im | [
"Draws",
"the",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean8.php#L58-L87 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean8.php | CINean8.getDimension | public function getDimension($w, $h) {
$startlength = 3;
$centerlength = 5;
$textlength = 8 * 7;
$endlength = 3;
$w += $startlength + $centerlength + $textlength + $endlength;
$h += $this->thickness;
return parent::getDimension($w, $h);
} | php | public function getDimension($w, $h) {
$startlength = 3;
$centerlength = 5;
$textlength = 8 * 7;
$endlength = 3;
$w += $startlength + $centerlength + $textlength + $endlength;
$h += $this->thickness;
return parent::getDimension($w, $h);
} | [
"public",
"function",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
"{",
"$",
"startlength",
"=",
"3",
";",
"$",
"centerlength",
"=",
"5",
";",
"$",
"textlength",
"=",
"8",
"*",
"7",
";",
"$",
"endlength",
"=",
"3",
";",
"$",
"w",
"+=",
"$",
"startlength",
"+",
"$",
"centerlength",
"+",
"$",
"textlength",
"+",
"$",
"endlength",
";",
"$",
"h",
"+=",
"$",
"this",
"->",
"thickness",
";",
"return",
"parent",
"::",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"}"
] | Returns the maximal size of a barcode.
@param int $w
@param int $h
@return int[] | [
"Returns",
"the",
"maximal",
"size",
"of",
"a",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean8.php#L96-L105 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean8.php | CINean8.addDefaultLabel | protected function addDefaultLabel() {
if ($this->isDefaultEanLabelEnabled()) {
$this->processChecksum();
$label = $this->getLabel();
$font = $this->font;
$this->labelLeft = new CINLabel(substr($label, 0, 4), $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT);
$labelLeftDimension = $this->labelLeft->getDimension();
$this->labelLeft->setOffset(($this->scale * 30 - $labelLeftDimension[0]) / 2 + $this->scale * 2);
$this->labelRight = new CINLabel(substr($label, 4, 3) . $this->keys[$this->checksumValue], $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT);
$labelRightDimension = $this->labelRight->getDimension();
$this->labelRight->setOffset(($this->scale * 30 - $labelRightDimension[0]) / 2 + $this->scale * 34);
$this->addLabel($this->labelLeft);
$this->addLabel($this->labelRight);
}
} | php | protected function addDefaultLabel() {
if ($this->isDefaultEanLabelEnabled()) {
$this->processChecksum();
$label = $this->getLabel();
$font = $this->font;
$this->labelLeft = new CINLabel(substr($label, 0, 4), $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT);
$labelLeftDimension = $this->labelLeft->getDimension();
$this->labelLeft->setOffset(($this->scale * 30 - $labelLeftDimension[0]) / 2 + $this->scale * 2);
$this->labelRight = new CINLabel(substr($label, 4, 3) . $this->keys[$this->checksumValue], $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT);
$labelRightDimension = $this->labelRight->getDimension();
$this->labelRight->setOffset(($this->scale * 30 - $labelRightDimension[0]) / 2 + $this->scale * 34);
$this->addLabel($this->labelLeft);
$this->addLabel($this->labelRight);
}
} | [
"protected",
"function",
"addDefaultLabel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isDefaultEanLabelEnabled",
"(",
")",
")",
"{",
"$",
"this",
"->",
"processChecksum",
"(",
")",
";",
"$",
"label",
"=",
"$",
"this",
"->",
"getLabel",
"(",
")",
";",
"$",
"font",
"=",
"$",
"this",
"->",
"font",
";",
"$",
"this",
"->",
"labelLeft",
"=",
"new",
"CINLabel",
"(",
"substr",
"(",
"$",
"label",
",",
"0",
",",
"4",
")",
",",
"$",
"font",
",",
"CINLabel",
"::",
"POSITION_BOTTOM",
",",
"CINLabel",
"::",
"ALIGN_LEFT",
")",
";",
"$",
"labelLeftDimension",
"=",
"$",
"this",
"->",
"labelLeft",
"->",
"getDimension",
"(",
")",
";",
"$",
"this",
"->",
"labelLeft",
"->",
"setOffset",
"(",
"(",
"$",
"this",
"->",
"scale",
"*",
"30",
"-",
"$",
"labelLeftDimension",
"[",
"0",
"]",
")",
"/",
"2",
"+",
"$",
"this",
"->",
"scale",
"*",
"2",
")",
";",
"$",
"this",
"->",
"labelRight",
"=",
"new",
"CINLabel",
"(",
"substr",
"(",
"$",
"label",
",",
"4",
",",
"3",
")",
".",
"$",
"this",
"->",
"keys",
"[",
"$",
"this",
"->",
"checksumValue",
"]",
",",
"$",
"font",
",",
"CINLabel",
"::",
"POSITION_BOTTOM",
",",
"CINLabel",
"::",
"ALIGN_LEFT",
")",
";",
"$",
"labelRightDimension",
"=",
"$",
"this",
"->",
"labelRight",
"->",
"getDimension",
"(",
")",
";",
"$",
"this",
"->",
"labelRight",
"->",
"setOffset",
"(",
"(",
"$",
"this",
"->",
"scale",
"*",
"30",
"-",
"$",
"labelRightDimension",
"[",
"0",
"]",
")",
"/",
"2",
"+",
"$",
"this",
"->",
"scale",
"*",
"34",
")",
";",
"$",
"this",
"->",
"addLabel",
"(",
"$",
"this",
"->",
"labelLeft",
")",
";",
"$",
"this",
"->",
"addLabel",
"(",
"$",
"this",
"->",
"labelRight",
")",
";",
"}",
"}"
] | Adds the default label. | [
"Adds",
"the",
"default",
"label",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean8.php#L110-L127 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean8.php | CINean8.isDefaultEanLabelEnabled | protected function isDefaultEanLabelEnabled() {
$label = $this->getLabel();
$font = $this->font;
return $label !== null && $label !== '' && $font !== null && $this->defaultLabel !== null;
} | php | protected function isDefaultEanLabelEnabled() {
$label = $this->getLabel();
$font = $this->font;
return $label !== null && $label !== '' && $font !== null && $this->defaultLabel !== null;
} | [
"protected",
"function",
"isDefaultEanLabelEnabled",
"(",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"getLabel",
"(",
")",
";",
"$",
"font",
"=",
"$",
"this",
"->",
"font",
";",
"return",
"$",
"label",
"!==",
"null",
"&&",
"$",
"label",
"!==",
"''",
"&&",
"$",
"font",
"!==",
"null",
"&&",
"$",
"this",
"->",
"defaultLabel",
"!==",
"null",
";",
"}"
] | Checks if the default ean label is enabled.
@return bool | [
"Checks",
"if",
"the",
"default",
"ean",
"label",
"is",
"enabled",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean8.php#L134-L138 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean8.php | CINean8.processChecksum | protected function processChecksum() {
if ($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if ($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
} | php | protected function processChecksum() {
if ($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if ($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
} | [
"protected",
"function",
"processChecksum",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"checksumValue",
"===",
"false",
")",
"{",
"// Calculate the checksum only once\r",
"$",
"this",
"->",
"calculateChecksum",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"checksumValue",
"!==",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"keys",
"[",
"$",
"this",
"->",
"checksumValue",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Overloaded method to display the checksum. | [
"Overloaded",
"method",
"to",
"display",
"the",
"checksum",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean8.php#L201-L211 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcodabar.php | CINcodabar.draw | public function draw($im) {
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]), true);
}
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
} | php | public function draw($im) {
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]), true);
}
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
} | [
"public",
"function",
"draw",
"(",
"$",
"im",
")",
"{",
"$",
"c",
"=",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"findCode",
"(",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
")",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"drawText",
"(",
"$",
"im",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"positionX",
",",
"$",
"this",
"->",
"thickness",
")",
";",
"}"
] | Draws the barcode.
@param resource $im | [
"Draws",
"the",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcodabar.php#L62-L69 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcodabar.php | CINcodabar.getDimension | public function getDimension($w, $h) {
$textLength = 0;
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$index = $this->findIndex($this->text[$i]);
if ($index !== false) {
$textLength += 8;
$textLength += substr_count($this->code[$index], '1');
}
}
$w += $textLength;
$h += $this->thickness;
return parent::getDimension($w, $h);
} | php | public function getDimension($w, $h) {
$textLength = 0;
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$index = $this->findIndex($this->text[$i]);
if ($index !== false) {
$textLength += 8;
$textLength += substr_count($this->code[$index], '1');
}
}
$w += $textLength;
$h += $this->thickness;
return parent::getDimension($w, $h);
} | [
"public",
"function",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
"{",
"$",
"textLength",
"=",
"0",
";",
"$",
"c",
"=",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"findIndex",
"(",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"{",
"$",
"textLength",
"+=",
"8",
";",
"$",
"textLength",
"+=",
"substr_count",
"(",
"$",
"this",
"->",
"code",
"[",
"$",
"index",
"]",
",",
"'1'",
")",
";",
"}",
"}",
"$",
"w",
"+=",
"$",
"textLength",
";",
"$",
"h",
"+=",
"$",
"this",
"->",
"thickness",
";",
"return",
"parent",
"::",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"}"
] | Returns the maximal size of a barcode.
@param int $w
@param int $h
@return int[] | [
"Returns",
"the",
"maximal",
"size",
"of",
"a",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcodabar.php#L78-L92 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcodabar.php | CINcodabar.validate | protected function validate() {
$c = strlen($this->text);
if ($c === 0) {
throw new CINParseException('codabar', 'No data has been entered.');
}
// Checking if all chars are allowed
for ($i = 0; $i < $c; $i++) {
if (array_search($this->text[$i], $this->keys) === false) {
throw new CINParseException('codabar', 'The character \'' . $this->text[$i] . '\' is not allowed.');
}
}
// Must start by A, B, C or D
if ($c == 0 || ($this->text[0] !== 'A' && $this->text[0] !== 'B' && $this->text[0] !== 'C' && $this->text[0] !== 'D')) {
throw new CINParseException('codabar', 'The text must start by the character A, B, C, or D.');
}
// Must end by A, B, C or D
$c2 = $c - 1;
if ($c2 === 0 || ($this->text[$c2] !== 'A' && $this->text[$c2] !== 'B' && $this->text[$c2] !== 'C' && $this->text[$c2] !== 'D')) {
throw new CINParseException('codabar', 'The text must end by the character A, B, C, or D.');
}
parent::validate();
} | php | protected function validate() {
$c = strlen($this->text);
if ($c === 0) {
throw new CINParseException('codabar', 'No data has been entered.');
}
// Checking if all chars are allowed
for ($i = 0; $i < $c; $i++) {
if (array_search($this->text[$i], $this->keys) === false) {
throw new CINParseException('codabar', 'The character \'' . $this->text[$i] . '\' is not allowed.');
}
}
// Must start by A, B, C or D
if ($c == 0 || ($this->text[0] !== 'A' && $this->text[0] !== 'B' && $this->text[0] !== 'C' && $this->text[0] !== 'D')) {
throw new CINParseException('codabar', 'The text must start by the character A, B, C, or D.');
}
// Must end by A, B, C or D
$c2 = $c - 1;
if ($c2 === 0 || ($this->text[$c2] !== 'A' && $this->text[$c2] !== 'B' && $this->text[$c2] !== 'C' && $this->text[$c2] !== 'D')) {
throw new CINParseException('codabar', 'The text must end by the character A, B, C, or D.');
}
parent::validate();
} | [
"protected",
"function",
"validate",
"(",
")",
"{",
"$",
"c",
"=",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"if",
"(",
"$",
"c",
"===",
"0",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'codabar'",
",",
"'No data has been entered.'",
")",
";",
"}",
"// Checking if all chars are allowed\r",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"array_search",
"(",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
",",
"$",
"this",
"->",
"keys",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'codabar'",
",",
"'The character \\''",
".",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
".",
"'\\' is not allowed.'",
")",
";",
"}",
"}",
"// Must start by A, B, C or D\r",
"if",
"(",
"$",
"c",
"==",
"0",
"||",
"(",
"$",
"this",
"->",
"text",
"[",
"0",
"]",
"!==",
"'A'",
"&&",
"$",
"this",
"->",
"text",
"[",
"0",
"]",
"!==",
"'B'",
"&&",
"$",
"this",
"->",
"text",
"[",
"0",
"]",
"!==",
"'C'",
"&&",
"$",
"this",
"->",
"text",
"[",
"0",
"]",
"!==",
"'D'",
")",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'codabar'",
",",
"'The text must start by the character A, B, C, or D.'",
")",
";",
"}",
"// Must end by A, B, C or D\r",
"$",
"c2",
"=",
"$",
"c",
"-",
"1",
";",
"if",
"(",
"$",
"c2",
"===",
"0",
"||",
"(",
"$",
"this",
"->",
"text",
"[",
"$",
"c2",
"]",
"!==",
"'A'",
"&&",
"$",
"this",
"->",
"text",
"[",
"$",
"c2",
"]",
"!==",
"'B'",
"&&",
"$",
"this",
"->",
"text",
"[",
"$",
"c2",
"]",
"!==",
"'C'",
"&&",
"$",
"this",
"->",
"text",
"[",
"$",
"c2",
"]",
"!==",
"'D'",
")",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'codabar'",
",",
"'The text must end by the character A, B, C, or D.'",
")",
";",
"}",
"parent",
"::",
"validate",
"(",
")",
";",
"}"
] | Validates the input. | [
"Validates",
"the",
"input",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcodabar.php#L97-L122 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode39extended.php | CINcode39extended.getDimension | public function getDimension($w, $h) {
$textlength = 13 * count($this->data);
$startlength = 13;
$checksumlength = 0;
if ($this->checksum === true) {
$checksumlength = 13;
}
$endlength = 13;
$w += $startlength + $textlength + $checksumlength + $endlength;
$h += $this->thickness;
return CINBarcode1D::getDimension($w, $h);
} | php | public function getDimension($w, $h) {
$textlength = 13 * count($this->data);
$startlength = 13;
$checksumlength = 0;
if ($this->checksum === true) {
$checksumlength = 13;
}
$endlength = 13;
$w += $startlength + $textlength + $checksumlength + $endlength;
$h += $this->thickness;
return CINBarcode1D::getDimension($w, $h);
} | [
"public",
"function",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
"{",
"$",
"textlength",
"=",
"13",
"*",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"startlength",
"=",
"13",
";",
"$",
"checksumlength",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"checksum",
"===",
"true",
")",
"{",
"$",
"checksumlength",
"=",
"13",
";",
"}",
"$",
"endlength",
"=",
"13",
";",
"$",
"w",
"+=",
"$",
"startlength",
"+",
"$",
"textlength",
"+",
"$",
"checksumlength",
"+",
"$",
"endlength",
";",
"$",
"h",
"+=",
"$",
"this",
"->",
"thickness",
";",
"return",
"CINBarcode1D",
"::",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"}"
] | Returns the maximal size of a barcode.
@param int $w
@param int $h
@return int[] | [
"Returns",
"the",
"maximal",
"size",
"of",
"a",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode39extended.php#L119-L132 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode39extended.php | CINcode39extended.setData | private function setData($data) {
$this->indcheck = $data[0];
$this->data = $data[1];
$this->calculateChecksum();
} | php | private function setData($data) {
$this->indcheck = $data[0];
$this->data = $data[1];
$this->calculateChecksum();
} | [
"private",
"function",
"setData",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"indcheck",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"calculateChecksum",
"(",
")",
";",
"}"
] | Saves data into the classes.
This method will save data, calculate real column number
(if -1 was selected), the real error level (if -1 was
selected)... It will add Padding to the end and generate
the error codes.
@param array $data | [
"Saves",
"data",
"into",
"the",
"classes",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode39extended.php#L169-L173 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode39extended.php | CINcode39extended.getExtendedVersion | private static function getExtendedVersion($char) {
$o = ord($char);
if ($o === 0) {
return '%U';
} elseif ($o >= 1 && $o <= 26) {
return '$' . chr($o + 64);
} elseif (($o >= 33 && $o <= 44) || $o === 47 || $o === 48) {
return '/' . chr($o + 32);
} elseif ($o >= 97 && $o <= 122) {
return '+' . chr($o - 32);
} elseif ($o >= 27 && $o <= 31) {
return '%' . chr($o + 38);
} elseif ($o >= 59 && $o <= 63) {
return '%' . chr($o + 11);
} elseif ($o >= 91 && $o <= 95) {
return '%' . chr($o - 16);
} elseif ($o >= 123 && $o <= 127) {
return '%' . chr($o - 43);
} elseif ($o === 64) {
return '%V';
} elseif ($o === 96) {
return '%W';
} elseif ($o > 127) {
return false;
} else {
return $char;
}
} | php | private static function getExtendedVersion($char) {
$o = ord($char);
if ($o === 0) {
return '%U';
} elseif ($o >= 1 && $o <= 26) {
return '$' . chr($o + 64);
} elseif (($o >= 33 && $o <= 44) || $o === 47 || $o === 48) {
return '/' . chr($o + 32);
} elseif ($o >= 97 && $o <= 122) {
return '+' . chr($o - 32);
} elseif ($o >= 27 && $o <= 31) {
return '%' . chr($o + 38);
} elseif ($o >= 59 && $o <= 63) {
return '%' . chr($o + 11);
} elseif ($o >= 91 && $o <= 95) {
return '%' . chr($o - 16);
} elseif ($o >= 123 && $o <= 127) {
return '%' . chr($o - 43);
} elseif ($o === 64) {
return '%V';
} elseif ($o === 96) {
return '%W';
} elseif ($o > 127) {
return false;
} else {
return $char;
}
} | [
"private",
"static",
"function",
"getExtendedVersion",
"(",
"$",
"char",
")",
"{",
"$",
"o",
"=",
"ord",
"(",
"$",
"char",
")",
";",
"if",
"(",
"$",
"o",
"===",
"0",
")",
"{",
"return",
"'%U'",
";",
"}",
"elseif",
"(",
"$",
"o",
">=",
"1",
"&&",
"$",
"o",
"<=",
"26",
")",
"{",
"return",
"'$'",
".",
"chr",
"(",
"$",
"o",
"+",
"64",
")",
";",
"}",
"elseif",
"(",
"(",
"$",
"o",
">=",
"33",
"&&",
"$",
"o",
"<=",
"44",
")",
"||",
"$",
"o",
"===",
"47",
"||",
"$",
"o",
"===",
"48",
")",
"{",
"return",
"'/'",
".",
"chr",
"(",
"$",
"o",
"+",
"32",
")",
";",
"}",
"elseif",
"(",
"$",
"o",
">=",
"97",
"&&",
"$",
"o",
"<=",
"122",
")",
"{",
"return",
"'+'",
".",
"chr",
"(",
"$",
"o",
"-",
"32",
")",
";",
"}",
"elseif",
"(",
"$",
"o",
">=",
"27",
"&&",
"$",
"o",
"<=",
"31",
")",
"{",
"return",
"'%'",
".",
"chr",
"(",
"$",
"o",
"+",
"38",
")",
";",
"}",
"elseif",
"(",
"$",
"o",
">=",
"59",
"&&",
"$",
"o",
"<=",
"63",
")",
"{",
"return",
"'%'",
".",
"chr",
"(",
"$",
"o",
"+",
"11",
")",
";",
"}",
"elseif",
"(",
"$",
"o",
">=",
"91",
"&&",
"$",
"o",
"<=",
"95",
")",
"{",
"return",
"'%'",
".",
"chr",
"(",
"$",
"o",
"-",
"16",
")",
";",
"}",
"elseif",
"(",
"$",
"o",
">=",
"123",
"&&",
"$",
"o",
"<=",
"127",
")",
"{",
"return",
"'%'",
".",
"chr",
"(",
"$",
"o",
"-",
"43",
")",
";",
"}",
"elseif",
"(",
"$",
"o",
"===",
"64",
")",
"{",
"return",
"'%V'",
";",
"}",
"elseif",
"(",
"$",
"o",
"===",
"96",
")",
"{",
"return",
"'%W'",
";",
"}",
"elseif",
"(",
"$",
"o",
">",
"127",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"$",
"char",
";",
"}",
"}"
] | Returns the extended reprensentation of the character.
@param string $char
@return string | [
"Returns",
"the",
"extended",
"reprensentation",
"of",
"the",
"character",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode39extended.php#L181-L208 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode93.php | CINcode93.parse | public function parse($text) {
$this->text = $text;
$data = array();
$indcheck = array();
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$pos = array_search($this->text[$i], $this->keys);
if ($pos === false) {
// Search in extended?
$extended = self::getExtendedVersion($this->text[$i]);
if ($extended === false) {
throw new CINParseException('code93', 'The character \'' . $this->text[$i] . '\' is not allowed.');
} else {
$extc = strlen($extended);
for ($j = 0; $j < $extc; $j++) {
$v = $extended[$j];
if ($v === '$') {
$indcheck[] = self::EXTENDED_1;
$data[] = $this->code[self::EXTENDED_1];
} elseif ($v === '%') {
$indcheck[] = self::EXTENDED_2;
$data[] = $this->code[self::EXTENDED_2];
} elseif ($v === '/') {
$indcheck[] = self::EXTENDED_3;
$data[] = $this->code[self::EXTENDED_3];
} elseif ($v === '+') {
$indcheck[] = self::EXTENDED_4;
$data[] = $this->code[self::EXTENDED_4];
} else {
$pos2 = array_search($v, $this->keys);
$indcheck[] = $pos2;
$data[] = $this->code[$pos2];
}
}
}
} else {
$indcheck[] = $pos;
$data[] = $this->code[$pos];
}
}
$this->setData(array($indcheck, $data));
$this->addDefaultLabel();
} | php | public function parse($text) {
$this->text = $text;
$data = array();
$indcheck = array();
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$pos = array_search($this->text[$i], $this->keys);
if ($pos === false) {
// Search in extended?
$extended = self::getExtendedVersion($this->text[$i]);
if ($extended === false) {
throw new CINParseException('code93', 'The character \'' . $this->text[$i] . '\' is not allowed.');
} else {
$extc = strlen($extended);
for ($j = 0; $j < $extc; $j++) {
$v = $extended[$j];
if ($v === '$') {
$indcheck[] = self::EXTENDED_1;
$data[] = $this->code[self::EXTENDED_1];
} elseif ($v === '%') {
$indcheck[] = self::EXTENDED_2;
$data[] = $this->code[self::EXTENDED_2];
} elseif ($v === '/') {
$indcheck[] = self::EXTENDED_3;
$data[] = $this->code[self::EXTENDED_3];
} elseif ($v === '+') {
$indcheck[] = self::EXTENDED_4;
$data[] = $this->code[self::EXTENDED_4];
} else {
$pos2 = array_search($v, $this->keys);
$indcheck[] = $pos2;
$data[] = $this->code[$pos2];
}
}
}
} else {
$indcheck[] = $pos;
$data[] = $this->code[$pos];
}
}
$this->setData(array($indcheck, $data));
$this->addDefaultLabel();
} | [
"public",
"function",
"parse",
"(",
"$",
"text",
")",
"{",
"$",
"this",
"->",
"text",
"=",
"$",
"text",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"indcheck",
"=",
"array",
"(",
")",
";",
"$",
"c",
"=",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"pos",
"=",
"array_search",
"(",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
",",
"$",
"this",
"->",
"keys",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"// Search in extended?\r",
"$",
"extended",
"=",
"self",
"::",
"getExtendedVersion",
"(",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"$",
"extended",
"===",
"false",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'code93'",
",",
"'The character \\''",
".",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
".",
"'\\' is not allowed.'",
")",
";",
"}",
"else",
"{",
"$",
"extc",
"=",
"strlen",
"(",
"$",
"extended",
")",
";",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"extc",
";",
"$",
"j",
"++",
")",
"{",
"$",
"v",
"=",
"$",
"extended",
"[",
"$",
"j",
"]",
";",
"if",
"(",
"$",
"v",
"===",
"'$'",
")",
"{",
"$",
"indcheck",
"[",
"]",
"=",
"self",
"::",
"EXTENDED_1",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"code",
"[",
"self",
"::",
"EXTENDED_1",
"]",
";",
"}",
"elseif",
"(",
"$",
"v",
"===",
"'%'",
")",
"{",
"$",
"indcheck",
"[",
"]",
"=",
"self",
"::",
"EXTENDED_2",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"code",
"[",
"self",
"::",
"EXTENDED_2",
"]",
";",
"}",
"elseif",
"(",
"$",
"v",
"===",
"'/'",
")",
"{",
"$",
"indcheck",
"[",
"]",
"=",
"self",
"::",
"EXTENDED_3",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"code",
"[",
"self",
"::",
"EXTENDED_3",
"]",
";",
"}",
"elseif",
"(",
"$",
"v",
"===",
"'+'",
")",
"{",
"$",
"indcheck",
"[",
"]",
"=",
"self",
"::",
"EXTENDED_4",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"code",
"[",
"self",
"::",
"EXTENDED_4",
"]",
";",
"}",
"else",
"{",
"$",
"pos2",
"=",
"array_search",
"(",
"$",
"v",
",",
"$",
"this",
"->",
"keys",
")",
";",
"$",
"indcheck",
"[",
"]",
"=",
"$",
"pos2",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"code",
"[",
"$",
"pos2",
"]",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"indcheck",
"[",
"]",
"=",
"$",
"pos",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"code",
"[",
"$",
"pos",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"setData",
"(",
"array",
"(",
"$",
"indcheck",
",",
"$",
"data",
")",
")",
";",
"$",
"this",
"->",
"addDefaultLabel",
"(",
")",
";",
"}"
] | Parses the text before displaying it.
@param mixed $text | [
"Parses",
"the",
"text",
"before",
"displaying",
"it",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode93.php#L94-L139 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode93.php | CINcode93.draw | public function draw($im) {
// Starting *
$this->drawChar($im, $this->code[$this->starting], true);
$c = count($this->data);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->data[$i], true);
}
// Checksum
$c = count($this->checksumValue);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->code[$this->checksumValue[$i]], true);
}
// Ending *
$this->drawChar($im, $this->code[$this->ending], true);
// Draw a Final Bar
$this->drawChar($im, '0', true);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
} | php | public function draw($im) {
// Starting *
$this->drawChar($im, $this->code[$this->starting], true);
$c = count($this->data);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->data[$i], true);
}
// Checksum
$c = count($this->checksumValue);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->code[$this->checksumValue[$i]], true);
}
// Ending *
$this->drawChar($im, $this->code[$this->ending], true);
// Draw a Final Bar
$this->drawChar($im, '0', true);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
} | [
"public",
"function",
"draw",
"(",
"$",
"im",
")",
"{",
"// Starting *\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"code",
"[",
"$",
"this",
"->",
"starting",
"]",
",",
"true",
")",
";",
"$",
"c",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"data",
"[",
"$",
"i",
"]",
",",
"true",
")",
";",
"}",
"// Checksum\r",
"$",
"c",
"=",
"count",
"(",
"$",
"this",
"->",
"checksumValue",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"code",
"[",
"$",
"this",
"->",
"checksumValue",
"[",
"$",
"i",
"]",
"]",
",",
"true",
")",
";",
"}",
"// Ending *\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"code",
"[",
"$",
"this",
"->",
"ending",
"]",
",",
"true",
")",
";",
"// Draw a Final Bar\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'0'",
",",
"true",
")",
";",
"$",
"this",
"->",
"drawText",
"(",
"$",
"im",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"positionX",
",",
"$",
"this",
"->",
"thickness",
")",
";",
"}"
] | Draws the barcode.
@param resource $im | [
"Draws",
"the",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode93.php#L146-L166 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode93.php | CINcode93.getDimension | public function getDimension($w, $h) {
$startlength = 9;
$textlength = 9 * count($this->data);
$checksumlength = 2 * 9;
$endlength = 9 + 1; // + final bar
$w += $startlength + $textlength + $checksumlength + $endlength;
$h += $this->thickness;
return parent::getDimension($w, $h);
} | php | public function getDimension($w, $h) {
$startlength = 9;
$textlength = 9 * count($this->data);
$checksumlength = 2 * 9;
$endlength = 9 + 1; // + final bar
$w += $startlength + $textlength + $checksumlength + $endlength;
$h += $this->thickness;
return parent::getDimension($w, $h);
} | [
"public",
"function",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
"{",
"$",
"startlength",
"=",
"9",
";",
"$",
"textlength",
"=",
"9",
"*",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"checksumlength",
"=",
"2",
"*",
"9",
";",
"$",
"endlength",
"=",
"9",
"+",
"1",
";",
"// + final bar\r",
"$",
"w",
"+=",
"$",
"startlength",
"+",
"$",
"textlength",
"+",
"$",
"checksumlength",
"+",
"$",
"endlength",
";",
"$",
"h",
"+=",
"$",
"this",
"->",
"thickness",
";",
"return",
"parent",
"::",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"}"
] | Returns the maximal size of a barcode.
@param int $w
@param int $h
@return int[] | [
"Returns",
"the",
"maximal",
"size",
"of",
"a",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode93.php#L175-L184 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode93.php | CINcode93.calculateChecksum | protected function calculateChecksum() {
// Checksum
// First CheckSUM "C"
// The "C" checksum character is the modulo 47 remainder of the sum of the weighted
// value of the data characters. The weighting value starts at "1" for the right-most
// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.
// After 20, the sequence wraps around back to 1.
// Second CheckSUM "K"
// Same as CheckSUM "C" but we count the CheckSum "C" at the end
// After 15, the sequence wraps around back to 1.
$sequence_multiplier = array(20, 15);
$this->checksumValue = array();
$indcheck = $this->indcheck;
for ($z = 0; $z < 2; $z++) {
$checksum = 0;
for ($i = count($indcheck), $j = 0; $i > 0; $i--, $j++) {
$multiplier = $i % $sequence_multiplier[$z];
if ($multiplier === 0) {
$multiplier = $sequence_multiplier[$z];
}
$checksum += $indcheck[$j] * $multiplier;
}
$this->checksumValue[$z] = $checksum % 47;
$indcheck[] = $this->checksumValue[$z];
}
} | php | protected function calculateChecksum() {
// Checksum
// First CheckSUM "C"
// The "C" checksum character is the modulo 47 remainder of the sum of the weighted
// value of the data characters. The weighting value starts at "1" for the right-most
// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.
// After 20, the sequence wraps around back to 1.
// Second CheckSUM "K"
// Same as CheckSUM "C" but we count the CheckSum "C" at the end
// After 15, the sequence wraps around back to 1.
$sequence_multiplier = array(20, 15);
$this->checksumValue = array();
$indcheck = $this->indcheck;
for ($z = 0; $z < 2; $z++) {
$checksum = 0;
for ($i = count($indcheck), $j = 0; $i > 0; $i--, $j++) {
$multiplier = $i % $sequence_multiplier[$z];
if ($multiplier === 0) {
$multiplier = $sequence_multiplier[$z];
}
$checksum += $indcheck[$j] * $multiplier;
}
$this->checksumValue[$z] = $checksum % 47;
$indcheck[] = $this->checksumValue[$z];
}
} | [
"protected",
"function",
"calculateChecksum",
"(",
")",
"{",
"// Checksum\r",
"// First CheckSUM \"C\"\r",
"// The \"C\" checksum character is the modulo 47 remainder of the sum of the weighted\r",
"// value of the data characters. The weighting value starts at \"1\" for the right-most\r",
"// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.\r",
"// After 20, the sequence wraps around back to 1.\r",
"// Second CheckSUM \"K\"\r",
"// Same as CheckSUM \"C\" but we count the CheckSum \"C\" at the end\r",
"// After 15, the sequence wraps around back to 1.\r",
"$",
"sequence_multiplier",
"=",
"array",
"(",
"20",
",",
"15",
")",
";",
"$",
"this",
"->",
"checksumValue",
"=",
"array",
"(",
")",
";",
"$",
"indcheck",
"=",
"$",
"this",
"->",
"indcheck",
";",
"for",
"(",
"$",
"z",
"=",
"0",
";",
"$",
"z",
"<",
"2",
";",
"$",
"z",
"++",
")",
"{",
"$",
"checksum",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"indcheck",
")",
",",
"$",
"j",
"=",
"0",
";",
"$",
"i",
">",
"0",
";",
"$",
"i",
"--",
",",
"$",
"j",
"++",
")",
"{",
"$",
"multiplier",
"=",
"$",
"i",
"%",
"$",
"sequence_multiplier",
"[",
"$",
"z",
"]",
";",
"if",
"(",
"$",
"multiplier",
"===",
"0",
")",
"{",
"$",
"multiplier",
"=",
"$",
"sequence_multiplier",
"[",
"$",
"z",
"]",
";",
"}",
"$",
"checksum",
"+=",
"$",
"indcheck",
"[",
"$",
"j",
"]",
"*",
"$",
"multiplier",
";",
"}",
"$",
"this",
"->",
"checksumValue",
"[",
"$",
"z",
"]",
"=",
"$",
"checksum",
"%",
"47",
";",
"$",
"indcheck",
"[",
"]",
"=",
"$",
"this",
"->",
"checksumValue",
"[",
"$",
"z",
"]",
";",
"}",
"}"
] | Overloaded method to calculate checksum. | [
"Overloaded",
"method",
"to",
"calculate",
"checksum",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode93.php#L201-L229 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode93.php | CINcode93.processChecksum | protected function processChecksum() {
if ($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if ($this->checksumValue !== false) {
$ret = '';
$c = count($this->checksumValue);
for ($i = 0; $i < $c; $i++) {
$ret .= $this->keys[$this->checksumValue[$i]];
}
return $ret;
}
return false;
} | php | protected function processChecksum() {
if ($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if ($this->checksumValue !== false) {
$ret = '';
$c = count($this->checksumValue);
for ($i = 0; $i < $c; $i++) {
$ret .= $this->keys[$this->checksumValue[$i]];
}
return $ret;
}
return false;
} | [
"protected",
"function",
"processChecksum",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"checksumValue",
"===",
"false",
")",
"{",
"// Calculate the checksum only once\r",
"$",
"this",
"->",
"calculateChecksum",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"checksumValue",
"!==",
"false",
")",
"{",
"$",
"ret",
"=",
"''",
";",
"$",
"c",
"=",
"count",
"(",
"$",
"this",
"->",
"checksumValue",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"ret",
".=",
"$",
"this",
"->",
"keys",
"[",
"$",
"this",
"->",
"checksumValue",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"return",
"$",
"ret",
";",
"}",
"return",
"false",
";",
"}"
] | Overloaded method to display the checksum. | [
"Overloaded",
"method",
"to",
"display",
"the",
"checksum",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode93.php#L234-L250 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php | CINBarcode1D.setThickness | public function setThickness($thickness) {
$thickness = intval($thickness);
if ($thickness <= 0) {
throw new CINArgumentException('The thickness must be larger than 0.', 'thickness');
}
$this->thickness = $thickness;
} | php | public function setThickness($thickness) {
$thickness = intval($thickness);
if ($thickness <= 0) {
throw new CINArgumentException('The thickness must be larger than 0.', 'thickness');
}
$this->thickness = $thickness;
} | [
"public",
"function",
"setThickness",
"(",
"$",
"thickness",
")",
"{",
"$",
"thickness",
"=",
"intval",
"(",
"$",
"thickness",
")",
";",
"if",
"(",
"$",
"thickness",
"<=",
"0",
")",
"{",
"throw",
"new",
"CINArgumentException",
"(",
"'The thickness must be larger than 0.'",
",",
"'thickness'",
")",
";",
"}",
"$",
"this",
"->",
"thickness",
"=",
"$",
"thickness",
";",
"}"
] | Sets the thickness.
@param int $thickness | [
"Sets",
"the",
"thickness",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php#L67-L74 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php | CINBarcode1D.getLabel | public function getLabel() {
$label = $this->label;
if ($this->label === self::AUTO_LABEL) {
$label = $this->text;
if ($this->displayChecksum === true && ($checksum = $this->processChecksum()) !== false) {
$label .= $checksum;
}
}
return $label;
} | php | public function getLabel() {
$label = $this->label;
if ($this->label === self::AUTO_LABEL) {
$label = $this->text;
if ($this->displayChecksum === true && ($checksum = $this->processChecksum()) !== false) {
$label .= $checksum;
}
}
return $label;
} | [
"public",
"function",
"getLabel",
"(",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"label",
";",
"if",
"(",
"$",
"this",
"->",
"label",
"===",
"self",
"::",
"AUTO_LABEL",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"text",
";",
"if",
"(",
"$",
"this",
"->",
"displayChecksum",
"===",
"true",
"&&",
"(",
"$",
"checksum",
"=",
"$",
"this",
"->",
"processChecksum",
"(",
")",
")",
"!==",
"false",
")",
"{",
"$",
"label",
".=",
"$",
"checksum",
";",
"}",
"}",
"return",
"$",
"label",
";",
"}"
] | Gets the label.
If the label was set to CINBarcode1D::AUTO_LABEL, the label will display the value from the text parsed.
@return string | [
"Gets",
"the",
"label",
".",
"If",
"the",
"label",
"was",
"set",
"to",
"CINBarcode1D",
"::",
"AUTO_LABEL",
"the",
"label",
"will",
"display",
"the",
"value",
"from",
"the",
"text",
"parsed",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php#L82-L92 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php | CINBarcode1D.setFont | public function setFont($font) {
if (is_int($font)) {
if ($font === 0) {
$font = null;
} else {
$font = new CINFontPhp($font);
}
}
$this->font = $font;
} | php | public function setFont($font) {
if (is_int($font)) {
if ($font === 0) {
$font = null;
} else {
$font = new CINFontPhp($font);
}
}
$this->font = $font;
} | [
"public",
"function",
"setFont",
"(",
"$",
"font",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"font",
")",
")",
"{",
"if",
"(",
"$",
"font",
"===",
"0",
")",
"{",
"$",
"font",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"font",
"=",
"new",
"CINFontPhp",
"(",
"$",
"font",
")",
";",
"}",
"}",
"$",
"this",
"->",
"font",
"=",
"$",
"font",
";",
"}"
] | Sets the font.
@param mixed $font CINFont or int | [
"Sets",
"the",
"font",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php#L118-L128 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php | CINBarcode1D.parse | public function parse($text) {
$this->text = $text;
$this->checksumValue = false; // Reset checksumValue
$this->validate();
parent::parse($text);
$this->addDefaultLabel();
} | php | public function parse($text) {
$this->text = $text;
$this->checksumValue = false; // Reset checksumValue
$this->validate();
parent::parse($text);
$this->addDefaultLabel();
} | [
"public",
"function",
"parse",
"(",
"$",
"text",
")",
"{",
"$",
"this",
"->",
"text",
"=",
"$",
"text",
";",
"$",
"this",
"->",
"checksumValue",
"=",
"false",
";",
"// Reset checksumValue\r",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"parent",
"::",
"parse",
"(",
"$",
"text",
")",
";",
"$",
"this",
"->",
"addDefaultLabel",
"(",
")",
";",
"}"
] | Parses the text before displaying it.
@param mixed $text | [
"Parses",
"the",
"text",
"before",
"displaying",
"it",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php#L135-L143 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php | CINBarcode1D.addDefaultLabel | protected function addDefaultLabel() {
$label = $this->getLabel();
$font = $this->font;
if ($label !== null && $label !== '' && $font !== null && $this->defaultLabel !== null) {
$this->defaultLabel->setText($label);
$this->defaultLabel->setFont($font);
$this->addLabel($this->defaultLabel);
}
} | php | protected function addDefaultLabel() {
$label = $this->getLabel();
$font = $this->font;
if ($label !== null && $label !== '' && $font !== null && $this->defaultLabel !== null) {
$this->defaultLabel->setText($label);
$this->defaultLabel->setFont($font);
$this->addLabel($this->defaultLabel);
}
} | [
"protected",
"function",
"addDefaultLabel",
"(",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"getLabel",
"(",
")",
";",
"$",
"font",
"=",
"$",
"this",
"->",
"font",
";",
"if",
"(",
"$",
"label",
"!==",
"null",
"&&",
"$",
"label",
"!==",
"''",
"&&",
"$",
"font",
"!==",
"null",
"&&",
"$",
"this",
"->",
"defaultLabel",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"defaultLabel",
"->",
"setText",
"(",
"$",
"label",
")",
";",
"$",
"this",
"->",
"defaultLabel",
"->",
"setFont",
"(",
"$",
"font",
")",
";",
"$",
"this",
"->",
"addLabel",
"(",
"$",
"this",
"->",
"defaultLabel",
")",
";",
"}",
"}"
] | Adds the default label. | [
"Adds",
"the",
"default",
"label",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php#L168-L176 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php | CINBarcode1D.drawChar | protected function drawChar($im, $code, $startBar = true) {
$colors = array(CINBarcode::COLOR_FG, CINBarcode::COLOR_BG);
$currentColor = $startBar ? 0 : 1;
$c = strlen($code);
for ($i = 0; $i < $c; $i++) {
for ($j = 0; $j < intval($code[$i]) + 1; $j++) {
$this->drawSingleBar($im, $colors[$currentColor]);
$this->nextX();
}
$currentColor = ($currentColor + 1) % 2;
}
} | php | protected function drawChar($im, $code, $startBar = true) {
$colors = array(CINBarcode::COLOR_FG, CINBarcode::COLOR_BG);
$currentColor = $startBar ? 0 : 1;
$c = strlen($code);
for ($i = 0; $i < $c; $i++) {
for ($j = 0; $j < intval($code[$i]) + 1; $j++) {
$this->drawSingleBar($im, $colors[$currentColor]);
$this->nextX();
}
$currentColor = ($currentColor + 1) % 2;
}
} | [
"protected",
"function",
"drawChar",
"(",
"$",
"im",
",",
"$",
"code",
",",
"$",
"startBar",
"=",
"true",
")",
"{",
"$",
"colors",
"=",
"array",
"(",
"CINBarcode",
"::",
"COLOR_FG",
",",
"CINBarcode",
"::",
"COLOR_BG",
")",
";",
"$",
"currentColor",
"=",
"$",
"startBar",
"?",
"0",
":",
"1",
";",
"$",
"c",
"=",
"strlen",
"(",
"$",
"code",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"intval",
"(",
"$",
"code",
"[",
"$",
"i",
"]",
")",
"+",
"1",
";",
"$",
"j",
"++",
")",
"{",
"$",
"this",
"->",
"drawSingleBar",
"(",
"$",
"im",
",",
"$",
"colors",
"[",
"$",
"currentColor",
"]",
")",
";",
"$",
"this",
"->",
"nextX",
"(",
")",
";",
"}",
"$",
"currentColor",
"=",
"(",
"$",
"currentColor",
"+",
"1",
")",
"%",
"2",
";",
"}",
"}"
] | Draws all chars thanks to $code. If $startBar is true, the line begins by a space.
If $startBar is false, the line begins by a bar.
@param resource $im
@param string $code
@param boolean $startBar | [
"Draws",
"all",
"chars",
"thanks",
"to",
"$code",
".",
"If",
"$startBar",
"is",
"true",
"the",
"line",
"begins",
"by",
"a",
"space",
".",
"If",
"$startBar",
"is",
"false",
"the",
"line",
"begins",
"by",
"a",
"bar",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php#L213-L225 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php | CINBarcode1D.drawSingleBar | protected function drawSingleBar($im, $color) {
$this->drawFilledRectangle($im, $this->positionX, 0, $this->positionX, $this->thickness - 1, $color);
} | php | protected function drawSingleBar($im, $color) {
$this->drawFilledRectangle($im, $this->positionX, 0, $this->positionX, $this->thickness - 1, $color);
} | [
"protected",
"function",
"drawSingleBar",
"(",
"$",
"im",
",",
"$",
"color",
")",
"{",
"$",
"this",
"->",
"drawFilledRectangle",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"positionX",
",",
"0",
",",
"$",
"this",
"->",
"positionX",
",",
"$",
"this",
"->",
"thickness",
"-",
"1",
",",
"$",
"color",
")",
";",
"}"
] | Draws a Bar of $color depending of the resolution.
@param resource $img
@param int $color | [
"Draws",
"a",
"Bar",
"of",
"$color",
"depending",
"of",
"the",
"resolution",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode1D.php#L233-L235 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINFontPhp.php | CINFontPhp.setRotationAngle | public function setRotationAngle($rotationAngle) {
$this->rotationAngle = (int)$rotationAngle;
if ($this->rotationAngle !== 90 && $this->rotationAngle !== 180 && $this->rotationAngle !== 270) {
$this->rotationAngle = 0;
}
$this->rotationAngle = (360 - $this->rotationAngle) % 360;
} | php | public function setRotationAngle($rotationAngle) {
$this->rotationAngle = (int)$rotationAngle;
if ($this->rotationAngle !== 90 && $this->rotationAngle !== 180 && $this->rotationAngle !== 270) {
$this->rotationAngle = 0;
}
$this->rotationAngle = (360 - $this->rotationAngle) % 360;
} | [
"public",
"function",
"setRotationAngle",
"(",
"$",
"rotationAngle",
")",
"{",
"$",
"this",
"->",
"rotationAngle",
"=",
"(",
"int",
")",
"$",
"rotationAngle",
";",
"if",
"(",
"$",
"this",
"->",
"rotationAngle",
"!==",
"90",
"&&",
"$",
"this",
"->",
"rotationAngle",
"!==",
"180",
"&&",
"$",
"this",
"->",
"rotationAngle",
"!==",
"270",
")",
"{",
"$",
"this",
"->",
"rotationAngle",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"rotationAngle",
"=",
"(",
"360",
"-",
"$",
"this",
"->",
"rotationAngle",
")",
"%",
"360",
";",
"}"
] | Sets the rotation in degree.
@param int | [
"Sets",
"the",
"rotation",
"in",
"degree",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINFontPhp.php#L67-L74 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINFontPhp.php | CINFontPhp.getDimension | public function getDimension() {
$w = imagefontwidth($this->font) * strlen($this->text);
$h = imagefontheight($this->font);
$rotationAngle = $this->getRotationAngle();
if ($rotationAngle === 90 || $rotationAngle === 270) {
return array($h, $w);
} else {
return array($w, $h);
}
} | php | public function getDimension() {
$w = imagefontwidth($this->font) * strlen($this->text);
$h = imagefontheight($this->font);
$rotationAngle = $this->getRotationAngle();
if ($rotationAngle === 90 || $rotationAngle === 270) {
return array($h, $w);
} else {
return array($w, $h);
}
} | [
"public",
"function",
"getDimension",
"(",
")",
"{",
"$",
"w",
"=",
"imagefontwidth",
"(",
"$",
"this",
"->",
"font",
")",
"*",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"$",
"h",
"=",
"imagefontheight",
"(",
"$",
"this",
"->",
"font",
")",
";",
"$",
"rotationAngle",
"=",
"$",
"this",
"->",
"getRotationAngle",
"(",
")",
";",
"if",
"(",
"$",
"rotationAngle",
"===",
"90",
"||",
"$",
"rotationAngle",
"===",
"270",
")",
"{",
"return",
"array",
"(",
"$",
"h",
",",
"$",
"w",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"}",
"}"
] | Returns the width and height that the text takes to be written.
@return int[] | [
"Returns",
"the",
"width",
"and",
"height",
"that",
"the",
"text",
"takes",
"to",
"be",
"written",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINFontPhp.php#L117-L127 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINFontPhp.php | CINFontPhp.draw | public function draw($im, $x, $y) {
if ($this->getRotationAngle() !== 0) {
if (!function_exists('imagerotate')) {
throw new CINDrawException('The method imagerotate doesn\'t exist on your server. Do not use any rotation.');
}
$w = imagefontwidth($this->font) * strlen($this->text);
$h = imagefontheight($this->font);
$gd = imagecreatetruecolor($w, $h);
imagefilledrectangle($gd, 0, 0, $w - 1, $h - 1, $this->backgroundColor->allocate($gd));
imagestring($gd, $this->font, 0, 0, $this->text, $this->foregroundColor->allocate($gd));
$gd = imagerotate($gd, $this->rotationAngle, 0);
imagecopy($im, $gd, $x, $y, 0, 0, imagesx($gd), imagesy($gd));
} else {
imagestring($im, $this->font, $x, $y, $this->text, $this->foregroundColor->allocate($im));
}
} | php | public function draw($im, $x, $y) {
if ($this->getRotationAngle() !== 0) {
if (!function_exists('imagerotate')) {
throw new CINDrawException('The method imagerotate doesn\'t exist on your server. Do not use any rotation.');
}
$w = imagefontwidth($this->font) * strlen($this->text);
$h = imagefontheight($this->font);
$gd = imagecreatetruecolor($w, $h);
imagefilledrectangle($gd, 0, 0, $w - 1, $h - 1, $this->backgroundColor->allocate($gd));
imagestring($gd, $this->font, 0, 0, $this->text, $this->foregroundColor->allocate($gd));
$gd = imagerotate($gd, $this->rotationAngle, 0);
imagecopy($im, $gd, $x, $y, 0, 0, imagesx($gd), imagesy($gd));
} else {
imagestring($im, $this->font, $x, $y, $this->text, $this->foregroundColor->allocate($im));
}
} | [
"public",
"function",
"draw",
"(",
"$",
"im",
",",
"$",
"x",
",",
"$",
"y",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getRotationAngle",
"(",
")",
"!==",
"0",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'imagerotate'",
")",
")",
"{",
"throw",
"new",
"CINDrawException",
"(",
"'The method imagerotate doesn\\'t exist on your server. Do not use any rotation.'",
")",
";",
"}",
"$",
"w",
"=",
"imagefontwidth",
"(",
"$",
"this",
"->",
"font",
")",
"*",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"$",
"h",
"=",
"imagefontheight",
"(",
"$",
"this",
"->",
"font",
")",
";",
"$",
"gd",
"=",
"imagecreatetruecolor",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"imagefilledrectangle",
"(",
"$",
"gd",
",",
"0",
",",
"0",
",",
"$",
"w",
"-",
"1",
",",
"$",
"h",
"-",
"1",
",",
"$",
"this",
"->",
"backgroundColor",
"->",
"allocate",
"(",
"$",
"gd",
")",
")",
";",
"imagestring",
"(",
"$",
"gd",
",",
"$",
"this",
"->",
"font",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"text",
",",
"$",
"this",
"->",
"foregroundColor",
"->",
"allocate",
"(",
"$",
"gd",
")",
")",
";",
"$",
"gd",
"=",
"imagerotate",
"(",
"$",
"gd",
",",
"$",
"this",
"->",
"rotationAngle",
",",
"0",
")",
";",
"imagecopy",
"(",
"$",
"im",
",",
"$",
"gd",
",",
"$",
"x",
",",
"$",
"y",
",",
"0",
",",
"0",
",",
"imagesx",
"(",
"$",
"gd",
")",
",",
"imagesy",
"(",
"$",
"gd",
")",
")",
";",
"}",
"else",
"{",
"imagestring",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"font",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"this",
"->",
"text",
",",
"$",
"this",
"->",
"foregroundColor",
"->",
"allocate",
"(",
"$",
"im",
")",
")",
";",
"}",
"}"
] | Draws the text on the image at a specific position.
$x and $y represent the left bottom corner.
@param resource $im
@param int $x
@param int $y | [
"Draws",
"the",
"text",
"on",
"the",
"image",
"at",
"a",
"specific",
"position",
".",
"$x",
"and",
"$y",
"represent",
"the",
"left",
"bottom",
"corner",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINFontPhp.php#L137-L153 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINLabel.php | CINLabel.setText | public function setText($text) {
$this->text = $text;
$this->font->setText($this->text);
} | php | public function setText($text) {
$this->text = $text;
$this->font->setText($this->text);
} | [
"public",
"function",
"setText",
"(",
"$",
"text",
")",
"{",
"$",
"this",
"->",
"text",
"=",
"$",
"text",
";",
"$",
"this",
"->",
"font",
"->",
"setText",
"(",
"$",
"this",
"->",
"text",
")",
";",
"}"
] | Sets the text.
@param string $text | [
"Sets",
"the",
"text",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L74-L77 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.