_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q268200 | RequestTrait.validateMethod | test | protected function validateMethod(string $method): void
{
if (! RequestMethod::isValid($method)) {
throw new InvalidMethod(
sprintf(
'Unsupported HTTP method "%s" provided',
$method
)
);
}
} | php | {
"resource": ""
} |
q268201 | Locator.locate | test | public function locate($command)
{
$paths = $this->locateAll($command);
return empty($paths) ? null : $paths[0];
} | php | {
"resource": ""
} |
q268202 | Locator.locateAll | test | public function locateAll($command)
{
return array_values(array_filter($this->_pathBuilder->getPermutations($command), $this->_executableTester));
} | php | {
"resource": ""
} |
q268203 | PEAR_Downloader_Package.& | test | function &download()
{
if (isset($this->_packagefile)) {
return $this->_packagefile;
}
if (isset($this->_downloadURL['url'])) {
$this->_isvalid = false;
$info = $this->getParsedPackage();
foreach ($info as $i => $p) {
$info[$i] = strtolower($p);
}
$err = $this->_fromUrl($this->_downloadURL['url'],
$this->_registry->parsedPackageNameToString($this->_parsedname, true));
$newinfo = $this->getParsedPackage();
foreach ($newinfo as $i => $p) {
$newinfo[$i] = strtolower($p);
}
if ($info != $newinfo) {
do {
if ($info['channel'] == 'pecl.php.net' && $newinfo['channel'] == 'pear.php.net') {
$info['channel'] = 'pear.php.net';
if ($info == $newinfo) {
// skip the channel check if a pecl package says it's a PEAR package
break;
}
}
if ($info['channel'] == 'pear.php.net' && $newinfo['channel'] == 'pecl.php.net') {
$info['channel'] = 'pecl.php.net';
if ($info == $newinfo) {
// skip the channel check if a pecl package says it's a PEAR package
break;
}
}
return PEAR::raiseError('CRITICAL ERROR: We are ' .
$this->_registry->parsedPackageNameToString($info) . ', but the file ' .
'downloaded claims to be ' .
$this->_registry->parsedPackageNameToString($this->getParsedPackage()));
} while (false);
}
if (PEAR::isError($err) || !$this->_valid) {
return $err;
}
}
$this->_type = 'local';
return $this->_packagefile;
} | php | {
"resource": ""
} |
q268204 | PEAR_Downloader_Package.removeInstalled | test | function removeInstalled(&$params)
{
if (!isset($params[0])) {
return;
}
$options = $params[0]->_downloader->getOptions();
if (!isset($options['downloadonly'])) {
foreach ($params as $i => $param) {
$package = $param->getPackage();
$channel = $param->getChannel();
// remove self if already installed with this version
// this does not need any pecl magic - we only remove exact matches
if ($param->_installRegistry->packageExists($package, $channel)) {
$packageVersion = $param->_installRegistry->packageInfo($package, 'version', $channel);
if (version_compare($packageVersion, $param->getVersion(), '==')) {
if (!isset($options['force'])) {
$info = $param->getParsedPackage();
unset($info['version']);
unset($info['state']);
if (!isset($options['soft'])) {
$param->_downloader->log(1, 'Skipping package "' .
$param->getShortName() .
'", already installed as version ' . $packageVersion);
}
$params[$i] = false;
}
} elseif (!isset($options['force']) && !isset($options['upgrade']) &&
!isset($options['soft'])) {
$info = $param->getParsedPackage();
$param->_downloader->log(1, 'Skipping package "' .
$param->getShortName() .
'", already installed as version ' . $packageVersion);
$params[$i] = false;
}
}
}
}
PEAR_Downloader_Package::removeDuplicates($params);
} | php | {
"resource": ""
} |
q268205 | PEAR_Downloader_Package.detectStupidDuplicates | test | function detectStupidDuplicates($params, &$errorparams)
{
$existing = array();
foreach ($params as $i => $param) {
$package = $param->getPackage();
$channel = $param->getChannel();
$group = $param->getGroup();
if (!isset($existing[$channel . '/' . $package])) {
$existing[$channel . '/' . $package] = array();
}
if (!isset($existing[$channel . '/' . $package][$group])) {
$existing[$channel . '/' . $package][$group] = array();
}
$existing[$channel . '/' . $package][$group][] = $i;
}
$indices = array();
foreach ($existing as $package => $groups) {
foreach ($groups as $group => $dupes) {
if (count($dupes) > 1) {
$indices = $indices + $dupes;
}
}
}
$indices = array_unique($indices);
foreach ($indices as $index) {
$errorparams[] = $params[$index];
}
return count($errorparams);
} | php | {
"resource": ""
} |
q268206 | PEAR_Downloader_Package._fromFile | test | function _fromFile(&$param)
{
$saveparam = $param;
if (is_string($param)) {
if (!@file_exists($param)) {
$test = explode('#', $param);
$group = array_pop($test);
if (@file_exists(implode('#', $test))) {
$this->setGroup($group);
$param = implode('#', $test);
$this->_explicitGroup = true;
}
}
if (@is_file($param)) {
$this->_type = 'local';
$options = $this->_downloader->getOptions();
$pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->_debug);
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pf = &$pkg->fromAnyFile($param, PEAR_VALIDATE_INSTALLING);
PEAR::popErrorHandling();
if (PEAR::isError($pf)) {
$this->_valid = false;
$param = $saveparam;
return $pf;
}
$this->_packagefile = &$pf;
if (!$this->getGroup()) {
$this->setGroup('default'); // install the default dependency group
}
return $this->_valid = true;
}
}
$param = $saveparam;
return $this->_valid = false;
} | php | {
"resource": ""
} |
q268207 | JsonParametersExtractor.getParameters | test | public function getParameters()
{
$bodyParams = json_decode($this->body, true);
if (!$bodyParams) {
return array();
}
$parameters = array();
foreach ($bodyParams as $paramName => $paramValue) {
$parameters[$paramName] = $paramValue;
}
return $parameters;
} | php | {
"resource": ""
} |
q268208 | Debug.enable | test | public static function enable(int $errorReportingLevel = E_ALL, bool $displayErrors = false): void
{
// If debug is already enabled
if (static::$enabled) {
// Don't do things twice
return;
}
// Debug is enabled
static::$enabled = true;
// The exception handler
$exceptionHandler = new ExceptionHandler($displayErrors);
// The error handler
$errorHandler = new ErrorHandler();
// Set the error reporting level
error_reporting($errorReportingLevel);
// Set the error handler
set_error_handler(
[
$errorHandler,
'handleError',
]
);
// Set the exception handler
set_exception_handler(
[
$exceptionHandler,
'handleException',
]
);
// Register a shutdown function
register_shutdown_function(
[
$exceptionHandler,
'handleShutdown',
]
);
} | php | {
"resource": ""
} |
q268209 | Budget.getAmountDifference | test | public function getAmountDifference()
{
$amount = ($this->hasChildren() ? $this->getGlobalAmount() : $this->getAmount());
return ($amount - $this->getTransactionsAmount());
} | php | {
"resource": ""
} |
q268210 | Budget.addMonthToBitmask | test | public function addMonthToBitmask($month)
{
$month = (int) $month;
if ($month < 1 || $month > 12) {
throw new \RangeException('Month is invalid!');
}
$bit = pow(2, $month - 1);
$bitmask = $this->getMonthBitmask() | $bit;
$this->setMonthBitmask($bitmask);
return $this;
} | php | {
"resource": ""
} |
q268211 | Budget.hasMonth | test | public function hasMonth($month)
{
$bitmask = $this->getMonthBitmask();
$month = (int) $month;
$bit = pow(2, $month - 1);
return ($bit === ($bit & $bitmask));
} | php | {
"resource": ""
} |
q268212 | HTTP_Request2_MultipartBody.getLength | test | public function getLength()
{
$boundaryLength = strlen($this->getBoundary());
$headerParamLength = strlen($this->_headerParam) - 4 + $boundaryLength;
$headerUploadLength = strlen($this->_headerUpload) - 8 + $boundaryLength;
$length = $boundaryLength + 6;
foreach ($this->_params as $p) {
$length += $headerParamLength + strlen($p[0]) + strlen($p[1]) + 2;
}
foreach ($this->_uploads as $u) {
$length += $headerUploadLength + strlen($u['name']) + strlen($u['type']) +
strlen($u['filename']) + $u['size'] + 2;
}
return $length;
} | php | {
"resource": ""
} |
q268213 | HTTP_Request2_MultipartBody.getBoundary | test | public function getBoundary()
{
if (empty($this->_boundary)) {
$this->_boundary = '--' . md5('PEAR-HTTP_Request2-' . microtime());
}
return $this->_boundary;
} | php | {
"resource": ""
} |
q268214 | DbalUserProvider.loadUserByUsername | test | public function loadUserByUsername($username)
{
$qb = $this->_conn->createQueryBuilder();
$qb->select('su.username, su.password')
->from('security_users', 'su')
->where(
$qb->expr()->orX(
$qb->expr()->eq('su.username', ':username'),
$qb->expr()->eq('su.email', ':username')
)
)
->setParameter(':username', strtolower($username));
$stmt = $qb->execute();
if (!$user = $stmt->fetch()) {
throw new UsernameNotFoundException(
sprintf('Username "%s" does not exist.', $username)
);
}
$qb->select('sr.role')
->leftJoin('su', 'security_users_roles', 'sur', 'su.id = sur.user_id')
->innerJoin('sur', 'security_roles', 'sr', 'sur.role_id = sr.id');
$stmt = $qb->execute();
$roles = $stmt->fetchAll(\PDO::FETCH_COLUMN);
return new User($user['username'], $user['password'], $roles);
} | php | {
"resource": ""
} |
q268215 | User.create | test | public function create($sendWelcome = true) {
if ($this->getIsNewRecord() == false) {
throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
}
$this->confirmed_at = time();
$this->password = $this->password == null ? Password::generate(8) : $this->password;
$this->trigger(self::BEFORE_CREATE);
if (!$this->save()) {
return false;
}
if($sendWelcome) {
$this->mailer->sendWelcomeMessage($this, null, true);
}
$this->trigger(self::AFTER_CREATE);
return true;
} | php | {
"resource": ""
} |
q268216 | Socket.setIpAddress | test | public function setIpAddress($ip, $port = 80) {
if (false !== strpos($ip, ':')) {
list($ip, $port) = explode(':', $ip);
}
if (empty($ip)) {
$ip = '127.0.0.1';
}
$this->ip = $ip;
$this->port = intval($port);
return $this;
} | php | {
"resource": ""
} |
q268217 | Mail.renderView | test | protected function renderView($view, array $parameters = array())
{
if ($this->_oContainer->has('templating')) {
return $this->_oContainer->get('templating')->render($view, $parameters);
}
if (!$this->_oContainer->has('twig')) {
throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.');
}
return $this->_oContainer->get('twig')->render($view, $parameters);
} | php | {
"resource": ""
} |
q268218 | EventStoreRepository.publishStream | test | protected function publishStream(StreamInterface $stream): EventStoreRepository
{
foreach ($stream as $domainEventMessage) {
$this
->getEventPublisher()
->publish($domainEventMessage);
}
return $this;
} | php | {
"resource": ""
} |
q268219 | LinkedResourceFetcher.onResourceMaterialize | test | public function onResourceMaterialize(ResourceMaterializeEvent $e)
{
/** @var $resource MaterializedResource */
$resource = $e->getResource();
// Only scan resources with .css extension.
if (preg_match('/\.css$/i', $resource->getPath())) {
$this->scanner->scan($resource, $resource->getContent());
$collection = $this->scanner->getQueue()->flush();
// TODO Aggregate collection scans and materialize post hoc.
// Materialize non-existing resources.
foreach ($collection as $linkedResource) {
if (!$this->mirror->exists($linkedResource)) {
try {
$this->mirror->materialize($linkedResource);
}
catch (MaterializeException $e) {}
}
}
}
} | php | {
"resource": ""
} |
q268220 | Message.params | test | public function params( /*...*/ ) {
$args = func_get_args();
if ( isset( $args[0] ) && is_array( $args[0] ) ) {
$args = $args[0];
}
$values = array_values( $args );
$this->params = array_merge( $this->params, $values );
return $this;
} | php | {
"resource": ""
} |
q268221 | Message.fetchMessage | test | protected function fetchMessage() {
if ( $this->message === null ) {
$this->message = $this->ctx->getMessageCache()->get(
$this->key,
array(
$this->ctx->getCurrentLanguage(),
$this->ctx->getDefaultLanguage(),
) );
}
return $this->message;
} | php | {
"resource": ""
} |
q268222 | SodiumCrypt.encrypt | test | public function encrypt(string $message, string $key = null): string
{
$key = $key ?? $this->getKey();
$nonce = random_bytes(
SODIUM_CRYPTO_SECRETBOX_NONCEBYTES
);
$cipher = base64_encode(
$nonce .
sodium_crypto_secretbox(
$message,
$nonce,
$key
)
);
sodium_memzero($message);
sodium_memzero($key);
return $cipher;
} | php | {
"resource": ""
} |
q268223 | SodiumCrypt.decrypt | test | public function decrypt(string $encrypted, string $key = null): string
{
$key = $key ?? $this->getKey();
$decoded = base64_decode($encrypted, true);
if ($decoded === false) {
throw new CryptException('The encoding failed');
}
if (mb_strlen($decoded, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) {
throw new CryptException('The message was truncated');
}
$nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
$cipherText = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
$plain = sodium_crypto_secretbox_open(
$cipherText,
$nonce,
$key
);
if ($plain === false) {
throw new CryptException('The message was tampered with in transit');
}
sodium_memzero($cipherText);
sodium_memzero($key);
return $plain;
} | php | {
"resource": ""
} |
q268224 | SodiumCrypt.decryptArray | test | public function decryptArray(string $encrypted, string $key = null): array
{
return \json_decode($this->decrypt($encrypted, $key), true);
} | php | {
"resource": ""
} |
q268225 | SodiumCrypt.encryptObject | test | public function encryptObject(object $object, string $key = null): string
{
return $this->encrypt(\json_encode($object), $key);
} | php | {
"resource": ""
} |
q268226 | SodiumCrypt.decryptObject | test | public function decryptObject(string $encrypted, string $key = null): object
{
return \json_decode($this->decrypt($encrypted, $key), true);
} | php | {
"resource": ""
} |
q268227 | Zend_Cache_Backend_Static.getOption | test | public function getOption($name)
{
$name = strtolower($name);
if ($name == 'tag_cache') {
return $this->getInnerCache();
}
return parent::getOption($name);
} | php | {
"resource": ""
} |
q268228 | AbstractPackageDependent.init | test | protected function init()
{
$clsname = get_called_class();
if (property_exists($clsname, 'defaults')) {
foreach($clsname::$defaults as $name=>$value) {
$this->{$name} = $value;
}
}
return $this;
} | php | {
"resource": ""
} |
q268229 | AbstractComponent.replaceMagicFields | test | public function replaceMagicFields($html)
{
$html = str_replace('%id%', $this->getId(), $html);
$html = str_replace('%class%', implode(' ', $this->classes), $html);
$html = str_replace('%style%', $this->getStyle(), $html);
$html = str_replace('%name%', $this->getName(), $html);
$html = str_replace('%label%', $this->getLabel(), $html);
$strAttributes = '';
foreach ($this->attributes as $key => $value) {
$strAttributes .= ' ' . $key . '="' . $value . '"';
}
$html = str_replace('%attributes%', $strAttributes, $html);
if (!is_array($this->getValue())) {
$html = str_replace('%value%', $this->getValue(), $html);
}
if (!is_array($this->getPlaceholder())) {
$html = str_replace('%placeholder%', $this->getPlaceholder(), $html);
}
$html = str_replace('%error%', $this->getError(), $html);
return $html;
} | php | {
"resource": ""
} |
q268230 | PsiToOrmQueryBuilderConverter.convert | test | public function convert(Query $query): QueryBuilder
{
$queryBuilder = $this->entityManager
->getRepository($query->getClassFqn())
->createQueryBuilder(self::FROM_ALIAS);
$this->buildSelects($queryBuilder, $query);
$this->buildJoins($queryBuilder, $query);
if ($query->hasExpression()) {
$this->buildWhere($queryBuilder, $query);
}
$this->buildOrderings($queryBuilder, $query);
$this->buildLimit($queryBuilder, $query);
return $queryBuilder;
} | php | {
"resource": ""
} |
q268231 | RichText.asText | test | public static function asText($richText)
{
$result = '';
foreach ($richText as $block) {
if (isset($block->text)) {
$result .= $block->text . "\n";
}
}
return $result;
} | php | {
"resource": ""
} |
q268232 | RichText.asHtml | test | public static function asHtml(array $richText, LinkResolver $linkResolver = null)
{
$groups = [];
if(is_array($richText) && key_exists('dimensions', $richText)) {
return self::asImageBlock($richText);
}
foreach ($richText as $block) {
$block = (object) $block;
$count = count($groups);
// Check if block is image
if(empty($block->type)) {
var_dump($richText);
die();
}
if ($count > 0) {
$lastOne = $groups[$count - 1];
if ('ul' == $lastOne->getTag() && $block->type === 'list-item') {
$lastOne->addBlock($block);
} elseif ('ol' == $lastOne->getTag() && $block->type === 'o-list-item') {
$lastOne->addBlock($block);
} elseif ($block->type === 'list-item') {
$newBlockGroup = new BlockGroup('ul', array());
$newBlockGroup->addBlock($block);
array_push($groups, $newBlockGroup);
} else {
if ($block->type === 'o-list-item') {
$newBlockGroup = new BlockGroup('ol', array());
$newBlockGroup->addBlock($block);
array_push($groups, $newBlockGroup);
} else {
$newBlockGroup = new BlockGroup(null, array());
$newBlockGroup->addBlock($block);
array_push($groups, $newBlockGroup);
}
}
} else {
if ($block->type === 'list-item') {
$tag = 'ul';
} elseif ($block->type === 'o-list-item') {
$tag = 'ol';
} else {
$tag = null;
}
$newBlockGroup = new BlockGroup($tag, array());
$newBlockGroup->addBlock($block);
array_push($groups, $newBlockGroup);
}
}
$html = '';
foreach ($groups as $group) {
$maybeTag = $group->getTag();
if ($maybeTag) {
$html = $html . '<' . $group->getTag() . '>';
foreach ($group->getBlocks() as $block) {
$html = $html . RichText::asHtmlBlock($block, $linkResolver);
}
$html = $html . '</' . $group->getTag() . '>';
} else {
foreach ($group->getBlocks() as $block) {
$html = $html . RichText::asHtmlBlock($block, $linkResolver);
}
}
}
return $html;
} | php | {
"resource": ""
} |
q268233 | RichText.asHtmlBlock | test | private static function asHtmlBlock(\stdClass $block, $linkResolver = null, $htmlSerializer = null)
{
$content = '';
if ($block->type === 'heading1' ||
$block->type === 'heading2' ||
$block->type === 'heading3' ||
$block->type === 'heading4' ||
$block->type === 'heading5' ||
$block->type === 'heading6' ||
$block->type === 'paragraph' ||
$block->type === 'list-item' ||
$block->type === 'o-list-item' ||
$block->type === 'preformatted'
) {
$content = RichText::insertSpans($block->text, $block->spans, $linkResolver, $htmlSerializer);
}
return RichText::serialize((object)$block, $content, $linkResolver, $htmlSerializer);
} | php | {
"resource": ""
} |
q268234 | NativeResponse.withoutCookie | test | public function withoutCookie(Cookie $cookie)
{
$cookie->setValue();
$cookie->setExpire();
return $this->withAddedHeader(
Header::SET_COOKIE,
(string) $cookie
);
} | php | {
"resource": ""
} |
q268235 | NativeResponse.send | test | public function send(): Response
{
$http_line = sprintf(
'HTTP/%s %s %s',
$this->getProtocolVersion(),
$this->getStatusCode(),
$this->getReasonPhrase()
);
header($http_line, true, $this->getStatusCode());
foreach ($this->getHeaders() as $name => $values) {
/** @var array $values */
foreach ($values as $value) {
header("$name: $value", false);
}
}
$stream = $this->getBody();
if ($stream->isSeekable()) {
$stream->rewind();
}
while (! $stream->eof()) {
echo $stream->read(1024 * 8);
}
return $this;
} | php | {
"resource": ""
} |
q268236 | NativeResponse.validateStatusCode | test | protected function validateStatusCode(int $code): int
{
if (StatusCode::MIN > $code || $code > StatusCode::MAX) {
throw new InvalidStatusCode(
sprintf(
'Invalid status code "%d"; must adhere to values set in the %s enum class.',
$code,
StatusCode::class
)
);
}
return $code;
} | php | {
"resource": ""
} |