/** * Checks if sufficient permissions are set to access the resource * Source must be readable, temporary read or writable, destination writable * * @param Model $Model * @param array $field * @return boolean */ public function checkAccess(Model $Model, $field) { extract($this->runtime[$Model->alias]); /* @var $source array */ /* @var $temporary string */ /* @var $destination string */ /* @var $hasPerformed boolean */ if (MediaValidation::file($source['file'], true)) { if (!MediaValidation::access($source['file'], 'r')) { return false; } } else { if (!MediaValidation::access($source['permission'], 'r')) { return false; } } if (!empty($temporary)) { if (MediaValidation::file($temporary['file'], true)) { if (!MediaValidation::access($temporary['file'], 'r')) { return false; } } elseif (MediaValidation::folder($temporary['dirname'], true)) { if (!MediaValidation::access($temporary['dirname'], 'w')) { return false; } } } if (!MediaValidation::access($destination['dirname'], 'w')) { return false; } return true; }
/** * Checks if sufficient permissions are set to access the resource * Source must be readable, temporary read or writable, destination writable * * @param Model $Model * @param array $field * @return boolean */ function checkAccess(&$Model, $field) { extract($this->runtime[$Model->alias]); if (MediaValidation::file($source['file'], true)) { if (!MediaValidation::access($source['file'], 'r')) { return false; } } else { if (!MediaValidation::access($source['permission'], 'r')) { return false; } } if (!empty($temporary)) { if (MediaValidation::file($temporary['file'], true)) { if (!MediaValidation::access($temporary['file'], 'r')) { return false; } } elseif (MediaValidation::folder($temporary['dirname'], true)) { if (!MediaValidation::access($temporary['dirname'], 'w')) { return false; } } } if (!MediaValidation::access($destination['dirname'], 'w')) { return false; } return true; }
function testAccess() { $result = MediaValidation::access('0444', 'r'); $this->assertTrue($result); $result = MediaValidation::access(0444, 'r'); $this->assertTrue($result); $result = MediaValidation::access('0004', 'r'); $this->assertTrue($result); $result = MediaValidation::access('0111', 'r'); $this->assertFalse($result); $result = MediaValidation::access('0222', 'w'); $this->assertTrue($result); $result = MediaValidation::access('0002', 'w'); $this->assertTrue($result); $result = MediaValidation::access('0111', 'w'); $this->assertFalse($result); }