예제 #1
0
 public function testItParsesCorrectlySundays()
 {
     $testingDates = [['date' => $this->createDateTime('D', '06:10'), 'expect' => true], ['date' => $this->createDateTime('L', '1:10')->getTimestamp(), 'expect' => false], ['date' => $this->createDateTime('L', '1:01')->getTimestamp(), 'expect' => false]];
     $checker = DateRangeChecker::load("D6-12");
     foreach ($testingDates as $testingDate) {
         $this->assertEquals($checker->check($testingDate['date']), $testingDate['expect']);
     }
 }
예제 #2
0
 protected function definePermissions($gate, $repository)
 {
     foreach ($repository->getPermissions() as $permissionSlug => $extra) {
         // Checks if the configuration for this permissions has a callback
         $gate->define($permissionSlug, function ($user) use($repository, $permissionSlug, $extra) {
             // if the permission has a date range in which its allowed, but if its true still checks for the proper roles
             if (isset($extra['date_range']) && !DateRangeChecker::load($extra['date_range'])->check()) {
                 return false;
             }
             $roles = $repository->getRolesByAuthenticatableAndPermission($user, $permissionSlug);
             // The user has at least one role that grants this permission
             if ($roles->count() > 0) {
                 if (isset($extra['callback']) && is_callable($extra['callback'])) {
                     // Returns the result for the callable function
                     return call_user_func_array($extra['callback'], func_get_args());
                 } else {
                     // There is no callable so its true
                     return true;
                 }
             }
             return false;
         });
     }
 }