_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q236300
Encode.detect
train
public function detect($str, $encodingList = ['UTF-8', 'CP1252']) { $charset = mb_detect_encoding($str, $encodingList); if ($charset === false) { // could not detect charset return false; } $this->from = $charset; return true; }
php
{ "resource": "" }
q236301
Encode.convert
train
public function convert($str) { if ($this->from != $this->to) { $str = iconv($this->from, $this->to, $str); } if ($str === false) { // the convertion was a failure throw new Exception('The convertion from "'.$this->from.'" to "'.$this->to.'" was a failure.'); } // deal with BOM issue for utf-...
php
{ "resource": "" }
q236302
Group.add
train
public function add($child, $other = null){ if($other){ throw new \Exception('Inserting before not supported'); }else{ $this->children[] = $child; } return $child; }
php
{ "resource": "" }
q236303
PurchaseController.getDetails
train
public function getDetails($purchaseId) { $purchase = Purchase::findOrFail($purchaseId); if (!in_array(Auth::user()->userId, [ $purchase->item->seller->userId, $purchase->buyer->userId ])) { return redirect('/inventory')->withErrors([ "You are...
php
{ "resource": "" }
q236304
PurchaseController.getCheckout
train
public function getCheckout($itemId) { $item = Item::findOrFail($itemId); if ($item->seller->userId == Auth::user()->userId) { return redirect($item->url)->withErrors([ 'You cannot purchase your own items.' ]); } if ($item->auction && !$item-...
php
{ "resource": "" }
q236305
PurchaseController.getPay
train
public function getPay($purchaseId) { $purchase = Purchase::findOrFail($purchaseId); if ($purchase->buyer->userId != Auth::user()->userId) { return redirect('/inventory/bought')->withErrors([ "You are not the buyer of this item." ]); } if ($p...
php
{ "resource": "" }
q236306
PurchaseController.getDispatched
train
public function getDispatched($purchaseId) { $purchase = Purchase::findOrFail($purchaseId); if ($purchase->item->seller->userId != Auth::user()->userId) { return redirect('/inventory/sold')->withErrors([ "You are not seller of this item." ]); } ...
php
{ "resource": "" }
q236307
PurchaseController.getCollectionAddress
train
public function getCollectionAddress($purchaseId) { $purchase = Purchase::findOrFail($purchaseId); if ($purchase->item->seller->userId != Auth::user()->userId) { return redirect('/inventory/sold')->withErrors([ "You are not the seller of this item." ]); ...
php
{ "resource": "" }
q236308
PurchaseController.postDispatched
train
public function postDispatched(Request $request) { $purchase = Purchase::findOrFail($request->input('purchase_id')); if ($purchase->item->seller->userId != Auth::user()->userId) { return redirect('/inventory/sold')->withErrors(["You are not seller of this item."]); } if...
php
{ "resource": "" }
q236309
PurchaseController.paymentReceived
train
public static function paymentReceived(Purchase $purchase, $amount) { $purchase->received += $amount; if ($purchase->received >= $purchase->grandTotal) { $purchase->paid = time(); $purchase->item->seller->sendEmail( 'You have received a payment', ...
php
{ "resource": "" }
q236310
PurchaseController.paymentRefunded
train
public static function paymentRefunded(Purchase $purchase, $amount) { $purchase->refunded = time(); $purchase->refundedAmount = $amount; $purchase->buyer->sendEmail( 'You have been refunded', 'emails.item.refunded', [ 'total' => $purchase...
php
{ "resource": "" }
q236311
PurchaseController.paymentFailed
train
public static function paymentFailed(Purchase $purchase, $amount) { Log::info("Payment failed ({$purchase->purchaseId})"); $purchase->buyer->sendEmail( 'Your payment has failed', 'emails.item.failed', [ 'total' => $amount, 'item_na...
php
{ "resource": "" }
q236312
Container.instance
train
public function instance($name, $instance) { list($name, $alias) = $this->extractName($name); $componentName = $this->getAlias($name); if ($this->isSingleton($componentName) && $this->resolved($componentName)) { throw new ComponentRegisterException('Can\'t register component, The ' . $name . ' component is s...
php
{ "resource": "" }
q236313
Container.extend
train
public function extend($name, Closure $extender) { $name = $this->getAlias($name); $component = &$this->components[$name]; if (!isset($component['extender'])) { $component['extender'] = []; } if ($this->isSingleton($name)) { $component = $this->make($name); $component = $this->resolveExtend($name,...
php
{ "resource": "" }
q236314
Container.make
train
public function make($name, $parameters = []) { $name = $this->getAlias($name); if (is_string($name) && $this->resolved($name)) { return $this->instances[$name]; } if (is_callable($name) || (is_string($name) && !$this->registered($name))) { return $this->build($name, $parameters ?: []); } list($bui...
php
{ "resource": "" }
q236315
Container.resolveExtend
train
public function resolveExtend($component, $extenders) { foreach ($extenders as $extender) { $component = $extender($component); } return $component; }
php
{ "resource": "" }
q236316
Container.extractComponentBuilder
train
protected function extractComponentBuilder($name) { $componentBuilder = $this->components[$name]; if (!$componentBuilder) { return [$name, false]; } return [$componentBuilder['builder'], $componentBuilder['singleton']]; }
php
{ "resource": "" }
q236317
Container.alias
train
public function alias($alias, $name) { if (is_array($alias)) { foreach ($alias as $key) { $this->alias($key, $name); } return; } $this->aliases[$alias] = $name; }
php
{ "resource": "" }
q236318
Container.getAlias
train
public function getAlias($alias) { if (!is_string($alias)) { return $alias; } if (array_key_exists($alias, $this->aliases)) { return $this->aliases[$alias]; } return $alias; }
php
{ "resource": "" }
q236319
Container.registered
train
public function registered($name) { $name = $this->getAlias($name); return array_key_exists($name, $this->components); }
php
{ "resource": "" }
q236320
Container.resolved
train
public function resolved($name) { $name = $this->getAlias($name); return array_key_exists($name, $this->instances); }
php
{ "resource": "" }
q236321
Container.extractName
train
private function extractName($name) { if (is_string($name)) { return [$name, null]; } if (is_array($name)) { return [key($name), current($name)]; } throw new ComponentRegisterException('The services\'s name must be a string or an array, ' . gettype($name) . ' given.'); }
php
{ "resource": "" }
q236322
Entity.getAttributes
train
public function getAttributes($updated = false) { if (! $updated) return $this->attributes; $attributes = array(); foreach ($this->attributes as $key => $value) { if (! array_key_exists($key, $this->o_attributes) || $value != $this->o_attributes[$key]) { $attribu...
php
{ "resource": "" }
q236323
Entity.toArray
train
public function toArray() { $args = func_get_args(); if ($args) { $attributes = []; foreach ($args as $key) { if ($this->hasAttribute($key)) { $attributes[$key] = $this->get($key); } } return $attribu...
php
{ "resource": "" }
q236324
EntityUtility.mergeArrayIntoEntity
train
public static function mergeArrayIntoEntity($targetEntity, $array) { foreach ($array as $property => $value) { if (!empty($value)) { if (is_a($targetEntity->{'get' . ucfirst($property)}(), '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage') ) ...
php
{ "resource": "" }
q236325
EntityUtility.arrayToObjectStorage
train
public static function arrayToObjectStorage($entity, $array) { $storage = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage'); foreach ($array as $item) { $storage->attach(EntityUtility::mergeArrayIntoEntity($entity, $item)); } return $storage...
php
{ "resource": "" }
q236326
EntityUtility.mergeEntities
train
public static function mergeEntities($targetEntity, $mergeEntity) { $reflect = new \ReflectionClass($mergeEntity); $properties = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED); foreach ($properties as $property) { if (!method_exists(...
php
{ "resource": "" }
q236327
MvcApplication.run
train
public function run() { if (PHP_SAPI === 'cli' && is_subclass_of($this, ConsoleAppInterface::class)) { $this->execConsoleApp(); } else if (is_subclass_of($this, WebAppInterface::class)) { $this->execWebApp(); } else { ...
php
{ "resource": "" }
q236328
MvcApplication.execWebApp
train
protected function execWebApp() { $config = $this->getConfigArray(); $container = new Container(["settings" => $config]); $app = new App($container); $this->setupDependencies($container); $this->setupMiddlewares($app, $container); $this->setupErrorHandler($container);...
php
{ "resource": "" }
q236329
MvcApplication.execConsoleApp
train
protected function execConsoleApp() { $app = new Application(); $config = $this->getConfigArray(); $container = new Container(["settings" => $config]); $this->setupDependencies($container); $this->setupCommands($app, $container); $app->run(); }
php
{ "resource": "" }
q236330
Render.add
train
public function add(View $view) { // Append to the stack. $this->stack->append($view); if ($view->getType() === View::PART_BODY_PLACEHOLDER) { $this->bodyKey = (count($this->stack) - 1); } return count($this->stack); }
php
{ "resource": "" }
q236331
Render.body
train
public function body(View $view) { if ($view->getType() !== View::PART_BODY) { throw new RendererException("You are replacing the body with a non-body view!"); } if ($this->bodyKey === null) { throw new RendererException("No body is defined in the template!"); ...
php
{ "resource": "" }
q236332
Render.hasBodyPlaceholderEmpty
train
public function hasBodyPlaceholderEmpty() { if ($this->bodyKey !== null) { if (isset($this->stack[$this->bodyKey])) { if ($this->stack[$this->bodyKey]->getType() === View::PART_BODY_PLACEHOLDER) { return true; } } } ...
php
{ "resource": "" }
q236333
Render.replaceAll
train
public function replaceAll($stack, $resetBodyKey = true) { if (! $stack instanceof DataCollection) { $stack = new DataCollection($stack); } $this->stack = $stack; if ($resetBodyKey) { $this->bodyKey = null; foreach ($stack as $key => $view) { ...
php
{ "resource": "" }
q236334
Render.run
train
public function run($return = false) { $output = ""; foreach ($this->stack as $view) { /** @var View $view */ $data = $view->getData(); if (! is_array($data)) { $data = array(); } if ($view->getType() === View::PART_BODY_PLACEHOLDER)...
php
{ "resource": "" }
q236335
ExceptionTrait.setExceptionDetails
train
protected function setExceptionDetails(string $reason, int $code, array $stack = []) { $this->setErrorDetails($reason, $code); $this->setDebugDetails($stack); }
php
{ "resource": "" }
q236336
ExceptionTrait.setDebugDetails
train
protected function setDebugDetails(array $stack) { $stackInfo = new StackInfo($stack); $this->setDebug(ArrayContainer::make([ 'class' => $stackInfo->getClassNameFromLastStack(), 'method' => $stackInfo->getMethodNameFromLastStack(), 'args' => $stackI...
php
{ "resource": "" }
q236337
ExceptionTrait.setErrorDetails
train
protected function setErrorDetails(string $reason, int $code) { $this->setError(ArrayContainer::make([ 'code' => $code, 'message' => $reason, ])); }
php
{ "resource": "" }
q236338
Post.setUrl
train
public function setUrl($date, $urlFormat = ':year/:month/:date/:title') { // $this->url = '/' . implode('/', explode('-', $this->getFileName(), 4)) . '.html'; $year = date('Y', strtotime($date)); $month = date('m', strtotime($date)); $day = date('d', strtotime($date)); $title = explode('-', $this->getFileNa...
php
{ "resource": "" }
q236339
PathFilter.buildFilterCallback
train
public function buildFilterCallback(array $except = []) { $filter = $this; return function ($path) use ($filter, $except) { return !$filter->filter([$path], $except, true); }; }
php
{ "resource": "" }
q236340
Connection.getCollections
train
public function getCollections($options = []) { $list = []; foreach ($this->db->listCollections($options) as $coll) { $list[] = $coll->getName(); } return $list; }
php
{ "resource": "" }
q236341
Connection.collection
train
public function collection($name) { $builder = new Builder($this, $name, $this->db->selectCollection($name)); return $builder; }
php
{ "resource": "" }
q236342
Connection.getIndexs
train
public function getIndexs($collection, $options = []) { if (! $this->hasCollection($collection)) { return []; } $list = []; foreach ($this->db->selectCollection($collection)->listIndexes($options) as $index) { $list[] = $index->getName(); } r...
php
{ "resource": "" }
q236343
Connection.createIndex
train
public function createIndex($collection, $columns, array $options = []) { $col = $this->db->selectCollection($collection); return $col->createIndex($columns, $options); }
php
{ "resource": "" }
q236344
Connection.dropIndex
train
public function dropIndex($collection, $indexName, array $options = []) { $col = $this->db->selectCollection($collection); return $col->dropIndex($indexName, $options); }
php
{ "resource": "" }
q236345
Connection.createClient
train
protected function createClient($dsn, array $config, array $options) { // By default driver options is an empty array. $driverOptions = []; if (isset($config['driver_options']) && is_array($config['driver_options'])) { $driverOptions = $config['driver_options']; } ...
php
{ "resource": "" }
q236346
Firewall.isPathCovered
train
public function isPathCovered($path) { foreach ($this->patterns as $pattern) { if (1 === preg_match('{'.$pattern.'}', $path)) { return true; } } return false; }
php
{ "resource": "" }
q236347
Firewall.addAuthenticationFactory
train
public function addAuthenticationFactory(AuthenticationFactoryInterface $authFactory, UserProviderInterface $userProvider) { $id = $authFactory->getId(); $this->authFactories[$id] = array( 'factory' => $authFactory, 'userProvider'...
php
{ "resource": "" }
q236348
Firewall.register
train
public function register(SecurityServiceProvider $provider) { $this->provider = $provider; if ($this->loginPath) { $this->provider->addUnsecurePattern("^{$this->loginPath}$"); } $config = array( 'logout' => array('logout_path' => $this->logoutPath), ...
php
{ "resource": "" }
q236349
Firewall.registerAuthenticationFactory
train
protected function registerAuthenticationFactory(\Silex\Application $app, $id, AuthenticationFactoryInterface $authFactory, UserProviderInterface $userProvider) ...
php
{ "resource": "" }
q236350
Firewall.registerUserProvider
train
protected function registerUserProvider(\Silex\Application $app) { $user_provider = 'security.user_provider.'.$this->name; $app[$user_provider] = $app->share(function () { return new ChainUserProvider($this->userProviders); }); return $user_provider; }
php
{ "resource": "" }
q236351
Firewall.registerContextListener
train
protected function registerContextListener(\Silex\Application $app) { $context_listener = 'security.context_listener.'.$this->name; $app[$context_listener] = $app->share(function () use ($app) { return new ContextListener( $app['security.token_storage'], $this->user...
php
{ "resource": "" }
q236352
Firewall.registerEntryPoint
train
protected function registerEntryPoint(\Silex\Application $app) { $entry_point = 'security.entry_point.'.$this->name. (empty($this->loginPath) ? '.http' : '.form'); $app[$entry_point] = $app->share(function () use ($app) { return $this->loginPath ? new Fo...
php
{ "resource": "" }
q236353
Firewall.generatePaths
train
protected function generatePaths() { if ($this->loginPath && !$this->loginCheckPath) { foreach ($this->patterns as $pattern) { // remove the ^ prefix $base = substr($pattern, 1); // skip a regex pattern if (preg_quote($base) != $bas...
php
{ "resource": "" }
q236354
Resources.startResourcesPlugin
train
protected function startResourcesPlugin() { $this->requiresPlugins(Paths::class); $this->onBoot('resources', function () { foreach ($this->viewDirs as $dirName => $namespace) { $viewPath = $this->resolvePath('viewsPath', compact('dirName')); $this->loadVie...
php
{ "resource": "" }
q236355
HCForms.generateFormData
train
private function generateFormData () { $files = $this->getConfigFiles (); $formDataHolder = []; if (!empty($files)) { foreach ($files as $file) { $file = json_decode (file_get_contents ($file), true); if (isset($file['formData'])) ...
php
{ "resource": "" }
q236356
HeaderCollection.add
train
public function add(string $name, string $value): void { $key = strtolower($name); if (!isset($this->headers[$key])) { $this->headers[$key] = [$name, $value]; return; } $this->headers[$key] = [$name, $this->headers[$key][1] . ', ' . $value]; }
php
{ "resource": "" }
q236357
HeaderCollection.get
train
public function get(string $name): ?string { $key = strtolower($name); if (!isset($this->headers[$key])) { return null; } return $this->headers[$key][1]; }
php
{ "resource": "" }
q236358
HeaderCollection.set
train
public function set(string $name, string $value): void { $key = strtolower($name); $this->headers[$key] = [$name, $value]; }
php
{ "resource": "" }
q236359
Collection.put
train
public function put($name, $value) { if (is_object($value) && !$this->isValidObjectInstance($value)) { throw new InvalidCollectionItemInstanceException(sprintf('%s must implement %s', $name, $this->classname)); } $this->items[$name] = $value; return $this->items[$name];...
php
{ "resource": "" }
q236360
Collection.isValidObjectInstance
train
private function isValidObjectInstance($object) { if (!is_null($this->classname) && !$this->isInstanceOrSubclassOf($object)) { return false; } return true; }
php
{ "resource": "" }
q236361
Collection.findOrFail
train
public function findOrFail($name) { $result = $this->find($name); if (is_null($result)) { throw new CollectionItemNotFoundException(sprintf('Collection item "%s" not found', $name)); } return $result; }
php
{ "resource": "" }
q236362
Collection.filterByKeys
train
private function filterByKeys(array $keys) { $results = []; foreach ($this->items as $key => $value) { if (!in_array($key, $keys)) { continue; } $results[$key] = $value; } return $results; }
php
{ "resource": "" }
q236363
Collection.only
train
public function only($key) { $keys = is_array($key) ? $key : func_get_args(); return new static($this->classname, $this->filterByKeys($keys)); }
php
{ "resource": "" }
q236364
Collection.filter
train
public function filter(callable $callback = null) { if (is_null($callback)) { return new static($this->classname, array_filter($this->items)); } return new static($this->classname, array_filter($this->items, $callback)); }
php
{ "resource": "" }
q236365
Predicate.nest
train
public function nest() { $target = $this->getCurrentPredicate(); if ($operator = $this->getDefaultOperator()) { $target->$operator; } $this->nestings[] = $target->nest(); $this->nestedOperators[] = $this->getDefaultOperator(); re...
php
{ "resource": "" }
q236366
Predicate.wOr
train
public function wOr() { $this->setDefaultOperator(PredicateSet::OP_OR); if (func_num_args()) { call_user_func_array([$this, 'condition'], func_get_args()); $this->endOr(); } return $this; }
php
{ "resource": "" }
q236367
Predicate.addCondition
train
protected function addCondition($method, array $params) { $target = $this->getCurrentPredicate(); # Set default operator if any. if ($operator = $this->getDefaultOperator()) { $target->$operator; } call_user_func_array([$target, $method], $params...
php
{ "resource": "" }
q236368
CartProvider.newCart
train
private function newCart() { $this->clearCart(); $this->setCart($this->repository->createNew(OrderTypes::TYPE_CART)); return $this->cart; }
php
{ "resource": "" }
q236369
Order.getOpenStatusCodes
train
public static function getOpenStatusCodes() { return array( self::STATUS_NEW, self::STATUS_ACCEPTED_BY_SELLER, self::STATUS_REJECTED_BY_SELLER, self::STATUS_IN_PICK_AT_SELLER, self::STATUS_READY_FOR_DISPATCH_TO_HUB, self::STATUS_IN_TRAN...
php
{ "resource": "" }
q236370
Order.getSumOfLineItems
train
public function getSumOfLineItems() { $amount = 0; foreach ($this->getLineItems() as $lineItem) { $amount += $lineItem->getPrice()*$lineItem->getQuantity(); } return round($amount, 2); }
php
{ "resource": "" }
q236371
Order.getLineItemForProduct
train
public function getLineItemForProduct(Product $product) { foreach ($this->getLineItems() as $lineItem) { if ($lineItem->getProduct()->getId() == $product->getId()) { return $lineItem; } } return $this->createLineItemForProduct($pro...
php
{ "resource": "" }
q236372
Order.createLineItemForProduct
train
public function createLineItemForProduct(Product $product) { $lineItem = new OrderLineItem(); $lineItem->setProduct($product); // Don't assume any quantity here // We will add it later $lineItem->setQuantity(0); $this->addLineItem($lineItem); // Copy Seller...
php
{ "resource": "" }
q236373
Order.getInvoiceIdForPaymentGateway
train
public function getInvoiceIdForPaymentGateway() { return implode(str_split(str_pad($this->getSeller()->getId(), 6, 0, STR_PAD_LEFT),3), '-') .' / ' .implode(str_split(str_pad($this->getId(), 6, 0, STR_PAD_LEFT),3), '-') .' / ' .$this->getSeller()->...
php
{ "resource": "" }
q236374
Order.canBeDispatchedBySeller
train
public function canBeDispatchedBySeller() { switch ($this->getStatusCode()) { case self::STATUS_ACCEPTED_BY_SELLER: case self::STATUS_IN_PICK_AT_SELLER: case self::STATUS_READY_FOR_DISPATCH_TO_HUB: return true; default: ...
php
{ "resource": "" }
q236375
Delivery.error
train
protected function error(Request $request, \Exception $exception) { return $request->getTarget() . ' threw ' . get_class($exception) . ': ' . $exception->getMessage() . "\n" . $exception->getTraceAsString(); }
php
{ "resource": "" }
q236376
ExpressionWrap.getValue
train
public function getValue() { $grammar = Manager::connection()->getQueryGrammar(); return vsprintf( $this->value, array_map(function($val) use($grammar) { return $grammar->wrap($val); }, $this->replace) ); }
php
{ "resource": "" }
q236377
FileArrayCache.clearCache
train
public function clearCache() { $objects = scandir($this->getCachePath()); $dir = $this->getCachePath(); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (is_dir($dir.$object)) { self::rrmdir($dir.$object); ...
php
{ "resource": "" }
q236378
FileArrayCache.buildLevelsString
train
private function buildLevelsString($levels) { $this->levelsString = join(DIRECTORY_SEPARATOR, array_fill(0, $levels, '%s')) . DIRECTORY_SEPARATOR; return $this; }
php
{ "resource": "" }
q236379
CopyDictionaryJob.create
train
public static function create( DictionaryInterface $sourceDictionary, WritableDictionaryInterface $targetDictionary, LoggerInterface $logger = null ): CopyDictionaryJob { $instance = new static($sourceDictionary, $targetDictionary); if ($logger) { $instance->setLo...
php
{ "resource": "" }
q236380
CopyDictionaryJob.setCopySource
train
public function setCopySource(int $copySource = self::COPY): CopyDictionaryJob { $this->copySource = $copySource; return $this; }
php
{ "resource": "" }
q236381
CopyDictionaryJob.setCopyTarget
train
public function setCopyTarget(int $copyTarget = self::COPY): CopyDictionaryJob { $this->copyTarget = $copyTarget; return $this; }
php
{ "resource": "" }
q236382
CopyDictionaryJob.addFilter
train
public function addFilter(string $expression): CopyDictionaryJob { // Check if the first and last char match - if not, we must encapsulate with '/'. if ($expression[0] !== substr($expression, -1)) { $expression = '/' . $expression . '/'; } // Test if the regex is valid. ...
php
{ "resource": "" }
q236383
CopyDictionaryJob.setFilters
train
public function setFilters(array $expressions): CopyDictionaryJob { $this->filters = []; foreach ($expressions as $expression) { $this->addFilter($expression); } return $this; }
php
{ "resource": "" }
q236384
CopyDictionaryJob.copyKey
train
private function copyKey(string $key): void { $source = $this->sourceDictionary->get($key); if ($source->isSourceEmpty()) { $this->logger->debug( '{key}: Is empty in source language and therefore skipped.', ['key' => $key] ); return...
php
{ "resource": "" }
q236385
CopyDictionaryJob.copySource
train
private function copySource(TranslationValueInterface $source, WritableTranslationValueInterface $target): void { if (self::DO_NOT_COPY === $this->copySource) { return; } if (($oldValue = $target->getSource()) === ($newValue = $source->getSource())) { $this->logger->...
php
{ "resource": "" }
q236386
CopyDictionaryJob.copyTarget
train
private function copyTarget(TranslationValueInterface $source, WritableTranslationValueInterface $target): void { if (self::DO_NOT_COPY === $this->copyTarget) { return; } if ((($oldValue = $target->getTarget()) === ($newValue = $source->getTarget())) || ($target->isT...
php
{ "resource": "" }
q236387
CopyDictionaryJob.cleanTarget
train
private function cleanTarget(): void { foreach ($this->targetDictionary->keys() as $key) { if (!$this->sourceDictionary->has($key) || $this->sourceDictionary->get($key)->isSourceEmpty()) { $this->logger->log($this->logLevel, 'Removing obsolete {key}.', ['key' => $key]); ...
php
{ "resource": "" }
q236388
CopyDictionaryJob.isFiltered
train
private function isFiltered($key): bool { foreach ($this->filters as $expression) { if (preg_match($expression, $key)) { $this->logger->debug(sprintf('"%1$s" is filtered by "%2$s', $key, $expression)); return true; } } return false; ...
php
{ "resource": "" }
q236389
Post.getContentReplies
train
public function getContentReplies(string $author, string $permalink) { $request = [ 'route' => 'get_content_replies', 'query' => [ 'author' => $author, 'permlink' => $permalink, ] ]; return par...
php
{ "resource": "" }
q236390
Post.getContentAllReplies
train
public function getContentAllReplies(string $author, string $permalink) { $request = $this->getContentReplies($author, $permalink); if(is_array($request)) { foreach ($request as $key => $item) { if($item['children'] > 0) $request[$...
php
{ "resource": "" }
q236391
ConsoleRunner.run
train
public static function run(HelperSet $helperSet, $commands = array()) { $cli = new Application('PoolDBM Command Line Interface', Version::VERSION); $cli->setCatchExceptions(true); $cli->setHelperSet(new HelperSet($helperSet)); self::addDefaultCommands($cli); $cli->addCommands...
php
{ "resource": "" }
q236392
Stdio.block
train
private function block($textblock) { $length = 0; foreach ($textblock as $line) { $n = strlen($line); if ($length < $n) { $length = $n; } } foreach ($textblock as $i => $line) { $textblock[$i] .= str_repeat(' ', $length...
php
{ "resource": "" }
q236393
EmojiDictionary.get
train
public static function get($symbol) { $symbol = strtolower($symbol); if (isset(static::$dictionary[$symbol])) return static::$dictionary[$symbol]; else return false; }
php
{ "resource": "" }
q236394
AdminProductOrderController.newAction
train
public function newAction() { $entity = new ProductOrder(); $form = $this->createCreateForm($entity); return array( 'entity' => $entity, 'form' => $form->createView(), ); }
php
{ "resource": "" }
q236395
Element.errors
train
public function errors() : array { $errors = []; foreach ($this->tests as $error => $test) { if (!$test($this->getValue())) { $errors[] = $error; } } return $errors; }
php
{ "resource": "" }
q236396
ValidatorTrait.validateWithRules
train
public function validateWithRules(array $validateRules, array $validateMessages = [], array $parametricConverter = []) { $this->validateDataWithRules($this->getParameters(), $validateRules, $validateMessages, $parametricConverter); }
php
{ "resource": "" }
q236397
ValidatorTrait.validateDataWithRules
train
public function validateDataWithRules(array $data, array $validateRules, array $validateMessages = [], array $parametricConverter = []) { foreach ($validateRules as $key => $rules) { $value = array_key_exists($key, $data) ? $data[$key] : null; if (array_key_exists('nullable', $rules...
php
{ "resource": "" }
q236398
ValidatorTrait.formatMessage
train
protected function formatMessage($parameter, $ruleName, $ruleParameter, $message = null) { $message = $message ?: (isset($this->validateMessages[$ruleName]) ? $this->validateMessages[$ruleName] : $this->validateMessages['default']); $message = str_replace(':parameter', $parameter, $message); ...
php
{ "resource": "" }
q236399
ValidatorTrait.getValueDescription
train
protected function getValueDescription($value) { switch (true) { case (is_numeric($value)): $value = strval($value); break; case (is_bool($value) && $value): $value = '(boolean) true'; break; case (is_bool(...
php
{ "resource": "" }