_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q251400 | Xls.readLabel | validation | private function readLabel()
{
$length = self::getUInt2d($this->data, $this->pos + 2);
$recordData = $this->readRecordData($this->data, $this->pos + 4, $length);
// move stream pointer to next record
$this->pos += 4 + $length;
// offset: 0; size: 2; index to row
$row = self::getUInt2d($recordData, 0);
// offset: 2; size: 2; index to column
$column = self::getUInt2d($recordData, 2);
$columnString = Coordinate::stringFromColumnIndex($column + 1);
// Read cell?
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
// offset: 4; size: 2; XF index
$xfIndex = self::getUInt2d($recordData, 4);
// add cell value
// todo: what if string is very long? continue record
if ($this->version == self::XLS_BIFF8) {
$string = self::readUnicodeStringLong(substr($recordData, 6));
$value = $string['value'];
} else {
$string = $this->readByteStringLong(substr($recordData, 6));
$value = $string['value'];
}
if ($this->readEmptyCells || trim($value) !== '') {
$cell = $this->phpSheet->getCell($columnString . ($row + 1));
$cell->setValueExplicit($value, DataType::TYPE_STRING);
if (!$this->readDataOnly) {
// add cell style
$cell->setXfIndex($this->mapCellXfIndex[$xfIndex]);
}
}
}
} | php | {
"resource": ""
} |
q251401 | Xls.readMsoDrawing | validation | private function readMsoDrawing()
{
$length = self::getUInt2d($this->data, $this->pos + 2);
// get spliced record data
$splicedRecordData = $this->getSplicedRecordData();
$recordData = $splicedRecordData['recordData'];
$this->drawingData .= $recordData;
} | php | {
"resource": ""
} |
q251402 | Xls.readPane | validation | private function readPane()
{
$length = self::getUInt2d($this->data, $this->pos + 2);
$recordData = $this->readRecordData($this->data, $this->pos + 4, $length);
// move stream pointer to next record
$this->pos += 4 + $length;
if (!$this->readDataOnly) {
// offset: 0; size: 2; position of vertical split
$px = self::getUInt2d($recordData, 0);
// offset: 2; size: 2; position of horizontal split
$py = self::getUInt2d($recordData, 2);
// offset: 4; size: 2; top most visible row in the bottom pane
$rwTop = self::getUInt2d($recordData, 4);
// offset: 6; size: 2; first visible left column in the right pane
$colLeft = self::getUInt2d($recordData, 6);
if ($this->frozen) {
// frozen panes
$cell = Coordinate::stringFromColumnIndex($px + 1) . ($py + 1);
$topLeftCell = Coordinate::stringFromColumnIndex($colLeft + 1) . ($rwTop + 1);
$this->phpSheet->freezePane($cell, $topLeftCell);
}
// unfrozen panes; split windows; not supported by PhpSpreadsheet core
}
} | php | {
"resource": ""
} |
q251403 | Xls.readSelection | validation | private function readSelection()
{
$length = self::getUInt2d($this->data, $this->pos + 2);
$recordData = $this->readRecordData($this->data, $this->pos + 4, $length);
// move stream pointer to next record
$this->pos += 4 + $length;
if (!$this->readDataOnly) {
// offset: 0; size: 1; pane identifier
$paneId = ord($recordData[0]);
// offset: 1; size: 2; index to row of the active cell
$r = self::getUInt2d($recordData, 1);
// offset: 3; size: 2; index to column of the active cell
$c = self::getUInt2d($recordData, 3);
// offset: 5; size: 2; index into the following cell range list to the
// entry that contains the active cell
$index = self::getUInt2d($recordData, 5);
// offset: 7; size: var; cell range address list containing all selected cell ranges
$data = substr($recordData, 7);
$cellRangeAddressList = $this->readBIFF5CellRangeAddressList($data); // note: also BIFF8 uses BIFF5 syntax
$selectedCells = $cellRangeAddressList['cellRangeAddresses'][0];
// first row '1' + last row '16384' indicates that full column is selected (apparently also in BIFF8!)
if (preg_match('/^([A-Z]+1\:[A-Z]+)16384$/', $selectedCells)) {
$selectedCells = preg_replace('/^([A-Z]+1\:[A-Z]+)16384$/', '${1}1048576', $selectedCells);
}
// first row '1' + last row '65536' indicates that full column is selected
if (preg_match('/^([A-Z]+1\:[A-Z]+)65536$/', $selectedCells)) {
$selectedCells = preg_replace('/^([A-Z]+1\:[A-Z]+)65536$/', '${1}1048576', $selectedCells);
}
// first column 'A' + last column 'IV' indicates that full row is selected
if (preg_match('/^(A\d+\:)IV(\d+)$/', $selectedCells)) {
$selectedCells = preg_replace('/^(A\d+\:)IV(\d+)$/', '${1}XFD${2}', $selectedCells);
}
$this->phpSheet->setSelectedCells($selectedCells);
}
} | php | {
"resource": ""
} |
q251404 | Xls.readSheetLayout | validation | private function readSheetLayout()
{
$length = self::getUInt2d($this->data, $this->pos + 2);
$recordData = $this->readRecordData($this->data, $this->pos + 4, $length);
// move stream pointer to next record
$this->pos += 4 + $length;
// local pointer in record data
$offset = 0;
if (!$this->readDataOnly) {
// offset: 0; size: 2; repeated record identifier 0x0862
// offset: 2; size: 10; not used
// offset: 12; size: 4; size of record data
// Excel 2003 uses size of 0x14 (documented), Excel 2007 uses size of 0x28 (not documented?)
$sz = self::getInt4d($recordData, 12);
switch ($sz) {
case 0x14:
// offset: 16; size: 2; color index for sheet tab
$colorIndex = self::getUInt2d($recordData, 16);
$color = Xls\Color::map($colorIndex, $this->palette, $this->version);
$this->phpSheet->getTabColor()->setRGB($color['rgb']);
break;
case 0x28:
// TODO: Investigate structure for .xls SHEETLAYOUT record as saved by MS Office Excel 2007
return;
break;
}
}
} | php | {
"resource": ""
} |
q251405 | Xls.readRangeProtection | validation | private function readRangeProtection()
{
$length = self::getUInt2d($this->data, $this->pos + 2);
$recordData = $this->readRecordData($this->data, $this->pos + 4, $length);
// move stream pointer to next record
$this->pos += 4 + $length;
// local pointer in record data
$offset = 0;
if (!$this->readDataOnly) {
$offset += 12;
// offset: 12; size: 2; shared feature type, 2 = enhanced protection, 4 = smart tag
$isf = self::getUInt2d($recordData, 12);
if ($isf != 2) {
// we only read FEAT records of type 2
return;
}
$offset += 2;
$offset += 5;
// offset: 19; size: 2; count of ref ranges this feature is on
$cref = self::getUInt2d($recordData, 19);
$offset += 2;
$offset += 6;
// offset: 27; size: 8 * $cref; list of cell ranges (like in hyperlink record)
$cellRanges = [];
for ($i = 0; $i < $cref; ++$i) {
try {
$cellRange = $this->readBIFF8CellRangeAddressFixed(substr($recordData, 27 + 8 * $i, 8));
} catch (PhpSpreadsheetException $e) {
return;
}
$cellRanges[] = $cellRange;
$offset += 8;
}
// offset: var; size: var; variable length of feature specific data
$rgbFeat = substr($recordData, $offset);
$offset += 4;
// offset: var; size: 4; the encrypted password (only 16-bit although field is 32-bit)
$wPassword = self::getInt4d($recordData, $offset);
$offset += 4;
// Apply range protection to sheet
if ($cellRanges) {
$this->phpSheet->protectCells(implode(' ', $cellRanges), strtoupper(dechex($wPassword)), true);
}
}
} | php | {
"resource": ""
} |
q251406 | Xls.readContinue | validation | private function readContinue()
{
$length = self::getUInt2d($this->data, $this->pos + 2);
$recordData = $this->readRecordData($this->data, $this->pos + 4, $length);
// check if we are reading drawing data
// this is in case a free CONTINUE record occurs in other circumstances we are unaware of
if ($this->drawingData == '') {
// move stream pointer to next record
$this->pos += 4 + $length;
return;
}
// check if record data is at least 4 bytes long, otherwise there is no chance this is MSODRAWING data
if ($length < 4) {
// move stream pointer to next record
$this->pos += 4 + $length;
return;
}
// dirty check to see if CONTINUE record could be a camouflaged MSODRAWING record
// look inside CONTINUE record to see if it looks like a part of an Escher stream
// we know that Escher stream may be split at least at
// 0xF003 MsofbtSpgrContainer
// 0xF004 MsofbtSpContainer
// 0xF00D MsofbtClientTextbox
$validSplitPoints = [0xF003, 0xF004, 0xF00D]; // add identifiers if we find more
$splitPoint = self::getUInt2d($recordData, 2);
if (in_array($splitPoint, $validSplitPoints)) {
// get spliced record data (and move pointer to next record)
$splicedRecordData = $this->getSplicedRecordData();
$this->drawingData .= $splicedRecordData['recordData'];
return;
}
// move stream pointer to next record
$this->pos += 4 + $length;
} | php | {
"resource": ""
} |
q251407 | Xls.readBIFF8CellAddressB | validation | private function readBIFF8CellAddressB($cellAddressStructure, $baseCell = 'A1')
{
list($baseCol, $baseRow) = Coordinate::coordinateFromString($baseCell);
$baseCol = Coordinate::columnIndexFromString($baseCol) - 1;
// offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767))
$rowIndex = self::getUInt2d($cellAddressStructure, 0);
$row = self::getUInt2d($cellAddressStructure, 0) + 1;
// bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
if (!(0x4000 & self::getUInt2d($cellAddressStructure, 2))) {
// offset: 2; size: 2; index to column or column offset + relative flags
// bit: 7-0; mask 0x00FF; column index
$colIndex = 0x00FF & self::getUInt2d($cellAddressStructure, 2);
$column = Coordinate::stringFromColumnIndex($colIndex + 1);
$column = '$' . $column;
} else {
// offset: 2; size: 2; index to column or column offset + relative flags
// bit: 7-0; mask 0x00FF; column index
$relativeColIndex = 0x00FF & self::getInt2d($cellAddressStructure, 2);
$colIndex = $baseCol + $relativeColIndex;
$colIndex = ($colIndex < 256) ? $colIndex : $colIndex - 256;
$colIndex = ($colIndex >= 0) ? $colIndex : $colIndex + 256;
$column = Coordinate::stringFromColumnIndex($colIndex + 1);
}
// bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
if (!(0x8000 & self::getUInt2d($cellAddressStructure, 2))) {
$row = '$' . $row;
} else {
$rowIndex = ($rowIndex <= 32767) ? $rowIndex : $rowIndex - 65536;
$row = $baseRow + $rowIndex;
}
return $column . $row;
} | php | {
"resource": ""
} |
q251408 | Xls.readBIFF8CellRangeAddressB | validation | private function readBIFF8CellRangeAddressB($subData, $baseCell = 'A1')
{
list($baseCol, $baseRow) = Coordinate::coordinateFromString($baseCell);
$baseCol = Coordinate::columnIndexFromString($baseCol) - 1;
// TODO: if cell range is just a single cell, should this funciton
// not just return e.g. 'A1' and not 'A1:A1' ?
// offset: 0; size: 2; first row
$frIndex = self::getUInt2d($subData, 0); // adjust below
// offset: 2; size: 2; relative index to first row (0... 65535) should be treated as offset (-32768... 32767)
$lrIndex = self::getUInt2d($subData, 2); // adjust below
// bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
if (!(0x4000 & self::getUInt2d($subData, 4))) {
// absolute column index
// offset: 4; size: 2; first column with relative/absolute flags
// bit: 7-0; mask 0x00FF; column index
$fcIndex = 0x00FF & self::getUInt2d($subData, 4);
$fc = Coordinate::stringFromColumnIndex($fcIndex + 1);
$fc = '$' . $fc;
} else {
// column offset
// offset: 4; size: 2; first column with relative/absolute flags
// bit: 7-0; mask 0x00FF; column index
$relativeFcIndex = 0x00FF & self::getInt2d($subData, 4);
$fcIndex = $baseCol + $relativeFcIndex;
$fcIndex = ($fcIndex < 256) ? $fcIndex : $fcIndex - 256;
$fcIndex = ($fcIndex >= 0) ? $fcIndex : $fcIndex + 256;
$fc = Coordinate::stringFromColumnIndex($fcIndex + 1);
}
// bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
if (!(0x8000 & self::getUInt2d($subData, 4))) {
// absolute row index
$fr = $frIndex + 1;
$fr = '$' . $fr;
} else {
// row offset
$frIndex = ($frIndex <= 32767) ? $frIndex : $frIndex - 65536;
$fr = $baseRow + $frIndex;
}
// bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
if (!(0x4000 & self::getUInt2d($subData, 6))) {
// absolute column index
// offset: 6; size: 2; last column with relative/absolute flags
// bit: 7-0; mask 0x00FF; column index
$lcIndex = 0x00FF & self::getUInt2d($subData, 6);
$lc = Coordinate::stringFromColumnIndex($lcIndex + 1);
$lc = '$' . $lc;
} else {
// column offset
// offset: 4; size: 2; first column with relative/absolute flags
// bit: 7-0; mask 0x00FF; column index
$relativeLcIndex = 0x00FF & self::getInt2d($subData, 4);
$lcIndex = $baseCol + $relativeLcIndex;
$lcIndex = ($lcIndex < 256) ? $lcIndex : $lcIndex - 256;
$lcIndex = ($lcIndex >= 0) ? $lcIndex : $lcIndex + 256;
$lc = Coordinate::stringFromColumnIndex($lcIndex + 1);
}
// bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
if (!(0x8000 & self::getUInt2d($subData, 6))) {
// absolute row index
$lr = $lrIndex + 1;
$lr = '$' . $lr;
} else {
// row offset
$lrIndex = ($lrIndex <= 32767) ? $lrIndex : $lrIndex - 65536;
$lr = $baseRow + $lrIndex;
}
return "$fc$fr:$lc$lr";
} | php | {
"resource": ""
} |
q251409 | Xls.getInt4d | validation | public static function getInt4d($data, $pos)
{
// FIX: represent numbers correctly on 64-bit system
// http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
// Changed by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
$_or_24 = ord($data[$pos + 3]);
if ($_or_24 >= 128) {
// negative number
$_ord_24 = -abs((256 - $_or_24) << 24);
} else {
$_ord_24 = ($_or_24 & 127) << 24;
}
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $_ord_24;
} | php | {
"resource": ""
} |
q251410 | Settings.write | validation | public function write(Spreadsheet $spreadsheet = null)
{
$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');
// Settings
$objWriter->startElement('office:document-settings');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:config', 'urn:oasis:names:tc:opendocument:xmlns:config:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('office:version', '1.2');
$objWriter->startElement('office:settings');
$objWriter->startElement('config:config-item-set');
$objWriter->writeAttribute('config:name', 'ooo:view-settings');
$objWriter->startElement('config:config-item-map-indexed');
$objWriter->writeAttribute('config:name', 'Views');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('config:config-item-set');
$objWriter->writeAttribute('config:name', 'ooo:configuration-settings');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
return $objWriter->getData();
} | php | {
"resource": ""
} |
q251411 | Borders.setDiagonalDirection | validation | public function setDiagonalDirection($pValue)
{
if ($pValue == '') {
$pValue = self::DIAGONAL_NONE;
}
if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['diagonalDirection' => $pValue]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->diagonalDirection = $pValue;
}
return $this;
} | php | {
"resource": ""
} |
q251412 | CustomFields.fromXML | validation | function fromXML($xmlElement)
{
foreach ($xmlElement->children() as $field) {
$this->custom_fields[trim($field->name)] = $field->type; // The trim is required to make a safer string from the object
}
} | php | {
"resource": ""
} |
q251413 | CustomFields.toString | validation | function toString()
{
// Generate custom field string
$customfields = "";
if (isset($this->custom_fields)) {
foreach ($this->custom_fields as $index => $type) {
$customfields .= $index . "=" . $type . ", ";
}
$customfields = rtrim($customfields, ', ');
}
return "CustomFields = {" . $customfields . "}";
} | php | {
"resource": ""
} |
q251414 | Cells.has | validation | public function has($pCoord)
{
if ($pCoord === $this->currentCoordinate) {
return true;
}
// Check if the requested entry exists in the index
return isset($this->index[$pCoord]);
} | php | {
"resource": ""
} |
q251415 | Cells.delete | validation | public function delete($pCoord)
{
if ($pCoord === $this->currentCoordinate && $this->currentCell !== null) {
$this->currentCell->detach();
$this->currentCoordinate = null;
$this->currentCell = null;
$this->currentCellIsDirty = false;
}
unset($this->index[$pCoord]);
// Delete the entry from cache
$this->cache->delete($this->cachePrefix . $pCoord);
} | php | {
"resource": ""
} |
q251416 | Cells.getHighestColumn | validation | public function getHighestColumn($row = null)
{
if ($row == null) {
$colRow = $this->getHighestRowAndColumn();
return $colRow['column'];
}
$columnList = [1];
foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r);
if ($r != $row) {
continue;
}
$columnList[] = Coordinate::columnIndexFromString($c);
}
return Coordinate::stringFromColumnIndex(max($columnList) + 1);
} | php | {
"resource": ""
} |
q251417 | Cells.getHighestRow | validation | public function getHighestRow($column = null)
{
if ($column == null) {
$colRow = $this->getHighestRowAndColumn();
return $colRow['row'];
}
$rowList = [0];
foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r);
if ($c != $column) {
continue;
}
$rowList[] = $r;
}
return max($rowList);
} | php | {
"resource": ""
} |
q251418 | Cells.cloneCellCollection | validation | public function cloneCellCollection(Worksheet $parent)
{
$this->storeCurrentCell();
$newCollection = clone $this;
$newCollection->parent = $parent;
if (($newCollection->currentCell !== null) && (is_object($newCollection->currentCell))) {
$newCollection->currentCell->attach($this);
}
// Get old values
$oldKeys = $newCollection->getAllCacheKeys();
$oldValues = $newCollection->cache->getMultiple($oldKeys);
$newValues = [];
$oldCachePrefix = $newCollection->cachePrefix;
// Change prefix
$newCollection->cachePrefix = $newCollection->getUniqueID();
foreach ($oldValues as $oldKey => $value) {
$newValues[str_replace($oldCachePrefix, $newCollection->cachePrefix, $oldKey)] = clone $value;
}
// Store new values
$stored = $newCollection->cache->setMultiple($newValues);
if (!$stored) {
$newCollection->__destruct();
throw new PhpSpreadsheetException('Failed to copy cells in cache');
}
return $newCollection;
} | php | {
"resource": ""
} |
q251419 | Cells.removeRow | validation | public function removeRow($row)
{
foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r);
if ($r == $row) {
$this->delete($coord);
}
}
} | php | {
"resource": ""
} |
q251420 | Cells.removeColumn | validation | public function removeColumn($column)
{
foreach ($this->getCoordinates() as $coord) {
sscanf($coord, '%[A-Z]%d', $c, $r);
if ($c == $column) {
$this->delete($coord);
}
}
} | php | {
"resource": ""
} |
q251421 | Cells.storeCurrentCell | validation | private function storeCurrentCell()
{
if ($this->currentCellIsDirty && !empty($this->currentCoordinate)) {
$this->currentCell->detach();
$stored = $this->cache->set($this->cachePrefix . $this->currentCoordinate, $this->currentCell);
if (!$stored) {
$this->__destruct();
throw new PhpSpreadsheetException("Failed to store cell {$this->currentCoordinate} in cache");
}
$this->currentCellIsDirty = false;
}
$this->currentCoordinate = null;
$this->currentCell = null;
} | php | {
"resource": ""
} |
q251422 | Cells.add | validation | public function add($pCoord, Cell $cell)
{
if ($pCoord !== $this->currentCoordinate) {
$this->storeCurrentCell();
}
$this->index[$pCoord] = true;
$this->currentCoordinate = $pCoord;
$this->currentCell = $cell;
$this->currentCellIsDirty = true;
return $cell;
} | php | {
"resource": ""
} |
q251423 | Cells.unsetWorksheetCells | validation | public function unsetWorksheetCells()
{
if ($this->currentCell !== null) {
$this->currentCell->detach();
$this->currentCell = null;
$this->currentCoordinate = null;
}
// Flush the cache
$this->__destruct();
$this->index = [];
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->parent = null;
} | php | {
"resource": ""
} |
q251424 | Cells.getAllCacheKeys | validation | private function getAllCacheKeys()
{
$keys = [];
foreach ($this->getCoordinates() as $coordinate) {
$keys[] = $this->cachePrefix . $coordinate;
}
return $keys;
} | php | {
"resource": ""
} |
q251425 | ContactfiltersService.createContactFilter | validation | function createContactFilter($newFilterObject, $createTargetGroup, $version = 1.0)
{
if ($version == 1.0) {
$queryParameters = array(
'createTargetGroup' => ($createTargetGroup) ? "true" : "false"
);
return $this->put("contactfilters/contactfilter", $newFilterObject->toXMLString(), $queryParameters);
} else if ($version == 2.0) {
$queryParameters = array(
'createTargetGroup' => ($createTargetGroup) ? "true" : "false"
);
return $this->post("contactfilters/v2", $newFilterObject, $queryParameters, "application/json");
}
} | php | {
"resource": ""
} |
q251426 | JSONDeserializer.json_decode | validation | static function json_decode($jsonString, $deserializationType = null) {
if(is_array($deserializationType) && count($deserializationType) > 1) {
$type = $deserializationType[0];
$innerType = $deserializationType[1];
} else {
$type = $deserializationType;
$innerType = null;
}
// return self::fromArray(json_decode($jsonString, true), $type, $innerType);
return self::fromArray(json_decode($jsonString), $type, $innerType);
} | php | {
"resource": ""
} |
q251427 | JSONDeserializer.fromArray | validation | private static function fromArray($object, $type = null, $innerType = null) {
if($type == 'array') {
foreach ($object as $element) {
// call this method on each element
$result[]= self::fromArray($element, $innerType);
}
// return the processed array
return $result;
} else if (class_exists($type)) {
// create the class we are deserializing
$class = new $type();
// if we can call fromArray on the class call it, otherwise
// return the object as-is and trigger a warning
if(is_subclass_of($class, 'AbstractJSONWrapper')) {
$class->fromArray($object);
return $class;
} else {
trigger_error( __CLASS__ . ": Trying to deserialize " . get_class($class));
return $object;
}
} else {
// if this is not a class, we have nothing to do
return $object;
}
} | php | {
"resource": ""
} |
q251428 | Authentication.buildAuthorizationHeader | validation | protected static function buildAuthorizationHeader(string $method, string $token, string $password = null)
{
switch ($method) {
case Client::AUTH_HTTP_PASSWORD:
return 'Basic '.base64_encode("$token:$password");
case Client::AUTH_OAUTH_TOKEN:
return "Bearer $token";
}
throw new RuntimeException(sprintf('Authentication method "%s" not implemented.', $method));
} | php | {
"resource": ""
} |
q251429 | ContactEventType.fromXML | validation | function fromXML($xmlElement)
{
if (isset($xmlElement->id)) $this->id = $xmlElement->id;
if (isset($xmlElement->name)) $this->name = $xmlElement->name;
if (isset($xmlElement->active)) $this->active = $xmlElement->active;
if (isset($xmlElement->anonymizable)) $this->anonymizable = $xmlElement->anonymizable;
if (isset($xmlElement->description)) $this->description = $xmlElement->description;
if (isset($xmlElement->created)) $this->created = $xmlElement->created;
if (isset($xmlElement->updated)) $this->updated = $xmlElement->updated;
if (isset($xmlElement->attributes)) {
$this->attributes = array();
foreach ($xmlElement->attributes->children() as $xmlAttribute) {
$attribute = array();
if (isset($xmlAttribute->name)) $attribute['name'] = trim($xmlAttribute->name);
if (isset($xmlAttribute->datatype)) $attribute['datatype'] = DataType::getDataType($xmlAttribute->datatype);
if (isset($xmlAttribute->description)) $attribute['description'] = trim($xmlAttribute->description);
if (isset($xmlAttribute->required)) $attribute['required'] = $xmlAttribute->required;
array_push($this->attributes, $attribute);
}
}
} | php | {
"resource": ""
} |
q251430 | RelsVBA.writeVBARelationships | validation | public function writeVBARelationships(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');
$objWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', 'rId1');
$objWriter->writeAttribute('Type', 'http://schemas.microsoft.com/office/2006/relationships/vbaProjectSignature');
$objWriter->writeAttribute('Target', 'vbaProjectSignature.bin');
$objWriter->endElement();
$objWriter->endElement();
return $objWriter->getData();
} | php | {
"resource": ""
} |
q251431 | SpgrContainer.getAllSpContainers | validation | public function getAllSpContainers()
{
$allSpContainers = [];
foreach ($this->children as $child) {
if ($child instanceof self) {
$allSpContainers = array_merge($allSpContainers, $child->getAllSpContainers());
} else {
$allSpContainers[] = $child;
}
}
return $allSpContainers;
} | php | {
"resource": ""
} |
q251432 | AbstractRequest.validate | validation | public function validate()
{
foreach (func_get_args() as $key) {
$value = $this->parameters->get($key);
if (! isset($value)) {
throw new InvalidRequestException("The $key parameter is required");
}
}
} | php | {
"resource": ""
} |
q251433 | Database.parseDsn | validation | public static function parseDsn($string = null)
{
$opts = null;
if (!empty($string)) {
$dsn = (object) DsnParser::parseUrl($string)->toArray();
$opts = [
'driver' => $dsn->driver,
'host' => $dsn->host,
'database' => $dsn->dbname,
'username' => $dsn->user,
'password' => isset($dsn->pass) ? $dsn->pass : null
];
}
return $opts;
} | php | {
"resource": ""
} |
q251434 | Database.getQueryPreview | validation | public static function getQueryPreview(QueryBuilder $query = null)
{
if (empty($query)) {
return "";
}
$sql = str_replace('?', "'%s'", $query->toSql());
$bindings = $query->getBindings();
return vsprintf($sql, $bindings);
} | php | {
"resource": ""
} |
q251435 | Database.getLastQuery | validation | public static function getLastQuery($connection = "")
{
$last_query = "";
$pretty_queries = self::getPrettyQueryLog($connection);
if (!empty($pretty_queries)) {
$last_query = $pretty_queries[ count($pretty_queries) - 1 ];
}
return $last_query;
} | php | {
"resource": ""
} |
q251436 | Database.getPrettyQueryLog | validation | public static function getPrettyQueryLog($connection = "")
{
$return_queries = [];
$queries = Capsule::connection($connection)->getQueryLog();
foreach ($queries as $query) {
$query_pattern = str_replace('?', "'%s'", $query['query']);
$return_queries[] = vsprintf($query_pattern, $query['bindings']);
}
return $return_queries;
} | php | {
"resource": ""
} |
q251437 | StringTable.createStringTable | validation | public function createStringTable(Worksheet $pSheet, $pExistingTable = null)
{
// Create string lookup table
$aStringTable = [];
$cellCollection = null;
$aFlippedStringTable = null; // For faster lookup
// Is an existing table given?
if (($pExistingTable !== null) && is_array($pExistingTable)) {
$aStringTable = $pExistingTable;
}
// Fill index array
$aFlippedStringTable = $this->flipStringTable($aStringTable);
// Loop through cells
foreach ($pSheet->getCoordinates() as $coordinate) {
$cell = $pSheet->getCell($coordinate);
$cellValue = $cell->getValue();
if (!is_object($cellValue) &&
($cellValue !== null) &&
$cellValue !== '' &&
!isset($aFlippedStringTable[$cellValue]) &&
($cell->getDataType() == DataType::TYPE_STRING || $cell->getDataType() == DataType::TYPE_STRING2 || $cell->getDataType() == DataType::TYPE_NULL)) {
$aStringTable[] = $cellValue;
$aFlippedStringTable[$cellValue] = true;
} elseif ($cellValue instanceof RichText &&
($cellValue !== null) &&
!isset($aFlippedStringTable[$cellValue->getHashCode()])) {
$aStringTable[] = $cellValue;
$aFlippedStringTable[$cellValue->getHashCode()] = true;
}
}
return $aStringTable;
} | php | {
"resource": ""
} |
q251438 | StringTable.writeStringTable | validation | public function writeStringTable(array $pStringTable)
{
// 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');
// String table
$objWriter->startElement('sst');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
$objWriter->writeAttribute('uniqueCount', count($pStringTable));
// Loop through string table
foreach ($pStringTable as $textElement) {
$objWriter->startElement('si');
if (!$textElement instanceof RichText) {
$textToWrite = StringHelper::controlCharacterPHP2OOXML($textElement);
$objWriter->startElement('t');
if ($textToWrite !== trim($textToWrite)) {
$objWriter->writeAttribute('xml:space', 'preserve');
}
$objWriter->writeRawData($textToWrite);
$objWriter->endElement();
} elseif ($textElement instanceof RichText) {
$this->writeRichText($objWriter, $textElement);
}
$objWriter->endElement();
}
$objWriter->endElement();
return $objWriter->getData();
} | php | {
"resource": ""
} |
q251439 | Content.writeRows | validation | private function writeRows(XMLWriter $objWriter, Worksheet $sheet)
{
$numberRowsRepeated = self::NUMBER_ROWS_REPEATED_MAX;
$span_row = 0;
$rows = $sheet->getRowIterator();
while ($rows->valid()) {
--$numberRowsRepeated;
$row = $rows->current();
if ($row->getCellIterator()->valid()) {
if ($span_row) {
$objWriter->startElement('table:table-row');
if ($span_row > 1) {
$objWriter->writeAttribute('table:number-rows-repeated', $span_row);
}
$objWriter->startElement('table:table-cell');
$objWriter->writeAttribute('table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX);
$objWriter->endElement();
$objWriter->endElement();
$span_row = 0;
}
$objWriter->startElement('table:table-row');
$this->writeCells($objWriter, $row);
$objWriter->endElement();
} else {
++$span_row;
}
$rows->next();
}
} | php | {
"resource": ""
} |
q251440 | Content.writeCellSpan | validation | private function writeCellSpan(XMLWriter $objWriter, $curColumn, $prevColumn)
{
$diff = $curColumn - $prevColumn - 1;
if (1 === $diff) {
$objWriter->writeElement('table:table-cell');
} elseif ($diff > 1) {
$objWriter->startElement('table:table-cell');
$objWriter->writeAttribute('table:number-columns-repeated', $diff);
$objWriter->endElement();
}
} | php | {
"resource": ""
} |
q251441 | Content.writeXfStyles | validation | private function writeXfStyles(XMLWriter $writer, Spreadsheet $spreadsheet)
{
foreach ($spreadsheet->getCellXfCollection() as $style) {
$writer->startElement('style:style');
$writer->writeAttribute('style:name', self::CELL_STYLE_PREFIX . $style->getIndex());
$writer->writeAttribute('style:family', 'table-cell');
$writer->writeAttribute('style:parent-style-name', 'Default');
// style:text-properties
// Font
$writer->startElement('style:text-properties');
$font = $style->getFont();
if ($font->getBold()) {
$writer->writeAttribute('fo:font-weight', 'bold');
$writer->writeAttribute('style:font-weight-complex', 'bold');
$writer->writeAttribute('style:font-weight-asian', 'bold');
}
if ($font->getItalic()) {
$writer->writeAttribute('fo:font-style', 'italic');
}
if ($color = $font->getColor()) {
$writer->writeAttribute('fo:color', sprintf('#%s', $color->getRGB()));
}
if ($family = $font->getName()) {
$writer->writeAttribute('fo:font-family', $family);
}
if ($size = $font->getSize()) {
$writer->writeAttribute('fo:font-size', sprintf('%.1fpt', $size));
}
if ($font->getUnderline() && $font->getUnderline() != Font::UNDERLINE_NONE) {
$writer->writeAttribute('style:text-underline-style', 'solid');
$writer->writeAttribute('style:text-underline-width', 'auto');
$writer->writeAttribute('style:text-underline-color', 'font-color');
switch ($font->getUnderline()) {
case Font::UNDERLINE_DOUBLE:
$writer->writeAttribute('style:text-underline-type', 'double');
break;
case Font::UNDERLINE_SINGLE:
$writer->writeAttribute('style:text-underline-type', 'single');
break;
}
}
$writer->endElement(); // Close style:text-properties
// style:table-cell-properties
$writer->startElement('style:table-cell-properties');
$writer->writeAttribute('style:rotation-align', 'none');
// Fill
if ($fill = $style->getFill()) {
switch ($fill->getFillType()) {
case Fill::FILL_SOLID:
$writer->writeAttribute('fo:background-color', sprintf(
'#%s',
strtolower($fill->getStartColor()->getRGB())
));
break;
case Fill::FILL_GRADIENT_LINEAR:
case Fill::FILL_GRADIENT_PATH:
/// TODO :: To be implemented
break;
case Fill::FILL_NONE:
default:
}
}
$writer->endElement(); // Close style:table-cell-properties
// End
$writer->endElement(); // Close style:style
}
} | php | {
"resource": ""
} |
q251442 | Content.writeCellMerge | validation | private function writeCellMerge(XMLWriter $objWriter, Cell $cell)
{
if (!$cell->isMergeRangeValueCell()) {
return;
}
$mergeRange = Coordinate::splitRange($cell->getMergeRange());
list($startCell, $endCell) = $mergeRange[0];
$start = Coordinate::coordinateFromString($startCell);
$end = Coordinate::coordinateFromString($endCell);
$columnSpan = Coordinate::columnIndexFromString($end[0]) - Coordinate::columnIndexFromString($start[0]) + 1;
$rowSpan = $end[1] - $start[1] + 1;
$objWriter->writeAttribute('table:number-columns-spanned', $columnSpan);
$objWriter->writeAttribute('table:number-rows-spanned', $rowSpan);
} | php | {
"resource": ""
} |
q251443 | Alignment.setHorizontal | validation | public function setHorizontal($pValue)
{
if ($pValue == '') {
$pValue = self::HORIZONTAL_GENERAL;
}
if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['horizontal' => $pValue]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->horizontal = $pValue;
}
return $this;
} | php | {
"resource": ""
} |
q251444 | Alignment.setVertical | validation | public function setVertical($pValue)
{
if ($pValue == '') {
$pValue = self::VERTICAL_BOTTOM;
}
if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['vertical' => $pValue]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->vertical = $pValue;
}
return $this;
} | php | {
"resource": ""
} |
q251445 | Alignment.setShrinkToFit | validation | public function setShrinkToFit($pValue)
{
if ($pValue == '') {
$pValue = false;
}
if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['shrinkToFit' => $pValue]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->shrinkToFit = $pValue;
}
return $this;
} | php | {
"resource": ""
} |
q251446 | Alignment.setIndent | validation | public function setIndent($pValue)
{
if ($pValue > 0) {
if ($this->getHorizontal() != self::HORIZONTAL_GENERAL &&
$this->getHorizontal() != self::HORIZONTAL_LEFT &&
$this->getHorizontal() != self::HORIZONTAL_RIGHT) {
$pValue = 0; // indent not supported
}
}
if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['indent' => $pValue]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->indent = $pValue;
}
return $this;
} | php | {
"resource": ""
} |
q251447 | Alignment.setReadOrder | validation | public function setReadOrder($pValue)
{
if ($pValue < 0 || $pValue > 2) {
$pValue = 0;
}
if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['readOrder' => $pValue]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->readOrder = $pValue;
}
return $this;
} | php | {
"resource": ""
} |
q251448 | AbstractMaileonService.get | validation | public function get($resourcePath, $queryParameters = array(),
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null)
{
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType);
return $this->performRequest($curlSession, $deserializationType);
} | php | {
"resource": ""
} |
q251449 | AbstractMaileonService.delete | validation | public function delete($resourcePath, $queryParameters = array(),
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null)
{
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType);
curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, "DELETE");
return $this->performRequest($curlSession, $deserializationType);
} | php | {
"resource": ""
} |
q251450 | AbstractMaileonService.performRequest | validation | private function performRequest($curlSession, $deserializationType = null)
{
$response = curl_exec($curlSession);
// coerce all false values to null
$response = $response ? $response : null;
try {
$result = new MaileonAPIResult($response, $curlSession, $this->throwException, $deserializationType);
$this->printDebugInformation($curlSession, $result);
curl_close($curlSession);
return $result;
} catch (MaileonAPIException $e) {
if ($this->debug) {
$this->printDebugInformation($curlSession, null, $this->throwException ? null : $e);
}
curl_close($curlSession);
if ($this->throwException) {
throw $e;
}
return null;
}
} | php | {
"resource": ""
} |
q251451 | CommandController.createAction | validation | public function createAction()
{
/** @var \Zend\Http\PhpEnvironment\Request $request */
$request = $this->getRequest();
$prg = $this->prg($request->getRequestUri(), true);
if ($prg instanceof ResponseInterface) {
return $prg;
} elseif ($prg === false) {
return $this->viewModel;
}
if ($this->contactForm->setData($prg)->isValid()) {
/** @var \MamuzContact\Entity\Contact $contact */
$contact = $this->contactForm->getData();
$this->commandService->persist($contact);
$this->viewModel->setVariable('contact', $contact);
}
return $this->viewModel;
} | php | {
"resource": ""
} |
q251452 | Contact.fromXML | validation | function fromXML($xmlElement)
{
if (isset($xmlElement->id)) $this->id = $xmlElement->id;
$this->email = (string)$xmlElement->email;
if (isset($xmlElement->permission)) $this->permission = Permission::getPermission((string)$xmlElement->permission);
if (isset($xmlElement->external_id)) (string)$this->external_id = $xmlElement->external_id;
if (isset($xmlElement->anonymous)) (string)$this->anonymous = $xmlElement->anonymous;
if (isset($xmlElement['anonymous'])) $this->anonymous = $xmlElement['anonymous'];
if (isset($xmlElement->created)) $this->created = $xmlElement->created;
if (isset($xmlElement->updated)) $this->updated = $xmlElement->updated;
if (isset($xmlElement->standard_fields)) {
$this->standard_fields = array();
foreach ($xmlElement->standard_fields->children() as $field) {
$this->standard_fields[trim($field->name)] = (string)$field->value; // The trim is required to make a safer string from the object
}
}
if (isset($xmlElement->custom_fields)) {
foreach ($xmlElement->custom_fields->children() as $field) {
$this->custom_fields[trim($field->name)] = (string)$field->value; // The trim is required to make a safer string from the object
}
}
} | php | {
"resource": ""
} |
q251453 | Contact.toCsvString | validation | function toCsvString()
{
// Generate standard field string
$standard_fields = "{";
if (isset($this->standard_fields)) {
foreach ($this->standard_fields as $index => $value) {
$standard_fields .= $index . "=" . $value . ",";
}
$standard_fields = rtrim($standard_fields, ',');
}
$standard_fields .= "}";
// Generate custom field string
$customfields = "{";
if (isset($this->custom_fields)) {
foreach ($this->custom_fields as $index => $value) {
$customfields .= $index . "=" . $value . ",";
}
$customfields = rtrim($customfields, ',');
}
$customfields .= "}";
$permission = "";
if (isset($this->permission)) {
$permission = $this->permission->getCode();
}
return $this->id
. ";" . $this->email
. ";" . $permission
. ";" . $this->external_id
. ";" . (($this->anonymous == true) ? "true" : "false")
. ";" . $this->created
. ";" . $this->updated
. ";\"" . $standard_fields . "\""
. ";\"" . $customfields . "\"";
} | php | {
"resource": ""
} |
q251454 | Border.getSharedComponent | validation | public function getSharedComponent()
{
switch ($this->parentPropertyName) {
case 'allBorders':
case 'horizontal':
case 'inside':
case 'outline':
case 'vertical':
throw new PhpSpreadsheetException('Cannot get shared component for a pseudo-border.');
break;
case 'bottom':
return $this->parent->getSharedComponent()->getBottom();
case 'diagonal':
return $this->parent->getSharedComponent()->getDiagonal();
case 'left':
return $this->parent->getSharedComponent()->getLeft();
case 'right':
return $this->parent->getSharedComponent()->getRight();
case 'top':
return $this->parent->getSharedComponent()->getTop();
}
} | php | {
"resource": ""
} |
q251455 | Border.setColor | validation | public function setColor(Color $pValue)
{
// make sure parameter is a real color and not a supervisor
$color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
if ($this->isSupervisor) {
$styleArray = $this->getColor()->getStyleArray(['argb' => $color->getARGB()]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->color = $color;
}
return $this;
} | php | {
"resource": ""
} |
q251456 | Ods.scanElementForText | validation | protected function scanElementForText(\DOMNode $element)
{
$str = '';
foreach ($element->childNodes as $child) {
/** @var \DOMNode $child */
if ($child->nodeType == XML_TEXT_NODE) {
$str .= $child->nodeValue;
} elseif ($child->nodeType == XML_ELEMENT_NODE && $child->nodeName == 'text:s') {
// It's a space
// Multiple spaces?
/** @var \DOMAttr $cAttr */
$cAttr = $child->attributes->getNamedItem('c');
if ($cAttr) {
$multiplier = (int) $cAttr->nodeValue;
} else {
$multiplier = 1;
}
$str .= str_repeat(' ', $multiplier);
}
if ($child->hasChildNodes()) {
$str .= $this->scanElementForText($child);
}
}
return $str;
} | php | {
"resource": ""
} |
q251457 | HashTable.addFromSource | validation | public function addFromSource(array $pSource = null)
{
// Check if an array was passed
if ($pSource == null) {
return;
}
foreach ($pSource as $item) {
$this->add($item);
}
} | php | {
"resource": ""
} |
q251458 | HashTable.add | validation | public function add(IComparable $pSource)
{
$hash = $pSource->getHashCode();
if (!isset($this->items[$hash])) {
$this->items[$hash] = $pSource;
$this->keyMap[count($this->items) - 1] = $hash;
}
} | php | {
"resource": ""
} |
q251459 | Engineering.cleanComplex | validation | private static function cleanComplex($complexNumber)
{
if ($complexNumber[0] == '+') {
$complexNumber = substr($complexNumber, 1);
}
if ($complexNumber[0] == '0') {
$complexNumber = substr($complexNumber, 1);
}
if ($complexNumber[0] == '.') {
$complexNumber = '0' . $complexNumber;
}
if ($complexNumber[0] == '+') {
$complexNumber = substr($complexNumber, 1);
}
return $complexNumber;
} | php | {
"resource": ""
} |
q251460 | Engineering.nbrConversionFormat | validation | private static function nbrConversionFormat($xVal, $places)
{
if ($places !== null) {
if (is_numeric($places)) {
$places = (int) $places;
} else {
return Functions::VALUE();
}
if ($places < 0) {
return Functions::NAN();
}
if (strlen($xVal) <= $places) {
return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10);
}
return Functions::NAN();
}
return substr($xVal, -10);
} | php | {
"resource": ""
} |
q251461 | Engineering.getConversionGroups | validation | public static function getConversionGroups()
{
$conversionGroups = [];
foreach (self::$conversionUnits as $conversionUnit) {
$conversionGroups[] = $conversionUnit['Group'];
}
return array_merge(array_unique($conversionGroups));
} | php | {
"resource": ""
} |
q251462 | Engineering.getConversionGroupUnits | validation | public static function getConversionGroupUnits($group = null)
{
$conversionGroups = [];
foreach (self::$conversionUnits as $conversionUnit => $conversionGroup) {
if (($group === null) || ($conversionGroup['Group'] == $group)) {
$conversionGroups[$conversionGroup['Group']][] = $conversionUnit;
}
}
return $conversionGroups;
} | php | {
"resource": ""
} |
q251463 | Auja.authenticationForm | validation | public function authenticationForm($title, $target) {
$formFactory = $this->app->make('Label305\AujaLaravel\Factory\AuthenticationFormFactory');
/* @var $formFactory AuthenticationFormFactory */
return $formFactory->create($title, $target);
} | php | {
"resource": ""
} |
q251464 | Auja.menuFor | validation | public function menuFor($model, $modelId = 0, ModelConfig $config = null) {
if (is_null($this->aujaConfigurator)) {
throw new \LogicException('Auja not initialized. Call Auja::init first.');
}
$modelName = $this->resolveModelName($model);
if ($modelId == 0) {
$menu = $this->noAssociationsMenuFor($modelName, $config);
} else {
$menu = $this->buildComplexIndexMenu($modelName, $modelId, $config);
}
return $menu;
} | php | {
"resource": ""
} |
q251465 | Auja.buildComplexIndexMenu | validation | private function buildComplexIndexMenu($modelName, $modelId, ModelConfig $config = null) {
$model = $this->aujaConfigurator->getModel($modelName);
$relations = $this->aujaConfigurator->getRelationsForModel($model);
$associationRelations = array();
foreach ($relations as $relation) {
if ($relation->getType() == Relation::HAS_MANY || $relation->getType() == Relation::HAS_AND_BELONGS_TO) { // TODO: What to do with one-to-one relations?
$associationRelations[] = $relation;
}
}
switch (count($associationRelations)) {
case 0:
$menu = $this->noAssociationsMenuFor($modelName, $config);
break;
case 1:
$menu = $this->singleAssociationMenuFor($modelName, $modelId, $associationRelations[0], $config);
break;
default:
$menu = $this->multipleAssociationsMenuFor($modelName, $modelId, $associationRelations, $config);
break;
}
return $menu;
} | php | {
"resource": ""
} |
q251466 | Auja.itemsFor | validation | public function itemsFor($model, $items = null, $targetUrl = null, $nextPageUrl = null, $offset = -1, ModelConfig $config = null) {
$modelName = $this->resolveModelName($model);
if ($items == null) {
$items = call_user_func(array($modelName, 'simplePaginate'), 10);
}
$factory = $this->app->make('Label305\AujaLaravel\Factory\ResourceItemsFactory');
/* @var $factory ResourceItemsFactory */
return $factory->create($modelName, $items, $targetUrl, $nextPageUrl, $offset, $config);
} | php | {
"resource": ""
} |
q251467 | Auja.noAssociationsMenuFor | validation | public function noAssociationsMenuFor($model, ModelConfig $config = null) {
$modelName = $this->resolveModelName($model);
$menuFactory = $this->app->make('Label305\AujaLaravel\Factory\NoAssociationsIndexMenuFactory');
/* @var $menuFactory NoAssociationsIndexMenuFactory */
return $menuFactory->create($modelName, $config);
} | php | {
"resource": ""
} |
q251468 | Auja.pageFor | validation | public function pageFor($model, $itemId = 0, ModelConfig $config = null) {
$modelName = $this->resolveModelName($model);
$item = $this->findItem($modelName, $itemId);
$pageFactory = $this->app->make('Label305\AujaLaravel\Factory\PageFactory');
/* @var $pageFactory PageFactory */
return $pageFactory->create($modelName, $item, $config);
} | php | {
"resource": ""
} |
q251469 | Auja.resolveModelName | validation | private function resolveModelName($model) {
if ($model instanceof Controller) {
$exploded = explode('\\', get_class($model));
$controllerName = array_pop($exploded);
return str_singular(str_replace('Controller', '', $controllerName));
} else if ($model instanceof Eloquent) {
return get_class($model);
} else {
return $model;
}
} | php | {
"resource": ""
} |
q251470 | Launcher.set_language | validation | public function set_language() {
$plugin_slug = App::EFG()->getOption( 'slug' );
$module_slug = Module::CustomImagesGrifus()->getOption( 'slug' );
$path = $plugin_slug . '/modules/' . $module_slug . '/languages/';
load_plugin_textdomain( $plugin_slug . '-images', false, $path );
} | php | {
"resource": ""
} |
q251471 | MD5.getContext | validation | public function getContext()
{
$s = '';
foreach (['a', 'b', 'c', 'd'] as $i) {
$v = $this->{$i};
$s .= chr($v & 0xff);
$s .= chr(($v >> 8) & 0xff);
$s .= chr(($v >> 16) & 0xff);
$s .= chr(($v >> 24) & 0xff);
}
return $s;
} | php | {
"resource": ""
} |
q251472 | Meta.write | validation | public function write(Spreadsheet $spreadsheet = null)
{
if (!$spreadsheet) {
$spreadsheet = $this->getParentWriter()->getSpreadsheet();
}
$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');
// Meta
$objWriter->startElement('office:document-meta');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('office:version', '1.2');
$objWriter->startElement('office:meta');
$objWriter->writeElement('meta:initial-creator', $spreadsheet->getProperties()->getCreator());
$objWriter->writeElement('dc:creator', $spreadsheet->getProperties()->getCreator());
$objWriter->writeElement('meta:creation-date', date(DATE_W3C, $spreadsheet->getProperties()->getCreated()));
$objWriter->writeElement('dc:date', date(DATE_W3C, $spreadsheet->getProperties()->getCreated()));
$objWriter->writeElement('dc:title', $spreadsheet->getProperties()->getTitle());
$objWriter->writeElement('dc:description', $spreadsheet->getProperties()->getDescription());
$objWriter->writeElement('dc:subject', $spreadsheet->getProperties()->getSubject());
$keywords = explode(' ', $spreadsheet->getProperties()->getKeywords());
foreach ($keywords as $keyword) {
$objWriter->writeElement('meta:keyword', $keyword);
}
//<meta:document-statistic meta:table-count="XXX" meta:cell-count="XXX" meta:object-count="XXX"/>
$objWriter->startElement('meta:user-defined');
$objWriter->writeAttribute('meta:name', 'Company');
$objWriter->writeRaw($spreadsheet->getProperties()->getCompany());
$objWriter->endElement();
$objWriter->startElement('meta:user-defined');
$objWriter->writeAttribute('meta:name', 'category');
$objWriter->writeRaw($spreadsheet->getProperties()->getCategory());
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
return $objWriter->getData();
} | php | {
"resource": ""
} |
q251473 | Csv.writeLine | validation | private function writeLine($pFileHandle, array $pValues)
{
// No leading delimiter
$writeDelimiter = false;
// Build the line
$line = '';
foreach ($pValues as $element) {
// Escape enclosures
$element = str_replace($this->enclosure, $this->enclosure . $this->enclosure, $element);
// Add delimiter
if ($writeDelimiter) {
$line .= $this->delimiter;
} else {
$writeDelimiter = true;
}
// Add enclosed string
$line .= $this->enclosure . $element . $this->enclosure;
}
// Add line ending
$line .= $this->lineEnding;
// Write to file
fwrite($pFileHandle, $line);
} | php | {
"resource": ""
} |
q251474 | UsersController.edit | validation | public function edit($id)
{
$user = User::findOrFail($id);
$roles = Role::lists('name', 'id');
return view('intothesource.usersmanager.users.edit', compact('user', 'roles'));
} | php | {
"resource": ""
} |
q251475 | DefaultSupportController.main | validation | public function main() {
$config = $this->app['config']['auja'] ?: $this->app['config']['auja-laravel::config'];
$authenticationForm = $this->app['auja']->authenticationForm(
$config['title'],
$this->app['url']->route('auja.support.login', [], false)
);
$username = ($this->app['auth']->user() == null) ? null : $this->app['auth']->user()->name;
$main = $this->app['auja']->main(
$config['title'],
$this->app['auth']->check(),
$username,
$this->app['url']->route('auja.support.logout', [], false),
$authenticationForm
);
$main->setColor(Main::COLOR_MAIN, $config['color']['main']);
$main->setColor(Main::COLOR_ALERT, $config['color']['alert']);
$main->setColor(Main::COLOR_SECONDARY, $config['color']['secondary']);
return new JsonResponse($main);
} | php | {
"resource": ""
} |
q251476 | ContentTypes.getImageMimeType | validation | private function getImageMimeType($pFile)
{
if (File::fileExists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
}
throw new WriterException("File $pFile does not exist");
} | php | {
"resource": ""
} |
q251477 | ContentTypes.writeDefaultContentType | validation | private function writeDefaultContentType(XMLWriter $objWriter, $pPartname, $pContentType)
{
if ($pPartname != '' && $pContentType != '') {
// Write content type
$objWriter->startElement('Default');
$objWriter->writeAttribute('Extension', $pPartname);
$objWriter->writeAttribute('ContentType', $pContentType);
$objWriter->endElement();
} else {
throw new WriterException('Invalid parameters passed.');
}
} | php | {
"resource": ""
} |
q251478 | Calculation.getInstance | validation | public static function getInstance(Spreadsheet $spreadsheet = null)
{
if ($spreadsheet !== null) {
$instance = $spreadsheet->getCalculationEngine();
if (isset($instance)) {
return $instance;
}
}
if (!isset(self::$instance) || (self::$instance === null)) {
self::$instance = new self();
}
return self::$instance;
} | php | {
"resource": ""
} |
q251479 | Calculation.wrapResult | validation | public static function wrapResult($value)
{
if (is_string($value)) {
// Error values cannot be "wrapped"
if (preg_match('/^' . self::CALCULATION_REGEXP_ERROR . '$/i', $value, $match)) {
// Return Excel errors "as is"
return $value;
}
// Return strings wrapped in quotes
return '"' . $value . '"';
// Convert numeric errors to NaN error
} elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
return Functions::NAN();
}
return $value;
} | php | {
"resource": ""
} |
q251480 | Calculation.unwrapResult | validation | public static function unwrapResult($value)
{
if (is_string($value)) {
if ((isset($value[0])) && ($value[0] == '"') && (substr($value, -1) == '"')) {
return substr($value, 1, -1);
}
// Convert numeric errors to NAN error
} elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
return Functions::NAN();
}
return $value;
} | php | {
"resource": ""
} |
q251481 | Calculation.calculateCellValue | validation | public function calculateCellValue(Cell $pCell = null, $resetLog = true)
{
if ($pCell === null) {
return null;
}
$returnArrayAsType = self::$returnArrayAsType;
if ($resetLog) {
// Initialise the logging settings if requested
$this->formulaError = null;
$this->debugLog->clearLog();
$this->cyclicReferenceStack->clear();
$this->cyclicFormulaCounter = 1;
self::$returnArrayAsType = self::RETURN_ARRAY_AS_ARRAY;
}
// Execute the calculation for the cell formula
$this->cellStack[] = [
'sheet' => $pCell->getWorksheet()->getTitle(),
'cell' => $pCell->getCoordinate(),
];
try {
$result = self::unwrapResult($this->_calculateFormulaValue($pCell->getValue(), $pCell->getCoordinate(), $pCell));
$cellAddress = array_pop($this->cellStack);
$this->spreadsheet->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
} catch (\Exception $e) {
$cellAddress = array_pop($this->cellStack);
$this->spreadsheet->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
throw new Exception($e->getMessage());
}
if ((is_array($result)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
self::$returnArrayAsType = $returnArrayAsType;
$testResult = Functions::flattenArray($result);
if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) {
return Functions::VALUE();
}
// If there's only a single cell in the array, then we allow it
if (count($testResult) != 1) {
// If keys are numeric, then it's a matrix result rather than a cell range result, so we permit it
$r = array_keys($result);
$r = array_shift($r);
if (!is_numeric($r)) {
return Functions::VALUE();
}
if (is_array($result[$r])) {
$c = array_keys($result[$r]);
$c = array_shift($c);
if (!is_numeric($c)) {
return Functions::VALUE();
}
}
}
$result = array_shift($testResult);
}
self::$returnArrayAsType = $returnArrayAsType;
if ($result === null) {
return 0;
} elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
return Functions::NAN();
}
return $result;
} | php | {
"resource": ""
} |
q251482 | Calculation.calculateFormula | validation | public function calculateFormula($formula, $cellID = null, Cell $pCell = null)
{
// Initialise the logging settings
$this->formulaError = null;
$this->debugLog->clearLog();
$this->cyclicReferenceStack->clear();
if ($this->spreadsheet !== null && $cellID === null && $pCell === null) {
$cellID = 'A1';
$pCell = $this->spreadsheet->getActiveSheet()->getCell($cellID);
} else {
// Disable calculation cacheing because it only applies to cell calculations, not straight formulae
// But don't actually flush any cache
$resetCache = $this->getCalculationCacheEnabled();
$this->calculationCacheEnabled = false;
}
// Execute the calculation
try {
$result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell));
} catch (\Exception $e) {
throw new Exception($e->getMessage());
}
if ($this->spreadsheet === null) {
// Reset calculation cacheing to its previous state
$this->calculationCacheEnabled = $resetCache;
}
return $result;
} | php | {
"resource": ""
} |
q251483 | Calculation.getMatrixDimensions | validation | public static function getMatrixDimensions(array &$matrix)
{
$matrixRows = count($matrix);
$matrixColumns = 0;
foreach ($matrix as $rowKey => $rowValue) {
if (!is_array($rowValue)) {
$matrix[$rowKey] = [$rowValue];
$matrixColumns = max(1, $matrixColumns);
} else {
$matrix[$rowKey] = array_values($rowValue);
$matrixColumns = max(count($rowValue), $matrixColumns);
}
}
$matrix = array_values($matrix);
return [$matrixRows, $matrixColumns];
} | php | {
"resource": ""
} |
q251484 | Calculation.isImplemented | validation | public function isImplemented($pFunction)
{
$pFunction = strtoupper($pFunction);
$notImplemented = !isset(self::$phpSpreadsheetFunctions[$pFunction]) || (is_array(self::$phpSpreadsheetFunctions[$pFunction]['functionCall']) && self::$phpSpreadsheetFunctions[$pFunction]['functionCall'][1] === 'DUMMY');
return !$notImplemented;
} | php | {
"resource": ""
} |
q251485 | Calculation.getImplementedFunctionNames | validation | public function getImplementedFunctionNames()
{
$returnValue = [];
foreach (self::$phpSpreadsheetFunctions as $functionName => $function) {
if ($this->isImplemented($functionName)) {
$returnValue[] = $functionName;
}
}
return $returnValue;
} | php | {
"resource": ""
} |
q251486 | UniqueBounce.fromXML | validation | function fromXML($xmlElement)
{
$this->contact = new ReportContact();
$this->contact->fromXML($xmlElement->contact);
if (isset($xmlElement->mailing_id)) $this->mailingId = $xmlElement->mailing_id;
if (isset($xmlElement->timestamp)) $this->timestamp = $xmlElement->timestamp;
if (isset($xmlElement->last_type)) $this->lastType = $xmlElement->last_type;
if (isset($xmlElement->count)) $this->count = $xmlElement->count;
if (isset($xmlElement->count_hard)) $this->countHard = $xmlElement->count_hard;
if (isset($xmlElement->count_soft)) $this->countSoft = $xmlElement->count_soft;
} | php | {
"resource": ""
} |
q251487 | OLE.ascToUcs | validation | public static function ascToUcs($ascii)
{
$rawname = '';
$iMax = strlen($ascii);
for ($i = 0; $i < $iMax; ++$i) {
$rawname .= $ascii[$i]
. "\x00";
}
return $rawname;
} | php | {
"resource": ""
} |
q251488 | Generator.getString | validation | public function getString($type = 'letter', $desired_length = null)
{
if (empty($desired_length)) {
$desired_length = $this->getInteger(1, 50);
}
$result = '';
while (strlen($result) < $desired_length) {
if ($type == 'letter') {
$result .= $this->getLetter();
} elseif ($type == 'number') {
$result .= $this->getInteger(1, 10);
} else {
// Mix letters/numbers.
$result .= $this->getUniqueHash();
}
}
return substr($result, 0, $desired_length);
} | php | {
"resource": ""
} |
q251489 | Generator.getGuid | validation | public function getGuid()
{
return sprintf(
'%04x%04x-%04x-%03x4-%04x-%04x%04x%04x',
mt_rand(0, 65535),
mt_rand(0, 65535), // 32 bits for "time_low"
mt_rand(0, 65535), // 16 bits for "time_mid"
mt_rand(0, 4095), // 12 bits before the 0100 of (version) 4 for "time_hi_and_version"
bindec(substr_replace(sprintf('%016b', mt_rand(0, 65535)), '01', 6, 2)),
// 8 bits, the last two of which (positions 6 and 7) are 01, for "clk_seq_hi_res"
// (hence, the 2nd hex digit after the 3rd hyphen can only be 1, 5, 9 or d)
// 8 bits for "clk_seq_low"
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(0, 65535) // 48 bits for "node"
);
} | php | {
"resource": ""
} |
q251490 | Generator.getDate | validation | public function getDate($params = [], $format = 'Y-m-d')
{
foreach ($params as $k => $v) {
$$k = $v;
}
if (!isset($min_year)) {
$min_year = date('Y') - 2;
}
if (!isset($max_year)) {
$max_year = date('Y');
}
if (!isset($min_month)) {
$min_month = 1;
}
if (!isset($max_month)) {
$max_month = 12;
}
// Pick a random year and month within the valid ranges.
$rand_year = rand($min_year, $max_year);
$rand_month = rand($min_month, $max_month);
// Create a date object using the first day of this random month/year.
$date = DateTime::createFromFormat('Y-m-d', join('-', [$rand_year, $rand_month, '01']));
// How many days in this random month?
$days_in_month = $date->format('t');
// Pick a day of the month.
$rand_day = rand(1, $days_in_month);
return DateTime::createFromFormat('Y-m-d', join('-', [$rand_year, $rand_month, $rand_day]))->format($format);
} | php | {
"resource": ""
} |
q251491 | Generator.getDln | validation | public function getDln($state_code = null, $min = 900000001, $max = 999999999)
{
$dln = new Entities\DriverLicense();
$dln->number = rand($min, $max);
$dln->state = !empty($state_code) ? $state_code : $this->getState();
$dln->expiration = $this->getExpiration();
return $dln;
} | php | {
"resource": ""
} |
q251492 | Generator.getFirstName | validation | public function getFirstName($gender = null)
{
if (empty($gender)) {
$gender = $this->getGender();
}
return FirstName::where('gender', $gender)->where('rank', '<=', 250)->orderByRaw(Database::random())->first()->name;
} | php | {
"resource": ""
} |
q251493 | Generator.getLastName | validation | public function getLastName($max = 250)
{
return LastName::where('rank', '<=', $max)->orderByRaw(Database::random())->first()->name;
} | php | {
"resource": ""
} |
q251494 | Generator.getFullName | validation | public function getFullName($gender = null)
{
if (empty($gender)) {
$gender = $this->getGender();
}
$person_name = new Entities\FullName;
$person_name->first = $this->getFirstName($gender);
$person_name->middle = $this->getMiddleName($gender);
$person_name->last = $this->getLastName();
$person_name->gender = $gender;
return $person_name;
} | php | {
"resource": ""
} |
q251495 | Generator.getStreet | validation | public function getStreet()
{
$number = rand(100, 9999);
$street_name = Street::orderByRaw(Database::random())->first()->name;
return $number . ' ' . $street_name;
} | php | {
"resource": ""
} |
q251496 | Generator.getApartment | validation | public function getApartment()
{
$types = ['Apt.', 'Apartment', 'Ste.', 'Suite', 'Box'];
// @codeCoverageIgnoreStart
if ($this->getBool(true, false)) {
$extra = $this->getLetter();
} else {
$extra = $this->getInteger(1, 9999);
}
// @codeCoverageIgnoreEnd
$type = $this->fromArray($types);
return $type . ' ' . $extra;
} | php | {
"resource": ""
} |
q251497 | Generator.getState | validation | public function getState($state_code = null)
{
if (!empty($state_code)) {
$res = Zipcode::where('state_code', $state_code)->orderByRaw(Database::random())->first();
} else {
$res = Zipcode::orderByRaw(Database::random())->first();
}
$State = new Entities\State;
$State->code = $res->state_code;
$State->name = $res->state;
return $State;
} | php | {
"resource": ""
} |
q251498 | Generator.getAddress | validation | public function getAddress($state_code = null, $zip = null)
{
$address = new Entities\Address;
if (!empty($zip) && !empty($state_code)) {
$result = Zipcode::where('zip', $zip)->where('state_code', $state_code)->orderByRaw(Database::random())->first();
} elseif (!empty($zip)) {
$result = Zipcode::where('zip', $zip)->orderByRaw(Database::random())->first();
} elseif (!empty($state_code)) {
$result = Zipcode::where('state_code', $state_code)->orderByRaw(Database::random())->first();
} else {
$result = Zipcode::orderByRaw(Database::random())->first();
}
$address->line_1 = $this->getStreet();
// @codeCoverageIgnoreStart
if ($this->getBool(true, false)) {
$address->line_2 = $this->getApartment();
} else {
$address->line_2 = null;
}
// @codeCoverageIgnoreEnd
$address->city = $result->city;
$address->zip = $result->zip;
$address->county = $result->county;
$address->state = new Entities\State;
$address->state->code = $result->state_code;
$address->state->name = $result->state;
return $address;
} | php | {
"resource": ""
} |
q251499 | Generator.getCompanyName | validation | public function getCompanyName($base_name = null)
{
$suffixes = ['Corporation', 'Company', 'Company, Limited', 'Computer Repair', 'Incorporated', 'and Sons', 'Group', 'Group, PLC', 'Furniture', 'Flowers', 'Sales', 'Systems', 'Tire', 'Auto', 'Plumbing', 'Roofing', 'Realty', 'Foods', 'Books'];
if (empty($base_name)) {
$base_name = $this->getLastName();
}
return $base_name . ' ' . $this->fromArray($suffixes);
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.