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
1aac7d61
Commit
1aac7d61
authored
May 23, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored InstallHandler.
parent
8f0b6467
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
27 deletions
+28
-27
composer.json
apps/bootstrap/composer.json
+2
-2
InstallHandler.php
extensions/composer/yii/composer/InstallHandler.php
+26
-25
No files found.
apps/bootstrap/composer.json
View file @
1aac7d61
...
@@ -27,11 +27,11 @@
...
@@ -27,11 +27,11 @@
]
]
},
},
"extra"
:
{
"extra"
:
{
"writable"
:
[
"
yii-install-
writable"
:
[
"runtime"
,
"runtime"
,
"www/assets"
"www/assets"
],
],
"executable"
:
[
"
yii-install-
executable"
:
[
"yii"
"yii"
]
]
}
}
...
...
extensions/composer/yii/composer/InstallHandler.php
View file @
1aac7d61
...
@@ -8,7 +8,8 @@
...
@@ -8,7 +8,8 @@
namespace
yii\composer
;
namespace
yii\composer
;
use
Composer\Script\CommandEvent
;
use
Composer\Script\CommandEvent
;
use
yii\console
;
use
yii\console\Application
;
use
yii\console\Exception
;
defined
(
'YII_DEBUG'
)
or
define
(
'YII_DEBUG'
,
true
);
defined
(
'YII_DEBUG'
)
or
define
(
'YII_DEBUG'
,
true
);
...
@@ -24,6 +25,11 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
...
@@ -24,6 +25,11 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
*/
*/
class
InstallHandler
class
InstallHandler
{
{
const
PARAM_WRITABLE
=
'yii-install-writable'
;
const
PARAM_EXECUTABLE
=
'yii-install-executable'
;
const
PARAM_CONFIG
=
'yii-install-config'
;
const
PARAM_COMMANDS
=
'yii-install-commands'
;
/**
/**
* Sets the correct permissions of files and directories.
* Sets the correct permissions of files and directories.
* @param CommandEvent $event
* @param CommandEvent $event
...
@@ -31,11 +37,11 @@ class InstallHandler
...
@@ -31,11 +37,11 @@ class InstallHandler
public
static
function
setPermissions
(
$event
)
public
static
function
setPermissions
(
$event
)
{
{
$options
=
array_merge
(
array
(
$options
=
array_merge
(
array
(
'writable'
=>
array
(),
self
::
PARAM_WRITABLE
=>
array
(),
'executable'
=>
array
(),
self
::
PARAM_EXECUTABLE
=>
array
(),
),
$event
->
getComposer
()
->
getPackage
()
->
getExtra
());
),
$event
->
getComposer
()
->
getPackage
()
->
getExtra
());
foreach
((
array
)
$options
[
'writable'
]
as
$path
)
{
foreach
((
array
)
$options
[
self
::
PARAM_WRITABLE
]
as
$path
)
{
echo
"Setting writable:
$path
..."
;
echo
"Setting writable:
$path
..."
;
if
(
is_dir
(
$path
))
{
if
(
is_dir
(
$path
))
{
chmod
(
$path
,
0777
);
chmod
(
$path
,
0777
);
...
@@ -46,7 +52,7 @@ class InstallHandler
...
@@ -46,7 +52,7 @@ class InstallHandler
}
}
}
}
foreach
((
array
)
$options
[
'executable'
]
as
$path
)
{
foreach
((
array
)
$options
[
self
::
PARAM_EXECUTABLE
]
as
$path
)
{
echo
"Setting executable:
$path
..."
;
echo
"Setting executable:
$path
..."
;
if
(
is_file
(
$path
))
{
if
(
is_file
(
$path
))
{
chmod
(
$path
,
0755
);
chmod
(
$path
,
0755
);
...
@@ -65,33 +71,28 @@ class InstallHandler
...
@@ -65,33 +71,28 @@ class InstallHandler
public
static
function
run
(
$event
)
public
static
function
run
(
$event
)
{
{
$options
=
array_merge
(
array
(
$options
=
array_merge
(
array
(
'run'
=>
array
(),
self
::
PARAM_COMMANDS
=>
array
(),
'config'
=>
null
,
),
$event
->
getComposer
()
->
getPackage
()
->
getExtra
());
),
$event
->
getComposer
()
->
getPackage
()
->
getExtra
());
// resolve and include config file
if
(
!
isset
(
$options
[
self
::
PARAM_CONFIG
]))
{
if
((
$options
[
'config'
]
===
null
))
{
throw
new
Exception
(
'Please specify the "'
.
self
::
PARAM_CONFIG
.
'" parameter in composer.json.'
);
throw
new
console\Exception
(
'Config file not specified in composer.json extra.config'
);
}
}
else
{
$configFile
=
getcwd
()
.
'/'
.
$options
[
self
::
PARAM_CONFIG
];
if
(
!
is_file
(
getcwd
()
.
'/'
.
$options
[
'config'
]))
{
if
(
!
is_file
(
$configFile
))
{
throw
new
console\Exception
(
"Config file '
{
$options
[
'config'
]
}
' specified in composer.json extra.config not found"
);
throw
new
Exception
(
"Config file does not exist:
$configFile
"
);
}
else
{
$config
=
require
(
$options
[
'config'
]);
}
}
}
// prepare console application
require
(
__DIR__
.
'/../../../yii2/yii/Yii.php'
);
require
(
__DIR__
.
'/../../../yii2/yii/Yii.php'
);
$application
=
new
\yii\console\Application
(
$config
);
$application
=
new
Application
(
require
(
$configFile
)
);
$request
=
$application
->
getRequest
();
$request
=
$application
->
getRequest
();
// run commands from extra.run
foreach
((
array
)
$options
[
self
::
PARAM_COMMANDS
]
as
$command
)
{
foreach
((
array
)
$options
[
'run'
]
as
$rawCommand
)
{
$params
=
str_getcsv
(
$command
,
' '
);
// see http://stackoverflow.com/a/6609509/291573
$opts
=
str_getcsv
(
$rawCommand
,
' '
);
// see http://stackoverflow.com/a/6609509/291573
array_shift
(
$params
);
$request
->
setParams
(
$
opt
s
);
$request
->
setParams
(
$
param
s
);
list
(
$
command
,
$params
)
=
$request
->
resolve
();
list
(
$
route
,
$params
)
=
$request
->
resolve
();
echo
"Running command: yii
c
{
$rawC
ommand
}
\n
"
;
echo
"Running command: yii
{
$c
ommand
}
\n
"
;
$application
->
runAction
(
$
command
,
$params
);
$application
->
runAction
(
$
route
,
$params
);
}
}
}
}
}
}
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