Example #1
0
 public static function makeThumb($dir, $file, $x = '')
 {
     $e = String::split('.', $file);
     $ext = $e[count($e) - 1];
     unset($e[count($e) - 1]);
     $f = String::unsplit('.', $e);
     return '<img src="' . URL . '/uploads/' . String::trim($dir, '/') . '/' . $f . '' . $x . '.' . $ext . '" />';
 }
Example #2
0
 /**
  * Create a IoC-container, that is: load a class with typehinting-autoload functionality
  *
  * @param string $concrete the class you want to load
  * @param string $method   the method you want to load
  * @param array  $args     the arguments for this method
  * @param array  $mainargs the arguments for submethods
  * 
  * @return mixed result object or value of the object
  */
 public static function init($concrete, $method = null, $args = [], $mainargs = [])
 {
     if ($method !== null) {
         // heeft een method
         $methodReflection = new reflectionMethod($concrete, $method);
         $parameters = [];
         $methodArguments = $methodReflection->getParameters();
         $i = 0;
         if (!empty($methodArguments)) {
             $nargs = [];
             foreach ($args as $k => $v) {
                 if (!is_integer($k)) {
                     $nargs[$k] = $v;
                     unset($args[$k]);
                 }
             }
             $args = array_values($args);
             foreach ($methodArguments as $k => $v) {
                 $class = $v->getClass();
                 if (!is_null($class)) {
                     $parameters[] = self::init($class->name, null, [], $mainargs);
                 } elseif (isset($nargs[$v->name])) {
                     $parameters[] = $nargs[$v->name];
                 } else {
                     $parameters[] = @$args[$i];
                     ++$i;
                 }
             }
         }
         if (!empty($parameters)) {
             $reflection = new reflectionClass($concrete);
             return $methodReflection->invokeArgs($reflection->newInstanceWithoutConstructor(), $parameters);
         } else {
             return $methodReflection->invoke(self::init($concrete));
         }
     } else {
         // gebruik construct (als die er is)
         $reflection = new reflectionClass($concrete);
         $constructor = $reflection->getConstructor();
         if (is_null($constructor)) {
             if (String::like($concrete, 'Application\\Validation\\%')) {
                 $o = new $concrete();
                 $r = $o->execute($o->_rules);
                 return $o;
             } elseif (String::like($concrete, '%\\%') === false) {
                 return new $concrete($args['id']);
             } else {
                 $obj = new $concrete();
                 return $obj;
             }
         } else {
             $parameters = [];
             $methodArguments = $constructor->getParameters();
             if (!empty($methodArguments)) {
                 foreach ($methodArguments as $k => $v) {
                     $class = $v->getClass();
                     if (!is_null($class)) {
                         $parameters[] = self::init($class->name, null, []);
                     } elseif (isset($args[$v->name])) {
                         $parameters[] = $args[$v->name];
                     }
                 }
             }
             if (!empty($parameters)) {
                 return $constructor->invokeArgs($reflection->newInstanceWithoutConstructor(), $parameters);
             } else {
                 if (String::like($concrete, 'Application\\Validation\\%')) {
                     $o = new $concrete();
                     $r = $o->execute($o->_rules);
                     return $o;
                 } elseif (String::like($concrete, '%\\%') === false && !empty($mainargs['id'])) {
                     return new $concrete($mainargs['id']);
                 } else {
                     return new $concrete();
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * Get the result of an key from the languages-array
  *
  * @param string $key  the name of the key
  * @param array  $args args that can be replaced
  *
  * @return string the result value of the key
  */
 public static function language($key, $args = [])
 {
     $lang = @self::$_language[$key];
     if (!empty($lang)) {
         if (!empty($args)) {
             foreach ($args as $name => $value) {
                 $lang = String::replace('{' . $name . '}', $value, $lang);
             }
         }
         return $lang;
     }
     throw new \ExceptionLanguage('Key "' . $key . '" could\'t be found');
 }
Example #4
0
 /**
  * Initialize the view
  *
  * @param  string  $path the path of the view/template
  * @param  array   $args the arguments for the view (set)
  */
 public function __construct($path, $args = array())
 {
     $this->_data['path'] = $path;
     $this->_data['url'] = T . String::replace('.', DS, $path) . '.phtml';
     $this->set($args);
 }
Example #5
0
 public static function urlWithoutSegment($segment, $url = null)
 {
     $segments = String::segments($url ? $url : self::$_vars['querystring']);
     if (($key = array_search($segment, $segments)) !== false) {
         unset($segments[$key]);
     }
     return '/' . String::unsplit('/', $segments);
 }
Example #6
0
 /**
  * Check: max:{num}
  *
  * @param string $string the string that must be checke
  * @param string $length what is the max length
  *
  * @return boolean  if it is suffice
  */
 public static function max($string, $length)
 {
     return String::length($string) <= $length ? true : false;
 }