/** * Generates a request based on the current apache variables. * @throws Exception */ public static function generate() { $headers = new Map(apache_request_headers()); $method = $_SERVER['REQUEST_METHOD']; $path = $_SERVER['REQUEST_URI']; switch ($headers->get('Content-Type', null)) { case 'application/json': $data = file_get_contents('php://input'); $values = json_decode($data, true); $params = new Map($values); break; case 'application/x-www-form-urlencoded': $params = new Map($_POST); break; default: if ($method === 'GET') { $params = new Map($_GET); } else { if ($method === 'POST' || $method === 'PUT') { $params = new Map($_POST); } else { $params = new Map(); } } break; } return new Request($path, $method, $headers, $params); }
/** @test */ public function removeAffectsGivenKeyOnly() { $map = new Map(array('foo' => 42, 'bar' => 1337)); $map->remove('foo'); $this->assertFalse($map->hasKey('foo')); $this->assertEquals(1337, $map->get('bar')); }
/** * @param <type> $key * @return Provider */ private function selectTypeOf($key) { if ($this->types->containsKey($key)) { return $this->types->get($key); } return null; }
/** * it sets coordinates of the left up and right down corners of the result map * * @param Map $resultMap */ protected function _setUpResultMapCorners(Map $resultMap) { $leftUpCorner = $this->_mapData->getLeftUpCornerPoint(); $resultMap->setLeftUpCorner($leftUpCorner['lon'], $leftUpCorner['lat']); $rightDownCorner = $this->_mapData->getRightDownCornerPoint(); $resultMap->setRightDownCorner($rightDownCorner['lon'], $rightDownCorner['lat']); }
/** * draw point on map * * @param Map $map */ public function draw(Map $map) { $image = $map->getImage(); $color = $this->_getDrawColor($image); $pointInPixels = $map->getPixelPointFromCoordinates($this->_coordinates['lon'], $this->_coordinates['lat']); imagesetpixel($image, $pointInPixels['x'], $pointInPixels['y'], $color); }
public function testIsDocumentIgnoredDest() { $this->assertTrue($this->map->isDocumentIgnored('dest-document-ignored', MapInterface::TYPE_DEST)); $this->assertTrue($this->map->isDocumentIgnored('dest-document-ignored1', MapInterface::TYPE_DEST)); // Second run to check cached value $this->assertTrue($this->map->isDocumentIgnored('dest-document-ignored', MapInterface::TYPE_DEST)); }
/** * draw line on map * * @param Map $map */ public function draw(Map $map) { $image = $map->getImage(); $startPointInPixels = $map->getPixelPointFromCoordinates($this->_startPoint->getLon(), $this->_startPoint->getLat()); $endPointInPixels = $map->getPixelPointFromCoordinates($this->_endPoint->getLon(), $this->_endPoint->getLat()); $this->_drawLine($image, $startPointInPixels['x'], $startPointInPixels['y'], $endPointInPixels['x'], $endPointInPixels['y']); }
function testPropertyDescriptor() { $name_d1 = 'd1'; $name_d2 = 'd2'; $p = new MockPlugin($this); $pi = new TestPluginInfo($p); $d1 = new MockPropertyDescriptor($this); $d1->setReturnReference('getName', $name_d1); $d2 = new MockPropertyDescriptor($this); $d2->setReturnReference('getName', $name_d2); $d3 = new MockPropertyDescriptor($this); $d3->setReturnReference('getName', $name_d1); $pi->addPropertyDescriptor($d1); $pi->addPropertyDescriptor($d2); $pi->addPropertyDescriptor($d3); $expected = new Map(); $expected->put($name_d2, $d2); $expected->put($name_d1, $d3); $descriptors = $pi->getpropertyDescriptors(); $this->assertTrue($expected->equals($descriptors)); $pi->removePropertyDescriptor($d3); $descriptors = $pi->getpropertyDescriptors(); $this->assertFalse($expected->equals($descriptors)); $this->assertEqual($descriptors->size(), 1); }
/** * method puts image onto map image * * @param Map $map * @param resources $imageToPut */ public function putImage(Map $map, $imageToPut) { $mapImage = $map->getImage(); $width = imagesx($imageToPut); $height = imagesy($imageToPut); imagecopy($mapImage, $imageToPut, imagesx($mapImage) - $width, 0, 0, 0, $width, $height); }
/** * Returns all layers found in a mapfile * * $file [string] : file path */ public function parseFile($file) { if (is_file($file)) { if (substr($file, -4) == '.map') { //create a map object try { $projLib = getenv("PROJ_LIB"); $mapFileContent = $this->fopen_file_get_contents($file); $mapFileContent = preg_replace('/(\\n|^)\\s*MAP\\s*(\\n|#)/', "\$0\nCONFIG PROJ_LIB {$projLib}\n", $mapFileContent, 1); $oMap = ms_newMapObjFromString($mapFileContent, dirname($file)); } catch (Exception $e) { $error = ms_getErrorObj(); throw new Exception($error->message); exit; } $map = new Map($oMap); $m = array(); $mapMetaData = array("wms_onlineresource"); $mapParameters = array("projection"); foreach ($mapMetaData as $metaData) { $m[$metaData] = $map->getMeta($metaData); } foreach ($mapParameters as $parameter) { $m[$parameter] = $map->getParam($parameter); } $layers = $map->parseLayers(); return $this->formatParsingOutput($m, $layers); } else { throw new Exception("Le fichier spécifié n'est pas un mapfile valide."); } } else { throw new Exception("Le fichier n'existe pas."); } }
/** * @param Map $map * @param bool $stopPropagation * @return $this */ public function setMap(Map $map, $stopPropagation = false) { if (!$stopPropagation) { $map->addController($this, true); } $this->map = $map; return $this; }
public function map($input) { $output = null; foreach ($this->map->getMapping() as $mapElement) { $mapElement->map($input, $output); } return $output; }
function getMapCornerPositionsAndRouteCoordinates($id) { $map = new Map(); $map->Load($id); $user = DataAccess::GetUserByID($map->UserID); $categories = DataAccess::GetCategoriesByUserID($user->ID); return Helper::GetOverviewMapData($map, true, false, false, $categories); }
private function setValues(array $years, Map $mapGroupedData, $dualY = false, $setToAxis = false) { $groups = $mapGroupedData->values(); foreach ($groups as $groupedData) { $group = $groupedData; $this->groupValuesByYear($years, $group, $dualY, $setToAxis); } }
public function Execute() { $viewData = array(); // no user specified - redirect to user list page if (!getCurrentUser()) { Helper::Redirect("users.php"); } // user is hidden - redirect to user list page if (!getCurrentUser()->Visible) { Helper::Redirect("users.php"); } // the requested map $map = new Map(); $map->Load($_GET["map"]); if (!$map->ID) { die("The map has been removed."); } DataAccess::UnprotectMapIfNeeded($map); if (Helper::MapIsProtected($map)) { die("The map is protected until " . date("Y-m-d H:i:s", Helper::StringToTime($map->ProtectedUntil, true)) . "."); } if ($map->UserID != getCurrentUser()->ID) { die; } $viewData["Comments"] = DataAccess::GetCommentsByMapId($map->ID); $viewData["Name"] = $map->Name . ' (' . date(__("DATE_FORMAT"), Helper::StringToTime($map->Date, true)) . ')'; // previous map in archive $previous = DataAccess::GetPreviousMap(getCurrentUser()->ID, $map->ID, Helper::GetLoggedInUserID()); $viewData["PreviousName"] = $previous == null ? null : $previous->Name . ' (' . date(__("DATE_FORMAT"), Helper::StringToTime($previous->Date, true)) . ')'; // next map in archive $next = DataAccess::GetNextMap(getCurrentUser()->ID, $map->ID, Helper::GetLoggedInUserID()); $viewData["NextName"] = $next == null ? null : $next->Name . ' (' . date(__("DATE_FORMAT"), Helper::StringToTime($next->Date, true)) . ')'; $size = $map->GetMapImageSize(); $viewData["ImageWidth"] = $size["Width"]; $viewData["ImageHeight"] = $size["Height"]; DataAccess::IncreaseMapViews($map); $viewData["Map"] = $map; $viewData["BackUrl"] = isset($_SERVER["HTTP_REFERER"]) && basename($_SERVER["HTTP_REFERER"]) == "users.php" ? "users.php" : "index.php?" . Helper::CreateQuerystring(getCurrentUser()); $viewData["Previous"] = $previous; $viewData["Next"] = $next; $viewData["ShowComments"] = isset($_GET["showComments"]) && ($_GET["showComments"] = true) || !__("COLLAPSE_VISITOR_COMMENTS"); $viewData["FirstMapImageName"] = Helper::GetMapImage($map); if ($map->BlankMapImage) { $viewData["SecondMapImageName"] = Helper::GetBlankMapImage($map); } $viewData["QuickRouteJpegExtensionData"] = $map->GetQuickRouteJpegExtensionData(); if (isset($viewData["QuickRouteJpegExtensionData"]) && $viewData["QuickRouteJpegExtensionData"]->IsValid) { $categories = DataAccess::GetCategoriesByUserID(getCurrentUser()->ID); $viewData["OverviewMapData"][] = Helper::GetOverviewMapData($map, true, false, false, $categories); $viewData["GoogleMapsUrl"] = "http://maps.google.com/maps" . "?q=" . urlencode(Helper::GlobalPath("export_kml.php?id=" . $map->ID . "&format=kml")) . "&language=" . Session::GetLanguageCode(); } if (USE_3DRERUN == '1' && DataAccess::GetSetting("LAST_WORLDOFO_CHECK_DOMA_TIME", "0") + RERUN_FREQUENCY * 3600 < time()) { $viewData["RerunMaps"] = Helper::GetMapsForRerunRequest(); $viewData["TotalRerunMaps"] = count(explode(",", $viewData["RerunMaps"])); $viewData["ProcessRerun"] = true; } return $viewData; }
public function setData(Map $map) { $leftUp = $map->getLeftUpCorner(); $rightDown = $map->getRightDownCorner(); $this->setLeft($leftUp['lon']); $this->setUp($leftUp['lat']); $this->setRight($rightDown['lon']); $this->setDown($rightDown['lat']); }
public static function run() { if ($_SERVER["REQUEST_METHOD"] == "POST") { $map = new Map($_POST); MapView::show($map->getLocations()); } else { MapView::show(null); } }
/** * it sets coordinates of the left up and right down corners of the result map * * @param Map $resultMap */ protected function _setUpResultMapCorners(Map $resultMap) { $centerPoint = $this->_mapData->getCenterPoint(); $centerPointInPixels = $this->_worldMap->getPixelXY($centerPoint['lon'], $centerPoint['lat']); $leftUpPointInPixels = array('x' => $centerPointInPixels['x'] - round($this->_mapData->getWidth() / 2), 'y' => $centerPointInPixels['y'] - round($this->_mapData->getHeight() / 2)); $resultMap->setLeftUpCorner($this->_worldMap->getLon($leftUpPointInPixels['x']), $this->_worldMap->getLat($leftUpPointInPixels['y'])); $rightDownPointInPixels = array('x' => $centerPointInPixels['x'] + round($this->_mapData->getWidth() / 2), 'y' => $centerPointInPixels['y'] + round($this->_mapData->getHeight() / 2)); $resultMap->setRightDownCorner($this->_worldMap->getLon($rightDownPointInPixels['x']), $this->_worldMap->getLat($rightDownPointInPixels['y'])); }
public function test_letter_frequency() { $words = new Map(['aardvark', 'roads', 'sparks']); $freqs = $words->map(function ($word) { return new MapOfInts(count_chars($word, 1)); })->reduce(function ($totals, $counts) { return $totals->translate($counts); }, new MapOfInts())->rekey('chr($_1)'); $this->assertSame(['a' => 5, 'd' => 2, 'k' => 2, 'r' => 4, 'v' => 1, 'o' => 1, 's' => 3, 'p' => 1], $freqs->toArray()); }
private function writeOnWorkSheet(Map $groupedValues, ExcelOutputFile $spreadSheet, array $years, $index = 0) { if (!$groupedValues->isEmpty()) { parent::titles($years); parent::addValuesToARow($groupedValues, $years); $spreadSheet->setNewDataToExcel($this->dataToExcel); $nameGroup = $groupedValues->get(0)->offsetGet(0)->getSubgroupName(); $spreadSheet->buildSpreadSheet($nameGroup, $index); } }
public function testFilteredValue() { $map = new Map(); $map->add(Path::factory('/test/description', 'desc')->setDefault('value')->filter(function ($val) { return strrev($val); })); $result = $map->execute($this->object); $this->assertTrue(is_array($result)); $this->assertArrayHasKey('desc', $result); $this->assertEquals(strrev("test description"), $result['desc']); }
protected function addValuesToARow(Map $values, array $years) { $list = $values->values(); $groupsNumber = $list->count(); for ($i = 0; $i < $groupsNumber; $i++) { $group = $list->offsetGet($i); $data = $group->offsetGet(0); $this->setValues($group, $data, $years); } $this->config(); }
public function testWrongPath() { $map = new Map(); $map->add(Path::factory('/test', 'test')->addChildren(Path::factory('wrong>path', 'wrong', 'defaultFalse'))); $result = $map->execute(new XmlFile(__DIR__ . '/test.xml')); $this->assertTrue(is_array($result)); $this->assertArrayHasKey('test', $result); $this->assertTrue(is_array($result['test'])); $this->assertArrayHasKey('wrong', $result['test']); $this->assertEquals('defaultFalse', $result['test']['wrong']); }
/** * {@inheritdoc} */ public function build(SetInterface $identities, ServerRequestInterface $request, HttpResource $definition, SpecificationInterface $specification = null, Range $range = null) : MapInterface { $map = new Map('string', HeaderInterface::class); if ($identities->size() === 0) { return $map; } $path = $request->url()->path(); return $map->put('Link', new Link($identities->reduce(new Set(HeaderValueInterface::class), function (Set $carry, IdentityInterface $identity) use($path) : Set { return $carry->add(new LinkValue(Url::fromString(rtrim((string) $path, '/') . '/' . $identity), 'resource', new Map('string', ParameterInterface::class))); }))); }
private function concatAnythingToStatement($anything) { $statements = $this->statements->values(); $attributesToSelect = ""; foreach ($statements as $statement) { if ($statement[$anything] != "") { $attributesToSelect .= " " . $statement[$anything]; } } return $attributesToSelect; }
/** * @param array $mapSchema * @return Map */ public static function create(array $mapSchema) { $map = new Map(); foreach ($mapSchema as $key => $value) { $tags = []; if (strpos($key, ':') !== false) { list($key, $tags) = explode(':', $key); $tags = self::normaliseTags($tags); } $map->add(new MapItem($key, $value, $tags)); } return $map; }
private function removeDuplicates(Map $images, Map $figures) : Map { $urls = $figures->reduce(new Set(UrlInterface::class), function (Set $urls, UrlInterface $url) : Set { return $urls->add($url); }); $urls = $images->reduce($urls, function (Set $urls, UrlInterface $url) : Set { return $urls->add($url); }); $urls = (new RemoveDuplicatedUrls())($urls); return $figures->merge($images)->filter(function (UrlInterface $url) use($urls) : bool { return $urls->contains($url); }); }
/** * Creates a new map from two arrays of instances. * * @param array $Instances The array of objects to map. * @param array $ToInstances The array of object to map to. * @return \Storm\Core\Containers\Map The created map * @throws \Storm\Core\StormException If the amount of instances is not equal to the amount of to instances */ public static function From(array $Instances, array $ToInstances) { if (count($Instances) !== count($ToInstances)) { throw new \Storm\Core\StormException('Lengths of supplied arrays must be equal: %d != %d', count($Instances), count($ToInstances)); } $Map = new Map(); $InstancesUnkeyed = array_values($Instances); $ToInstancesUnkeyed = array_values($ToInstances); foreach ($InstancesUnkeyed as $Key => $Instance) { $Map->MapNew($Instance, $ToInstancesUnkeyed[$Key]); } return $Map; }
/** * it draws object on map * * @param Map $map */ public function draw(Map $map) { $points = array(); $count = 0; foreach ($this->_points as $point) { $coordinates = $map->getPixelPointFromCoordinates($point->getLon(), $point->getLat()); $points[] = $coordinates['x']; $points[] = $coordinates['y']; $count++; } if ($count < 3) { return; } imagefilledpolygon($map->getImage(), $points, $count, $this->_getDrawColor($map->getImage())); }
/** * (non-PHPdoc) * @see \scipper\Datatransfer\TransferService::generateEmptyDocument() */ public function generateDocument(Map $map) { if (!class_exists("PHPExcel")) { throw new GenerationException("dependency 'PHPExcel' not found"); } $excel = new \PHPExcel(); $excel->removeSheetByIndex(0); $excel->getProperties()->setCreator($map->getCreator()); $excel->getProperties()->setTitle($map->getTitle()); $protectedStyle = new \PHPExcel_Style(); $protectedStyle->applyFromArray(array("fill" => array("type" => \PHPExcel_Style_Fill::FILL_SOLID, "color" => array("argb" => "55CCCCCC")), "borders" => array("bottom" => array("style" => \PHPExcel_Style_Border::BORDER_THIN), "right" => array("style" => \PHPExcel_Style_Border::BORDER_MEDIUM)))); $i = 0; foreach ($map->getSheets() as $sheet) { $active = $excel->addSheet(new \PHPExcel_Worksheet(NULL, $sheet->getTitle()), $i); $active->getProtection()->setSheet(true); $active->getStyle("A1:Z30")->getProtection()->setLocked(\PHPExcel_Style_Protection::PROTECTION_UNPROTECTED); foreach ($sheet->getCells() as $cell) { //Convert content to list format ist necessary if ($cell->getType() == "select") { $dataValidation = $active->getCell($cell->getCoord())->getDataValidation(); $dataValidation->setType(\PHPExcel_Cell_DataValidation::TYPE_LIST); $dataValidation->setAllowBlank(false); $dataValidation->setShowInputMessage(true); $dataValidation->setShowDropDown(true); $dataValidation->setFormula1($cell->getContent()); } else { $active->setCellValue($cell->getCoord(), $cell->getValue()); } //Add protection is necessary if ($cell->isProtected()) { $active->protectCells($cell->getCoord(), "123"); $active->setSharedStyle($protectedStyle, $cell->getCoord()); // } elseif(!$cell->isProtected() && $active->getProtection()->isProtectionEnabled()) { // $active->unprotectCells($cell->getCoord()); } $active->getColumnDimension($cell->getX())->setAutoSize(true); if (!$cell->isVisible()) { $active->getColumnDimension($cell->getX())->setVisible(false); } } $i++; } $excel->setActiveSheetIndex(0); $writer = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007'); $filename = $this->documentRoot . $excel->getProperties()->getTitle() . ".xlsx"; $writer->save($filename); return $filename; }