Skip to content

Instantly share code, notes, and snippets.

@sasezaki
Created January 12, 2012 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sasezaki/1601031 to your computer and use it in GitHub Desktop.
Save sasezaki/1601031 to your computer and use it in GitHub Desktop.
Idea - to get zf2 autoload_classmap.php by theseer's Autoload(phpab)
<?php
return array(
___CLASSLIST___
);
$phpab -n -t autoload_classmap.tpl --indent 4 --file-prefix "__DIR__." . > autoload_classmap.php
diff --git src/autoloadbuilder.php src/autoloadbuilder.php
index 32967bb..8938069 100644
--- src/autoloadbuilder.php
+++ src/autoloadbuilder.php
@@ -60,6 +60,12 @@ namespace TheSeer\Autoload {
protected $baseDir;
/**
+ *
+ * @var string
+ */
+ protected $filePrefix = '';
+
+ /**
* Indenting char(s)
*
* @var string
@@ -172,6 +178,17 @@ namespace TheSeer\Autoload {
}
/**
+ * Setter for prefix each file path
+ *
+ * @param string $fileprefix
+ *
+ * @return void
+ */
+ public function setFilePrefix($filePrefix) {
+ $this->filePrefix = $filePrefix;
+ }
+
+ /**
* Overwrite default or previously set indenting option
*
* @param string $indent Char(s) to use for indenting
@@ -271,9 +288,10 @@ namespace TheSeer\Autoload {
*/
public function render() {
$entries = array();
+ $prefix = $this->filePrefix;
foreach($this->classes as $class => $file) {
$fname = $this->resolvePath($file);
- $entries[] = "'$class' => '$fname'";
+ $entries[] = "'$class' => $prefix'$fname'";
}
$baseDir = '';
@@ -310,4 +328,4 @@ namespace TheSeer\Autoload {
}
-}
\ No newline at end of file
+}
diff --git src/cli.php src/cli.php
index cd06481..e53106d 100644
--- src/cli.php
+++ src/cli.php
@@ -116,6 +116,11 @@ namespace TheSeer\Autoload {
'', 'indent', \ezcConsoleInput::TYPE_STRING, null, false,
'String used for indenting (default: 3 spaces)'
));
+
+ $input->registerOption( new \ezcConsoleOption(
+ '', 'file-prefix', \ezcConsoleInput::TYPE_STRING, null, false,
+ 'Prefix for each file line (default: "")'
+ ));
$lintOption = $input->registerOption( new \ezcConsoleOption(
'', 'lint', \ezcConsoleInput::TYPE_NONE, null, false,
@@ -307,6 +312,10 @@ namespace TheSeer\Autoload {
$args = $input->getArguments();
$ab->setBaseDir(realpath($args[0]));
}
+ $fileprefix = $input->getOption('file-prefix');
+ if ($fileprefix->value) {
+ $ab->setFilePrefix($fileprefix->value);
+ }
$template = $input->getOption('template');
if ($template->value) {
@@ -480,6 +489,7 @@ Usage: phpab [switches] <directory>
--format Dateformat string for timestamp
--linebreak Linebreak style (CR, CRLF or LF, default: LF)
--indent String used for indenting or number of spaces (default: 16 (compat 12) spaces)
+ --file-prefix Prefix for each file path
--tolerant Ignore Class Redeclarations in the same file
@sasezaki
Copy link
Author

Currently, phpab seems not has option sorting by dirname.

above result is..

<?php
return array(
    'ZendDeveloperTools\\Controller\\DeveloperToolsController' => __DIR__.'/src/ZendDeveloperTools/Controller/DeveloperToolsController.php',
    'ZendDeveloperTools\\Module' => __DIR__.'/Module.php',
    'ZendDeveloperTools\\Service\\DeveloperTools' => __DIR__.'/src/ZendDeveloperTools/Service/DeveloperTools.php',
    'ZendDeveloperTools\\View\\Listener' => __DIR__.'/src/ZendDeveloperTools/View/Listener.php'
);

vs

https://github.com/zendframework/ZendDeveloperTools/blob/master/autoload_classmap.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment