Ejemplo n.º 1
0
 /**
  * @covers Gacela\Collection\Arr::valid
  */
 public function testValid()
 {
     foreach ($this->object as $obj) {
         if ($this->object->key() < 4) {
             $this->assertTrue($this->object->valid());
         } else {
             $this->assertFalse($this->object->valid());
         }
     }
 }
Ejemplo n.º 2
0
Archivo: Str.php Proyecto: jbzoo/utils
 /**
  * Truncate the string to given length of words.
  *
  * @param string $string
  * @param int    $limit
  * @param string $append
  * @return string
  */
 public static function limitWords($string, $limit = 100, $append = '...')
 {
     preg_match('/^\\s*+(?:\\S++\\s*+){1,' . $limit . '}/u', $string, $matches);
     if (!Arr::key(0, $matches) || self::len($string) === self::len($matches[0])) {
         return $string;
     }
     return rtrim($matches[0]) . $append;
 }
Ejemplo n.º 3
0
Archivo: Url.php Proyecto: jbzoo/utils
 /**
  * Checks to see if the page is being server over SSL or not
  *
  * @param bool $trustProxyHeaders
  * @return boolean
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public static function isHttps($trustProxyHeaders = false)
 {
     // Check standard HTTPS header
     if (Arr::key('HTTPS', $_SERVER)) {
         return !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
     }
     if ($trustProxyHeaders && Arr::key('X-FORWARDED-PROTO', $_SERVER)) {
         return $_SERVER['X-FORWARDED-PROTO'] === 'https';
     }
     // Default to not SSL
     return false;
 }
Ejemplo n.º 4
0
Archivo: Sys.php Proyecto: jbzoo/utils
 /**
  * Return document root
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @return string
  */
 public static function getDocRoot()
 {
     $result = '.';
     $root = Arr::key('DOCUMENT_ROOT', $_SERVER, true);
     if ($root) {
         $result = $root;
     }
     $result = FS::clean($result);
     $result = FS::real($result);
     if (!$result) {
         $result = FS::real('.');
         // @codeCoverageIgnore
     }
     return $result;
 }
Ejemplo n.º 5
0
Archivo: Arr.php Proyecto: jbzoo/utils
 /**
  * Group array by key
  *
  * @param array  $arrayList
  * @param string $key
  * @return array
  */
 public static function groupByKey(array $arrayList, $key = 'id')
 {
     $result = array();
     foreach ($arrayList as $item) {
         if (is_object($item)) {
             if (isset($item->{$key})) {
                 $result[$item->{$key}][] = $item;
             }
         } elseif (is_array($item)) {
             if (Arr::key($key, $item)) {
                 $result[$item[$key]][] = $item;
             }
         }
     }
     return $result;
 }
Ejemplo n.º 6
0
 /**
  * @return string
  */
 public static function getGravatarBuiltInDefaultImage()
 {
     return Arr::key(2, self::getGravatarBuiltInImages(), true);
 }
Ejemplo n.º 7
0
 /**
  * Normalize color from array
  *
  * @param array $origColor
  * @return integer[]
  * @throws Exception
  */
 protected static function _normalizeColorArray(array $origColor)
 {
     $result = array();
     if (Arr::key('r', $origColor) && Arr::key('g', $origColor) && Arr::key('b', $origColor)) {
         $result = array(self::color($origColor['r']), self::color($origColor['g']), self::color($origColor['b']), self::alpha(Arr::key('a', $origColor) ? $origColor['a'] : 0));
     } elseif (Arr::key(0, $origColor) && Arr::key(1, $origColor) && Arr::key(2, $origColor)) {
         $result = array(self::color($origColor[0]), self::color($origColor[1]), self::color($origColor[2]), self::alpha(Arr::key(3, $origColor) ? $origColor[3] : 0));
     }
     return $result;
 }