Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #816 from weierophinney/hotfix/remove-zfals

Remove zfals.php
  • Loading branch information...
commit e1a670c9b535035079ab4bca8a741f8047e615e1 2 parents e17fb72 + b88a85f
Rob Allen authored February 23, 2012

Showing 1 changed file with 0 additions and 154 deletions. Show diff stats Hide diff stats

  1. 154  bin/zfals.php
154  bin/zfals.php
... ...
@@ -1,154 +0,0 @@
1  
-<?php
2  
-$libPath = __DIR__ . '/../library';
3  
-if (!is_dir($libPath)) {
4  
-    echo "Unable to find Zend Framework library; aborting" . PHP_EOL;
5  
-    exit(2);
6  
-}
7  
-$libPath  = realpath($libPath);
8  
-
9  
-// Add ZF to the include_path, if it isn't already
10  
-$incPath = get_include_path();
11  
-if (!strstr($incPath, $libPath)) {
12  
-    set_include_path($libPath . PATH_SEPARATOR . $incPath);
13  
-}
14  
-
15  
-// Setup autoloading
16  
-require_once 'Zend/Loader/StandardAutoloader.php';
17  
-
18  
-$loader = new Zend\Loader\StandardAutoloader();
19  
-$loader->register();
20  
-
21  
-$rules = array(
22  
-    'help|h'        => 'Get usage message',
23  
-    'library|l-s'   => 'Library to parse; if none provided, assumes current directory',
24  
-    'namespace|n-s' => 'Namespace in which to create map; by default, uses last segment of library directory name',
25  
-    'output|o-s'    => 'Where to write autoload file; if not provided, assumes "_autoload.php" in library directory',
26  
-    'overwrite|w'   => 'Whether or not to overwrite existing autoload file',
27  
-    'keepdepth|k-i' => 'How many additional segments of the library path to keep in the generated classfile map',
28  
-    'usedir|d'      => 'Prepend filenames with __DIR__',
29  
-);
30  
-
31  
-try {
32  
-    $opts = new Zend\Console\Getopt($rules);
33  
-    $opts->parse();
34  
-} catch (Zend\Console\Getopt\Exception $e) {
35  
-    echo $e->getUsageMessage();
36  
-    exit(2);
37  
-}
38  
-
39  
-if ($opts->getOption('h')) {
40  
-    echo $opts->getUsageMessage();
41  
-    exit();
42  
-}
43  
-
44  
-$path = $libPath;
45  
-if (array_key_exists('PWD', $_SERVER)) {
46  
-    $path = $_SERVER['PWD'];
47  
-}
48  
-if (isset($opts->l)) {
49  
-    $path = $opts->l;
50  
-    if (!is_dir($path)) {
51  
-        echo "Invalid library directory provided" . PHP_EOL . PHP_EOL;
52  
-        echo $opts->getUsageMessage();
53  
-        exit(2);
54  
-    }
55  
-    $path = realpath($path);
56  
-}
57  
-
58  
-$namespace = substr($path, strrpos($path, DIRECTORY_SEPARATOR) + 1);
59  
-if (isset($opts->n)) {
60  
-    $tmp = $opts->n;
61  
-    if (!empty($tmp)) {
62  
-        if (!preg_match('#^[a-z][a-z0-9]*(\\\\[a-z][a-z[0-9_]])*#', $tmp)) {
63  
-            echo "Invalid namespace provided; aborting." . PHP_EOL
64  
-                . PHP_EOL
65  
-                . $opts->getUsageMessage();
66  
-            exit(2);
67  
-        }
68  
-        $namespace = $tmp;
69  
-    }
70  
-}
71  
-
72  
-$usingStdout = false;
73  
-$output = $path . DIRECTORY_SEPARATOR . '_autoload.php';
74  
-if (isset($opts->o)) {
75  
-    $output = $opts->o;
76  
-    if ('-' == $output) {
77  
-        $output = STDOUT;
78  
-        $usingStdout = true;
79  
-    } elseif (!is_writeable(dirname($output))) {
80  
-        echo "Cannot write to '$output'; aborting." . PHP_EOL
81  
-            . PHP_EOL
82  
-            . $opts->getUsageMessage();
83  
-        exit(2);
84  
-    } elseif (file_exists($output)) {
85  
-        if (!$opts->getOption('w')) {
86  
-            echo "Autoload file already exists at '$output'," . PHP_EOL
87  
-                . "but 'overwrite' flag was not specified; aborting." . PHP_EOL 
88  
-                . PHP_EOL
89  
-                . $opts->getUsageMessage();
90  
-            exit(2);
91  
-        }
92  
-    }
93  
-}
94  
-
95  
-$strip     = $path;
96  
-$keepDepth = 0;
97  
-if (isset($opts->k)) {
98  
-    $keepDepth = $opts->k;
99  
-    if ($keepDepth < 0) {
100  
-        $keepDepth = 0;
101  
-    }
102  
-}
103  
-if ($keepDepth > 0) {
104  
-    $segments = explode(DIRECTORY_SEPARATOR, $path);
105  
-    do {
106  
-        array_pop($segments);
107  
-        --$keepDepth;
108  
-    } while (count($segments) > 0 && $keepDepth > 0);
109  
-    $strip = implode(DIRECTORY_SEPARATOR, $segments);
110  
-}
111  
-
112  
-$prefixWithDir = $opts->getOption('d');
113  
-
114  
-if (!$usingStdout) {
115  
-    echo "Creating class file map for library in '$path'..." . PHP_EOL;
116  
-}
117  
-
118  
-// Get the ClassFileLocator, and pass it the library path
119  
-$l = new \Zend\File\ClassFileLocator($path);
120  
-
121  
-// Iterate over each element in the path, and create a map of 
122  
-// classname => filename, where the filename is relative to the library path
123  
-$map    = new \stdClass;
124  
-$strip .= DIRECTORY_SEPARATOR;
125  
-foreach ($l as $file) {
126  
-    $namespace = empty($file->namespace) ? '' : $file->namespace . '\\';
127  
-    $filename  = str_replace($strip, '', $file->getRealPath());
128  
-
129  
-    $map->{$namespace . $file->classname} = $filename;
130  
-}
131  
-
132  
-// Create a file with the class/file map.
133  
-// Stupid syntax highlighters make separating < from PHP declaration necessary
134  
-$map     = var_export((array) $map, true);
135  
-$content =<<<EOT
136  
-<?php
137  
-namespace $namespace;
138  
-\$_map = $map;
139  
-spl_autoload_register(function(\$class) use (\$_map) {
140  
-    if (array_key_exists(\$class, \$_map)) {
141  
-        require_once \$_map[\$class];
142  
-    }
143  
-});
144  
-EOT;
145  
-
146  
-// If requested to prefix with __DIR__, modify the content
147  
-if ($prefixWithDir) {
148  
-    $content = preg_replace('#(=> )#', '$1__DIR__ . DIRECTORY_SEPARATOR . ', $content);
149  
-}
150  
-file_put_contents($output, $content);
151  
-
152  
-if (!$usingStdout) {
153  
-    echo "Wrote autoload file to '" . realpath($output) . "'" . PHP_EOL;
154  
-}

0 notes on commit e1a670c

Please sign in to comment.
Something went wrong with that request. Please try again.