_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q21200
Passport.keyPath
train
public static function keyPath($file) { $file = ltrim($file, '/\\'); return static::$keyPath ? rtrim(static::$keyPath, '/\\').DIRECTORY_SEPARATOR.$file : storage_path($file); }
php
{ "resource": "" }
q21201
CurlClient.closeCurlHandle
train
private function closeCurlHandle() { if (!is_null($this->curlHandle)) { curl_close($this->curlHandle); $this->curlHandle = null; } }
php
{ "resource": "" }
q21202
CurlClient.resetCurlHandle
train
private function resetCurlHandle() { if (!is_null($this->curlHandle) && $this->getEnablePersistentConnections()) { curl_reset($this->curlHandle); } else { $this->initCurlHandle(); } }
php
{ "resource": "" }
q21203
CurlClient.hasHeader
train
private function hasHeader($headers, $name) { foreach ($headers as $header) { if (strncasecmp($header, "{$name}: ", strlen($name) + 2) === 0) { return true; } } return false; }
php
{ "resource": "" }
q21204
Webhook.constructEvent
train
public static function constructEvent($payload, $sigHeader, $secret, $tolerance = self::DEFAULT_TOLERANCE) { $data = json_decode($payload, true); $jsonError = json_last_error(); if ($data === null && $jsonError !== JSON_ERROR_NONE) { $msg = "Invalid payload: $payload " ...
php
{ "resource": "" }
q21205
WebhookSignature.verifyHeader
train
public static function verifyHeader($payload, $header, $secret, $tolerance = null) { // Extract timestamp and signatures from header $timestamp = self::getTimestamp($header); $signatures = self::getSignatures($header, self::EXPECTED_SCHEME); if ($timestamp == -1) { throw ...
php
{ "resource": "" }
q21206
WebhookSignature.getTimestamp
train
private static function getTimestamp($header) { $items = explode(",", $header); foreach ($items as $item) { $itemParts = explode("=", $item, 2); if ($itemParts[0] == "t") { if (!is_numeric($itemParts[1])) { return -1; } ...
php
{ "resource": "" }
q21207
WebhookSignature.getSignatures
train
private static function getSignatures($header, $scheme) { $signatures = []; $items = explode(",", $header); foreach ($items as $item) { $itemParts = explode("=", $item, 2); if ($itemParts[0] == $scheme) { array_push($signatures, $itemParts[1]); ...
php
{ "resource": "" }
q21208
StripeObject.constructFrom
train
public static function constructFrom($values, $opts = null) { $obj = new static(isset($values['id']) ? $values['id'] : null); $obj->refreshFrom($values, $opts); return $obj; }
php
{ "resource": "" }
q21209
StripeObject.updateAttributes
train
public function updateAttributes($values, $opts = null, $dirty = true) { foreach ($values as $k => $v) { // Special-case metadata to always be cast as a StripeObject // This is necessary in case metadata is empty, as PHP arrays do // not differentiate between lists and ha...
php
{ "resource": "" }
q21210
StripeObject.dirty
train
public function dirty() { $this->_unsavedValues = new Util\Set(array_keys($this->_values)); foreach ($this->_values as $k => $v) { $this->dirtyValue($v); } }
php
{ "resource": "" }
q21211
StripeObject.deepCopy
train
protected static function deepCopy($obj) { if (is_array($obj)) { $copy = []; foreach ($obj as $k => $v) { $copy[$k] = self::deepCopy($v); } return $copy; } elseif ($obj instanceof StripeObject) { return $obj::constructFrom( ...
php
{ "resource": "" }
q21212
StripeObject.emptyValues
train
public static function emptyValues($obj) { if (is_array($obj)) { $values = $obj; } elseif ($obj instanceof StripeObject) { $values = $obj->_values; } else { throw new \InvalidArgumentException( "empty_values got got unexpected object type: ...
php
{ "resource": "" }
q21213
Util.convertStripeObjectToArray
train
public static function convertStripeObjectToArray($values) { $results = []; foreach ($values as $k => $v) { // FIXME: this is an encapsulation violation if ($k[0] == '_') { continue; } if ($v instanceof StripeObject) { $...
php
{ "resource": "" }
q21214
Util.secureCompare
train
public static function secureCompare($a, $b) { if (self::$isHashEqualsAvailable === null) { self::$isHashEqualsAvailable = function_exists('hash_equals'); } if (self::$isHashEqualsAvailable) { return hash_equals($a, $b); } else { if (strlen($a) !=...
php
{ "resource": "" }
q21215
Util.objectsToIds
train
public static function objectsToIds($h) { if ($h instanceof \Stripe\ApiResource) { return $h->id; } elseif (static::isList($h)) { $results = []; foreach ($h as $v) { array_push($results, static::objectsToIds($v)); } return $...
php
{ "resource": "" }
q21216
OAuth.authorizeUrl
train
public static function authorizeUrl($params = null, $opts = null) { $params = $params ?: []; $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase; $params['client_id'] = self::_getClientId($params); if (!array_key_exists('respons...
php
{ "resource": "" }
q21217
RequestOptions.discardNonPersistentHeaders
train
public function discardNonPersistentHeaders() { foreach ($this->headers as $k => $v) { if (!in_array($k, self::$HEADERS_TO_PERSIST)) { unset($this->headers[$k]); } } }
php
{ "resource": "" }
q21218
RandomGenerator.uuid
train
public function uuid() { $arr = array_values(unpack('N1a/n4b/N1c', openssl_random_pseudo_bytes(16))); $arr[2] = ($arr[2] & 0x0fff) | 0x4000; $arr[3] = ($arr[3] & 0x3fff) | 0x8000; return vsprintf('%08x-%04x-%04x-%04x-%04x%08x', $arr); }
php
{ "resource": "" }
q21219
SearchableTrait.scopeSearch
train
public function scopeSearch(Builder $q, $search, $threshold = null, $entireText = false, $entireTextOnly = false) { return $this->scopeSearchRestricted($q, $search, null, $threshold, $entireText, $entireTextOnly); }
php
{ "resource": "" }
q21220
SearchableTrait.getColumns
train
protected function getColumns() { if (array_key_exists('columns', $this->searchable)) { $driver = $this->getDatabaseDriver(); $prefix = Config::get("database.connections.$driver.prefix"); $columns = []; foreach($this->searchable['columns'] as $column => $prior...
php
{ "resource": "" }
q21221
SearchableTrait.makeJoins
train
protected function makeJoins(Builder $query) { foreach ($this->getJoins() as $table => $keys) { $query->leftJoin($table, function ($join) use ($keys) { $join->on($keys[0], '=', $keys[1]); if (array_key_exists(2, $keys) && array_key_exists(3, $keys)) { ...
php
{ "resource": "" }
q21222
SearchableTrait.makeGroupBy
train
protected function makeGroupBy(Builder $query) { if ($groupBy = $this->getGroupBy()) { $query->groupBy($groupBy); } else { $driver = $this->getDatabaseDriver(); if ($driver == 'sqlsrv') { $columns = $this->getTableColumns(); } else { ...
php
{ "resource": "" }
q21223
SearchableTrait.getSearchQueriesForColumn
train
protected function getSearchQueriesForColumn(Builder $query, $column, $relevance, array $words) { $queries = []; $queries[] = $this->getSearchQuery($query, $column, $relevance, $words, 15); $queries[] = $this->getSearchQuery($query, $column, $relevance, $words, 5, '', '%'); $queries...
php
{ "resource": "" }
q21224
SearchableTrait.getSearchQuery
train
protected function getSearchQuery(Builder $query, $column, $relevance, array $words, $relevance_multiplier, $pre_word = '', $post_word = '') { $like_comparator = $this->getDatabaseDriver() == 'pgsql' ? 'ILIKE' : 'LIKE'; $cases = []; foreach ($words as $word) { $cases[] =...
php
{ "resource": "" }
q21225
SearchableTrait.getCaseCompare
train
protected function getCaseCompare($column, $compare, $relevance) { if($this->getDatabaseDriver() == 'pgsql') { $field = "LOWER(" . $column . ") " . $compare . " ?"; return '(case when ' . $field . ' then ' . $relevance . ' else 0 end)'; } $column = str_replace('.', '`.`'...
php
{ "resource": "" }
q21226
SearchableTrait.mergeQueries
train
protected function mergeQueries(Builder $clone, Builder $original) { $tableName = DB::connection($this->connection)->getTablePrefix() . $this->getTable(); if ($this->getDatabaseDriver() == 'pgsql') { $original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as {$tableName}"...
php
{ "resource": "" }
q21227
Telegram.setWebhook
train
public function setWebhook($url, $certificate = '') { if ($certificate == '') { $requestBody = ['url' => $url]; } else { $requestBody = ['url' => $url, 'certificate' => "@$certificate"]; } return $this->endpoint('setWebhook', $requestBody, true); }
php
{ "resource": "" }
q21228
Telegram.ChatID
train
public function ChatID() { $type = $this->getUpdateType(); if ($type == self::CALLBACK_QUERY) { return @$this->data['callback_query']['message']['chat']['id']; } if ($type == self::CHANNEL_POST) { return @$this->data['channel_post']['chat']['id']; } ...
php
{ "resource": "" }
q21229
Telegram.getUpdateType
train
public function getUpdateType() { $update = $this->data; if (isset($update['inline_query'])) { return self::INLINE_QUERY; } if (isset($update['callback_query'])) { return self::CALLBACK_QUERY; } if (isset($update['edited_message'])) { ...
php
{ "resource": "" }
q21230
TransRef.getPool
train
private static function getPool($type = 'alnum') { switch ($type) { case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX...
php
{ "resource": "" }
q21231
TransRef.getHashedToken
train
public static function getHashedToken($length = 25) { $token = ""; $max = strlen(static::getPool()); for ($i = 0; $i < $length; $i++) { $token .= static::getPool()[static::secureCrypt(0, $max)]; } return $token; }
php
{ "resource": "" }
q21232
Paystack.setRequestOptions
train
private function setRequestOptions() { $authBearer = 'Bearer '. $this->secretKey; $this->client = new Client( [ 'base_uri' => $this->baseUrl, 'headers' => [ 'Authorization' => $authBearer, 'Content-Type' => 'applic...
php
{ "resource": "" }
q21233
Paystack.getAuthorizationResponse
train
public function getAuthorizationResponse($data) { $this->makePaymentRequest($data); $this->url = $this->getResponse()['data']['authorization_url']; return $this->getResponse(); }
php
{ "resource": "" }
q21234
Paystack.verifyTransactionAtGateway
train
private function verifyTransactionAtGateway() { $transactionRef = request()->query('trxref'); $relativeUrl = "/transaction/verify/{$transactionRef}"; $this->response = $this->client->get($this->baseUrl . $relativeUrl, []); }
php
{ "resource": "" }
q21235
Paystack.isTransactionVerificationValid
train
public function isTransactionVerificationValid() { $this->verifyTransactionAtGateway(); $result = $this->getResponse()['message']; switch ($result) { case self::VS: $validate = true; break; case self::ITF: $validate = ...
php
{ "resource": "" }
q21236
Paystack.createPlan
train
public function createPlan() { $data = [ "name" => request()->name, "description" => request()->desc, "amount" => intval(request()->amount), "interval" => request()->interval, "send_invoices" => request()->send_invoices, "send_sms" => r...
php
{ "resource": "" }
q21237
Paystack.updatePlan
train
public function updatePlan($plan_code) { $data = [ "name" => request()->name, "description" => request()->desc, "amount" => intval(request()->amount), "interval" => request()->interval, "send_invoices" => request()->send_invoices, "send...
php
{ "resource": "" }
q21238
Paystack.updateCustomer
train
public function updateCustomer($customer_id) { $data = [ "email" => request()->email, "first_name" => request()->fname, "last_name" => request()->lname, "phone" => request()->phone, "metadata" => request()->additional_info /* key => value pairs arr...
php
{ "resource": "" }
q21239
Paystack.exportTransactions
train
public function exportTransactions() { $data = [ "from" => request()->from, "to" => request()->to, 'settled' => request()->settled ]; $this->setRequestOptions(); return $this->setHttpResponse('/transaction/export', 'GET', $data)->getResponse(); ...
php
{ "resource": "" }
q21240
Paystack.createSubscription
train
public function createSubscription() { $data = [ "customer" => request()->customer, //Customer email or code "plan" => request()->plan, "authorization" => request()->authorization_code ]; $this->setRequestOptions(); $this->setHttpResponse('/subscr...
php
{ "resource": "" }
q21241
Paystack.enableSubscription
train
public function enableSubscription() { $data = [ "code" => request()->code, "token" => request()->token, ]; $this->setRequestOptions(); return $this->setHttpResponse('/subscription/enable', 'POST', $data)->getResponse(); }
php
{ "resource": "" }
q21242
Paystack.createPage
train
public function createPage() { $data = [ "name" => request()->name, "description" => request()->description, "amount" => request()->amount ]; $this->setRequestOptions(); $this->setHttpResponse('/page', 'POST', $data); }
php
{ "resource": "" }
q21243
Paystack.updatePage
train
public function updatePage($page_id) { $data = [ "name" => request()->name, "description" => request()->description, "amount" => request()->amount ]; $this->setRequestOptions(); return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getRe...
php
{ "resource": "" }
q21244
Paystack.listSubAccounts
train
public function listSubAccounts($per_page,$page){ $this->setRequestOptions(); return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse(); }
php
{ "resource": "" }
q21245
Paystack.updateSubAccount
train
public function updateSubAccount($subaccount_code){ $data = [ "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, "account_number" => request()->account_number, "percentage_charge" => request()->percentage_charge, ...
php
{ "resource": "" }
q21246
PathsHelper.getAsciiContent
train
public function getAsciiContent(string $resource): string { $file = $this->config->getAsciiContentPath($resource); // Disabled: if (null === $file) { return ''; } // Specified by user: if ($this->fileSystem->exists($file)) { return $this->fil...
php
{ "resource": "" }
q21247
PathsHelper.getGitDir
train
public function getGitDir(): string { $gitDir = $this->config->getGitDir(); if (!$this->fileSystem->exists($gitDir)) { throw new RuntimeException('The configured GIT directory could not be found.'); } return $this->getRelativePath($gitDir); }
php
{ "resource": "" }
q21248
PathsHelper.getGitHookExecutionPath
train
public function getGitHookExecutionPath(): string { $gitPath = $this->getGitDir(); return $this->fileSystem->makePathRelative($this->getWorkingDir(), $this->getAbsolutePath($gitPath)); }
php
{ "resource": "" }
q21249
PathsHelper.getGitHooksDir
train
public function getGitHooksDir(): string { $gitPath = $this->getGitDir(); $absoluteGitPath = $this->getAbsolutePath($gitPath); $gitRepoPath = $absoluteGitPath.'/.git'; if (is_file($gitRepoPath)) { $fileContent = $this->fileSystem->readFromFileInfo(new SplFileInfo($gitRep...
php
{ "resource": "" }
q21250
PathsHelper.getBinDir
train
public function getBinDir(): string { $binDir = $this->config->getBinDir(); if (!$this->fileSystem->exists($binDir)) { throw new RuntimeException('The configured BIN directory could not be found.'); } return $this->getRelativePath($binDir); }
php
{ "resource": "" }
q21251
PathsHelper.getRelativeProjectPath
train
public function getRelativeProjectPath(string $path): string { $realPath = $this->getAbsolutePath($path); $gitPath = $this->getAbsolutePath($this->getGitDir()); if (0 !== strpos($realPath, $gitPath)) { return $realPath; } return rtrim($this->getRelativePath($rea...
php
{ "resource": "" }
q21252
Str.containsOneOf
train
public static function containsOneOf($haystack, array $needles) { foreach ($needles as $needle) { if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { return true; } } return false; }
php
{ "resource": "" }
q21253
ProcessArgumentsCollection.addArgumentArrayWithSeparatedValue
train
public function addArgumentArrayWithSeparatedValue(string $argument, array $values) { foreach ($values as $value) { $this->add(sprintf($argument, $value)); $this->add($value); } }
php
{ "resource": "" }
q21254
PhpParserCompilerPass.process
train
public function process(ContainerBuilder $container) { $traverserConfigurator = $container->findDefinition('grumphp.parser.php.configurator.traverser'); foreach ($container->findTaggedServiceIds(self::TAG) as $id => $tags) { $definition = $container->findDefinition($id); $thi...
php
{ "resource": "" }
q21255
PhpParserCompilerPass.markServiceAsPrototype
train
public function markServiceAsPrototype(Definition $definition) { if (method_exists($definition, 'setShared')) { $definition->setShared(false); return; } if (method_exists($definition, 'setScope')) { $definition->setScope('prototype'); return...
php
{ "resource": "" }
q21256
GrumPHPPlugin.postPackageInstall
train
public function postPackageInstall(PackageEvent $event) { /** @var InstallOperation $operation */ $operation = $event->getOperation(); $package = $operation->getPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // Schedule init when com...
php
{ "resource": "" }
q21257
GrumPHPPlugin.postPackageUpdate
train
public function postPackageUpdate(PackageEvent $event) { /** @var UpdateOperation $operation */ $operation = $event->getOperation(); $package = $operation->getTargetPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // Schedule init when...
php
{ "resource": "" }
q21258
GrumPHPPlugin.prePackageUninstall
train
public function prePackageUninstall(PackageEvent $event) { /** @var UninstallOperation $operation */ $operation = $event->getOperation(); $package = $operation->getPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // First remove the ho...
php
{ "resource": "" }
q21259
InitCommand.useExoticConfigFile
train
protected function useExoticConfigFile() { try { $configPath = $this->paths()->getAbsolutePath($this->input->getOption('config')); if ($configPath !== $this->paths()->getDefaultConfigPath()) { return $this->paths()->getRelativeProjectPath($configPath); } ...
php
{ "resource": "" }
q21260
DevelopmentIntegrator.integrate
train
public static function integrate(Event $event) { $filesystem = new Filesystem(); $composerBinDir = $event->getComposer()->getConfig()->get('bin-dir'); $executable = getcwd().'/bin/grumphp'; $composerExecutable = $composerBinDir.'/grumphp'; $filesystem->copy( self...
php
{ "resource": "" }
q21261
GrumPHP.getAsciiContentPath
train
public function getAsciiContentPath(string $resource) { if (null === $this->container->getParameter('ascii')) { return null; } $paths = $this->container->getParameter('ascii'); if (!array_key_exists($resource, $paths)) { return null; } // Dea...
php
{ "resource": "" }
q21262
Application.updateUserConfigPath
train
private function updateUserConfigPath(string $configPath): string { if ($configPath !== $this->getDefaultConfigPath()) { $configPath = getcwd().DIRECTORY_SEPARATOR.$configPath; } return $configPath; }
php
{ "resource": "" }
q21263
CommitMessage.getSubjectLine
train
private function getSubjectLine($context) { $commitMessage = $context->getCommitMessage(); $lines = $this->getCommitMessageLinesWithoutComments($commitMessage); return (string) $lines[0]; }
php
{ "resource": "" }
q21264
StashUnstagedChangesSubscriber.doSaveStash
train
private function doSaveStash() { $pending = $this->repository->getWorkingCopy()->getDiffPending(); if (!\count($pending->getFiles())) { return; } try { $this->io->write(['<fg=yellow>Detected unstaged changes... Stashing them!</fg=yellow>']); $this...
php
{ "resource": "" }
q21265
StashUnstagedChangesSubscriber.registerShutdownHandler
train
private function registerShutdownHandler() { if ($this->shutdownFunctionRegistered) { return; } $subscriber = $this; register_shutdown_function(function () use ($subscriber) { if (!$error = error_get_last()) { return; } ...
php
{ "resource": "" }
q21266
YamlLinter.supportsFlags
train
public static function supportsFlags(): bool { $rc = new ReflectionClass(Yaml::class); $method = $rc->getMethod('parse'); $params = $method->getParameters(); return 'flags' === $params[1]->getName(); }
php
{ "resource": "" }
q21267
TasksCollection.sortByPriority
train
public function sortByPriority(GrumPHP $grumPHP): self { $priorityQueue = new SplPriorityQueue(); $stableSortIndex = PHP_INT_MAX; foreach ($this->getIterator() as $task) { $metadata = $grumPHP->getTaskMetadata($task->getName()); $priorityQueue->insert($task, [$metadat...
php
{ "resource": "" }
q21268
Composer.ensureProjectBinDirInSystemPath
train
public static function ensureProjectBinDirInSystemPath(string $binDir) { $pathStr = 'PATH'; if (!isset($_SERVER[$pathStr]) && isset($_SERVER['Path'])) { $pathStr = 'Path'; } if (!is_dir($binDir)) { return; } // add the bin dir to the PATH to ...
php
{ "resource": "" }
q21269
FilesCollection.paths
train
public function paths(array $patterns): self { $filter = new Iterator\PathFilterIterator($this->getIterator(), $patterns, []); return new self(iterator_to_array($filter)); }
php
{ "resource": "" }
q21270
FilesCollection.notPaths
train
public function notPaths(array $pattern): self { $filter = new Iterator\PathFilterIterator($this->getIterator(), [], $pattern); return new self(iterator_to_array($filter)); }
php
{ "resource": "" }
q21271
FilesCollection.filter
train
public function filter(Closure $closure): self { $filter = new Iterator\CustomFilterIterator($this->getIterator(), [$closure]); return new self(iterator_to_array($filter)); }
php
{ "resource": "" }
q21272
ConfigureCommand.buildConfiguration
train
protected function buildConfiguration(InputInterface $input, OutputInterface $output): array { /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $questionString = $this->createQuestionString( 'Do you want to create a grumphp.yml file?', 'Yes'...
php
{ "resource": "" }
q21273
ConfigureCommand.guessBinDir
train
protected function guessBinDir(): string { $defaultBinDir = $this->config->getBinDir(); if (!$this->composer()->hasConfiguration()) { return $defaultBinDir; } $config = $this->composer()->getConfiguration(); if (!$config->has('bin-dir')) { return $def...
php
{ "resource": "" }
q21274
Pinyin.convert
train
public function convert($string, $option = PINYIN_DEFAULT) { $pinyin = $this->romanize($string, $option); return $this->splitWords($pinyin, $option); }
php
{ "resource": "" }
q21275
Pinyin.permalink
train
public function permalink($string, $delimiter = '-', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, '-'); } if (!in_array($delimiter, array('_', '-', '.', ''), true)) { throw new InvalidArgumentException("Delimite...
php
{ "resource": "" }
q21276
Pinyin.abbr
train
public function abbr($string, $delimiter = '', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ''); } return implode($delimiter, array_map(function ($pinyin) { return \is_numeric($pinyin) ? $pinyin : mb_substr($pin...
php
{ "resource": "" }
q21277
Pinyin.phrase
train
public function phrase($string, $delimiter = ' ', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ' '); } return implode($delimiter, $this->convert($string, $option)); }
php
{ "resource": "" }
q21278
Pinyin.sentence
train
public function sentence($string, $delimiter = ' ', $option = \PINYIN_NO_TONE) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ' '); } return implode($delimiter, $this->convert($string, $option | \PINYIN_KEEP_PUNCTUATION | \PINYIN_KEEP_ENGLISH | \PINYI...
php
{ "resource": "" }
q21279
Pinyin.getLoader
train
public function getLoader() { if (!($this->loader instanceof DictLoaderInterface)) { $dataDir = dirname(__DIR__).'/data/'; $loaderName = $this->loader; $this->loader = new $loaderName($dataDir); } return $this->loader; }
php
{ "resource": "" }
q21280
Pinyin.romanize
train
protected function romanize($string, $option = \PINYIN_DEFAULT) { $string = $this->prepare($string, $option); $dictLoader = $this->getLoader(); if ($this->hasOption($option, \PINYIN_NAME)) { $string = $this->convertSurname($string, $dictLoader); } $dictLoader->...
php
{ "resource": "" }
q21281
Pinyin.convertSurname
train
protected function convertSurname($string, $dictLoader) { $dictLoader->mapSurname(function ($dictionary) use (&$string) { foreach ($dictionary as $surname => $pinyin) { if (0 === strpos($string, $surname)) { $string = $pinyin.mb_substr($string, mb_strlen($surn...
php
{ "resource": "" }
q21282
Pinyin.splitWords
train
protected function splitWords($pinyin, $option) { $split = array_filter(preg_split('/\s+/i', $pinyin)); if (!$this->hasOption($option, PINYIN_TONE)) { foreach ($split as $index => $pinyin) { $split[$index] = $this->formatTone($pinyin, $option); } } ...
php
{ "resource": "" }
q21283
Pinyin.prepare
train
protected function prepare($string, $option = \PINYIN_DEFAULT) { $string = preg_replace_callback('~[a-z0-9_-]+~i', function ($matches) { return "\t".$matches[0]; }, $string); $regex = array('\p{Han}', '\p{Z}', '\p{M}', "\t"); if ($this->hasOption($option, \PINYIN_KEEP_N...
php
{ "resource": "" }
q21284
GeneratorFileDictLoader.getGenerator
train
protected function getGenerator(array $handles) { foreach ($handles as $handle) { $handle->seek(0); while (false === $handle->eof()) { $string = str_replace(['\'', ' ', PHP_EOL, ','], '', $handle->fgets()); if (false === strpos($string, '=>')) { ...
php
{ "resource": "" }
q21285
GeneratorFileDictLoader.traversing
train
protected function traversing(Generator $generator, Closure $callback) { foreach ($generator as $string => $pinyin) { $callback([$string => $pinyin]); } }
php
{ "resource": "" }
q21286
TagParser.extractTagAttributes
train
public function extractTagAttributes($code) { $param = array(); $regexes = array( '([a-zA-Z0-9_]+)=([^"\'\s>]+)', // read the parameters : name=value '([a-zA-Z0-9_]+)=["]([^"]*)["]', // read the parameters : name="value" "([a-zA-Z0-9_]+)=[']([^']*)[']" // read t...
php
{ "resource": "" }
q21287
Css.getOldValues
train
public function getOldValues() { return isset($this->table[count($this->table)-1]) ? $this->table[count($this->table)-1] : $this->value; }
php
{ "resource": "" }
q21288
Css.setDefaultFont
train
public function setDefaultFont($default = null) { $old = $this->defaultFont; $this->defaultFont = $default; if ($default) { $this->value['font-family'] = $default; } return $old; }
php
{ "resource": "" }
q21289
Css.setPosition
train
public function setPosition() { // get the current position $currentX = $this->pdf->GetX(); $currentY = $this->pdf->GetY(); // save it $this->value['xc'] = $currentX; $this->value['yc'] = $currentY; if ($this->value['position'] === 'relative' || $this->value...
php
{ "resource": "" }
q21290
Css.getLastHeight
train
public function getLastHeight($mode = false) { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['height']) { $h = $this->table[$k]['height']; if ($mode) { $h+= $this->table[$k]['border']['t']['width'] + $this->table[$k]['paddi...
php
{ "resource": "" }
q21291
Css.getLastValue
train
public function getLastValue($key) { $nb = count($this->table); if ($nb>0) { return $this->table[$nb-1][$key]; } else { return null; } }
php
{ "resource": "" }
q21292
Css.getLastAbsoluteX
train
protected function getLastAbsoluteX() { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['x'] && $this->table[$k]['position']) { return $this->table[$k]['x']; } } return $this->pdf->getlMargin(); }
php
{ "resource": "" }
q21293
Css.getLastAbsoluteY
train
protected function getLastAbsoluteY() { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['y'] && $this->table[$k]['position']) { return $this->table[$k]['y']; } } return $this->pdf->gettMargin(); }
php
{ "resource": "" }
q21294
Css.duplicateBorder
train
protected function duplicateBorder(&$val) { // 1 value => L => RTB if (count($val) == 1) { $val[1] = $val[0]; $val[2] = $val[0]; $val[3] = $val[0]; // 2 values => L => R & T => B } elseif (count($val) == 2) { $val[2] = $val[0]; ...
php
{ "resource": "" }
q21295
Css.analyseStyle
train
protected function analyseStyle($code) { // clean the spaces $code = preg_replace('/[\s]+/', ' ', $code); // remove the comments $code = preg_replace('/\/\*.*?\*\//s', '', $code); // split each CSS code "selector { value }" preg_match_all('/([^{}]+){([^}]*)}/isU', $...
php
{ "resource": "" }
q21296
AbstractSvgTag.openSvg
train
protected function openSvg($properties) { if (!$this->svgDrawer->isDrawing()) { $e = new HtmlParsingException('The asked ['.$this->getName().'] tag is not in a [DRAW] tag'); $e->setInvalidTag($this->getName()); throw $e; } $transform = null; if (a...
php
{ "resource": "" }
q21297
AbstractHtmlTag.open
train
public function open($properties) { $this->parsingCss->save(); $this->overrideStyles(); $this->parsingCss->analyse($this->getName(), $properties); $this->parsingCss->setPosition(); $this->parsingCss->fontSet(); return true; }
php
{ "resource": "" }
q21298
Debug.displayLine
train
protected function displayLine($name, $timeTotal, $timeStep, $memoryUsage, $memoryPeak) { $output = str_pad($name, 30, ' ', STR_PAD_RIGHT). str_pad($timeTotal, 12, ' ', STR_PAD_LEFT). str_pad($timeStep, 12, ' ', STR_PAD_LEFT). str_pad($memoryUsage, 15, ' ', ST...
php
{ "resource": "" }
q21299
Debug.start
train
public function start() { $time = microtime(true); $this->startTime = $time; $this->lastTime = $time; $this->displayLine('step', 'time', 'delta', 'memory', 'peak'); $this->addStep('Init debug'); return $this; }
php
{ "resource": "" }