Пример #1
0
 protected function executeColumnMethods(BaseColumn $column, $methods)
 {
     $safeCall = function ($methodName) use(&$column) {
         if (is_callable($methodName)) {
             $callback = $methodName;
         } else {
             $callback = array($column, $methodName);
         }
         if (!is_callable($callback)) {
             throw new InvalidArgumentException(sprintf('Column method not callable. Column - "%s", method - "%s"', $column->getFieldName(), $methodName));
         }
         return call_user_func($callback, $column);
     };
     //
     if (is_scalar($methods)) {
         $methodName = is_string($methods) && !empty($methods) ? $methods : 'getViewValue';
         $columnResult = $safeCall($methodName);
     } else {
         if (is_array($methods)) {
             $columnResult = array();
             foreach ($methods as $name => $methodName) {
                 $columnResult[$name] = $safeCall($methodName);
             }
         } else {
             if (is_callable($methods)) {
                 $columnResult = call_user_func($methods, $column);
             } else {
                 throw new Exception(sprintf('Unable to process parse data for column `%s`, unknown methods in model fields declaration  %s', $column->getFieldName(), print_r($methods, true)));
             }
         }
     }
     return $columnResult;
 }