コード例 #1
0
 /**
  * Helper method
  *
  * @param   string input
  * @param   bool lower whether this is the lower boundary
  * @return  util.Date
  */
 protected function parseDate($input, $lower)
 {
     switch ($input) {
         case '__NOW__':
             if ($lower) {
                 $r = DateUtil::getMidnight(Date::now());
             } else {
                 $r = DateUtil::getMidnight(DateUtil::addDays(Date::now(), 1));
             }
             break;
         case '__FUTURE__':
             $r = Date::now();
             break;
         case '__UNLIMITED__':
             $r = null;
             break;
         default:
             $r = new Date($input);
     }
     return $r;
 }
コード例 #2
0
 /**
  * Parse raw listing entry.
  *
  * @param   string $raw a single line
  * @param   peer.ftp.FtpConnection $connection
  * @param   string $base default "/"
  * @param   util.Date $ref default NULL
  * @return  peer.ftp.FtpEntry
  */
 public function entryFrom($raw, FtpConnection $conn = null, $base = '/', Date $ref = null)
 {
     sscanf($raw, '%s %d %s %s %d %s %d %[^ ] %[^$]', $permissions, $numlinks, $user, $group, $size, $month, $day, $date, $filename);
     // Only qualify filenames if they appear unqualified in the listing
     if ('/' !== $filename[0]) {
         $filename = $base . $filename;
     }
     // Create a directory or an entry
     if ('d' === $permissions[0]) {
         $e = new FtpDir($filename, $conn);
     } else {
         $e = new FtpFile($filename, $conn);
     }
     // If the entry contains a timestamp, the year is omitted, "Apr 4 20:16"
     // instead of "Apr 4 2009". This compact format is used when the file
     // time is within six months* from the current date, in either direction!
     //
     // *] #define SIXMONTHS       ((365 / 2) * 86400) := 15724800
     //    See http://svn.freebsd.org/base/projects/releng_7_xen/bin/ls/print.c
     if (strstr($date, ':')) {
         $ref || ($ref = Date::now());
         $d = new Date($month . ' ' . $day . ' ' . $ref->getYear() . ' ' . $date);
         if ($d->getTime() - $ref->getTime() > 15724800) {
             $d = DateUtil::addMonths($d, -12);
         }
     } else {
         $d = new Date($month . ' ' . $day . ' ' . $date);
     }
     try {
         $e->setPermissions(substr($permissions, 1));
         $e->setNumlinks($numlinks);
         $e->setUser($user);
         $e->setGroup($group);
         $e->setSize($size);
         $e->setDate($d);
     } catch (\lang\IllegalArgumentException $e) {
         throw new \lang\FormatException('Cannot parse "' . $raw . '": ' . $e->getMessage());
     }
     return $e;
 }
コード例 #3
0
 /**
  * LIST: This command causes a list of file names and file details 
  * to be sent from the FTP site to the client.
  *
  * @param   peer.Socket socket
  * @param   string params
  */
 public function onList($socket, $params)
 {
     if (!($dataSocket = $this->openDatasock($socket))) {
         return;
     }
     // Split options from arguments
     if (substr($params, 0, 1) === '-') {
         list($options, $params) = explode(' ', substr($params, 1), 2);
         $this->cat && $this->cat->debug('+++ Options:', $options);
     } else {
         $options = '';
     }
     if (!($entry = $this->storage->lookup($socket->hashCode(), $params))) {
         $this->answer($socket, 550, $params . ': No such file or directory');
         $dataSocket->close();
         unset($dataSocket);
         $this->cat && $this->cat->debug($socket, $this->datasock[$socket->hashCode()]);
         return;
     }
     // Invoke interceptor
     if (!$this->checkInterceptors($socket, $entry, 'onRead')) {
         $dataSocket->close();
         return;
     }
     $this->answer($socket, 150, sprintf('Opening %s mode data connection for filelist', $this->sessions[$socket->hashCode()]->typeName()));
     // If a collection was specified, list its elements, otherwise,
     // list the single element
     if ($entry instanceof StorageCollection && !strstr($options, 'd')) {
         $elements = $entry->elements();
     } else {
         $elements = [$entry];
     }
     $before6Months = DateUtil::addMonths(Date::now(), -6)->getTime();
     for ($i = 0, $s = sizeof($elements); $i < $s; $i++) {
         $buf = sprintf('%s  %2d %s  %s  %8d %s %s', $this->permissionString($elements[$i]->getPermissions()), $elements[$i]->numLinks(), $elements[$i]->getOwner(), $elements[$i]->getGroup(), $elements[$i]->getSize(), date($elements[$i]->getModifiedStamp() < $before6Months ? 'M d  Y' : 'M d H:i', $elements[$i]->getModifiedStamp()), $elements[$i]->getName());
         $this->cat && $this->cat->debug('    ', $buf);
         $dataSocket->write($buf . $this->eol($this->sessions[$socket->hashCode()]->getType()));
     }
     $dataSocket->close();
     $this->answer($socket, 226, 'Transfer complete');
 }
コード例 #4
0
 public function testSetTimezone()
 {
     $this->assertEquals(\util\Date::create(2000, 1, 1, 17, 15, 11, new TimeZone('GMT')), DateUtil::setTimeZone($this->fixture, new TimeZone('America/New_York')));
 }
コード例 #5
0
 public function multipleResultForDoSelect()
 {
     $this->setResults(new MOckResultSet(array(0 => array('job_id' => 1, 'title' => 'Unit tester', 'valid_from' => Date::now(), 'expire_at' => null), 1 => array('job_id' => 9, 'title' => 'PHP programmer', 'valid_from' => Date::now(), 'expire_at' => DateUtil::addDays(Date::now(), 7)))));
     $peer = Job::getPeer();
     $jobs = $peer->doSelect(new \rdbms\Criteria(array('job_id', 10, LESS_THAN)));
     $this->assertArray($jobs);
     $this->assertEquals(2, sizeof($jobs));
     $this->assertClass($jobs[0], 'net.xp_framework.unittest.rdbms.dataset.Job');
     $this->assertEquals(1, $jobs[0]->getJob_id());
     $this->assertClass($jobs[1], 'net.xp_framework.unittest.rdbms.dataset.Job');
     $this->assertEquals(9, $jobs[1]->getJob_id());
 }
コード例 #6
0
 public function multipleResultForDoSelect()
 {
     $this->setResults(new MockResultSet([0 => ['job_id' => 1, 'title' => 'Unit tester', 'valid_from' => Date::now(), 'expire_at' => null], 1 => ['job_id' => 9, 'title' => 'PHP programmer', 'valid_from' => Date::now(), 'expire_at' => DateUtil::addDays(Date::now(), 7)]]));
     $peer = Job::getPeer();
     $jobs = $peer->doSelect(new \rdbms\Criteria(['job_id', 10, LESS_THAN]));
     $this->assertInstanceOf('var[]', $jobs);
     $this->assertEquals(2, sizeof($jobs));
     $this->assertInstanceOf(Job::class, $jobs[0]);
     $this->assertEquals(1, $jobs[0]->getJob_id());
     $this->assertInstanceOf(Job::class, $jobs[1]);
     $this->assertEquals(9, $jobs[1]->getJob_id());
 }