Skip to content

Commit

Permalink
Closes #12: Added class map.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesiarmes committed Nov 28, 2016
1 parent 1390cca commit 371cc95
Show file tree
Hide file tree
Showing 6 changed files with 889 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -8,6 +8,10 @@ changes to your fork in a separate branch that you would then use for the pull
request. All contributions should follow the
[PSR-2](http://www.php-fig.org/psr/psr-2/) coding standard.

If you add, remove or rename any classes used in the formation of a request or
response, be sure to run script/build-classmap.php to rebuild the ClassMap
class.

## Contributing Documentation
See the
[contributing documentation](https://github.com/jamesiarmes/php-ews/blob/gh-pages/CONTRIBUTING.md)
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Expand Up @@ -15,6 +15,9 @@
"php": ">=5.3.9",
"ext-soap": "*"
},
"require-dev": {
"mustache/mustache": "~2.0"
},
"config": {
"bin-dir": "bin"
},
Expand Down
59 changes: 59 additions & 0 deletions script/build-classmap.php
@@ -0,0 +1,59 @@
#!/usr/bin/env php
<?php
/**
* Builds the SOAP classmap.
*
* @todo Ensure that StringType maps to String.
* @todo Determine how to handle duplicate keys in the resulting class map.
*/

// Define source code paths.
$base_path = dirname(__DIR__);
$src_path = "$base_path/src/jamesiarmes/PhpEws";

require_once "$base_path/vendor/autoload.php";

// Defines overrides for any files that had to be renamed to avoid reserved
// words.
$overrides = array(
'Type\\\StringType' => 'String',
);

// Iterate over the different type namespaces, building out the mapping for
// each.
$map = array();
foreach (array('ArrayType', 'Enumeration', 'Request', 'Response', 'Type') as $namespace) {
$i = count($map);
$map[$i] = array('namespace' => $namespace, 'map' => array());

// Iterate over the files for this namespace, adding each to the map.
foreach (new DirectoryIterator("$src_path/$namespace") as $file) {
if ($file->isDot()) {
continue;
}

// If there is an override for this class, rename the base name to
// match.
$classname = $basename = basename($file, '.php');
if (isset($overrides["$namespace\\\\$basename"])) {
$basename = $overrides["$namespace\\\\$basename"];
}

$map[$i]['map'][] = array(
'type' => $basename,
'class' => "\\\\jamesiarmes\\\\PhpEws\\\\$namespace\\\\$classname",
);
}
}

// Load and render the template.
$engine = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader($base_path . '/templates')
));
$template = $engine->loadTemplate('ClassMap');
file_put_contents(
"$src_path/ClassMap.php",
$template->render(array('maps' => $map))
);

fwrite(STDOUT, "Class map written to \"$src_path/ClassMap.php\".\n");

0 comments on commit 371cc95

Please sign in to comment.