当前位置: 首页>>代码示例>>PHP>>正文


PHP Flight::setting方法代码示例

本文整理汇总了PHP中Flight::setting方法的典型用法代码示例。如果您正苦于以下问题:PHP Flight::setting方法的具体用法?PHP Flight::setting怎么用?PHP Flight::setting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Flight的用法示例。


在下文中一共展示了Flight::setting方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($paths, $pattern)
 {
     $this->paths = $paths;
     $this->pattern = $pattern;
     $this->ignores = $this->update_ignores(\Flight::setting("ignores"));
     $settings = \Flight::get("organizer.settings");
     $settings["ignores"] = $this->ignores;
     \Flight::write_settings($settings);
 }
开发者ID:raws,项目名称:sf-organizer,代码行数:9,代码来源:explorer.php

示例2: array

<?php

require "lib/flight/Flight.php";
require "lib/organizer/settings.php";
Flight::load_settings();
require "lib/organizer/explorer.php";
Flight::register("explorer", "organizer\\Explorer", array(Flight::setting("from.folders"), Flight::setting("from.pattern")));
Flight::route("/", function () {
    Flight::render("index", array(), "content");
    Flight::render("layout");
});
Flight::route("POST /", function () {
    require "lib/organizer/organizer.php";
    $files = array();
    for ($i = 0; $i < count($_POST["paths"]); $i++) {
        $files[$_POST["paths"][$i]] = array("name" => $_POST["names"][$i], "type" => $_POST["types"][$i]);
    }
    $settings = Flight::get("organizer.settings");
    $organizer = new organizer\Organizer($settings);
    $result = $organizer->organize($files);
    header("Content-type: application/json");
    echo json_encode($result);
});
Flight::route("/entries", function () {
    Flight::render("_entries", array("paths" => Flight::explorer()->get_entries()));
});
Flight::route("/settings", function () {
    if (($settings = Flight::get("organizer.settings")) == null) {
        $settings = array("paths" => array());
    }
    Flight::render("settings", array("settings" => $settings), "content");
开发者ID:raws,项目名称:sf-organizer,代码行数:31,代码来源:index.php

示例3: organize

 public function organize($paths)
 {
     $result = array();
     if (($ignores = \Flight::setting("ignores")) == null) {
         $ignores = array();
     }
     /*
      * Iterate over each path and attempt to move it to its new location,
      * based on the settings this Organizer was initialized with.
      */
     foreach ($paths as $path => $options) {
         // Make sure the original file exists and is able to be (re)moved
         if (!is_writable($path)) {
             $result[$path] = array("status" => "error", "error" => "Original file does not exist or is not writable");
             continue;
         }
         // Validate and act on media type
         if ($options["type"] === "movie") {
             $options["type"] = "movies";
         }
         if (isset($this->settings["to"][$options["type"]])) {
             $dest_dir = $this->settings["to"][$options["type"]];
         } else {
             if ($options["type"] === "delete") {
                 if (unlink($path)) {
                     $result[$path] = array("status" => "success", "deleted" => TRUE);
                     continue;
                 } else {
                     $result[$path] = array("status" => "error", "error" => "Original file could not be deleted", "deleted" => FALSE);
                     continue;
                 }
             } else {
                 if ($options["type"] === "ignore") {
                     $ignores[$path] = time();
                     $result[$path] = array("status" => "success", "ignored" => TRUE);
                     continue;
                 } else {
                     $result[$path] = array("status" => "error", "error" => "Media type is unrecognized", "type" => $options["type"]);
                     continue;
                 }
             }
         }
         // Construct destination directory
         $pathinfo = pathinfo($options["name"]);
         if ($options["type"] === "movies") {
             $dest_dir .= "/" . $pathinfo["filename"];
         } else {
             if ($options["type"] === "tv") {
                 if (preg_match("/^\\s*(.*)\\s*-\\s*S(\\d+)E\\d+/", $options["name"], $matches)) {
                     $show = trim($matches[1]);
                     $season = intval($matches[2]);
                     $dest_dir .= "/" . $show . "/Season " . $season;
                 } else {
                     $result[$path] = array("status" => "error", "error" => "TV episode name is formatted incorrectly");
                     continue;
                 }
             }
         }
         mkdir($dest_dir, 0755, TRUE);
         // May return FALSE if directory already exists
         if (!is_writable($dest_dir)) {
             $result[$path] = array("status" => "error", "error" => "Destination folder cannot be written to", "path" => $dest_dir);
             continue;
         }
         // Construct destination path
         $dest_path = $dest_dir . "/" . $options["name"];
         if (file_exists($dest_path)) {
             $result[$path] = array("status" => "error", "error" => "Destination file already exists", "path" => $dest_path);
             continue;
         }
         // Attempt to move original file to destination
         if (rename($path, $dest_path)) {
             $result[$path] = array("status" => "success", "path" => $dest_path);
         } else {
             $result[$path] = array("status" => "error", "error" => "Could not move original file to destination", "path" => $dest_path);
         }
     }
     // Write settings with any new ignores added
     $settings = \Flight::get("organizer.settings");
     $settings["ignores"] = $ignores;
     \Flight::write_settings($settings);
     return $result;
 }
开发者ID:raws,项目名称:sf-organizer,代码行数:83,代码来源:organizer.php


注:本文中的Flight::setting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。