Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
PSDI Army
yii2
Commits
95b18d55
Commit
95b18d55
authored
Sep 09, 2012
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more on console apps
parent
ea1c5c78
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
13 deletions
+69
-13
Application.php
framework/console/Application.php
+1
-1
Controller.php
framework/console/Controller.php
+53
-0
CreateController.php
framework/console/controllers/CreateController.php
+10
-8
MessageController.php
framework/console/controllers/MessageController.php
+1
-1
MigrateController.php
framework/console/controllers/MigrateController.php
+1
-1
ShellController.php
framework/console/controllers/ShellController.php
+2
-2
index.php
framework/console/create/default/index.php
+1
-0
No files found.
framework/console/Application.php
View file @
95b18d55
...
...
@@ -132,7 +132,7 @@ class Application extends \yii\base\Application
'help'
=>
'yii\console\controllers\HelpController'
,
'migrate'
=>
'yii\console\controllers\MigrateController'
,
'shell'
=>
'yii\console\controllers\ShellController'
,
'
app'
=>
'yii\console\controllers\App
Controller'
,
'
create'
=>
'yii\console\controllers\Create
Controller'
,
);
}
...
...
framework/console/Controller.php
View file @
95b18d55
...
...
@@ -60,4 +60,56 @@ class Controller extends \yii\base\Controller
\Yii
::
$application
->
end
(
1
);
}
}
/**
* Reads input via the readline PHP extension if that's available, or fgets() if readline is not installed.
*
* @param string $message to echo out before waiting for user input
* @param string $default the default string to be returned when user does not write anything.
* Defaults to null, means that default string is disabled.
* @return mixed line read as a string, or false if input has been closed
*/
public
function
prompt
(
$message
,
$default
=
null
)
{
if
(
$default
!==
null
)
{
$message
.=
" [
$default
] "
;
}
else
{
$message
.=
' '
;
}
if
(
extension_loaded
(
'readline'
))
{
$input
=
readline
(
$message
);
if
(
$input
!==
false
)
{
readline_add_history
(
$input
);
}
}
else
{
echo
$message
;
$input
=
fgets
(
STDIN
);
}
if
(
$input
===
false
)
{
return
false
;
}
else
{
$input
=
trim
(
$input
);
return
(
$input
===
''
&&
$default
!==
null
)
?
$default
:
$input
;
}
}
/**
* Asks user to confirm by typing y or n.
*
* @param string $message to echo out before waiting for user input
* @param boolean $default this value is returned if no selection is made.
* @return boolean whether user confirmed
*/
public
function
confirm
(
$message
,
$default
=
false
)
{
echo
$message
.
' (yes|no) ['
.
(
$default
?
'yes'
:
'no'
)
.
']:'
;
$input
=
trim
(
fgets
(
STDIN
));
return
empty
(
$input
)
?
$default
:
!
strncasecmp
(
$input
,
'y'
,
1
);
}
}
\ No newline at end of file
framework/console/controllers/
App
Controller.php
→
framework/console/controllers/
Create
Controller.php
View file @
95b18d55
<?php
/**
*
WebAppCommand
class file.
*
CreateController
class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
...
...
@@ -18,21 +18,23 @@ use yii\console\Controller;
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
App
Controller
extends
Controller
class
Create
Controller
extends
Controller
{
private
$_rootPath
;
/**
* Generates Yii application at the path specified via appPath parameter.
*
* @param string $
appP
ath the directory where the new application will be created.
* @param string $
p
ath the directory where the new application will be created.
* If the directory does not exist, it will be created. After the application
* is created, please make sure the directory has enough permissions.
* @param string $type application type. If not specified default application
* skeleton will be used.
* @return integer the exit status
*/
public
function
actionIndex
(
$
appPath
)
public
function
actionIndex
(
$
path
,
$type
=
'default'
)
{
$path
=
strtr
(
$
appP
ath
,
'/\\'
,
DIRECTORY_SEPARATOR
);
$path
=
strtr
(
$
p
ath
,
'/\\'
,
DIRECTORY_SEPARATOR
);
if
(
strpos
(
$path
,
DIRECTORY_SEPARATOR
)
===
false
)
$path
=
'.'
.
DIRECTORY_SEPARATOR
.
$path
;
$dir
=
rtrim
(
realpath
(
dirname
(
$path
)),
'\\/'
);
...
...
@@ -42,11 +44,11 @@ class AppController extends Controller
$this
->
_rootPath
=
$path
=
$dir
;
else
$this
->
_rootPath
=
$path
=
$dir
.
DIRECTORY_SEPARATOR
.
basename
(
$path
);
if
(
$this
->
confirm
(
"Create
a Web
application under '
$path
'?"
))
if
(
$this
->
confirm
(
"Create
\"
$type
\"
application under '
$path
'?"
))
{
$sourceDir
=
realpath
(
dirname
(
__FILE__
)
.
'/../views/webapp'
);
$sourceDir
=
realpath
(
__DIR__
.
'/../create/'
.
$type
);
if
(
$sourceDir
===
false
)
die
(
"
\n
Unable to locate the source directory.
\n
"
);
die
(
"
\n
Unable to locate the source directory
for
\"
$type
\"
.
\n
"
);
$list
=
$this
->
buildFileList
(
$sourceDir
,
$path
);
$list
[
'index.php'
][
'callback'
]
=
array
(
$this
,
'generateIndex'
);
$list
[
'index-test.php'
][
'callback'
]
=
array
(
$this
,
'generateIndex'
);
...
...
framework/console/controllers/MessageController.php
View file @
95b18d55
<?php
/**
* MessageCo
mmand
class file.
* MessageCo
ntroller
class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
...
...
framework/console/controllers/MigrateController.php
View file @
95b18d55
<?php
/**
* MigrateCo
mmand
class file.
* MigrateCo
ntroller
class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
...
...
framework/console/controllers/ShellController.php
View file @
95b18d55
<?php
/**
* ShellCo
mmand
class file.
* ShellCo
ntroller
class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
...
...
@@ -13,7 +13,7 @@ namespace yii\console\controllers;
use
yii\console\Controller
;
/**
*
ShellC
ommand executes the specified Web application and provides a shell for interaction.
*
This c
ommand executes the specified Web application and provides a shell for interaction.
*
* @property string $help The help information for the shell command.
*
...
...
framework/console/create/default/index.php
0 → 100644
View file @
95b18d55
<?php
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