Beispiel #1
0
 /**
  * @return Option
  */
 public function getLanguage()
 {
     if (filter_input(INPUT_SERVER, 'HTTP_ACCEPT_LANGUAGE')) {
         return Option::Some(substr(filter_input(INPUT_SERVER, 'HTTP_ACCEPT_LANGUAGE'), 0, 2));
     }
     return Option::None();
 }
Beispiel #2
0
 /**
  * @param string $section
  * @param string $key
  * @return Option
  */
 public function find($section, $key)
 {
     if (isset($this->_settings[$section][$key])) {
         return Option::Some($this->_settings[$section][$key]);
     }
     return Option::None();
 }
Beispiel #3
0
 /**
  * @param $args
  * @return Option
  */
 public static function ifInstance(...$args)
 {
     if (self::hasInstance(...$args)) {
         return Option::Some(self::getInstance(...$args));
     } else {
         return Option::None();
     }
 }
Beispiel #4
0
 /**
  * @return Option
  */
 public function findAny()
 {
     if (count(array_keys($_FILES)) == 0) {
         return Option::None();
     } else {
         $key = array_keys($_FILES)[0];
         return Option::Some($_FILES[$key]);
     }
 }
Beispiel #5
0
 /**
  * @param $key
  * @return Option
  */
 public static function getMy($key)
 {
     $hash = self::hash($key);
     if (self::$redis->exists(self::myPrefix() . ":" . $hash)) {
         return Option::Some(unserialize(self::$redis->get(self::myPrefix() . ":" . $hash)));
     } else {
         return Option::None();
     }
 }
Beispiel #6
0
 /**
  * @param string $artist
  * @param string $album
  * @return Option
  */
 public function getAlbumCover($artist, $album)
 {
     $data = self::exec(self::API_URL, array("format" => "json", "method" => "album.getinfo", "api_key" => self::API_KEY, "artist" => $artist, "album" => $album));
     if (isset($data["album"]["image"])) {
         $images = $data["album"]["image"];
         $image_url = $images[count($images) - 1]["#text"];
         return Option::Some($image_url);
     } else {
         return Option::None();
     }
 }
Beispiel #7
0
 /**
  * @param $keys
  * @return Option
  */
 public function get(...$keys)
 {
     $handle =& $_SESSION;
     foreach ($keys as $key) {
         if (isset($handle[$key])) {
             $handle =& $handle[$key];
         } else {
             return Option::None();
         }
     }
     return Option::Some($handle);
 }
Beispiel #8
0
 /**
  * Reads audio file metadata and returns Metadata object.
  *
  * @param string $filename
  * @param string $original_filename
  * @return Some
  */
 public static function read($filename, $original_filename = null)
 {
     $escaped_filename = escapeshellarg($filename);
     $file_format = strtolower(pathinfo($original_filename, PATHINFO_EXTENSION));
     $command = sprintf(self::$settings->get("command_templates", "read_metadata"), self::$settings->get("tools", "ffprobe_cmd"), $escaped_filename);
     exec($command, $result, $status);
     if ($status != 0) {
         return Option::None();
     }
     /**
      * @var Option[] $metadata
      * @var Option[] $o_format
      * @var Option[] $o_tags
      */
     $metadata = Option::Some(json_decode(implode("", $result), true));
     $o_format = $metadata["format"];
     $o_tags = $o_format["tags"];
     $object = new Metadata();
     $object->format_name = $file_format;
     $object->filename = $o_format["filename"]->get();
     $object->duration = $o_format["duration"]->map(function ($value) {
         return intval($value * 1000);
     })->get();
     $object->size = $o_format["size"]->toInt()->get();
     $object->bitrate = $o_format["bit_rate"]->toInt()->get();
     $object->meta_artist = $o_tags["artist"]->orEmpty();
     $object->meta_title = $o_tags["title"]->orEmpty();
     $object->meta_genre = $o_tags["genre"]->orEmpty();
     $object->meta_date = $o_tags["date"]->orEmpty();
     $object->meta_album = $o_tags["album"]->orEmpty();
     $object->meta_track_number = $o_tags["track"]->toInt()->orNull();
     $object->meta_disc_number = $o_tags["disc"]->toInt()->orNull();
     $object->meta_album_artist = $o_tags["album_artist"]->orEmpty();
     $object->is_compilation = $o_tags["compilation"]->map("bool")->getOrElse("false");
     $object->meta_comment = $o_tags["comment"]->orEmpty();
     return Option::Some($object);
 }
 /**
  * @param string $key
  * @return Option
  */
 public function get($key)
 {
     return $this->isDefined($key) ? Option::Some($this->getValue($key)) : Option::None();
 }
Beispiel #10
0
/**
 * @param $arg
 * @return Option
 */
function part_audio_type($arg)
{
    $formats = array("mp3" => "audio/mp3", "ogg" => "audio/ogg", "flac" => "audio/flac", "m4a" => "audio/aac", "aac" => "audio/aac", "ape" => "audio/ape", "wma" => "audio/x-ms-wma", "wav" => "audio/x-wav");
    return isset($formats[$arg]) ? Option::Some($formats[$arg]) : Option::None();
}
Beispiel #11
0
 public function findHardRoute()
 {
     if (class_exists($this->route->getRouteClass())) {
         return Option::Some(array("action" => $this->route->getRouteClass(), "args" => array()));
     }
     return Option::None();
 }
 /**
  * @param string $query
  * @param array $params
  * @param string $class
  * @param array|null $ctr_args
  * @throws ApplicationException
  * @return Option
  */
 public function fetchOneObject($query, array $params = null, $class, array $ctr_args = [])
 {
     $resource = $this->createResource($query, $params);
     $object = $resource->fetchObject($class, $ctr_args);
     return Option::Some($object)->reject(false);
 }
Beispiel #13
0
 /**
  * @param $callback
  * @return Option
  */
 public function firstMatching($callback)
 {
     foreach ($this->array as $item) {
         if ($callback($item)) {
             return Option::Some($item);
         }
     }
     return Option::None();
 }