Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param array $data
- * @return Easy|null
- * @throws EasyException
- */
- public function associate(array $data = null,$class=null)
- {
- if(!is_null($data)){
- if(is_null($class)) { $class = $this->_this; }
- if(is_string($class))
- {
- $class = new $class;
- }
- foreach($data as $key => $val)
- {
- $func = "set".$this->filter($key,true);
- if(method_exists($class ,$func ))
- {
- $class->$func($val); //call_user_func([$class,$func],$val);
- }
- else
- {
- throw new EasyException('V funkci associate došlo k chybě. Snažíte se přiradit hodnotu v array ale funkce k ní neexistuje: '.$func.' [ '.get_class($class).' ]');
- }
- }
- return $class;
- }
- }
- /**
- * @param $var
- * @param bool $forFunction
- * @return mixed|string
- * @throws EasyException
- */
- public function filter($var, $forFunction = false)
- {
- if(is_string($var))
- {
- $count = substr_count($var,'_');
- $lastPos = 0;
- $editVar = $var;
- for($i = 0; $i < $count; $i++)
- {
- $pos = strpos($editVar,'_',$lastPos);
- $editVar = substr_replace($editVar,'',$pos,1);
- $stringArray = str_split($editVar);
- $editVar = substr_replace($editVar,strtoupper($stringArray[$pos]),$pos,1);
- $lastPos = $pos;
- }
- if($forFunction)
- {
- return ucfirst($editVar);
- }
- else
- {
- return $editVar;
- }
- }
- else
- {
- throw new EasyException("Funkce filter přímá pouze string!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment