Exemple #1
0
 public static function init()
 {
     $args = getopt('f:t:d:o:', array('tc::'));
     if (isset($args['f']) && isset($args['t']) && isset($args['d'])) {
         self::$query_date = $args['d'];
         self::$from_station_name = $args['f'];
         self::$to_station_name = $args['t'];
         self::$station_train_code = isset($args['tc']) ? $args['tc'] : '';
     } else {
         $usage = "请输入参数:\n-f\t出发地,如北京 \n-t\t目的地,如郓城 \n-d\t出发日,如2016-01-06 \n--tc\t车次,支持多车次查询如--tc='D2320,D2322'";
         self::show($usage);
         exit;
     }
     $stations = explode('|', self::$station_names);
     $total = count($stations);
     for ($i = 0; $i < $total && (empty(self::$from_station_code) || empty(self::$to_station_code)); $i++) {
         if (empty(self::$from_station_code) && $stations[$i] == self::$from_station_name) {
             self::$from_station_code = isset($stations[$i + 1]) ? $stations[$i + 1] : '';
         } else {
             if (empty(self::$to_station_code) && $stations[$i] == self::$to_station_name) {
                 self::$to_station_code = isset($stations[$i + 1]) ? $stations[$i + 1] : '';
             }
         }
     }
     if (empty(self::$from_station_code) || empty(self::$to_station_code) || empty(self::$query_date)) {
         $usage = "请输入参数:\n-f\t出发地,如北京 \n-t\t目的地,如郓城 \n-d\t出发日,如2016-01-06 \n";
         self::show($usage);
         exit;
     }
 }
Exemple #2
0
 public static function init_param()
 {
     $args = getopt('f:t:d:m:n:o');
     //出发地,目的地,出发日
     if (isset($args['f']) && isset($args['t']) && isset($args['d'])) {
         self::$query_date = strtotime($args['d']) ? $args['d'] : '';
         self::$from_station_name = $args['f'];
         self::$to_station_name = $args['t'];
         self::$from_station_code = isset(self::$station[$args['f']]) ? self::$station[$args['f']] : '';
         self::$to_station_code = isset(self::$station[$args['t']]) ? self::$station[$args['t']] : '';
     }
     if (empty(self::$from_station_code) || empty(self::$to_station_code) || empty(self::$query_date)) {
         self::usage();
     }
     //指定车次
     if (isset($args['m'])) {
         $trains = explode(',', $args['m']);
         foreach ($trains as $train) {
             self::$limit_train_list[] = strtoupper($train);
         }
     }
     //指定车座
     if (isset($args['n'])) {
         $tickets = explode(',', $args['n']);
         foreach ($tickets as $ticket) {
             if (!isset(self::$ticket_hash[$ticket])) {
                 self::error("无效车座: {$ticket}");
             }
             self::$limit_ticket_list[] = self::$ticket_hash[$ticket];
         }
     } else {
         self::$limit_ticket_list = self::$ticket_hash;
     }
 }