_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q251000 | Assertion.contain | validation | function contain($value = null): self {
if ($this->hasFlag('file')) return $this->expect(@file_get_contents($this->target), stringContains($value));
return $this->expect($this->target, is_string($this->target) ? stringContains($value) : contains($value));
} | php | {
"resource": ""
} |
q251001 | Assertion.containOnly | validation | function containOnly(string $type): self {
return $this->expect($this->target, containsOnly($type));
} | php | {
"resource": ""
} |
q251002 | Assertion.containOnlyInstancesOf | validation | function containOnlyInstancesOf(string $className): self {
return $this->expect($this->target, containsOnlyInstancesOf($className));
} | php | {
"resource": ""
} |
q251003 | Assertion.empty | validation | function empty(): self {
if (is_object($this->target) && !($this->target instanceof \Countable)) {
$constraint = countOf(0);
$target = get_object_vars($this->target);
}
else if (is_string($this->target)) {
$constraint = equalTo(0);
$target = $this->hasFlag('file') ? @filesize($this->target) : mb_strlen($this->target);
// TODO file/directory flag handling!
}
else {
$constraint = isEmpty();
$target = $this->target;
}
return $this->expect($target, $constraint);
} | php | {
"resource": ""
} |
q251004 | Assertion.endWith | validation | function endWith(string $value): self {
return $this->expect($this->target, stringEndsWith($value));
} | php | {
"resource": ""
} |
q251005 | Assertion.equal | validation | function equal($value): self {
if ($this->hasFlag('file')) {
if ($this->hasFlag('negate')) assertFileNotEquals($value, $this->target, $this->message);
else assertFileEquals($value, $this->target, $this->message);
return $this;
}
$target = $this->hasFlag('length') ? $this->getLength($this->target) : $this->target;
return $this->expect($target, equalTo($value));
} | php | {
"resource": ""
} |
q251006 | Assertion.exist | validation | function exist(): self {
if ($this->hasFlag('directory')) $constraint = directoryExists();
else if ($this->hasFlag('file')) $constraint = fileExists();
else throw new \BadMethodCallException('This assertion is not a file or directory one.');
return $this->expect($this->target, $constraint);
} | php | {
"resource": ""
} |
q251007 | Assertion.instanceOf | validation | function instanceOf(string $className): self {
return $this->expect($this->target, isInstanceOf($className));
} | php | {
"resource": ""
} |
q251008 | Assertion.least | validation | function least($value): self {
$target = $this->hasFlag('length') ? $this->getLength($this->target) : $this->target;
return $this->expect($target, greaterThanOrEqual($value));
} | php | {
"resource": ""
} |
q251009 | Assertion.lengthOf | validation | function lengthOf(int $value = null): self {
if ($value === null) return $this->setFlag('length');
if (is_string($this->target)) {
$constraint = equalTo($value);
$target = mb_strlen($this->target);
}
else {
$constraint = countOf($value);
$target = $this->target;
}
return $this->expect($target, $constraint);
} | php | {
"resource": ""
} |
q251010 | Assertion.match | validation | function match(string $pattern): self {
return $this->expect($this->target, matchesRegularExpression($pattern));
} | php | {
"resource": ""
} |
q251011 | Assertion.matchFormat | validation | function matchFormat(string $format): self {
return $this->expect($this->target, matches($format));
} | php | {
"resource": ""
} |
q251012 | Assertion.most | validation | function most($value): self {
$target = $this->hasFlag('length') ? $this->getLength($this->target) : $this->target;
return $this->expect($target, lessThanOrEqual($value));
} | php | {
"resource": ""
} |
q251013 | Assertion.property | validation | function property(string $name, $value = null): self {
$isArray = is_array($this->target) || $this->target instanceof \ArrayAccess;
if (!$isArray && !is_object($this->target)) throw new \BadMethodCallException('The target is not an array nor an object.');
$hasProperty = $isArray ? array_key_exists($name, $this->target) : property_exists($this->target, $name);
$hasPropertyConstraint = $isArray ? arrayHasKey($name) : objectHasAttribute($name);
$property = $isArray ? ($this->target[$name] ?? null) : ($this->target->$name ?? null);
if (!$hasProperty || $value === null) $this->expect($this->target, $hasPropertyConstraint);
else {
assertThat($this->target, $hasPropertyConstraint);
$this->expect($property, equalTo($value));
}
$this->target = $property;
return $this;
} | php | {
"resource": ""
} |
q251014 | Assertion.readable | validation | function readable(): self {
if (!$this->hasFlag('directory') && !$this->hasFlag('file'))
throw new \BadMethodCallException('This assertion is not a file or directory one.');
return $this->expect($this->target, isReadable());
} | php | {
"resource": ""
} |
q251015 | Assertion.satisfy | validation | function satisfy(callable $predicate): self {
return $this->expect(call_user_func($predicate, $this->target), isTrue());
} | php | {
"resource": ""
} |
q251016 | Assertion.startWith | validation | function startWith(string $value): self {
return $this->expect($this->target, stringStartsWith($value));
} | php | {
"resource": ""
} |
q251017 | Assertion.throw | validation | function throw(string $className = ''): self {
if (!is_callable($this->target)) throw new \BadMethodCallException('The function target is not callable.');
$exception = null;
try { call_user_func($this->target); }
catch (\Throwable $e) { $exception = $e; }
$constraint = logicalNot(isNull());
return $this->expect($exception, mb_strlen($className) ? logicalAnd($constraint, isInstanceOf($className)) : $constraint);
} | php | {
"resource": ""
} |
q251018 | Assertion.within | validation | function within($start, $finish): self {
$target = $this->hasFlag('length') ? $this->getLength($this->target) : $this->target;
return $this->expect($target, logicalAnd(greaterThanOrEqual($start), lessThanOrEqual($finish)));
} | php | {
"resource": ""
} |
q251019 | Assertion.writable | validation | function writable(): self {
if (!$this->hasFlag('directory') && !$this->hasFlag('file'))
throw new \BadMethodCallException('This assertion is not a file or directory one.');
return $this->expect($this->target, isWritable());
} | php | {
"resource": ""
} |
q251020 | Assertion.expect | validation | private function expect($target, Constraint $constraint): self {
assertThat($target, $this->hasFlag('negate') ? logicalNot($constraint) : $constraint, $this->message);
return $this;
} | php | {
"resource": ""
} |
q251021 | Assertion.getLength | validation | private function getLength($value): int {
if (is_array($value) || $value instanceof \Countable) return count($value);
if ($value instanceof \Traversable) return iterator_count($value);
if (is_string($value)) return mb_strlen($value);
throw new \InvalidArgumentException("The specified value is not iterable: $value");
} | php | {
"resource": ""
} |
q251022 | Assertion.setFlag | validation | private function setFlag(string $name, bool $value = true): self {
$this->flags[$name] = $value;
return $this;
} | php | {
"resource": ""
} |
q251023 | Parser.parseIf | validation | private function parseIf() {
// consume required tokens
$if_open = $this->pop('IF_OPEN');
$output = 'if(' . $if_open[1] . ') {' . "\n";
$this->currLine++;
$seeking = true;
while($seeking) {
list($type, $value) = $this->peek();
switch($type) {
case 'IF_CLOSE':
$this->pop();
$output .= "}\n";
$seeking = false;
$this->currLine++;
break;
case 'ELSE':
$this->pop();
$output .= "} else {\n";
$this->currLine++;
break;
case 'ELSE_IF':
$token = $this->pop();
$output .= '} elseif(' . $token[1] . ") {\n";
$this->currLine++;
break;
default:
$output .= $this->parseExpression();
break;
}
}
return $output;
} | php | {
"resource": ""
} |
q251024 | Parser.parseExpression | validation | public function parseExpression() {
$token = $this->peek();
// check first token
$type = $token[0];
switch($type) {
case 'IF_OPEN':
return $this->parseIf();
case 'FOR_OPEN':
return $this->parseFor();
case 'FILTERED_VALUE':
return $this->parseFilteredValue();
case 'VALUE':
return $this->parseValue();
case 'HTML':
return $this->parseHTML();
case 'ESCAPE':
return $this->parseEscape();
case 'INCLUDE':
return $this->parseInclude();
default:
throw new SyntaxErrorException(
"Could not parse expression, invalid token '$type'");
}
} | php | {
"resource": ""
} |
q251025 | Parser.parseHTML | validation | public function parseHTML() {
$token = $this->pop('HTML');
$value = $this->stripQuotes($token[1]);
$this->currLine += substr_count($value, "\n");
return '$output .= \'' . $value . "';\n";
} | php | {
"resource": ""
} |
q251026 | Parser.parseFor | validation | public function parseFor() {
// consume required tokens
$for_open_token = $this->pop('FOR_OPEN');
$this->currLine++;
// create output so far
$output = '$for_index = 0; foreach(' .
$for_open_token[1][1] . ' as ' .
$for_open_token[1][0] . ') {' . "\n";
while(true) {
list($type, $value) = $this->peek();
if($type == 'FOR_CLOSE') {
// pop the element, and add the value
$this->pop();
$output .= '$for_index++; }' . "\n";
$this->currLine++;
break;
} else {
$output .= $this->parseExpression();
}
}
return $output;
} | php | {
"resource": ""
} |
q251027 | Parser.parseEscape | validation | public function parseEscape() {
$token = $this->pop('ESCAPE');
$value = $this->stripQuotes($token[1]);
$this->currLine += substr_count($value, "\n");
return '$output .= \'' . $value . "';\n";
} | php | {
"resource": ""
} |
q251028 | Parser.parseFilteredValue | validation | public function parseFilteredValue() {
list($type, $filters) = $this->pop('FILTERED_VALUE');
$value = array_shift($filters);
$opening = '';
$closing = '';
foreach($filters as $filter) {
if(function_exists($filter)) {
$opening .= $filter . '(';
$closing .= ')';
} else {
$opening .= '\Katar\Katar::getInstance()->filter(\'' .
$filter . '\', ';
$closing .= ')';
}
}
return '$output .= ' . $opening . $value . $closing . ";\n";
} | php | {
"resource": ""
} |
q251029 | Conditional.setConditions | validation | public function setConditions($pValue)
{
if (!is_array($pValue)) {
$pValue = [$pValue];
}
$this->condition = $pValue;
return $this;
} | php | {
"resource": ""
} |
q251030 | Chart.setBottomRightPosition | validation | public function setBottomRightPosition($cell, $xOffset = null, $yOffset = null)
{
$this->bottomRightCellRef = $cell;
if ($xOffset !== null) {
$this->setBottomRightXOffset($xOffset);
}
if ($yOffset !== null) {
$this->setBottomRightYOffset($yOffset);
}
return $this;
} | php | {
"resource": ""
} |
q251031 | Cell.getFormattedValue | validation | public function getFormattedValue()
{
return (string) NumberFormat::toFormattedString(
$this->getCalculatedValue(),
$this->getStyle()
->getNumberFormat()->getFormatCode()
);
} | php | {
"resource": ""
} |
q251032 | Cell.getCalculatedValue | validation | public function getCalculatedValue($resetLog = true)
{
if ($this->dataType == DataType::TYPE_FORMULA) {
try {
$result = Calculation::getInstance(
$this->getWorksheet()->getParent()
)->calculateCellValue($this, $resetLog);
// We don't yet handle array returns
if (is_array($result)) {
while (is_array($result)) {
$result = array_pop($result);
}
}
} catch (Exception $ex) {
if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->calculatedValue !== null)) {
return $this->calculatedValue; // Fallback for calculations referencing external files.
}
throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(
$this->getWorksheet()->getTitle() . '!' . $this->getCoordinate() . ' -> ' . $ex->getMessage()
);
}
if ($result === '#Not Yet Implemented') {
return $this->calculatedValue; // Fallback if calculation engine does not support the formula.
}
return $result;
} elseif ($this->value instanceof RichText) {
return $this->value->getPlainText();
}
return $this->value;
} | php | {
"resource": ""
} |
q251033 | Cell.setDataType | validation | public function setDataType($pDataType)
{
if ($pDataType == DataType::TYPE_STRING2) {
$pDataType = DataType::TYPE_STRING;
}
$this->dataType = $pDataType;
return $this->updateInCollection();
} | php | {
"resource": ""
} |
q251034 | Cell.hasDataValidation | validation | public function hasDataValidation()
{
if (!isset($this->parent)) {
throw new Exception('Cannot check for data validation when cell is not bound to a worksheet');
}
return $this->getWorksheet()->dataValidationExists($this->getCoordinate());
} | php | {
"resource": ""
} |
q251035 | Cell.getDataValidation | validation | public function getDataValidation()
{
if (!isset($this->parent)) {
throw new Exception('Cannot get data validation for cell that is not bound to a worksheet');
}
return $this->getWorksheet()->getDataValidation($this->getCoordinate());
} | php | {
"resource": ""
} |
q251036 | Cell.setDataValidation | validation | public function setDataValidation(DataValidation $pDataValidation = null)
{
if (!isset($this->parent)) {
throw new Exception('Cannot set data validation for cell that is not bound to a worksheet');
}
$this->getWorksheet()->setDataValidation($this->getCoordinate(), $pDataValidation);
return $this->updateInCollection();
} | php | {
"resource": ""
} |
q251037 | Cell.hasHyperlink | validation | public function hasHyperlink()
{
if (!isset($this->parent)) {
throw new Exception('Cannot check for hyperlink when cell is not bound to a worksheet');
}
return $this->getWorksheet()->hyperlinkExists($this->getCoordinate());
} | php | {
"resource": ""
} |
q251038 | Cell.getHyperlink | validation | public function getHyperlink()
{
if (!isset($this->parent)) {
throw new Exception('Cannot get hyperlink for cell that is not bound to a worksheet');
}
return $this->getWorksheet()->getHyperlink($this->getCoordinate());
} | php | {
"resource": ""
} |
q251039 | Cell.setHyperlink | validation | public function setHyperlink(Hyperlink $pHyperlink = null)
{
if (!isset($this->parent)) {
throw new Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
}
$this->getWorksheet()->setHyperlink($this->getCoordinate(), $pHyperlink);
return $this->updateInCollection();
} | php | {
"resource": ""
} |
q251040 | Cell.compareCells | validation | public static function compareCells(self $a, self $b)
{
if ($a->getRow() < $b->getRow()) {
return -1;
} elseif ($a->getRow() > $b->getRow()) {
return 1;
} elseif (Coordinate::columnIndexFromString($a->getColumn()) < Coordinate::columnIndexFromString($b->getColumn())) {
return -1;
}
return 1;
} | php | {
"resource": ""
} |
q251041 | Settings.setChartRenderer | validation | public static function setChartRenderer($rendererClass)
{
if (!is_a($rendererClass, IRenderer::class, true)) {
throw new Exception('Chart renderer must implement ' . IRenderer::class);
}
self::$chartRenderer = $rendererClass;
} | php | {
"resource": ""
} |
q251042 | Settings.setLibXmlLoaderOptions | validation | public static function setLibXmlLoaderOptions($options)
{
if ($options === null && defined('LIBXML_DTDLOAD')) {
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
}
self::$libXmlLoaderOptions = $options;
} | php | {
"resource": ""
} |
q251043 | Settings.getLibXmlLoaderOptions | validation | public static function getLibXmlLoaderOptions()
{
if (self::$libXmlLoaderOptions === null && defined('LIBXML_DTDLOAD')) {
self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
} elseif (self::$libXmlLoaderOptions === null) {
self::$libXmlLoaderOptions = true;
}
return self::$libXmlLoaderOptions;
} | php | {
"resource": ""
} |
q251044 | Properties.setCreated | validation | public function setCreated($time)
{
if ($time === null) {
$time = time();
} elseif (is_string($time)) {
if (is_numeric($time)) {
$time = (int) $time;
} else {
$time = strtotime($time);
}
}
$this->created = $time;
return $this;
} | php | {
"resource": ""
} |
q251045 | Properties.setModified | validation | public function setModified($time)
{
if ($time === null) {
$time = time();
} elseif (is_string($time)) {
if (is_numeric($time)) {
$time = (int) $time;
} else {
$time = strtotime($time);
}
}
$this->modified = $time;
return $this;
} | php | {
"resource": ""
} |
q251046 | Escher.readDefault | validation | private function readDefault()
{
// offset 0; size: 2; recVer and recInstance
$verInstance = Xls::getUInt2d($this->data, $this->pos);
// offset: 2; size: 2: Record Type
$fbt = Xls::getUInt2d($this->data, $this->pos + 2);
// bit: 0-3; mask: 0x000F; recVer
$recVer = (0x000F & $verInstance) >> 0;
$length = Xls::getInt4d($this->data, $this->pos + 4);
$recordData = substr($this->data, $this->pos + 8, $length);
// move stream pointer to next record
$this->pos += 8 + $length;
} | php | {
"resource": ""
} |
q251047 | Escher.readBSE | validation | private function readBSE()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4;
$length = Xls::getInt4d($this->data, $this->pos + 4);
$recordData = substr($this->data, $this->pos + 8, $length);
// move stream pointer to next record
$this->pos += 8 + $length;
// add BSE to BstoreContainer
$BSE = new BSE();
$this->object->addBSE($BSE);
$BSE->setBLIPType($recInstance);
// offset: 0; size: 1; btWin32 (MSOBLIPTYPE)
$btWin32 = ord($recordData[0]);
// offset: 1; size: 1; btWin32 (MSOBLIPTYPE)
$btMacOS = ord($recordData[1]);
// offset: 2; size: 16; MD4 digest
$rgbUid = substr($recordData, 2, 16);
// offset: 18; size: 2; tag
$tag = Xls::getUInt2d($recordData, 18);
// offset: 20; size: 4; size of BLIP in bytes
$size = Xls::getInt4d($recordData, 20);
// offset: 24; size: 4; number of references to this BLIP
$cRef = Xls::getInt4d($recordData, 24);
// offset: 28; size: 4; MSOFO file offset
$foDelay = Xls::getInt4d($recordData, 28);
// offset: 32; size: 1; unused1
$unused1 = ord($recordData[32]);
// offset: 33; size: 1; size of nameData in bytes (including null terminator)
$cbName = ord($recordData[33]);
// offset: 34; size: 1; unused2
$unused2 = ord($recordData[34]);
// offset: 35; size: 1; unused3
$unused3 = ord($recordData[35]);
// offset: 36; size: $cbName; nameData
$nameData = substr($recordData, 36, $cbName);
// offset: 36 + $cbName, size: var; the BLIP data
$blipData = substr($recordData, 36 + $cbName);
// record is a container, read contents
$reader = new self($BSE);
$reader->load($blipData);
} | php | {
"resource": ""
} |
q251048 | Escher.readBlipJPEG | validation | private function readBlipJPEG()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4;
$length = Xls::getInt4d($this->data, $this->pos + 4);
$recordData = substr($this->data, $this->pos + 8, $length);
// move stream pointer to next record
$this->pos += 8 + $length;
$pos = 0;
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
$rgbUid1 = substr($recordData, 0, 16);
$pos += 16;
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
if (in_array($recInstance, [0x046B, 0x06E3])) {
$rgbUid2 = substr($recordData, 16, 16);
$pos += 16;
}
// offset: var; size: 1; tag
$tag = ord($recordData[$pos]);
$pos += 1;
// offset: var; size: var; the raw image data
$data = substr($recordData, $pos);
$blip = new Blip();
$blip->setData($data);
$this->object->setBlip($blip);
} | php | {
"resource": ""
} |
q251049 | Escher.readOPT | validation | private function readOPT()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4;
$length = Xls::getInt4d($this->data, $this->pos + 4);
$recordData = substr($this->data, $this->pos + 8, $length);
// move stream pointer to next record
$this->pos += 8 + $length;
$this->readOfficeArtRGFOPTE($recordData, $recInstance);
} | php | {
"resource": ""
} |
q251050 | Escher.readClientTextbox | validation | private function readClientTextbox()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4;
$length = Xls::getInt4d($this->data, $this->pos + 4);
$recordData = substr($this->data, $this->pos + 8, $length);
// move stream pointer to next record
$this->pos += 8 + $length;
} | php | {
"resource": ""
} |
q251051 | Escher.readClientAnchor | validation | private function readClientAnchor()
{
$length = Xls::getInt4d($this->data, $this->pos + 4);
$recordData = substr($this->data, $this->pos + 8, $length);
// move stream pointer to next record
$this->pos += 8 + $length;
// offset: 2; size: 2; upper-left corner column index (0-based)
$c1 = Xls::getUInt2d($recordData, 2);
// offset: 4; size: 2; upper-left corner horizontal offset in 1/1024 of column width
$startOffsetX = Xls::getUInt2d($recordData, 4);
// offset: 6; size: 2; upper-left corner row index (0-based)
$r1 = Xls::getUInt2d($recordData, 6);
// offset: 8; size: 2; upper-left corner vertical offset in 1/256 of row height
$startOffsetY = Xls::getUInt2d($recordData, 8);
// offset: 10; size: 2; bottom-right corner column index (0-based)
$c2 = Xls::getUInt2d($recordData, 10);
// offset: 12; size: 2; bottom-right corner horizontal offset in 1/1024 of column width
$endOffsetX = Xls::getUInt2d($recordData, 12);
// offset: 14; size: 2; bottom-right corner row index (0-based)
$r2 = Xls::getUInt2d($recordData, 14);
// offset: 16; size: 2; bottom-right corner vertical offset in 1/256 of row height
$endOffsetY = Xls::getUInt2d($recordData, 16);
// set the start coordinates
$this->object->setStartCoordinates(Coordinate::stringFromColumnIndex($c1 + 1) . ($r1 + 1));
// set the start offsetX
$this->object->setStartOffsetX($startOffsetX);
// set the start offsetY
$this->object->setStartOffsetY($startOffsetY);
// set the end coordinates
$this->object->setEndCoordinates(Coordinate::stringFromColumnIndex($c2 + 1) . ($r2 + 1));
// set the end offsetX
$this->object->setEndOffsetX($endOffsetX);
// set the end offsetY
$this->object->setEndOffsetY($endOffsetY);
} | php | {
"resource": ""
} |
q251052 | AbstractApi.pureGet | validation | protected function pureGet(string $path, array $params = [], array $headers = [])
{
if ($params) {
$path .= '?'.http_build_query($params);
}
return $this->client->get($path, $headers);
} | php | {
"resource": ""
} |
q251053 | AbstractApi.putRaw | validation | protected function putRaw(string $path, $body = null, array $headers = [])
{
$response = $this->client->put($path, $headers, $body);
return ResponseMediator::getContent($response);
} | php | {
"resource": ""
} |
q251054 | AbstractApi.deleteRaw | validation | protected function deleteRaw(string $path, $body = null, array $headers = [])
{
$response = $this->client->delete($path, $headers, $body);
return ResponseMediator::getContent($response);
} | php | {
"resource": ""
} |
q251055 | BlacklistsService.addEntriesToBlacklist | validation | public function addEntriesToBlacklist($id, $entries, $importName = null)
{
if ($importName == null) {
$importName = "phpclient_import_" . uniqid();
}
$action = new AddEntriesAction();
$action->importName = $importName;
$action->entries = $entries;
return $this->post("blacklists/" . $id . "/actions", $action->toXMLString());
} | php | {
"resource": ""
} |
q251056 | NamedRange.setWorksheet | validation | public function setWorksheet(Worksheet $value = null)
{
if ($value !== null) {
$this->worksheet = $value;
}
return $this;
} | php | {
"resource": ""
} |
q251057 | XMLWriter.writeRawData | validation | public function writeRawData($text)
{
if (is_array($text)) {
$text = implode("\n", $text);
}
return $this->writeRaw(htmlspecialchars($text));
} | php | {
"resource": ""
} |
q251058 | SheetView.setView | validation | public function setView($pValue)
{
// MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview' via the user interface
if ($pValue === null) {
$pValue = self::SHEETVIEW_NORMAL;
}
if (in_array($pValue, self::$sheetViewTypes)) {
$this->sheetviewType = $pValue;
} else {
throw new PhpSpreadsheetException('Invalid sheetview layout type.');
}
return $this;
} | php | {
"resource": ""
} |
q251059 | PolynomialBestFit.polynomialRegression | validation | private function polynomialRegression($order, $yValues, $xValues)
{
// calculate sums
$x_sum = array_sum($xValues);
$y_sum = array_sum($yValues);
$xx_sum = $xy_sum = 0;
for ($i = 0; $i < $this->valueCount; ++$i) {
$xy_sum += $xValues[$i] * $yValues[$i];
$xx_sum += $xValues[$i] * $xValues[$i];
$yy_sum += $yValues[$i] * $yValues[$i];
}
/*
* This routine uses logic from the PHP port of polyfit version 0.1
* written by Michael Bommarito and Paul Meagher
*
* The function fits a polynomial function of order $order through
* a series of x-y data points using least squares.
*
*/
for ($i = 0; $i < $this->valueCount; ++$i) {
for ($j = 0; $j <= $order; ++$j) {
$A[$i][$j] = pow($xValues[$i], $j);
}
}
for ($i = 0; $i < $this->valueCount; ++$i) {
$B[$i] = [$yValues[$i]];
}
$matrixA = new Matrix($A);
$matrixB = new Matrix($B);
$C = $matrixA->solve($matrixB);
$coefficients = [];
for ($i = 0; $i < $C->getRowDimension(); ++$i) {
$r = $C->get($i, 0);
if (abs($r) <= pow(10, -9)) {
$r = 0;
}
$coefficients[] = $r;
}
$this->intersect = array_shift($coefficients);
$this->slope = $coefficients;
$this->calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum);
foreach ($this->xValues as $xKey => $xValue) {
$this->yBestFitValues[$xKey] = $this->getValueOfYForX($xValue);
}
} | php | {
"resource": ""
} |
q251060 | Bloc.setSegmentSize | validation | public function setSegmentSize($size) {
if (null !== $this->memory) {
throw new Exception\RuntimeException(
'You can not change the segment size because memory is already allocated.'
. ' Use realloc() function to create new memory segment.'
);
}
$this->segmentSize = (integer) $size;
return $this;
} | php | {
"resource": ""
} |
q251061 | AutoFilter.getColumn | validation | public function getColumn($pColumn)
{
$this->testColumnInRange($pColumn);
if (!isset($this->columns[$pColumn])) {
$this->columns[$pColumn] = new AutoFilter\Column($pColumn, $this);
}
return $this->columns[$pColumn];
} | php | {
"resource": ""
} |
q251062 | AutoFilter.shiftColumn | validation | public function shiftColumn($fromColumn, $toColumn)
{
$fromColumn = strtoupper($fromColumn);
$toColumn = strtoupper($toColumn);
if (($fromColumn !== null) && (isset($this->columns[$fromColumn])) && ($toColumn !== null)) {
$this->columns[$fromColumn]->setParent();
$this->columns[$fromColumn]->setColumnIndex($toColumn);
$this->columns[$toColumn] = $this->columns[$fromColumn];
$this->columns[$toColumn]->setParent($this);
unset($this->columns[$fromColumn]);
ksort($this->columns);
}
return $this;
} | php | {
"resource": ""
} |
q251063 | Rels.writeRelationships | validation | public function writeRelationships(Spreadsheet $spreadsheet)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
if (!empty($customPropertyList)) {
// Relationship docProps/app.xml
$this->writeRelationship(
$objWriter,
4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties',
'docProps/custom.xml'
);
}
// Relationship docProps/app.xml
$this->writeRelationship(
$objWriter,
3,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
'docProps/app.xml'
);
// Relationship docProps/core.xml
$this->writeRelationship(
$objWriter,
2,
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
'docProps/core.xml'
);
// Relationship xl/workbook.xml
$this->writeRelationship(
$objWriter,
1,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
'xl/workbook.xml'
);
// a custom UI in workbook ?
if ($spreadsheet->hasRibbon()) {
$this->writeRelationShip(
$objWriter,
5,
'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility',
$spreadsheet->getRibbonXMLData('target')
);
}
$objWriter->endElement();
return $objWriter->getData();
} | php | {
"resource": ""
} |
q251064 | Rels.writeWorkbookRelationships | validation | public function writeWorkbookRelationships(Spreadsheet $spreadsheet)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationship styles.xml
$this->writeRelationship(
$objWriter,
1,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
'styles.xml'
);
// Relationship theme/theme1.xml
$this->writeRelationship(
$objWriter,
2,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
'theme/theme1.xml'
);
// Relationship sharedStrings.xml
$this->writeRelationship(
$objWriter,
3,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',
'sharedStrings.xml'
);
// Relationships with sheets
$sheetCount = $spreadsheet->getSheetCount();
for ($i = 0; $i < $sheetCount; ++$i) {
$this->writeRelationship(
$objWriter,
($i + 1 + 3),
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',
'worksheets/sheet' . ($i + 1) . '.xml'
);
}
// Relationships for vbaProject if needed
// id : just after the last sheet
if ($spreadsheet->hasMacros()) {
$this->writeRelationShip(
$objWriter,
($i + 1 + 3),
'http://schemas.microsoft.com/office/2006/relationships/vbaProject',
'vbaProject.bin'
);
++$i; //increment i if needed for an another relation
}
$objWriter->endElement();
return $objWriter->getData();
} | php | {
"resource": ""
} |
q251065 | Rels.writeWorksheetRelationships | validation | public function writeWorksheetRelationships(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet, $pWorksheetId = 1, $includeCharts = false)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Write drawing relationships?
$d = 0;
if ($includeCharts) {
$charts = $pWorksheet->getChartCollection();
} else {
$charts = [];
}
if (($pWorksheet->getDrawingCollection()->count() > 0) ||
(count($charts) > 0)) {
$this->writeRelationship(
$objWriter,
++$d,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing',
'../drawings/drawing' . $pWorksheetId . '.xml'
);
}
// Write hyperlink relationships?
$i = 1;
foreach ($pWorksheet->getHyperlinkCollection() as $hyperlink) {
if (!$hyperlink->isInternal()) {
$this->writeRelationship(
$objWriter,
'_hyperlink_' . $i,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
$hyperlink->getUrl(),
'External'
);
++$i;
}
}
// Write comments relationship?
$i = 1;
if (count($pWorksheet->getComments()) > 0) {
$this->writeRelationship(
$objWriter,
'_comments_vml' . $i,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
'../drawings/vmlDrawing' . $pWorksheetId . '.vml'
);
$this->writeRelationship(
$objWriter,
'_comments' . $i,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
'../comments' . $pWorksheetId . '.xml'
);
}
// Write header/footer relationship?
$i = 1;
if (count($pWorksheet->getHeaderFooter()->getImages()) > 0) {
$this->writeRelationship(
$objWriter,
'_headerfooter_vml' . $i,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
'../drawings/vmlDrawingHF' . $pWorksheetId . '.vml'
);
}
$objWriter->endElement();
return $objWriter->getData();
} | php | {
"resource": ""
} |
q251066 | Rels.writeDrawingRelationships | validation | public function writeDrawingRelationships(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet, &$chartRef, $includeCharts = false)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Loop through images and write relationships
$i = 1;
$iterator = $pWorksheet->getDrawingCollection()->getIterator();
while ($iterator->valid()) {
if ($iterator->current() instanceof \PhpOffice\PhpSpreadsheet\Worksheet\Drawing
|| $iterator->current() instanceof MemoryDrawing) {
// Write relationship for image drawing
$this->writeRelationship(
$objWriter,
$i,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
'../media/' . str_replace(' ', '', $iterator->current()->getIndexedFilename())
);
}
$iterator->next();
++$i;
}
if ($includeCharts) {
// Loop through charts and write relationships
$chartCount = $pWorksheet->getChartCount();
if ($chartCount > 0) {
for ($c = 0; $c < $chartCount; ++$c) {
$this->writeRelationship(
$objWriter,
$i++,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart',
'../charts/chart' . ++$chartRef . '.xml'
);
}
}
}
$objWriter->endElement();
return $objWriter->getData();
} | php | {
"resource": ""
} |
q251067 | Rels.writeRelationship | validation | private function writeRelationship(XMLWriter $objWriter, $pId, $pType, $pTarget, $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
// Write relationship
$objWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', 'rId' . $pId);
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode);
}
$objWriter->endElement();
} else {
throw new WriterException('Invalid parameters passed.');
}
} | php | {
"resource": ""
} |
q251068 | Protection.setPassword | validation | public function setPassword($pValue, $pAlreadyHashed = false)
{
if (!$pAlreadyHashed) {
$pValue = PasswordHasher::hashPassword($pValue);
}
$this->password = $pValue;
return $this;
} | php | {
"resource": ""
} |
q251069 | AujaRouter.getCreateAssociationName | validation | public function getCreateAssociationName($modelName, $otherModelName) {
return sprintf('auja.%s.%s.create', $this->toUrlName($modelName), $this->toUrlName($otherModelName));
} | php | {
"resource": ""
} |
q251070 | AujaRouter.getAssociationName | validation | public function getAssociationName($modelName, $otherModelName) {
return sprintf('auja.%s.%s', $this->toUrlName($modelName), $this->toUrlName($otherModelName));
} | php | {
"resource": ""
} |
q251071 | AujaRouter.getAssociationMenuName | validation | public function getAssociationMenuName($modelName, $otherModelName) {
return sprintf('auja.%s.%s.menu', $this->toUrlName($modelName), $this->toUrlName($otherModelName));
} | php | {
"resource": ""
} |
q251072 | AujaRouter.resource | validation | public function resource($modelName, $controller) {
if (php_sapi_name() == 'cli') {
/* Don't run when we're running artisan commands. */
return;
}
if (!class_exists($controller)) {
throw new ExpectedAujaControllerException($controller . ' does not exist.');
}
if (!is_subclass_of($controller, 'Label305\AujaLaravel\Controllers\Interfaces\AujaControllerInterface')) {
throw new ExpectedAujaControllerException(
$controller . ' does not implement Label305\AujaLaravel\Controllers\Interfaces\AujaControllerInterface'
);
}
/* Default routes */
$this->registerIndex($modelName, $controller);
$this->registerMenu($modelName, $controller);
$this->registerShowMenu($modelName, $controller);
$this->registerCreate($modelName, $controller);
$this->registerStore($modelName, $controller);
$this->registerShow($modelName, $controller);
$this->registerEdit($modelName, $controller);
$this->registerUpdate($modelName, $controller);
$this->registerDelete($modelName, $controller);
/* Associated routes */
$model = $this->auja->getModel(ucfirst(str_singular(camel_case($modelName)))); // TODO: prettify
$relations = $this->auja->getRelationsForModel($model);
foreach ($relations as $relation) {
$otherModelName = $relation->getRight()->getName();
if ($relation->getType() == Relation::BELONGS_TO) {
$this->registerBelongsToAssociationMenu($modelName, $otherModelName, $controller);
} else {
$this->registerAssociation($modelName, $otherModelName, $controller);
$this->registerAssociationMenu($modelName, $otherModelName, $controller);
$this->registerCreateAssociation($modelName, $otherModelName, $controller);
}
}
} | php | {
"resource": ""
} |
q251073 | Security.setRevisionsPassword | validation | public function setRevisionsPassword($pValue, $pAlreadyHashed = false)
{
if (!$pAlreadyHashed) {
$pValue = PasswordHasher::hashPassword($pValue);
}
$this->revisionsPassword = $pValue;
return $this;
} | php | {
"resource": ""
} |
q251074 | Security.setWorkbookPassword | validation | public function setWorkbookPassword($pValue, $pAlreadyHashed = false)
{
if (!$pAlreadyHashed) {
$pValue = PasswordHasher::hashPassword($pValue);
}
$this->workbookPassword = $pValue;
return $this;
} | php | {
"resource": ""
} |
q251075 | Drawing.pixelsToCellDimension | validation | public static function pixelsToCellDimension($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont)
{
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['width'] / Font::$defaultColumnWidths[$name][$size]['px'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * 11 * Font::$defaultColumnWidths['Calibri'][11]['width'] / Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
}
return $colWidth;
} | php | {
"resource": ""
} |
q251076 | Drawing.imagecreatefrombmp | validation | public static function imagecreatefrombmp($p_sFile)
{
// Load the image into a string
$file = fopen($p_sFile, 'rb');
$read = fread($file, 10);
while (!feof($file) && ($read != '')) {
$read .= fread($file, 1024);
}
$temp = unpack('H*', $read);
$hex = $temp[1];
$header = substr($hex, 0, 108);
// Process the header
// Structure: http://www.fastgraph.com/help/bmp_header_format.html
if (substr($header, 0, 4) == '424d') {
// Cut it in parts of 2 bytes
$header_parts = str_split($header, 2);
// Get the width 4 bytes
$width = hexdec($header_parts[19] . $header_parts[18]);
// Get the height 4 bytes
$height = hexdec($header_parts[23] . $header_parts[22]);
// Unset the header params
unset($header_parts);
}
// Define starting X and Y
$x = 0;
$y = 1;
// Create newimage
$image = imagecreatetruecolor($width, $height);
// Grab the body from the image
$body = substr($hex, 108);
// Calculate if padding at the end-line is needed
// Divided by two to keep overview.
// 1 byte = 2 HEX-chars
$body_size = (strlen($body) / 2);
$header_size = ($width * $height);
// Use end-line padding? Only when needed
$usePadding = ($body_size > ($header_size * 3) + 4);
// Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption
// Calculate the next DWORD-position in the body
for ($i = 0; $i < $body_size; $i += 3) {
// Calculate line-ending and padding
if ($x >= $width) {
// If padding needed, ignore image-padding
// Shift i to the ending of the current 32-bit-block
if ($usePadding) {
$i += $width % 4;
}
// Reset horizontal position
$x = 0;
// Raise the height-position (bottom-up)
++$y;
// Reached the image-height? Break the for-loop
if ($y > $height) {
break;
}
}
// Calculation of the RGB-pixel (defined as BGR in image-data)
// Define $i_pos as absolute position in the body
$i_pos = $i * 2;
$r = hexdec($body[$i_pos + 4] . $body[$i_pos + 5]);
$g = hexdec($body[$i_pos + 2] . $body[$i_pos + 3]);
$b = hexdec($body[$i_pos] . $body[$i_pos + 1]);
// Calculate and draw the pixel
$color = imagecolorallocate($image, $r, $g, $b);
imagesetpixel($image, $x, $height - $y, $color);
// Raise the horizontal position
++$x;
}
// Unset the body / free the memory
unset($body);
// Return image-object
return $image;
} | php | {
"resource": ""
} |
q251077 | BaseReader.openFile | validation | protected function openFile($pFilename)
{
File::assertFile($pFilename);
// Open file
$this->fileHandle = fopen($pFilename, 'r');
if ($this->fileHandle === false) {
throw new Exception('Could not open file ' . $pFilename . ' for reading.');
}
} | php | {
"resource": ""
} |
q251078 | Slim.createSymmetricAuthenticatedJsonRequest | validation | public function createSymmetricAuthenticatedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SharedAuthenticationKey $key,
array $headers = []
): RequestInterface {
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
return $this->createSymmetricAuthenticatedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | php | {
"resource": ""
} |
q251079 | Slim.createSymmetricAuthenticatedJsonResponse | validation | public function createSymmetricAuthenticatedJsonResponse(
int $status,
array $arrayToJsonify,
SharedAuthenticationKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
return $this->createSymmetricAuthenticatedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | php | {
"resource": ""
} |
q251080 | Slim.createSymmetricEncryptedJsonRequest | validation | public function createSymmetricEncryptedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SharedEncryptionKey $key,
array $headers = []
): RequestInterface {
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
return $this->createSymmetricEncryptedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | php | {
"resource": ""
} |
q251081 | Slim.createSymmetricEncryptedJsonResponse | validation | public function createSymmetricEncryptedJsonResponse(
int $status,
array $arrayToJsonify,
SharedEncryptionKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
return $this->createSymmetricEncryptedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | php | {
"resource": ""
} |
q251082 | Slim.createSealedJsonRequest | validation | public function createSealedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SealingPublicKey $key,
array $headers = []
): RequestInterface {
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
return $this->createSealedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | php | {
"resource": ""
} |
q251083 | Slim.createSealedJsonResponse | validation | public function createSealedJsonResponse(
int $status,
array $arrayToJsonify,
SealingPublicKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
return $this->createSealedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | php | {
"resource": ""
} |
q251084 | Slim.createSignedJsonRequest | validation | public function createSignedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SigningSecretKey $key,
array $headers = []
): RequestInterface {
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
return $this->createSignedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | php | {
"resource": ""
} |
q251085 | Slim.createSignedJsonResponse | validation | public function createSignedJsonResponse(
int $status,
array $arrayToJsonify,
SigningSecretKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
return $this->createSignedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | php | {
"resource": ""
} |
q251086 | Slim.createSymmetricEncryptedRequest | validation | public function createSymmetricEncryptedRequest(
string $method,
string $uri,
string $body,
SharedEncryptionKey $key,
array $headers = []
): RequestInterface {
return new Request(
$method,
Uri::createFromString($uri),
new Headers($headers),
[],
[],
$this->stringToStream(
Base64UrlSafe::encode(Simple::encrypt($body, $key))
),
[]
);
} | php | {
"resource": ""
} |
q251087 | Slim.createSealedRequest | validation | public function createSealedRequest(
string $method,
string $uri,
string $body,
SealingPublicKey $key,
array $headers = []
): RequestInterface {
return new Request(
$method,
Uri::createFromString($uri),
new Headers($headers),
[],
[],
$this->stringToStream(
Base64UrlSafe::encode(Simple::seal($body, $key))
),
[]
);
} | php | {
"resource": ""
} |
q251088 | Slim.createSealedResponse | validation | public function createSealedResponse(
int $status,
string $body,
SealingPublicKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
return new Response(
$status,
new Headers($headers),
$this->stringToStream(
Base64UrlSafe::encode(Simple::seal($body, $key))
)
);
} | php | {
"resource": ""
} |
q251089 | Slim.createSignedRequest | validation | public function createSignedRequest(
string $method,
string $uri,
string $body,
SigningSecretKey $key,
array $headers = []
): RequestInterface {
$signature = \ParagonIE_Sodium_Compat::crypto_sign_detached(
$body,
$key->getString(true)
);
if (isset($headers[Sapient::HEADER_SIGNATURE_NAME])) {
$headers[Sapient::HEADER_SIGNATURE_NAME][] = Base64UrlSafe::encode($signature);
} else {
$headers[Sapient::HEADER_SIGNATURE_NAME] = Base64UrlSafe::encode($signature);
}
return new Request(
$method,
Uri::createFromString($uri),
new Headers($headers),
[],
[],
$this->stringToStream($body),
[]
);
} | php | {
"resource": ""
} |
q251090 | Slim.createSignedResponse | validation | public function createSignedResponse(
int $status,
string $body,
SigningSecretKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
$signature = \ParagonIE_Sodium_Compat::crypto_sign_detached(
$body,
$key->getString(true)
);
if (isset($headers[Sapient::HEADER_SIGNATURE_NAME])) {
$headers[Sapient::HEADER_SIGNATURE_NAME][] = Base64UrlSafe::encode($signature);
} else {
$headers[Sapient::HEADER_SIGNATURE_NAME] = Base64UrlSafe::encode($signature);
}
return new Response(
$status,
new Headers($headers),
$this->stringToStream($body)
);
} | php | {
"resource": ""
} |
q251091 | Slim.stringToStream | validation | public function stringToStream(string $input): StreamInterface
{
/** @var resource $stream */
$stream = \fopen('php://temp', 'w+');
if (!\is_resource($stream)) {
throw new \Error('Could not create stream');
}
\fwrite($stream, $input);
\rewind($stream);
return new Stream($stream);
} | php | {
"resource": ""
} |
q251092 | PasswordHasher.hashPassword | validation | public static function hashPassword($pPassword)
{
$password = 0x0000;
$charPos = 1; // char position
// split the plain text password in its component characters
$chars = preg_split('//', $pPassword, -1, PREG_SPLIT_NO_EMPTY);
foreach ($chars as $char) {
$value = ord($char) << $charPos++; // shifted ASCII value
$rotated_bits = $value >> 15; // rotated bits beyond bit 15
$value &= 0x7fff; // first 15 bits
$password ^= ($value | $rotated_bits);
}
$password ^= strlen($pPassword);
$password ^= 0xCE4B;
return strtoupper(dechex($password));
} | php | {
"resource": ""
} |
q251093 | Drawing.setPath | validation | public function setPath($pValue, $pVerifyFile = true)
{
if ($pVerifyFile) {
if (file_exists($pValue)) {
$this->path = $pValue;
if ($this->width == 0 && $this->height == 0) {
// Get width/height
list($this->width, $this->height) = getimagesize($pValue);
}
} else {
throw new PhpSpreadsheetException("File $pValue not found!");
}
} else {
$this->path = $pValue;
}
return $this;
} | php | {
"resource": ""
} |
q251094 | CacheItem.expiresAt | validation | public function expiresAt($expires)
{
if ($expires instanceof DateTimeInterface) {
$this->expires = $expires;
} else {
$this->expires = null;
}
return $this;
} | php | {
"resource": ""
} |
q251095 | BIFFwriter.append | validation | protected function append($data)
{
if (strlen($data) - 4 > $this->limit) {
$data = $this->addContinue($data);
}
$this->_data .= $data;
$this->_datasize += strlen($data);
} | php | {
"resource": ""
} |
q251096 | BIFFwriter.storeBof | validation | protected function storeBof($type)
{
$record = 0x0809; // Record identifier (BIFF5-BIFF8)
$length = 0x0010;
// by inspection of real files, MS Office Excel 2007 writes the following
$unknown = pack('VV', 0x000100D1, 0x00000406);
$build = 0x0DBB; // Excel 97
$year = 0x07CC; // Excel 97
$version = 0x0600; // BIFF8
$header = pack('vv', $record, $length);
$data = pack('vvvv', $version, $type, $build, $year);
$this->append($header . $data . $unknown);
} | php | {
"resource": ""
} |
q251097 | BIFFwriter.addContinue | validation | private function addContinue($data)
{
$limit = $this->limit;
$record = 0x003C; // Record identifier
// The first 2080/8224 bytes remain intact. However, we have to change
// the length field of the record.
$tmp = substr($data, 0, 2) . pack('v', $limit) . substr($data, 4, $limit);
$header = pack('vv', $record, $limit); // Headers for continue records
// Retrieve chunks of 2080/8224 bytes +4 for the header.
$data_length = strlen($data);
for ($i = $limit + 4; $i < ($data_length - $limit); $i += $limit) {
$tmp .= $header;
$tmp .= substr($data, $i, $limit);
}
// Retrieve the last chunk of data
$header = pack('vv', $record, strlen($data) - $i);
$tmp .= $header;
$tmp .= substr($data, $i);
return $tmp;
} | php | {
"resource": ""
} |
q251098 | DataValidator.isValid | validation | public function isValid(Cell $cell)
{
if (!$cell->hasDataValidation()) {
return true;
}
$cellValue = $cell->getValue();
$dataValidation = $cell->getDataValidation();
if (!$dataValidation->getAllowBlank() && ($cellValue === null || $cellValue === '')) {
return false;
}
// TODO: write check on all cases
switch ($dataValidation->getType()) {
case DataValidation::TYPE_LIST:
return $this->isValueInList($cell);
}
return false;
} | php | {
"resource": ""
} |
q251099 | DataValidator.isValueInList | validation | private function isValueInList(Cell $cell)
{
$cellValue = $cell->getValue();
$dataValidation = $cell->getDataValidation();
$formula1 = $dataValidation->getFormula1();
if (!empty($formula1)) {
// inline values list
if ($formula1[0] === '"') {
return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true);
} elseif (strpos($formula1, ':') > 0) {
// values list cells
$matchFormula = '=MATCH(' . $cell->getCoordinate() . ', ' . $formula1 . ', 0)';
$calculation = Calculation::getInstance($cell->getWorksheet()->getParent());
try {
$result = $calculation->calculateFormula($matchFormula, $cell->getCoordinate(), $cell);
return $result !== Functions::NA();
} catch (Exception $ex) {
return false;
}
}
}
return true;
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.