_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q256600
Hooks.set
test
public function set($name, $content) { if ($this->has($name)) { throw new LogicException(sprintf('A hook "%s" is already defined', $name)); } $path = $this->getPath($name); file_put_contents($path, $content); chmod($path, 0777); }
php
{ "resource": "" }
q256601
Hooks.remove
test
public function remove($name) { if (!$this->has($name)) { throw new LogicException(sprintf('The hook "%s" was not found', $name)); } unlink($this->getPath($name)); }
php
{ "resource": "" }
q256602
Log.countCommits
test
public function countCommits() { if (null !== $this->revisions && count($this->revisions)) { $output = $this->repository->run('rev-list', array_merge(array('--count'), $this->revisions->getAsTextArray(), array('--'), $this->paths)); } else { $output = $this->repository->run('rev-list', array_merge(array('--count', '--all', '--'), $this->paths)); } return (int) $output; }
php
{ "resource": "" }
q256603
Repository.getReferences
test
public function getReferences() { if (null === $this->referenceBag) { $this->referenceBag = new ReferenceBag($this); } return $this->referenceBag; }
php
{ "resource": "" }
q256604
Repository.getCommit
test
public function getCommit($hash) { if (!isset($this->objects[$hash])) { $this->objects[$hash] = new Commit($this, $hash); } return $this->objects[$hash]; }
php
{ "resource": "" }
q256605
Repository.getTree
test
public function getTree($hash) { if (!isset($this->objects[$hash])) { $this->objects[$hash] = new Tree($this, $hash); } return $this->objects[$hash]; }
php
{ "resource": "" }
q256606
Repository.getBlob
test
public function getBlob($hash) { if (!isset($this->objects[$hash])) { $this->objects[$hash] = new Blob($this, $hash); } return $this->objects[$hash]; }
php
{ "resource": "" }
q256607
Repository.getLog
test
public function getLog($revisions = null, $paths = null, $offset = null, $limit = null) { return new Log($this, $revisions, $paths, $offset, $limit); }
php
{ "resource": "" }
q256608
Repository.getSize
test
public function getSize() { $commandlineArguments = array('du', '-skc', $this->gitDir); $commandline = $this->normalizeCommandlineArguments($commandlineArguments); $process = new Process($commandline); $process->run(); if (!preg_match('/(\d+)\s+total$/', trim($process->getOutput()), $vars)) { $message = sprintf("Unable to parse process output\ncommand: %s\noutput: %s", $process->getCommandLine(), $process->getOutput()); if (null !== $this->logger) { $this->logger->error($message); } if (true === $this->debug) { throw new RuntimeException('unable to parse repository size output'); } return; } return $vars[1]; }
php
{ "resource": "" }
q256609
Repository.shell
test
public function shell($command, array $env = array()) { $argument = sprintf('%s \'%s\'', $command, $this->gitDir); $prefix = ''; foreach ($env as $name => $value) { $prefix .= sprintf('export %s=%s;', escapeshellarg($name), escapeshellarg($value)); } proc_open($prefix.'git shell -c '.escapeshellarg($argument), array(STDIN, STDOUT, STDERR), $pipes); }
php
{ "resource": "" }
q256610
Repository.getDescription
test
public function getDescription() { $file = $this->gitDir.'/description'; $exists = is_file($file); if (null !== $this->logger && true === $this->debug) { if (false === $exists) { $this->logger->debug(sprintf('no description file in repository ("%s")', $file)); } else { $this->logger->debug(sprintf('reading description file in repository ("%s")', $file)); } } if (false === $exists) { return static::DEFAULT_DESCRIPTION; } return file_get_contents($this->gitDir.'/description'); }
php
{ "resource": "" }
q256611
Repository.run
test
public function run($command, $args = array()) { $process = $this->getProcess($command, $args); if ($this->logger) { $this->logger->info(sprintf('run command: %s "%s" ', $command, implode(' ', $args))); $before = microtime(true); } $process->run(); $output = $process->getOutput(); if ($this->logger && $this->debug) { $duration = microtime(true) - $before; $this->logger->debug(sprintf('last command (%s) duration: %sms', $command, sprintf('%.2f', $duration * 1000))); $this->logger->debug(sprintf('last command (%s) return code: %s', $command, $process->getExitCode())); $this->logger->debug(sprintf('last command (%s) output: %s', $command, $output)); } if (!$process->isSuccessful()) { $error = sprintf("error while running %s\n output: \"%s\"", $command, $process->getErrorOutput()); if ($this->logger) { $this->logger->error($error); } if ($this->debug) { throw new ProcessException($process); } return; } return $output; }
php
{ "resource": "" }
q256612
Repository.cloneTo
test
public function cloneTo($path, $bare = true, array $options = array()) { return Admin::cloneTo($path, $this->gitDir, $bare, $options); }
php
{ "resource": "" }
q256613
Commit.getParents
test
public function getParents() { $result = array(); foreach ($this->getData('parentHashes') as $parentHash) { $result[] = $this->repository->getCommit($parentHash); } return $result; }
php
{ "resource": "" }
q256614
Commit.getShortMessage
test
public function getShortMessage($length = 50, $preserve = false, $separator = '...') { $message = $this->getData('subjectMessage'); if (StringHelper::strlen($message) > $length) { if ($preserve && false !== ($breakpoint = StringHelper::strpos($message, ' ', $length))) { $length = $breakpoint; } return rtrim(StringHelper::substr($message, 0, $length)).$separator; } return $message; }
php
{ "resource": "" }
q256615
Commit.getIncludingBranches
test
public function getIncludingBranches($local = true, $remote = true) { $arguments = array('--contains', $this->revision); if ($local && $remote) { $arguments[] = '-a'; } elseif (!$local && $remote) { $arguments[] = '-r'; } elseif (!$local && !$remote) { throw new InvalidArgumentException('You should a least set one argument to true'); } try { $result = $this->repository->run('branch', $arguments); } catch (ProcessException $e) { return array(); } if (!$result) { return array(); } $branchesName = explode("\n", trim(str_replace('*', '', $result))); $branchesName = array_filter($branchesName, function ($v) { return false === StringHelper::strpos($v, '->'); }); $branchesName = array_map('trim', $branchesName); $references = $this->repository->getReferences(); $branches = array(); foreach ($branchesName as $branchName) { if (false === $local) { $branches[] = $references->getRemoteBranch($branchName); } elseif (0 === StringHelper::strrpos($branchName, 'remotes/')) { $branches[] = $references->getRemoteBranch(str_replace('remotes/', '', $branchName)); } else { $branches[] = $references->getBranch($branchName); } } return $branches; }
php
{ "resource": "" }
q256616
Admin.init
test
public static function init($path, $bare = true, array $options = array()) { $process = static::getProcess('init', array_merge(array('-q'), $bare ? array('--bare') : array(), array($path)), $options); $process->run(); if (!$process->isSuccessFul()) { throw new RuntimeException(sprintf("Error on repository initialization, command wasn't successful (%s). Error output:\n%s", $process->getCommandLine(), $process->getErrorOutput())); } return new Repository($path, $options); }
php
{ "resource": "" }
q256617
Admin.isValidRepository
test
public static function isValidRepository($url, array $options = array()) { $process = static::getProcess('ls-remote', array($url), $options); $process->run(); return $process->isSuccessFul(); }
php
{ "resource": "" }
q256618
Admin.cloneTo
test
public static function cloneTo($path, $url, $bare = true, array $options = array()) { $args = $bare ? array('--bare') : array(); return static::cloneRepository($path, $url, $args, $options); }
php
{ "resource": "" }
q256619
Admin.cloneBranchTo
test
public static function cloneBranchTo($path, $url, $branch, $bare = true, $options = array()) { $args = array('--branch', $branch); if ($bare) { $args[] = '--bare'; } return static::cloneRepository($path, $url, $args, $options); }
php
{ "resource": "" }
q256620
Admin.cloneRepository
test
public static function cloneRepository($path, $url, array $args = array(), array $options = array()) { $process = static::getProcess('clone', array_merge(array('-q'), $args, array($url, $path)), $options); $process->run(); if (!$process->isSuccessFul()) { throw new RuntimeException(sprintf('Error while initializing repository: %s', $process->getErrorOutput())); } return new Repository($path, $options); }
php
{ "resource": "" }
q256621
Blame.getGroupedLines
test
public function getGroupedLines() { $result = array(); $commit = null; $current = array(); foreach ($this->getLines() as $lineNumber => $line) { if ($commit !== $line->getCommit()) { if (count($current)) { $result[] = array($commit, $current); } $commit = $line->getCommit(); $current = array(); } $current[$lineNumber] = $line; } if (count($current)) { $result[] = array($commit, $current); } return $result; }
php
{ "resource": "" }
q256622
Blame.getLines
test
public function getLines() { if (null !== $this->lines) { return $this->lines; } $args = array('-p'); if (null !== $this->lineRange) { $args[] = '-L'; $args[] = $this->lineRange; } $args[] = $this->revision->getRevision(); $args[] = '--'; $args[] = $this->file; $parser = new BlameParser($this->repository); $parser->parse($this->repository->run('blame', $args)); $this->lines = $parser->lines; return $this->lines; }
php
{ "resource": "" }
q256623
ReferenceBag.get
test
public function get($fullname) { $this->initialize(); if (!isset($this->references[$fullname])) { throw new ReferenceNotFoundException($fullname); } return $this->references[$fullname]; }
php
{ "resource": "" }
q256624
ReferenceBag.getBranches
test
public function getBranches() { $this->initialize(); $result = array(); foreach ($this->references as $reference) { if ($reference instanceof Reference\Branch) { $result[] = $reference; } } return $result; }
php
{ "resource": "" }
q256625
ReferenceBag.getLocalBranches
test
public function getLocalBranches() { $result = array(); foreach ($this->getBranches() as $branch) { if ($branch->isLocal()) { $result[] = $branch; } } return $result; }
php
{ "resource": "" }
q256626
ReferenceBag.getRemoteBranches
test
public function getRemoteBranches() { $result = array(); foreach ($this->getBranches() as $branch) { if ($branch->isRemote()) { $result[] = $branch; } } return $result; }
php
{ "resource": "" }
q256627
Blob.getContent
test
public function getContent() { if (null === $this->content) { $this->content = $this->repository->run('cat-file', array('-p', $this->hash)); } return $this->content; }
php
{ "resource": "" }
q256628
Blob.getMimetype
test
public function getMimetype() { if (null === $this->mimetype) { $finfo = new \finfo(FILEINFO_MIME); $this->mimetype = $finfo->buffer($this->getContent()); } return $this->mimetype; }
php
{ "resource": "" }
q256629
Diff.toArray
test
public function toArray() { return array( 'rawDiff' => $this->rawDiff, 'files' => array_map( function (File $file) { return $file->toArray(); }, $this->files ), ); }
php
{ "resource": "" }
q256630
EmailParser.parse
test
public function parse($text) { $text = str_replace(array("\r\n", "\r"), "\n", $text); foreach ($this->quoteHeadersRegex as $regex) { if (preg_match($regex, $text, $matches)) { $text = str_replace($matches[1], str_replace("\n", ' ', $matches[1]), $text); } } $fragment = null; $text_array = explode("\n", $text); while (($line = array_pop($text_array)) !== NULL) { $line = ltrim($line, "\n"); if (!$this->isSignature($line)) { $line = rtrim($line); } if ($fragment) { $first = reset($fragment->lines); if ($this->isSignature($first)) { $fragment->isSignature = true; $this->addFragment($fragment); $fragment = null; } elseif (empty($line) && $this->isQuoteHeader($first)) { $fragment->isQuoted = true; $this->addFragment($fragment); $fragment = null; } } $isQuoted = $this->isQuote($line); if (null === $fragment || !$this->isFragmentLine($fragment, $line, $isQuoted)) { if ($fragment) { $this->addFragment($fragment); } $fragment = new FragmentDTO(); $fragment->isQuoted = $isQuoted; } array_unshift($fragment->lines, $line); } if ($fragment) { $this->addFragment($fragment); } $email = $this->createEmail($this->fragments); $this->fragments = array(); return $email; }
php
{ "resource": "" }
q256631
GenericBuilder.writeFormatted
test
public function writeFormatted(QueryInterface $query) { if (null === $this->sqlFormatter) { $this->sqlFormatter = (new \ReflectionClass($this->sqlFormatterClass))->newInstance(); } return $this->sqlFormatter->format($this->write($query)); }
php
{ "resource": "" }
q256632
GenericBuilder.writeColumnName
test
public function writeColumnName(Column $column) { $name = $column->getName(); if ($name === Column::ALL) { return $this->writeColumnAll(); } return $name; }
php
{ "resource": "" }
q256633
SyntaxFactory.createColumns
test
public static function createColumns(array &$arguments, $table = null) { $createdColumns = []; foreach ($arguments as $index => $column) { if (!is_object($column)) { $newColumn = array($column); $column = self::createColumn($newColumn, $table); if (!is_numeric($index)) { $column->setAlias($index); } $createdColumns[] = $column; } else if ($column instanceof Column) { $createdColumns[] = $column; } } return \array_filter($createdColumns); }
php
{ "resource": "" }
q256634
SyntaxFactory.createColumn
test
public static function createColumn(array &$argument, $table = null) { $columnName = \array_values($argument); $columnName = $columnName[0]; $columnAlias = \array_keys($argument); $columnAlias = $columnAlias[0]; if (\is_numeric($columnAlias) || \strpos($columnName, '*') !== false) { $columnAlias = null; } return new Column($columnName, (string) $table, $columnAlias); }
php
{ "resource": "" }
q256635
SyntaxFactory.createTable
test
public static function createTable($table) { $tableName = $table; if (\is_array($table)) { $tableName = \current($table); $tableAlias = \key($table); } $newTable = new Table($tableName); if (isset($tableAlias) && !is_numeric($tableAlias)) { $newTable->setAlias($tableAlias); } return $newTable; }
php
{ "resource": "" }
q256636
AbstractBaseQuery.getSql
test
public function getSql($formatted = false) { if ($formatted) { return $this->getBuilder()->writeFormatted($this); } return $this->getBuilder()->write($this); }
php
{ "resource": "" }
q256637
CacheableEloquent.bootCacheableEloquent
test
public static function bootCacheableEloquent(): void { static::updated(function (Model $cachedModel) { ! $cachedModel->isCacheClearEnabled() || $cachedModel::forgetCache(); }); static::created(function (Model $cachedModel) { ! $cachedModel->isCacheClearEnabled() || $cachedModel::forgetCache(); }); static::deleted(function (Model $cachedModel) { ! $cachedModel->isCacheClearEnabled() || $cachedModel::forgetCache(); }); }
php
{ "resource": "" }
q256638
CacheableEloquent.storeCacheKey
test
protected static function storeCacheKey(string $modelName, string $cacheKey): void { $keysFile = storage_path('framework/cache/data/rinvex.cacheable.json'); $cacheKeys = static::getCacheKeys($keysFile); if (! isset($cacheKeys[$modelName]) || ! in_array($cacheKey, $cacheKeys[$modelName])) { $cacheKeys[$modelName][] = $cacheKey; file_put_contents($keysFile, json_encode($cacheKeys)); } }
php
{ "resource": "" }
q256639
CacheableEloquent.getCacheKeys
test
protected static function getCacheKeys($file): array { if (! file_exists($file)) { $dir = dirname($file); is_dir($dir) || mkdir($dir); file_put_contents($file, null); } return json_decode(file_get_contents($file), true) ?: []; }
php
{ "resource": "" }
q256640
CacheableEloquent.flushCacheKeys
test
protected static function flushCacheKeys(string $modelName): array { $flushedKeys = []; $keysFile = storage_path('framework/cache/data/rinvex.cacheable.json'); $cacheKeys = static::getCacheKeys($keysFile); if (isset($cacheKeys[$modelName])) { $flushedKeys = $cacheKeys[$modelName]; unset($cacheKeys[$modelName]); file_put_contents($keysFile, json_encode($cacheKeys)); } return $flushedKeys; }
php
{ "resource": "" }
q256641
CacheableEloquent.forgetCache
test
public static function forgetCache() { static::fireCacheFlushEvent('cache.flushing'); // Flush cache tags if (method_exists(app('cache')->getStore(), 'tags')) { app('cache')->tags(static::class)->flush(); } else { // Flush cache keys, then forget actual cache foreach (static::flushCacheKeys(static::class) as $cacheKey) { app('cache')->forget($cacheKey); } } static::fireCacheFlushEvent('cache.flushed', false); }
php
{ "resource": "" }
q256642
CacheableEloquent.resetCacheConfig
test
public function resetCacheConfig() { ! $this->cacheDriver || $this->cacheDriver = null; ! $this->cacheLifetime || $this->cacheLifetime = -1; return $this; }
php
{ "resource": "" }
q256643
CacheableEloquent.generateCacheKey
test
protected function generateCacheKey($builder, array $columns): string { $query = $builder instanceof Builder ? $builder->getQuery() : $builder; $vars = [ 'aggregate' => $query->aggregate, 'columns' => $query->columns, 'distinct' => $query->distinct, 'from' => $query->from, 'joins' => $query->joins, 'wheres' => $query->wheres, 'groups' => $query->groups, 'havings' => $query->havings, 'orders' => $query->orders, 'limit' => $query->limit, 'offset' => $query->offset, 'unions' => $query->unions, 'unionLimit' => $query->unionLimit, 'unionOffset' => $query->unionOffset, 'unionOrders' => $query->unionOrders, 'lock' => $query->lock, ]; return md5(json_encode([ $vars, $columns, static::class, $this->getCacheDriver(), $this->getCacheLifetime(), $builder instanceof Builder ? $builder->getEagerLoads() : null, $builder->getBindings(), $builder->toSql(), ])); }
php
{ "resource": "" }
q256644
CacheableEloquent.cacheQuery
test
public function cacheQuery($builder, array $columns, Closure $closure) { $modelName = $this->getMorphClass(); $lifetime = $this->getCacheLifetime(); $cacheKey = $this->generateCacheKey($builder, $columns); // Switch cache driver on runtime if ($driver = $this->getCacheDriver()) { app('cache')->setDefaultDriver($driver); } // We need cache tags, check if default driver supports it if (method_exists(app('cache')->getStore(), 'tags')) { $result = $lifetime === -1 ? app('cache')->tags($modelName)->rememberForever($cacheKey, $closure) : app('cache')->tags($modelName)->remember($cacheKey, $lifetime, $closure); return $result; } $result = $lifetime === -1 ? app('cache')->rememberForever($cacheKey, $closure) : app('cache')->remember($cacheKey, $lifetime, $closure); // Default cache driver doesn't support tags, let's do it manually static::storeCacheKey($modelName, $cacheKey); // We're done, let's clean up! $this->resetCacheConfig(); return $result; }
php
{ "resource": "" }
q256645
ValidationUtils.validate
test
public static function validate( HppRequest $hppRequest ) { self::Initialise(); $violations = self::$validator->validate( $hppRequest ); if ( $violations->count() > 0 ) { $validationMessages = array(); foreach ( $violations as $violation ) { /* @var ConstraintViolationInterface $violation */ $validationMessages[] = $violation->getMessage(); } $message = "HppRequest failed validation with the following errors:"; foreach ( $validationMessages as $validationMessage ) { $message .= $validationMessage . '.'; } self::$logger->info( $message ); throw new RealexValidationException( "HppRequest failed validation", $validationMessages ); } }
php
{ "resource": "" }
q256646
ValidationUtils.validateResponse
test
public static function validateResponse( HppResponse $hppResponse, $secret ) { self::Initialise(); if ( ! $hppResponse->isHashValid( $secret ) ) { self::$logger->error( "HppResponse contains an invalid security hash." ); throw new RealexValidationException( "HppResponse contains an invalid security hash", array( "HppResponse contains an invalid security hash" ) ); } }
php
{ "resource": "" }
q256647
HppRequest.addAutoSettleFlag
test
public function addAutoSettleFlag( $autoSettleFlag ) { if ( is_bool( $autoSettleFlag ) ) { $this->autoSettleFlag = $autoSettleFlag ? Flag::TRUE : Flag::FALSE; } else { $this->autoSettleFlag = $autoSettleFlag; } return $this; }
php
{ "resource": "" }
q256648
HppRequest.addReturnTss
test
public function addReturnTss( $returnTss ) { if ( is_bool( $returnTss ) ) { $this->returnTss = $returnTss ? Flag::TRUE : Flag::FALSE; } else { $this->returnTss = $returnTss; } return $this; }
php
{ "resource": "" }
q256649
HppRequest.addValidateCardOnly
test
public function addValidateCardOnly( $validateCardOnly ) { if ( is_bool( $validateCardOnly ) ) { $this->validateCardOnly = $validateCardOnly ? Flag::TRUE : Flag::FALSE; } else { $this->validateCardOnly = $validateCardOnly; } return $this; }
php
{ "resource": "" }
q256650
HppRequest.addDccEnable
test
public function addDccEnable( $dccEnable ) { if ( is_bool( $dccEnable ) ) { $this->dccEnable = $dccEnable ? Flag::TRUE : Flag::FALSE; } else { $this->dccEnable = $dccEnable; } return $this; }
php
{ "resource": "" }
q256651
HppRequest.addCardStorageEnable
test
public function addCardStorageEnable( $cardStorageEnable ) { if ( is_bool( $cardStorageEnable ) ) { $this->cardStorageEnable = $cardStorageEnable ? Flag::TRUE : Flag::FALSE; } else { $this->cardStorageEnable = $cardStorageEnable; } return $this; }
php
{ "resource": "" }
q256652
HppRequest.addOfferSaveCard
test
public function addOfferSaveCard( $offerSaveCard ) { if ( is_bool( $offerSaveCard ) ) { $this->offerSaveCard = $offerSaveCard ? Flag::TRUE : Flag::FALSE; } else { $this->offerSaveCard = $offerSaveCard; } return $this; }
php
{ "resource": "" }
q256653
HppRequest.addPayerExists
test
public function addPayerExists( $payerExists ) { if ( is_bool( $payerExists ) ) { $this->payerExists = $payerExists ? Flag::TRUE : Flag::FALSE; } else { $this->payerExists = $payerExists; } return $this; }
php
{ "resource": "" }
q256654
HppRequest.addHppVersion
test
public function addHppVersion( $hppVersion ){ if ( is_bool( $hppVersion ) ) { $this->cardStorageEnable = $hppVersion ? Flag::TRUE : Flag::FALSE; } else { $this->hppVersion = $hppVersion; } return $this; }
php
{ "resource": "" }
q256655
HppRequest.generateDefaults
test
public function generateDefaults( $secret ) { //generate timestamp if not set if ( is_null( $this->timeStamp ) ) { $this->timeStamp = GenerationUtils::generateTimestamp(); } //generate order ID if not set if ( is_null( $this->orderId ) ) { $this->orderId = GenerationUtils::generateOrderId(); } //generate hash $this->hash( $secret ); return $this; }
php
{ "resource": "" }
q256656
HppRequest.encode
test
public function encode( $charSet ) { $this->account = base64_encode( $this->account ); $this->amount = base64_encode( $this->amount ); $this->autoSettleFlag = base64_encode( $this->autoSettleFlag ); $this->billingCode = base64_encode( $this->billingCode ); $this->billingCountry = base64_encode( $this->billingCountry ); $this->cardPaymentButtonText = base64_encode( $this->cardPaymentButtonText ); $this->cardStorageEnable = base64_encode( $this->cardStorageEnable ); $this->commentOne = base64_encode( $this->commentOne ); $this->commentTwo = base64_encode( $this->commentTwo ); $this->currency = base64_encode( $this->currency ); $this->customerNumber = base64_encode( $this->customerNumber ); $this->hash = base64_encode( $this->hash ); $this->language = base64_encode( $this->language ); $this->merchantId = base64_encode( $this->merchantId ); $this->offerSaveCard = base64_encode( $this->offerSaveCard ); $this->orderId = base64_encode( $this->orderId ); $this->payerExists = base64_encode( $this->payerExists ); $this->payerReference = base64_encode( $this->payerReference ); $this->paymentReference = base64_encode( $this->paymentReference ); $this->productId = base64_encode( $this->productId ); $this->returnTss = base64_encode( $this->returnTss ); $this->shippingCode = base64_encode( $this->shippingCode ); $this->shippingCountry = base64_encode( $this->shippingCountry ); $this->timeStamp = base64_encode( $this->timeStamp ); $this->variableReference = base64_encode( $this->variableReference ); $this->validateCardOnly = base64_encode( $this->validateCardOnly ); $this->dccEnable = base64_encode( $this->dccEnable ); $this->hppVersion = base64_encode( $this->hppVersion ); $this->hppSelectStoredCard = base64_encode( $this->hppSelectStoredCard ); $this->postResponse = base64_encode( $this->postResponse ); $this->postDimensions = base64_encode( $this->postDimensions ); if ( is_array( $this->supplementaryData ) ) { foreach ( $this->supplementaryData as $key => $value ) { $this->supplementaryData[ $key ] = base64_encode( $value ); } } return $this; }
php
{ "resource": "" }
q256657
HppRequest.decode
test
public function decode( $charSet ) { $this->account = base64_decode( $this->account ); $this->amount = base64_decode( $this->amount ); $this->autoSettleFlag = base64_decode( $this->autoSettleFlag ); $this->billingCode = base64_decode( $this->billingCode ); $this->billingCountry = base64_decode( $this->billingCountry ); $this->cardPaymentButtonText = base64_decode( $this->cardPaymentButtonText ); $this->cardStorageEnable = base64_decode( $this->cardStorageEnable ); $this->commentOne = base64_decode( $this->commentOne ); $this->commentTwo = base64_decode( $this->commentTwo ); $this->currency = base64_decode( $this->currency ); $this->customerNumber = base64_decode( $this->customerNumber ); $this->hash = base64_decode( $this->hash ); $this->language = base64_decode( $this->language ); $this->merchantId = base64_decode( $this->merchantId ); $this->offerSaveCard = base64_decode( $this->offerSaveCard ); $this->orderId = base64_decode( $this->orderId ); $this->payerExists = base64_decode( $this->payerExists ); $this->payerReference = base64_decode( $this->payerReference ); $this->paymentReference = base64_decode( $this->paymentReference ); $this->productId = base64_decode( $this->productId ); $this->returnTss = base64_decode( $this->returnTss ); $this->shippingCode = base64_decode( $this->shippingCode ); $this->shippingCountry = base64_decode( $this->shippingCountry ); $this->timeStamp = base64_decode( $this->timeStamp ); $this->variableReference = base64_decode( $this->variableReference ); $this->validateCardOnly = base64_decode( $this->validateCardOnly ); $this->dccEnable = base64_decode( $this->dccEnable ); $this->hppVersion = base64_decode( $this->hppVersion ); $this->hppSelectStoredCard = base64_decode( $this->hppSelectStoredCard ); $this->postResponse = base64_decode( $this->postResponse ); $this->postDimensions = base64_decode( $this->postDimensions ); if ( is_array( $this->supplementaryData ) ) { foreach ( $this->supplementaryData as $key => $value ) { $this->supplementaryData[ $key ] = base64_decode( $value ); } } return $this; }
php
{ "resource": "" }
q256658
HppResponse.encode
test
public function encode( $charset ) { $this->merchantId = base64_encode( $this->merchantId ); $this->account = base64_encode( $this->account ); $this->amount = base64_encode( $this->amount ); $this->authCode = base64_encode( $this->authCode ); $this->batchId = base64_encode( $this->batchId ); $this->cavv = base64_encode( $this->cavv ); $this->cvnResult = base64_encode( $this->cvnResult ); $this->eci = base64_encode( $this->eci ); $this->commentOne = base64_encode( $this->commentOne ); $this->commentTwo = base64_encode( $this->commentTwo ); $this->message = base64_encode( $this->message ); $this->pasRef = base64_encode( $this->pasRef ); $this->hash = base64_encode( $this->hash ); $this->result = base64_encode( $this->result ); $this->xid = base64_encode( $this->xid ); $this->orderId = base64_encode( $this->orderId ); $this->timeStamp = base64_encode( $this->timeStamp ); $this->AVSAddressResult = base64_encode( $this->AVSAddressResult ); $this->AVSPostCodeResult = base64_encode( $this->AVSPostCodeResult ); if (is_array($this->tss)) { foreach ( $this->tss as $key => $value ) { $this->tss[ $key ] = base64_encode( $value ); } } if (is_array($this->supplementaryData)) { foreach ( $this->supplementaryData as $key => $value ) { $this->supplementaryData[ $key ] = base64_encode( $value ); } } return $this; }
php
{ "resource": "" }
q256659
HppResponse.decode
test
public function decode( $charset ) { $this->merchantId = base64_decode( $this->merchantId ); $this->account = base64_decode( $this->account ); $this->amount = base64_decode( $this->amount ); $this->authCode = base64_decode( $this->authCode ); $this->batchId = base64_decode( $this->batchId ); $this->cavv = base64_decode( $this->cavv ); $this->cvnResult = base64_decode( $this->cvnResult ); $this->eci = base64_decode( $this->eci ); $this->commentOne = base64_decode( $this->commentOne ); $this->commentTwo = base64_decode( $this->commentTwo ); $this->message = base64_decode( $this->message ); $this->pasRef = base64_decode( $this->pasRef ); $this->hash = base64_decode( $this->hash ); $this->result = base64_decode( $this->result ); $this->xid = base64_decode( $this->xid ); $this->orderId = base64_decode( $this->orderId ); $this->timeStamp = base64_decode( $this->timeStamp ); $this->AVSAddressResult = base64_decode( $this->AVSAddressResult ); $this->AVSPostCodeResult = base64_decode( $this->AVSPostCodeResult ); if (is_array($this->tss)) { foreach ( $this->tss as $key => $value ) { $this->tss[ $key ] = base64_decode( $value ); } } if (is_array($this->supplementaryData)) { foreach ( $this->supplementaryData as $key => $value ) { $this->supplementaryData[ $key ] = base64_decode( $value ); } } return $this; }
php
{ "resource": "" }
q256660
TypeValidationRule.getFieldConfigRules
test
private function getFieldConfigRules() { return [ 'name' => ['type' => TypeService::TYPE_STRING, 'required' => true], 'type' => ['type' => TypeService::TYPE_ANY, 'required' => true], 'args' => ['type' => TypeService::TYPE_ARRAY], 'description' => ['type' => TypeService::TYPE_STRING], 'resolve' => ['type' => TypeService::TYPE_CALLABLE], 'isDeprecated' => ['type' => TypeService::TYPE_BOOLEAN], 'deprecationReason' => ['type' => TypeService::TYPE_STRING], 'cost' => ['type' => TypeService::TYPE_ANY] ]; }
php
{ "resource": "" }
q256661
Processor.unpackDeferredResults
test
public static function unpackDeferredResults($result) { while ($result instanceof DeferredResult) { $result = $result->result; } if (is_array($result)) { foreach ($result as $key => $value) { $result[$key] = static::unpackDeferredResults($value); } } return $result; }
php
{ "resource": "" }
q256662
Processor.deferredResolve
test
protected function deferredResolve($resolvedValue, FieldInterface $field, callable $callback) { if ($resolvedValue instanceof DeferredResolverInterface) { $deferredResult = new DeferredResult($resolvedValue, function ($resolvedValue) use ($field, $callback) { // Allow nested deferred resolvers. return $this->deferredResolve($resolvedValue, $field, $callback); }); // Whenever we stumble upon a deferred resolver, add it to the queue // to be resolved later. $type = $field->getType()->getNamedType(); if ($type instanceof AbstractScalarType || $type instanceof AbstractEnumType) { array_push($this->deferredResultsLeaf, $deferredResult); } else { array_push($this->deferredResultsComplex, $deferredResult); } return $deferredResult; } // For simple values, invoke the callback immediately. return $callback($resolvedValue); }
php
{ "resource": "" }
q256663
ArrayConnection.cursorToKey
test
public static function cursorToKey($cursor) { if ($decoded = base64_decode($cursor)) { return substr($decoded, strlen(self::PREFIX)); } return null; }
php
{ "resource": "" }
q256664
ArrayConnection.cursorToOffsetWithDefault
test
public static function cursorToOffsetWithDefault($cursor, $default, $array = []) { if (!is_string($cursor)) { return $default; } $key = self::cursorToKey($cursor); if (empty($array)) { $offset = $key; } else { $offset = array_search($key, array_keys($array)); } return is_null($offset) ? $default : (int) $offset; }
php
{ "resource": "" }
q256665
Compiler.listNodeCompiler
test
public function listNodeCompiler(array &$theme): void { $this->checkNode($theme); $attr = $this->getNodeAttribute($theme); foreach ([ 'key', 'value', 'index', ] as $key) { null === $attr[$key] && $attr[$key] = '$'.$key; } foreach ([ 'for', 'key', 'value', 'index', ] as $key) { if ('$'.$key === $attr[$key]) { continue; } $attr[$key] = $this->parseContent($attr[$key]); } // 编译 $theme['content'] = $this->withPhpTag($attr['index'].' = 1;').PHP_EOL. $this->withPhpTag( 'if (is_array('.$attr['for'].')): foreach ('.$attr['for']. ' as '.$attr['key'].' => '. $attr['value'].'):' ). $this->getNodeBody($theme). $this->withPhpTag($attr['index'].'++;').PHP_EOL. $this->withPhpTag('endforeach; endif;'); }
php
{ "resource": "" }
q256666
JsonRpcProtocol.createRequestData
test
public function createRequestData(array $payload, $method) { if (! is_string($method)) { throw new \InvalidArgumentException('The $method argument has to be null or of type string'); } // Every JSON RPC request has a unique ID so that the request and its response can be linked. // WARNING: There is no absolute guarantee that this ID is unique! // Use this class like a singleton to ensure uniqueness. // Note: According to the specs of the JSON RPC protocol we can send an int or a string, // so uniqid() - which returns a string - should work. Unfortunately it does not. self::$lastId = ++self::$lastId; $id = self::$lastId; $data = [ 'jsonrpc' => self::PROTOCOL_VERSION, // Set the protocol version 'method' => $method, // Set the method of the JSON RPC API call 'params' => $payload, // Set the parameters / the payload 'id' => $id, // Set the ID of this request. (Omitting it would mean we do not expect a response) ]; $jsonData = json_encode($data); return $jsonData; }
php
{ "resource": "" }
q256667
SentencesBag.getAllSentences
test
public function getAllSentences() { $splitTexts = $this->responseContent->splitted_texts; $sentences = []; foreach ($splitTexts as $splitText) { foreach ($splitText as $sentence) { $sentences[] = $sentence; } } return $sentences; }
php
{ "resource": "" }
q256668
DeepLy.splitText
test
public function splitText($text, $from = self::LANG_AUTO) { $splitTextBag = $this->requestSplitText($text, $from); $sentences = $splitTextBag->getAllSentences(); return $sentences; }
php
{ "resource": "" }
q256669
DeepLy.detectLanguage
test
public function detectLanguage($text) { // Note: We always use English as the target language. If the source language is English as well, // DeepL automatically seems to set the target language to French so this is not a problem. $translationBag = $this->requestTranslation($text, self::LANG_EN, self::LANG_AUTO); return $translationBag->getSourceLanguage(); }
php
{ "resource": "" }
q256670
DeepLy.getLangCodes
test
public function getLangCodes($withAuto = true) { if (! is_bool($withAuto)) { throw new \InvalidArgumentException('The $withAuto argument has to be boolean'); } if ($withAuto) { return self::LANG_CODES; } // ATTENTION! This only works as long as self::LANG_AUTO is the first item! return array_slice(self::LANG_CODES, 1); }
php
{ "resource": "" }
q256671
Table.getDefaults
test
public function getDefaults(array $overrides = null): array { if (empty($overrides)) { return $this->defaults; } $diff = array_diff_key($overrides, $this->fields); if (!empty($diff)) { throw new SimpleCrudException( sprintf('The field %s does not exist in the table %s', implode(array_keys($diff)), $this) ); } return $overrides + $this->defaults; }
php
{ "resource": "" }
q256672
Table.cache
test
public function cache(Row $row): Row { if ($row->id) { $this->cache[$row->id] = $row; } return $row; }
php
{ "resource": "" }
q256673
Table.getCached
test
public function getCached($id): ?Row { if (!$this->isCached($id)) { return null; } $row = $this->cache[$id]; if ($row && !$row->id) { return $this->cache[$id] = null; } return $row; }
php
{ "resource": "" }
q256674
Table.offsetExists
test
public function offsetExists($offset): bool { if ($this->isCached($offset)) { return $this->getCached($offset) !== null; } return $this->selectAggregate('COUNT') ->where('id = ', $offset) ->limit(1) ->run() === 1; }
php
{ "resource": "" }
q256675
Table.offsetGet
test
public function offsetGet($offset): ?Row { if ($this->isCached($offset)) { return $this->getCached($offset); } return $this->cache[$offset] = $this->select() ->one() ->where('id = ', $offset) ->run(); }
php
{ "resource": "" }
q256676
Table.offsetSet
test
public function offsetSet($offset, $value): Row { //Insert on missing offset if ($offset === null) { $value['id'] = null; return $this->create($value)->save(); } //Update if the element is cached and exists $row = $this->getCached($offset); if ($row) { return $row->edit($value)->save(); } //Update if the element it's not cached if (!$this->isCached($row)) { $this->update() ->columns($value) ->where('id = ', $offset) ->run(); } }
php
{ "resource": "" }
q256677
Table.offsetUnset
test
public function offsetUnset($offset) { $this->cache[$offset] = null; $this->delete() ->where('id = ', $offset) ->run(); }
php
{ "resource": "" }
q256678
Table.getJoinField
test
public function getJoinField(Table $table): ?Field { $field = $table->getForeignKey(); return $this->fields[$field] ?? null; }
php
{ "resource": "" }
q256679
RowCollection.delete
test
public function delete(): self { $ids = array_values($this->id); if (count($ids)) { $this->table->delete() ->where('id IN ', $ids) ->run(); $this->id = null; } return $this; }
php
{ "resource": "" }
q256680
FieldFactory.getClassName
test
private function getClassName(string $name, string $type): ?string { foreach ($this->fields as $className => $definition) { foreach ($definition['names'] as $defName) { if ($defName === $name || ($defName[0] === '/' && preg_match($defName, $name))) { return $className; } } if (in_array($type, $definition['types'])) { return $className; } } return $this->defaultType; }
php
{ "resource": "" }
q256681
Database.setConfig
test
public function setConfig(string $name, $value): self { $this->config[$name] = $value; return $this; }
php
{ "resource": "" }
q256682
Database.getFieldFactory
test
public function getFieldFactory(): FieldFactory { if ($this->fieldFactory === null) { return $this->fieldFactory = new FieldFactory(); } return $this->fieldFactory; }
php
{ "resource": "" }
q256683
Database.execute
test
public function execute(string $query, array $marks = null): PDOStatement { $statement = $this->connection->prepare($query); $statement->execute($marks); return $statement; }
php
{ "resource": "" }
q256684
Database.executeTransaction
test
public function executeTransaction(callable $callable) { try { $transaction = $this->beginTransaction(); $return = $callable($this); if ($transaction) { $this->commit(); } } catch (Exception $exception) { if ($transaction) { $this->rollBack(); } throw $exception; } return $return; }
php
{ "resource": "" }
q256685
Database.beginTransaction
test
public function beginTransaction(): bool { if (!$this->inTransaction()) { $this->connection->beginTransaction(); return $this->inTransaction = true; } return false; }
php
{ "resource": "" }
q256686
Point.isValid
test
private static function isValid($data): bool { if (!is_array($data)) { return false; } if (!isset($data[0]) || !isset($data[1]) || count($data) > 2) { return false; } return is_numeric($data[0]) && is_numeric($data[1]); }
php
{ "resource": "" }
q256687
Row.__isset
test
public function __isset(string $name): bool { $valueName = $this->getValueName($name); return (isset($valueName) && !is_null($this->getValue($valueName))) || isset($this->data[$name]); }
php
{ "resource": "" }
q256688
Row.edit
test
public function edit(array $values): self { foreach ($values as $name => $value) { $this->__set($name, $value); } return $this; }
php
{ "resource": "" }
q256689
Row.delete
test
public function delete(): self { $id = $this->id; if (!empty($id)) { $this->table->delete() ->where('id = ', $id) ->run(); $this->values['id'] = null; } return $this; }
php
{ "resource": "" }
q256690
Row.relate
test
public function relate(Row ...$rows): self { $table1 = $this->table; foreach ($rows as $row) { $table2 = $row->getTable(); //Has one if ($field = $table1->getJoinField($table2)) { $this->{$field->getName()} = $row->id; continue; } //Has many if ($field = $table2->getJoinField($table1)) { $row->{$field->getName()} = $this->id; $row->save(); continue; } //Has many to many if ($joinTable = $table1->getJoinTable($table2)) { $joinTable->insert([ $joinTable->getJoinField($table1)->getName() => $this->id, $joinTable->getJoinField($table2)->getName() => $row->id, ]) ->run(); continue; } throw new RuntimeException( sprintf('The tables %s and %s are not related', $table1, $table2) ); } return $this->save(); }
php
{ "resource": "" }
q256691
Row.unrelate
test
public function unrelate(Row ...$rows): self { $table1 = $this->table; foreach ($rows as $row) { $table2 = $row->getTable(); //Has one if ($field = $table1->getJoinField($table2)) { $this->{$field->getName()} = null; continue; } //Has many if ($field = $table2->getJoinField($table1)) { $row->{$field->getName()} = null; $row->save(); continue; } //Has many to many if ($joinTable = $table1->getJoinTable($table2)) { $joinTable->delete() ->where("{$joinTable->getJoinField($table1)} = ", $this->id) ->where("{$joinTable->getJoinField($table2)} = ", $row->id) ->run(); continue; } throw new RuntimeException( sprintf('The tables %s and %s are not related', $table1, $table2) ); } return $this->save(); }
php
{ "resource": "" }
q256692
Row.unrelateAll
test
public function unrelateAll(Table ...$tables): self { $table1 = $this->table; foreach ($tables as $table2) { //Has one if ($field = $table1->getJoinField($table2)) { $this->{$field->getName()} = null; continue; } //Has many if ($field = $table2->getJoinField($table1)) { $table2->update([ $field->getName() => null, ]) ->relatedWith($table1) ->run(); continue; } //Has many to many if ($joinTable = $table1->getJoinTable($table2)) { $joinTable->delete() ->where("{$joinTable->getJoinField($table1)} = ", $this->id) ->where("{$joinTable->getJoinField($table2)} IS NOT NULL") ->run(); continue; } throw new RuntimeException( sprintf('The tables %s and %s are not related', $table1, $table2) ); } return $this->save(); }
php
{ "resource": "" }
q256693
Row.select
test
public function select(Table $table): Select { //Has one if ($this->table->getJoinField($table)) { return $table->select()->one()->relatedWith($this); } return $table->select()->relatedWith($this); }
php
{ "resource": "" }
q256694
Row.getValueName
test
private function getValueName(string $name): ?string { if (array_key_exists($name, $this->values)) { return $name; } //It's a localizable field $language = $this->table->getDatabase()->getConfig(Database::CONFIG_LOCALE); if (!is_null($language)) { $name .= "_{$language}"; if (array_key_exists($name, $this->values)) { return $name; } } return null; }
php
{ "resource": "" }
q256695
Quota.setLimits
test
public function setLimits($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Api\QuotaLimit::class); $this->limits = $arr; return $this; }
php
{ "resource": "" }
q256696
Quota.setMetricRules
test
public function setMetricRules($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Api\MetricRule::class); $this->metric_rules = $arr; return $this; }
php
{ "resource": "" }
q256697
Logging.setProducerDestinations
test
public function setProducerDestinations($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Api\Logging\LoggingDestination::class); $this->producer_destinations = $arr; return $this; }
php
{ "resource": "" }
q256698
Logging.setConsumerDestinations
test
public function setConsumerDestinations($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Api\Logging\LoggingDestination::class); $this->consumer_destinations = $arr; return $this; }
php
{ "resource": "" }
q256699
ConfigChange.setAdvices
test
public function setAdvices($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Api\Advice::class); $this->advices = $arr; return $this; }
php
{ "resource": "" }