protected function sort($items, $type = self::TYPE_BOTH, $by = self::KEY_NAME, $direction = self::ASC)
    {
        $returnArray = array();
        if (count($items) > 0) {
            $tmpArray = array();
            foreach($items as $key => $value) {
                $tmpArray[$key] = $value[$by];
            }

            natcasesort($tmpArray);

            if ($direction == self::DESC) {
                $tmpArray = array_reverse($tmpArray, true);
            }

            foreach($tmpArray as $key => $value) {
                $returnArray[] = $items[$key];
            }

            // If sorting by name, lets seperate the files from the dirs.
            if ($by == self::KEY_NAME && $type == self::TYPE_BOTH) {
                $files = array();
                $dirs  = array();

                foreach ($returnArray as $value) {
                    if ($value[self::KEY_TYPE] == self::TYPE_FILE) {
                        $files[] = $value;
                    } elseif ($value[self::KEY_TYPE] == self::TYPE_DIR) {
                        $dirs[] = $value;
                    }
                }

                if ($direction == self::DESC) {
                    $returnArray = array_merge($files, $dirs);
                } else {
                    $returnArray = array_merge($dirs, $files);
                }
            }
        }
        return $returnArray;
    }