Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue fix code structure #1329

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix code structure
  • Loading branch information
abhijitrakas committed Nov 29, 2018
commit 30dd6d0f5340f7af76e04e387723a9e78f774968
4 changes: 3 additions & 1 deletion php/EE/Bootstrap/AutoloaderStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EE\Bootstrap;

use EE;

/**
* Abstract class AutoloaderStep.
*
Expand Down Expand Up @@ -42,7 +44,7 @@ public function process( BootstrapState $state ) {
require $autoloader_path;
$found_autoloader = true;
} catch ( \Exception $exception ) {
\EE::warning(
EE::warning(
"Failed to load autoloader '{$autoloader_path}'. Reason: "
. $exception->getMessage()
);
Expand Down
6 changes: 4 additions & 2 deletions php/EE/Bootstrap/IncludePackageAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EE\Bootstrap;

use EE;

/**
* Class IncludePackageAutoloader.
*
Expand Down Expand Up @@ -33,7 +35,7 @@ protected function get_autoloader_paths() {
$autoloader_path = $runner()->get_packages_dir_path() . 'vendor/autoload.php';

if ( is_readable( $autoloader_path ) ) {
\EE::debug(
EE::debug(
'Loading packages from: ' . $autoloader_path,
'bootstrap'
);
Expand All @@ -52,6 +54,6 @@ protected function get_autoloader_paths() {
* @return void
*/
protected function handle_failure() {
\EE::debug( 'No package autoload found to load.', 'bootstrap' );
EE::debug( 'No package autoload found to load.', 'bootstrap' );
}
}
4 changes: 3 additions & 1 deletion php/EE/Bootstrap/InitializeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EE\Bootstrap;

use DirectoryIterator;

