Exemplo n.º 1
0
 /**
  * Test the creation based on a times other than a day.
  */
 function test_non_day_creation()
 {
     // 5 hours
     $duration = Duration::withDaysHoursMinutesSeconds(0, 5, 0, 0);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 5);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 3600 * 5);
     $this->assertTrue($duration->isEqualTo(Duration::withHours(5)));
     // 15 minutes
     $duration = Duration::withDaysHoursMinutesSeconds(0, 0, 15, 0);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 15);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 15 * 60);
     $this->assertTrue($duration->isEqualTo(Duration::withMinutes(15)));
     // 35 seconds
     $duration = Duration::withDaysHoursMinutesSeconds(0, 0, 0, 35);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 35);
     $this->assertEqual($duration->asSeconds(), 35);
     $this->assertTrue($duration->isEqualTo(Duration::withSeconds(35)));
     // 3 days, 2 hours, 23 minutes, and 12 seconds
     $duration = Duration::withDaysHoursMinutesSeconds(3, 2, 23, 12);
     $this->assertEqual($duration->days(), 3);
     $this->assertEqual($duration->hours(), 2);
     $this->assertEqual($duration->minutes(), 23);
     $this->assertEqual($duration->seconds(), 12);
     $this->assertEqual($duration->asSeconds(), ((3 * 24 + 2) * 60 + 23) * 60 + 12);
     // 48 hours
     $duration = Duration::withDaysHoursMinutesSeconds(0, 48, 0, 0);
     $this->assertEqual($duration->days(), 2);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 86400 * 2);
     // Month
     $duration = Duration::withMonth('June');
     $this->assertEqual($duration->days(), 30);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withMonth('July');
     $this->assertEqual($duration->days(), 31);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withMonth(9);
     $this->assertEqual($duration->days(), 30);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     // Weeks
     $duration = Duration::withWeeks(1);
     $this->assertEqual($duration->days(), 7);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(5);
     $this->assertEqual($duration->days(), 35);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.5);
     $this->assertEqual($duration->days(), 10);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.5);
     $this->assertEqual($duration->days(), 10);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.374);
     $this->assertEqual($duration->days(), 9);
     $this->assertEqual($duration->hours(), 14);
     $this->assertEqual($duration->minutes(), 49);
     $this->assertEqual($duration->seconds(), 55);
     $duration = Duration::withWeeks(-1.374);
     $this->assertEqual($duration->days(), -9);
     $this->assertEqual($duration->hours(), -14);
     $this->assertEqual($duration->minutes(), -49);
     $this->assertEqual($duration->seconds(), -55);
     //Zero
     $duration = Duration::zero();
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
 }
 /**
  * Initialize this cache for an authorization manager
  * 
  * @param object AuthorizationManager $manager
  * @return void
  * @access private
  * @since 4/22/08
  */
 private function initialize(AuthorizationManager $manager)
 {
     // Initialize our paremeters
     $this->_queue = array();
     $this->_agentIdStrings = array();
     $this->loadSingleAz_stmts = array();
     // get our configuration
     $this->authorizationManager = $manager;
     $this->_configuration = $manager->_configuration;
     $this->_authorizationManagerObjectCache = $manager->_cache;
     // [Re]set up our cache if it doesn't exist or if we have a new user.
     if (!isset($_SESSION['__isAuthorizedCache'])) {
         $_SESSION['__isAuthorizedCache'] = array();
     }
     // If we have been operating for more than the configured cache expiry time,
     // reset our cache so that authorization revokation can take effect.
     if (!isset($_SESSION['__isAuthorizedCacheInitTime'])) {
         $_SESSION['__isAuthorizedCacheInitTime'] = DateAndTime::now();
     }
     if (DateAndTime::now()->isGreaterThan($_SESSION['__isAuthorizedCacheInitTime']->plus(Duration::withMinutes(10)))) {
         $_SESSION['__isAuthorizedCache'] = array();
         $_SESSION['__isAuthorizedCacheInitTime'] = DateAndTime::now();
     }
     if (!isset($_SESSION['__isAuthorizedCacheUnknownIds'])) {
         $_SESSION['__isAuthorizedCacheUnknownIds'] = array();
     }
     if (!isset($_SESSION['__isAuthorizedCache']['USER']) || !isset($_SESSION['__isAuthorizedCacheAgents']['USER']) || !isset($_SESSION['__isAuthorizedCacheTime']['USER']) || $_SESSION['__isAuthorizedCacheAgents']['USER'] != implode(", ", $this->getAgentIdStringArray('USER'))) {
         $_SESSION['__isAuthorizedCacheAgents']['USER'] = implode(", ", $this->getAgentIdStringArray('USER'));
         $_SESSION['__isAuthorizedCache']['USER'] = array();
         $_SESSION['__isAuthorizedCacheTime']['USER'] = DateAndTime::now();
     }
     // Unload any expired Node AZs
     $this->_synchronizeCache();
 }
 /**
  * Answer the delay (in seconds) that the modification time should be cached without
  * checking the source again. 
  * 
  * @return object Duration
  * @access public
  * @since 5/13/08
  */
 public function getCacheDuration()
 {
     // A default of 1 minute is used. Override this method to add longer
     // or shorter times.
     return Duration::withMinutes(1);
 }