This repository has been archived by the owner on Feb 15, 2018. It is now read-only.
/
index.php
107 lines (97 loc) · 3.06 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Autoload generator
*
* @link http://github.com/dmkuznetsov/php-autoloader
* @copyright Copyright (c) 2012-2013 Dmitry Kuznetsov <kuznetsov2d@gmail.com>
* @license http://raw.github.com/dmkuznetsov/php-autoloader/master/LICENSE.txt New BSD License
*/
require_once dirname(__FILE__) . '/src/Autoload/LogInterface.php';
require_once dirname(__FILE__) . '/src/Autoload/Log.php';
require_once dirname(__FILE__) . '/src/Autoload/Info.php';
require_once dirname( __FILE__ ) . '/src/Autoload.php';
$options = getopt( '', array( 'dir:', 'file:', 'suffix:', 'absolute-path', 'no-verbose', 'help' ) );
if ( array_key_exists( 'help', $options ) )
{
help();
}
checkOptions( $options );
$verbose = !array_key_exists( 'no-verbose', $options );
$relative = !array_key_exists( 'absolute-path', $options );
$options[ 'suffix' ] = isset( $options[ 'suffix' ] ) && !empty( $options[ 'suffix' ] ) ? $options[ 'suffix' ] : rand( 100, 999 );
$log = new \Dm\Utils\Autoload\Log( $verbose );
$log->log( "Start autoload generator" );
$info = new \Dm\Utils\Autoload\Info( $log );
$status = $info->checkFileStatus( $options[ 'file' ] );
if ( $status )
{
$status = $info->checkDirStatus( $options[ 'dir' ] );
}
if ( !$status )
{
exit( "\nCanceled.\n" );
}
if ($relative) {
$log->log("Use relative paths");
} else {
$log->log("Use absolute paths");
}
$classMap = new \Dm\Utils\Autoload( $options[ 'file' ], $options[ 'dir' ], $options[ 'suffix' ], $relative, $log );
$classMap->run();
$classMap->save();
exit( "\n" );
/**
* @param array $options
*/
function checkOptions( array $options )
{
$messages = array();
if ( !array_key_exists( 'file', $options ) )
{
$messages[ ] = 'Please specify file for input data.' . "\n";
}
if ( !array_key_exists( 'dir', $options ) )
{
$messages[ ] = 'Please specify dir for analyze.' . "\n";
}
if ( !empty( $messages ) )
{
array_unshift( $messages, 'ERROR!' );
showMessage( $messages, false );
help();
}
}
function help()
{
$content = array();
$content[] = 'PHP AUTOLOAD GENERATOR';
$content[] = 'Script for generate universal autoload.';
$content[] = 'Support classes, interfaces, namespaces, traits (PHP >= 5.3 required).';
$content[] = '';
$content[] = 'USAGE';
$content[] = 'php autoload.phar --file=/www/project/autoload.php --dir=/www/project/src --suffix="project_name"';
$content[] = '';
$content[] = 'AVAILABLE OPTIONS';
$content[] = '--file - path to your autoload.php';
$content[] = '--dir - path to your project';
$content[] = '--suffix - suffix for autoload function';
$content[] = '--absolute-path - use absolute paths';
$content[] = '--no-verbose - hide log';
$content[] = '--help - show help';
$content[] = '';
$content[] = 'Dmitry Kuznetsov <kuznetsov2d@gmail.com>, 2012-'.date('Y');
$content[] = 'https://github.com/dmkuznetsov/php-autoloader';
showMessage( $content );
}
function showMessage( $message, $stop = true )
{
if ( is_array( $message ) )
{
$message = implode( "\n", $message );
}
echo $message . "\n";
if ( $stop )
{
exit;
}
}