MapFile PHP Library
♻️ Version 2.0
PHP Library to read/write MapServer mapfiles.
This library is based on MapServer 7.2.0 documentation (last updated on 16 June 2017).
composer require jbelien/mapfile-php-library
$map = new MapFileModelMap();
$map->name = 'my-mapfile';
$map->projection = 'EPSG:4326';
$map->scalebar = new MapFileModelScalebar();
$map->scalebar->units = 'kilometers';
$layer = new MapFileModelLayer();
$layer->name = 'my-layer';
$layer->type = 'POLYGON';
$layer->status = 'ON';
$layer->data = 'my-shapefile';
$layer->projection = 'EPSG:4326';
$class = new MapFileModelLayerClass();
$style = new MapFileModelStyle();
$style->color = [0, 0, 0];
$class->style->add($style);
$label = new MapFileModelLabel();
$label->text = '[label]';
$label->color = [0, 0, 0];
$label->size = 12;
$class->label->add($label);
$layer->class->add($class);
$map->layer->add($layer);
(new MapFileWriterMap($map))->save('my-mapfile.map');
Have a look at the source code to see all the available options.
$map = (new MapFileParserMap())->parse('my-mapfile.map');
foreach ($map->layer as $layer) {
echo $layer->name;
}