Skip to content

Commit

Permalink
added and used package.namespace for composer.json autoload
Browse files Browse the repository at this point in the history
used package/vendor instead of config->package/vendor
  • Loading branch information
hiqsol committed May 29, 2015
1 parent 43150ff commit 7817ae0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
8 changes: 2 additions & 6 deletions .hidev/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"package": {
"name": "hidev",
"namespace": "hidev",
"label": "HiDev",
"title": "HiDev - integrate your development",
"type": "project",
Expand Down Expand Up @@ -57,14 +58,9 @@
},
"composer.json": {
"require": {
"yiisoft/yii2": "2.*",
"yiisoft/yii2": "~2.0",
"hiqdev/yii2-collection": "*@dev"
},
"autoload": {
"psr-4": {
"hiqdev\\hidev\\": ""
}
},
"bin": ["hidev"]
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
}
],
"require": {
"yiisoft/yii2": "2.*",
"yiisoft/yii2": "~2.0",
"hiqdev/yii2-collection": "*@dev"
},
"autoload": {
"psr-4": {
"hiqdev\\hidev\\": ""
"hidev\\": ""
}
},
"bin": [
Expand Down
3 changes: 0 additions & 3 deletions goals/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ public function make()
/// throw new InvalidParamException("Don't know how to make '$this->name'");
}


public function getConfig()
{
return Yii::$app->get('config');
}

/* XXX makes loops
public function getPackage()
{
return $this->getConfig()->getItem('package');
Expand All @@ -93,6 +91,5 @@ public function getVendor()
{
return $this->getConfig()->getItem('vendor');
}
*/

}
38 changes: 24 additions & 14 deletions goals/ComposerJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ class ComposerJson extends Template

public function init()
{
$package = $this->config->package;
$sets = [
'name' => $this->fullName,
'type' => $this->type,
'description' => $package->title,
'keywords' => $package->keywords,
'homepage' => $package->homepage,
'license' => $package->license,
'description' => $this->package->title,
'keywords' => $this->package->keywords,
'homepage' => $this->package->homepage,
'license' => $this->package->license,
'support' => $this->support,
'authors' => $this->authors,
'require' => $this->require,
Expand All @@ -45,36 +44,47 @@ public function init()
*/
public function getType()
{
return $this->rawItem('type') ?: $this->config->package->type;
return $this->rawItem('type') ?: $this->package->type;
}

public function getFullName()
{
return $this->config->package->fullName;
return $this->package->fullName;
}

public function getSupport()
{
$support = $this->getItem('support');
$package = $this->config->package;
$support->smartAdd([
'email' => $this->config->vendor->email,
'source' => $package->source,
'issues' => $package->issues,
'wiki' => $package->wiki,
'forum' => $package->forum,
'email' => $this->vendor->email,
'source' => $this->package->source,
'issues' => $this->package->issues,
'wiki' => $this->package->wiki,
'forum' => $this->package->forum,
],'first');
return $support;
}

public function getAuthors()
{
$res = [];
foreach ($this->config->package->authors->getItems() as $name => $data) {
foreach ($this->package->authors->getItems() as $name => $data) {
$data['name'] = $name;
$res[] = array_merge(compact('name'), $data);
}
return $res;
}

public function getAutoload()
{
if (!$this->rawItem('autoload')) {
$this->setItem('autoload', [
'psr-4' => [
$this->package->namespace . '\\' => $this->package->src
]
]);
}

return $this->getItem('autoload');
}
}
2 changes: 1 addition & 1 deletion goals/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class License extends Template
{
public function getTemplate()
{
return 'licenses/' . $this->config->package->license;
return 'licenses/' . $this->package->license;
}
}
7 changes: 6 additions & 1 deletion goals/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function getNamespace()
return $this->getItem('namespace') ?: ($this->getVendor()->name . '\\' . $this->name);
}

public function getSrc()
{
return $this->rawItem('src') ?: '';
}

public function getHomepage()
{
return $this->getItem('homepage') ?: ($this->vendor->homepage . $this->name);
Expand All @@ -92,7 +97,7 @@ public function getAuthors()

public function getVendor()
{
return $this->getConfig()->vendor;
return $this->getConfig()->getVendor();
}

}

0 comments on commit 7817ae0

Please sign in to comment.