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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
3f3a09e9
Commit
3f3a09e9
authored
Nov 02, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for generating default alias for extensions.
parent
d8b94d64
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
5 deletions
+58
-5
Installer.php
extensions/composer/Installer.php
+53
-5
Application.php
framework/yii/base/Application.php
+5
-0
No files found.
extensions/composer/Installer.php
View file @
3f3a09e9
...
...
@@ -11,6 +11,7 @@ use Composer\Package\PackageInterface;
use
Composer\Installer\LibraryInstaller
;
use
Composer\Repository\InstalledRepositoryInterface
;
use
Composer\Script\CommandEvent
;
use
Composer\Util\Filesystem
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -22,6 +23,8 @@ class Installer extends LibraryInstaller
const
EXTRA_WRITABLE
=
'writable'
;
const
EXTRA_EXECUTABLE
=
'executable'
;
const
EXTENSION_FILE
=
'yiisoft/extensions.php'
;
/**
* @inheritdoc
*/
...
...
@@ -65,8 +68,11 @@ class Installer extends LibraryInstaller
'version'
=>
$package
->
getVersion
(),
];
$alias
=
$this
->
generateDefaultAlias
(
$package
);
if
(
!
empty
(
$alias
))
{
$extension
[
'alias'
]
=
$alias
;
}
$extra
=
$package
->
getExtra
();
if
(
isset
(
$extra
[
self
::
EXTRA_BOOTSTRAP
])
&&
is_string
(
$extra
[
self
::
EXTRA_BOOTSTRAP
]))
{
$extension
[
'bootstrap'
]
=
$extra
[
self
::
EXTRA_BOOTSTRAP
];
}
...
...
@@ -76,6 +82,28 @@ class Installer extends LibraryInstaller
$this
->
saveExtensions
(
$extensions
);
}
protected
function
generateDefaultAlias
(
PackageInterface
$package
)
{
$autoload
=
$package
->
getAutoload
();
if
(
!
empty
(
$autoload
[
'psr-0'
]))
{
$fs
=
new
Filesystem
;
$vendorDir
=
$fs
->
normalizePath
(
$this
->
vendorDir
);
foreach
(
$autoload
[
'psr-0'
]
as
$name
=>
$path
)
{
$name
=
str_replace
(
'\\'
,
'/'
,
trim
(
$name
,
'\\'
));
if
(
!
$fs
->
isAbsolutePath
(
$path
))
{
$path
=
$this
->
vendorDir
.
'/'
.
$path
;
}
$path
=
$fs
->
normalizePath
(
$path
);
if
(
strpos
(
$path
.
'/'
,
$vendorDir
.
'/'
)
===
0
)
{
return
"['@
$name
' => '<vendor-dir>/"
.
ltrim
(
var_export
(
substr
(
$path
,
strlen
(
$vendorDir
)),
true
),
"'"
)
.
"']"
;
}
else
{
return
"['@
$name
' => "
.
var_export
(
$path
,
true
)
.
']'
;
}
}
}
return
false
;
}
protected
function
removePackage
(
PackageInterface
$package
)
{
$packages
=
$this
->
loadExtensions
();
...
...
@@ -85,14 +113,34 @@ class Installer extends LibraryInstaller
protected
function
loadExtensions
()
{
$file
=
$this
->
vendorDir
.
'/yiisoft/extensions.php'
;
return
is_file
(
$file
)
?
require
(
$file
)
:
[];
$file
=
$this
->
vendorDir
.
'/'
.
self
::
EXTENSION_FILE
;
if
(
!
is_file
(
$file
))
{
return
[];
}
$extensions
=
require
(
$file
);
$vendorDir
=
str_replace
(
'\\'
,
'/'
,
$this
->
vendorDir
);
$n
=
strlen
(
$vendorDir
);
foreach
(
$extensions
as
&
$extension
)
{
if
(
isset
(
$extension
[
'alias'
]))
{
foreach
(
$extension
[
'alias'
]
as
$alias
=>
$path
)
{
$path
=
str_replace
(
'\\'
,
'/'
,
$path
);
if
(
strpos
(
$path
.
'/'
,
$vendorDir
.
'/'
)
===
0
)
{
$extension
[
'alias'
][
$alias
]
=
'<vendor-dir>'
.
substr
(
$path
,
$n
);
}
}
}
}
return
$extensions
;
}
protected
function
saveExtensions
(
array
$extensions
)
{
$file
=
$this
->
vendorDir
.
'/yiisoft/extensions.php'
;
file_put_contents
(
$file
,
"<?php
\n
return "
.
var_export
(
$extensions
,
true
)
.
";
\n
"
);
$file
=
$this
->
vendorDir
.
'/'
.
self
::
EXTENSION_FILE
;
$array
=
str_replace
(
"'<vendor-dir>"
,
'$vendorDir . \''
,
var_export
(
$extensions
,
true
));
file_put_contents
(
$file
,
"<?php
\n\n\$
vendorDir = dirname(__DIR__);
\n\n
return
$array
;
\n
"
);
}
...
...
framework/yii/base/Application.php
View file @
3f3a09e9
...
...
@@ -208,6 +208,11 @@ abstract class Application extends Module
protected
function
initExtensions
(
$extensions
)
{
foreach
(
$extensions
as
$extension
)
{
if
(
!
empty
(
$extension
[
'alias'
]))
{
foreach
(
$extension
[
'alias'
]
as
$name
=>
$path
)
{
Yii
::
setAlias
(
$name
,
$path
);
}
}
if
(
isset
(
$extension
[
'bootstrap'
]))
{
/** @var Extension $class */
$class
=
$extension
[
'bootstrap'
];
...
...
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