/**
* Class InitializeLogger.
*
Expand Down Expand Up @@ -31,7 +33,7 @@ public function process( BootstrapState $state ) {
*/
private function declare_loggers() {
$logger_dir = EE_ROOT . '/php/EE/Loggers';
$iterator = new \DirectoryIterator( $logger_dir );
$iterator = new DirectoryIterator( $logger_dir );

// Make sure the base class is declared first.
include_once "$logger_dir/Base.php";
Expand Down
8 changes: 5 additions & 3 deletions php/EE/Bootstrap/RegisterDeferredCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EE\Bootstrap;

use EE;

/**
* Class RegisterDeferredCommands.
*
Expand All @@ -27,7 +29,7 @@ public function process( BootstrapState $state ) {

// Process deferred command additions for commands added through
// plugins.
\EE::add_hook(
EE::add_hook(
'find_command_to_run_pre',
array( $this, 'add_deferred_commands' )
);
Expand All @@ -39,10 +41,10 @@ public function process( BootstrapState $state ) {
* Add deferred commands that are still waiting to be processed.
*/
public function add_deferred_commands() {
$deferred_additions = \EE::get_deferred_additions();
$deferred_additions = EE::get_deferred_additions();

foreach ( $deferred_additions as $name => $addition ) {
\EE::add_command(
EE::add_command(
$name,
$addition['callable'],
$addition['args']
Expand Down
7 changes: 5 additions & 2 deletions php/EE/Bootstrap/RegisterFrameworkCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace EE\Bootstrap;

use DirectoryIterator;
use EE;

/**
* Class RegisterFrameworkCommands.
*
Expand All @@ -21,7 +24,7 @@ final class RegisterFrameworkCommands implements BootstrapStep {
public function process( BootstrapState $state ) {
$cmd_dir = EE_ROOT . '/php/commands';

$iterator = new \DirectoryIterator( $cmd_dir );
$iterator = new DirectoryIterator( $cmd_dir );

foreach ( $iterator as $filename ) {
if ( '.php' !== substr( $filename, - 4 ) ) {
Expand All @@ -31,7 +34,7 @@ public function process( BootstrapState $state ) {
try {
include_once "$cmd_dir/$filename";
} catch ( \Exception $exception ) {
\EE::warning(
EE::warning(
"Could not add command {$cmd_dir}/{$filename}. Reason: " . $exception->getMessage()
);
}
Expand Down
4 changes: 3 additions & 1 deletion php/EE/Bootstrap/RunnerInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EE\Bootstrap;

use EE;

/**
* Class RunnerInstance.
*
Expand All @@ -27,6 +29,6 @@ public function __invoke() {
require_once EE_ROOT . '/php/EE/Configurator.php';
}

return \EE::get_runner();
return EE::get_runner();
}
}
12 changes: 7 additions & 5 deletions php/EE/Completions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EE;

use EE;

class Completions {

private $words;
Expand Down Expand Up @@ -52,7 +54,7 @@ public function __construct( $line ) {
if ( $command->can_have_subcommands() ) {
// add completion when command is `ee` and alias isn't set.
if ( 'ee' === $command->get_name() && false === $is_alias && false == $is_help ) {
$aliases = \EE::get_configurator()->get_aliases();
$aliases = EE::get_configurator()->get_aliases();
foreach ( $aliases as $name => $_ ) {
$this->add( "$name " );
}
Expand Down Expand Up @@ -109,9 +111,9 @@ private function get_command( $words ) {
}
}

$r = \EE::get_runner()->find_command_to_run( $positional_args );
$r = EE::get_runner()->find_command_to_run( $positional_args );
if ( ! is_array( $r ) && array_pop( $positional_args ) == $this->cur_word ) {
$r = \EE::get_runner()->find_command_to_run( $positional_args );
$r = EE::get_runner()->find_command_to_run( $positional_args );
}

if ( ! is_array( $r ) ) {
Expand All @@ -125,7 +127,7 @@ private function get_command( $words ) {

private function get_global_parameters() {
$params = array();
foreach ( \EE::get_configurator()->get_spec() as $key => $details ) {
foreach ( EE::get_configurator()->get_spec() as $key => $details ) {
if ( false === $details['runtime'] ) {
continue;
}
Expand Down Expand Up @@ -160,7 +162,7 @@ private function add( $opt ) {

public function render() {
foreach ( $this->opts as $opt ) {
\EE::line( $opt );
EE::line( $opt );
}
}
}
7 changes: 4 additions & 3 deletions php/EE/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace EE;

use Mustangostang\Spyc;
use EE\Utils;

/**
* Handles file- and runtime-based configuration values.
Expand Down Expand Up @@ -276,7 +277,7 @@ public function merge_array( $config ) {
$value = $config[ $key ];

if ( 'require' == $key ) {
$value = \EE\Utils\expand_globs( $value );
$value = Utils\expand_globs( $value );
}

if ( $details['multiple'] ) {
Expand Down Expand Up @@ -311,7 +312,7 @@ private static function load_yml( $yml_file ) {

if ( isset( $config['require'] ) ) {
self::arrayify( $config['require'] );
$config['require'] = \EE\Utils\expand_globs( $config['require'] );
$config['require'] = Utils\expand_globs( $config['require'] );
foreach ( $config['require'] as &$path ) {
self::absolutize( $path, $yml_file_dir );
}
Expand All @@ -336,7 +337,7 @@ private static function arrayify( &$val ) {
* @param string $base Base path to prepend.
*/
private static function absolutize( &$path, $base ) {
if ( ! empty( $path ) && ! \EE\Utils\is_path_absolute( $path ) ) {
if ( ! empty( $path ) && ! Utils\is_path_absolute( $path ) ) {
$path = $base . DIRECTORY_SEPARATOR . $path;
}
}
Expand Down
33 changes: 19 additions & 14 deletions php/EE/Dispatcher/CommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace EE\Dispatcher;

use EE;
use ReflectionFunction;
use ReflectionClass;
use EE\DocParser;

/**
* Creates CompositeCommand or Subcommand instances.
*
Expand All @@ -23,16 +28,16 @@ public static function create( $name, $callable, $parent ) {

if ( ( is_object( $callable ) && ( $callable instanceof \Closure ) )
|| ( is_string( $callable ) && function_exists( $callable ) ) ) {
$reflection = new \ReflectionFunction( $callable );
$reflection = new ReflectionFunction( $callable );
$command = self::create_subcommand( $parent, $name, $callable, $reflection );
} elseif ( is_array( $callable ) && is_callable( $callable ) ) {
$reflection = new \ReflectionClass( $callable[0] );
$reflection = new ReflectionClass( $callable[0] );
$command = self::create_subcommand(
$parent, $name, array( $callable[0], $callable[1] ),
$reflection->getMethod( $callable[1] )
);
} else {
$reflection = new \ReflectionClass( $callable );
$reflection = new ReflectionClass( $callable );
if ( $reflection->isSubclassOf( '\EE\Dispatcher\CommandNamespace' ) ) {
$command = self::create_namespace( $parent, $name, $callable );
} elseif ( $reflection->hasMethod( '__invoke' ) ) {
Expand Down Expand Up @@ -74,7 +79,7 @@ private static function create_subcommand( $parent, $name, $callable, $reflectio
$inherited_method = $reflection->getDeclaringClass()->getParentClass()->getMethod( $reflection->name );

$doc_comment = self::get_doc_comment( $inherited_method );
$docparser = new \EE\DocParser( $doc_comment );
$docparser = new DocParser( $doc_comment );
}

if ( is_array( $callable ) ) {
Expand All @@ -87,7 +92,7 @@ private static function create_subcommand( $parent, $name, $callable, $reflectio
}
}
if ( ! $doc_comment ) {
\EE::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' );
EE::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' );
}

$when_invoked = function ( $args, $assoc_args ) use ( $callable ) {
Expand All @@ -110,12 +115,12 @@ private static function create_subcommand( $parent, $name, $callable, $reflectio
* @param mixed $callable
*/
private static function create_composite_command( $parent, $name, $callable ) {
$reflection = new \ReflectionClass( $callable );
$reflection = new ReflectionClass( $callable );
$doc_comment = self::get_doc_comment( $reflection );
if ( ! $doc_comment ) {
\EE::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' );
EE::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' );
}
$docparser = new \EE\DocParser( $doc_comment );
$docparser = new DocParser( $doc_comment );

$container = new CompositeCommand( $parent, $name, $docparser );

Expand Down Expand Up @@ -144,12 +149,12 @@ private static function create_composite_command( $parent, $name, $callable ) {
* @param mixed $callable
*/
private static function create_namespace( $parent, $name, $callable ) {
$reflection = new \ReflectionClass( $callable );
$reflection = new ReflectionClass( $callable );
$doc_comment = self::get_doc_comment( $reflection );
if ( ! $doc_comment ) {
\EE::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' );
EE::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' );
}
$docparser = new \EE\DocParser( $doc_comment );
$docparser = new DocParser( $doc_comment );

return new CommandNamespace( $parent, $name, $docparser );
}
Expand All @@ -169,12 +174,12 @@ private static function is_good_method( $method ) {
* @param ReflectionMethod $reflection
*/
private static function get_inherited_docparser( $doc_comment, $reflection ) {
$docparser = new \EE\DocParser( $doc_comment );
$docparser = new DocParser( $doc_comment );
while ( $docparser->has_tag( 'inheritdoc' ) ) {
$inherited_method = $reflection->getDeclaringClass()->getParentClass()->getMethod( $reflection->name );

$doc_comment = self::get_doc_comment( $inherited_method );
$docparser = new \EE\DocParser( $doc_comment );
$docparser = new DocParser( $doc_comment );
}

return $docparser;
Expand Down Expand Up @@ -216,7 +221,7 @@ private static function get_doc_comment( $reflection ) {
} elseif ( is_readable( $filename ) && ( $contents = file_get_contents( $filename ) ) ) {
self::$file_contents[ $filename ] = $contents = explode( "\n", $contents );
} else {
\EE::debug( "Could not read contents for filename '{$filename}'.", 'commandfactory' );
EE::debug( "Could not read contents for filename '{$filename}'.", 'commandfactory' );
return null;
}

Expand Down
8 changes: 4 additions & 4 deletions php/EE/Dispatcher/CommandNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function show_usage() {
foreach ( $methods as $name => $subcommand ) {
$prefix = ( 0 == $i++ ) ? 'usage: ' : ' or: ';

if ( \EE::get_runner()->is_command_disabled( $subcommand ) ) {
if ( EE::get_runner()->is_command_disabled( $subcommand ) ) {
continue;
}

\EE::line( $subcommand->get_usage( $prefix ) );
EE::line( $subcommand->get_usage( $prefix ) );
$count++;
}

Expand All @@ -43,8 +43,8 @@ public function show_usage() {
? "See 'ee help $cmd_name <command>' for more information on a specific command."
: "The namespace $cmd_name does not contain any usable commands in the current context.";

\EE::line();
\EE::line( $message );
EE::line();
EE::line( $message );

}
}
13 changes: 7 additions & 6 deletions php/EE/Dispatcher/CompositeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace EE\Dispatcher;

use \EE\Utils;
use EE;

/**
* A non-leaf node in the command tree.
Expand Down Expand Up @@ -34,7 +35,7 @@ public function __construct( $parent, $name, $docparser ) {

$when_to_invoke = $docparser->get_tag( 'when' );
if ( $when_to_invoke ) {
\EE::get_runner()->register_early_invoke( $when_to_invoke, $this );
EE::get_runner()->register_early_invoke( $when_to_invoke, $this );
}
}

Expand Down Expand Up @@ -177,17 +178,17 @@ public function show_usage() {
foreach ( $methods as $name => $subcommand ) {
$prefix = ( 0 == $i++ ) ? 'usage: ' : ' or: ';

if ( \EE::get_runner()->is_command_disabled( $subcommand ) ) {
if ( EE::get_runner()->is_command_disabled( $subcommand ) ) {
continue;
}

\EE::line( $subcommand->get_usage( $prefix ) );
EE::line( $subcommand->get_usage( $prefix ) );
}

$cmd_name = implode( ' ', array_slice( get_path( $this ), 1 ) );

\EE::line();
\EE::line( "See 'ee help $cmd_name <command>' for more information on a specific command." );
EE::line();
EE::line( "See 'ee help $cmd_name <command>' for more information on a specific command." );
}

/**
Expand Down Expand Up @@ -272,7 +273,7 @@ protected function get_global_params( $root_command = false ) {
$binding['is_subcommand'] = true;
}

foreach ( \EE::get_configurator()->get_spec() as $key => $details ) {
foreach ( EE::get_configurator()->get_spec() as $key => $details ) {
if ( false === $details['runtime'] ) {
continue;
}
Expand Down
Loading