Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
fc927aa6
Commit
fc927aa6
authored
Feb 07, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaning up artisan.
parent
007863a6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
66 deletions
+90
-66
artisan.php
laravel/cli/artisan.php
+1
-1
command.php
laravel/cli/command.php
+89
-12
console.php
laravel/cli/console.php
+0
-53
No files found.
laravel/cli/artisan.php
View file @
fc927aa6
...
...
@@ -15,7 +15,7 @@ Bundle::start(DEFAULT_BUNDLE);
* retrieve them from the various parts of the CLI code. We can use
* the Request class to access them conveniently.
*/
list
(
$arguments
,
$_SERVER
[
'CLI'
])
=
Co
nsole
::
options
(
$_SERVER
[
'argv'
]);
list
(
$arguments
,
$_SERVER
[
'CLI'
])
=
Co
mmand
::
options
(
$_SERVER
[
'argv'
]);
$_SERVER
[
'CLI'
]
=
array_change_key_case
(
$_SERVER
[
'CLI'
],
CASE_UPPER
);
...
...
laravel/cli/command.php
View file @
fc927aa6
...
...
@@ -9,28 +9,35 @@ class Command {
/**
* Run a CLI task with the given arguments.
*
* <code>
* // Call the migrate artisan task
* Command::run(array('migrate'));
*
* // Call the migrate task with some arguments
* Command::run(array('migrate:rollback', 'bundle-name'))
* </code>
*
* @param array $arguments
* @return void
*/
public
static
function
run
(
$arguments
=
array
())
{
if
(
!
isset
(
$arguments
[
0
]))
{
throw
new
\Exception
(
"Whoops! You forgot to provide the task name."
);
}
static
::
validate
(
$arguments
);
list
(
$bundle
,
$task
,
$method
)
=
static
::
parse
(
$arguments
[
0
]);
// If the task exists within a bundle, we will start the bundle so that
//
any dependencies can be registered in the application IoC container.
//
If the task is registered in the container, it will be resolved
//
via the
container instead of by this class.
// If the task exists within a bundle, we will start the bundle so that
any
//
dependencies can be registered in the application IoC container. If the
//
task is registered in the container, it will be resolved via the
// container instead of by this class.
if
(
Bundle
::
exists
(
$bundle
))
Bundle
::
start
(
$bundle
);
// Once the bundle has been started, we will attempt to resolve the
// task instance. Tasks may be resolved through the file system or
// through the application IoC container.
if
(
is_null
(
$task
=
static
::
resolve
(
$bundle
,
$task
)))
// Once the bundle has been started, we will attempt to resolve the task
// instance. Tasks may be resolved through the file system or through
// the application IoC container.
$task
=
static
::
resolve
(
$bundle
,
$task
);
if
(
is_null
(
$task
))
{
throw
new
\Exception
(
"Sorry, I can't find that task."
);
}
...
...
@@ -38,6 +45,20 @@ class Command {
$task
->
$method
(
array_slice
(
$arguments
,
1
));
}
/**
* Determine if the given command arguments are valid.
*
* @param array $arguments
* @return void
*/
protected
static
function
validate
(
$arguments
)
{
if
(
!
isset
(
$arguments
[
0
]))
{
throw
new
\Exception
(
"You forgot to provide the task name."
);
}
}
/**
* Parse the task name to extract the bundle, task, and method.
*
...
...
@@ -66,6 +87,14 @@ class Command {
/**
* Resolve an instance of the given task name.
*
* <code>
* // Resolve an instance of a task
* $task = Command::resolve('application', 'migrate');
*
* // Resolve an instance of a task wtihin a bundle
* $task = Command::resolve('bundle', 'foo');
* </code>
*
* @param string $bundle
* @param string $task
* @return object
...
...
@@ -95,6 +124,54 @@ class Command {
}
}
/**
* Parse the command line arguments and return the results.
*
* @param array $argv
* @return array
*/
public
static
function
options
(
$argv
)
{
$options
=
array
();
$arguments
=
array
();
for
(
$i
=
0
,
$count
=
count
(
$argv
);
$i
<
$count
;
$i
++
)
{
$argument
=
$argv
[
$i
];
// If the CLI argument starts with a double hyphen, it is an option,
// so we will extract the value and add it to the array of options
// to be returned by the method.
if
(
starts_with
(
$argument
,
'--'
))
{
// By default, we will assume the value of the options is true,
// but if the option contains an equals sign, we will take the
// value to the right of the equals sign as the value and
// remove the value from the option key.
list
(
$key
,
$value
)
=
array
(
substr
(
$argument
,
2
),
true
);
if
((
$equals
=
strpos
(
$argument
,
'='
))
!==
false
)
{
$key
=
substr
(
$argument
,
2
,
$equals
-
2
);
$value
=
substr
(
$argument
,
$equals
+
1
);
}
$options
[
$key
]
=
$value
;
}
// If the CLI argument does not start with a double hyphen it's
// simply an argument to be passed to the console task so we'll
// add it to the array of "regular" arguments.
else
{
$arguments
[]
=
$argument
;
}
}
return
array
(
$arguments
,
$options
);
}
/**
* Format a bundle and task into a task class name.
*
...
...
laravel/cli/console.php
deleted
100644 → 0
View file @
007863a6
<?php
namespace
Laravel\CLI
;
class
Console
{
/**
* Parse the command line arguments and return the results.
*
* @param array $argv
* @return array
*/
public
static
function
options
(
$argv
)
{
$options
=
array
();
$arguments
=
array
();
for
(
$i
=
0
,
$count
=
count
(
$argv
);
$i
<
$count
;
$i
++
)
{
$argument
=
$argv
[
$i
];
// If the CLI argument starts with a double hyphen, it is an option,
// so we will extract the value and add it to the array of options
// to be returned by the method.
if
(
starts_with
(
$argument
,
'--'
))
{
// By default, we will assume the value of the options is true,
// but if the option contains an equals sign, we will take the
// value to the right of the equals sign as the value and
// remove the value from the option key.
list
(
$key
,
$value
)
=
array
(
substr
(
$argument
,
2
),
true
);
if
((
$equals
=
strpos
(
$argument
,
'='
))
!==
false
)
{
$key
=
substr
(
$argument
,
2
,
$equals
-
2
);
$value
=
substr
(
$argument
,
$equals
+
1
);
}
$options
[
$key
]
=
$value
;
}
// If the CLI argument does not start with a double hyphen it is
// simply an argument to be passed to the console task so we'll
// add it to the array of "regular" arguments.
else
{
$arguments
[]
=
$argument
;
}
}
return
array
(
$arguments
,
$options
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment