Skip to content

Commit

Permalink
Dev Used Hash helper in PluginEvent for more reliable parameter merging.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Oct 25, 2013
1 parent b08e5d3 commit 80a8e6d
Showing 1 changed file with 5 additions and 48 deletions.
53 changes: 5 additions & 48 deletions application/libraries/PluginManager/PluginEvent.php
@@ -1,4 +1,7 @@
<?php

Yii::import('application.helpers.Hash');

class PluginEvent
{
/**
Expand Down Expand Up @@ -68,38 +71,7 @@ public function __construct($event, $sender = null)
*/
public function get($key = null, $default = null)
{
if ($key != null)
{
$keys = explode('.', $key);
$array = $this->_parameters;

// Retrieve using dot notation.
while (count($keys) > 1)
{
$first = array_shift($keys);
if (isset($array[$first]))
{
$array = $array[$first];
}
else
{
return $default;
}
}

if (isset($array[$keys[0]]))
{
return $array[$keys[0]];
}
else
{
return $default;
}
}
else
{
return $this->_parameters;
}
return Hash::get($this->_parameters, $key);
}

/**
Expand Down Expand Up @@ -188,22 +160,7 @@ public function isStopped()
*/
public function set($key, $value)
{
// Split by . to allow for arrays using dotnotation.
$keys = explode('.', $key);
while (count($keys) > 0)
{
$key = array_pop($keys);
if ($key == '')
{
$value = array($value);
}
else
{
$value = array($key => $value);
}

}
$this->_parameters = array_merge_recursive($this->_parameters, $value);
$this->_parameters = Hash::insert($this->_parameters, $key, $value);
return $this;
}

Expand Down

0 comments on commit 80a8e6d

Please sign in to comment.