Skip to content

Commit

Permalink
fixed core components determination
Browse files Browse the repository at this point in the history
  • Loading branch information
anton committed Nov 6, 2012
1 parent 369993f commit 87770cf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
27 changes: 22 additions & 5 deletions components/entity/AmEntity.php
Expand Up @@ -35,6 +35,10 @@ class AmEntity extends AmModel
* @var string name as it appears in the config.
*/
protected $name;
/**
* @var string
*/
protected $defaultName;
/**
* @var string Yii alias to the entity class.
*/
Expand Down Expand Up @@ -271,11 +275,24 @@ public function setName($name)
*/
public function getDefaultName()
{
$id = $this->getId();
$tmp = explode('.', $id);
$name = array_pop($tmp);
$name[0] = strtolower($name[0]);
return $name;
if (null === $this->defaultName) {
$id = $this->getId();
$tmp = explode('.', $id);
$name = array_pop($tmp);
$name[0] = strtolower($name[0]);
$this->defaultName = $name;
}
return $this->defaultName;
}

/**
* @param string $name
* @return AmEntity
*/
public function setDefaultName($name)
{
$this->defaultName = $name;
return $this;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions models/AmEntityCoreComponents.php
Expand Up @@ -4,11 +4,11 @@ class AmEntityCoreComponents extends AmEntityComponents
{
public function getChild($id)
{
$components = $this->scan();
if (false === array_search($id, $components)) {
$name = array_search($id, $this->scan());
if (false === $name) {
return null;
}
return $this->createChild($id);
return $this->createChild($id, $name);
}

protected function scan()
Expand Down Expand Up @@ -45,7 +45,7 @@ protected function createChildren($results)
protected function createChild($id, $name = null)
{
$entity = parent::createChild($id);
$entity->setName($name);
$entity->setDefaultName($name);
$entity->setFullClassName($this->getParent()->getId() . '.' . $id);
return $entity;
}
Expand Down
2 changes: 1 addition & 1 deletion models/AmEntityCoreModules.php
Expand Up @@ -27,7 +27,7 @@ protected function createChildren($results)
protected function createChild($id, $name = null)
{
$entity = parent::createChild($id);
$entity->setName($name);
$entity->setDefaultName($name);
$entity->setFullClassName($this->getParent()->getId() . '.' . $id);
return $entity;
}
Expand Down

0 comments on commit 87770cf

Please sign in to comment.