@@ -37,97 +37,97 @@ |
||
37 | 37 | |
38 | 38 | class Listener { |
39 | 39 | |
40 | - /** @var INotificationManager */ |
|
41 | - protected $notificationManager; |
|
42 | - /** @var IShareManager */ |
|
43 | - protected $shareManager; |
|
44 | - /** @var IGroupManager */ |
|
45 | - protected $groupManager; |
|
46 | - |
|
47 | - public function __construct( |
|
48 | - INotificationManager $notificationManager, |
|
49 | - IShareManager $shareManager, |
|
50 | - IGroupManager $groupManager |
|
51 | - ) { |
|
52 | - $this->notificationManager = $notificationManager; |
|
53 | - $this->shareManager = $shareManager; |
|
54 | - $this->groupManager = $groupManager; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param GenericEvent $event |
|
59 | - */ |
|
60 | - public function shareNotification(GenericEvent $event): void { |
|
61 | - /** @var IShare $share */ |
|
62 | - $share = $event->getSubject(); |
|
63 | - $notification = $this->instantiateNotification($share); |
|
64 | - |
|
65 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
66 | - $notification->setSubject(Notifier::INCOMING_USER_SHARE) |
|
67 | - ->setUser($share->getSharedWith()); |
|
68 | - $this->notificationManager->notify($notification); |
|
69 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
70 | - $notification->setSubject(Notifier::INCOMING_GROUP_SHARE); |
|
71 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
72 | - |
|
73 | - foreach ($group->getUsers() as $user) { |
|
74 | - if ($user->getUID() === $share->getShareOwner() || |
|
75 | - $user->getUID() === $share->getSharedBy()) { |
|
76 | - continue; |
|
77 | - } |
|
78 | - |
|
79 | - $notification->setUser($user->getUID()); |
|
80 | - $this->notificationManager->notify($notification); |
|
81 | - } |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param GenericEvent $event |
|
87 | - */ |
|
88 | - public function userAddedToGroup(GenericEvent $event): void { |
|
89 | - /** @var IGroup $group */ |
|
90 | - $group = $event->getSubject(); |
|
91 | - /** @var IUser $user */ |
|
92 | - $user = $event->getArgument('user'); |
|
93 | - |
|
94 | - $offset = 0; |
|
95 | - while (true) { |
|
96 | - $shares = $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_GROUP, null, 50, $offset); |
|
97 | - if (empty($shares)) { |
|
98 | - break; |
|
99 | - } |
|
100 | - |
|
101 | - foreach ($shares as $share) { |
|
102 | - if ($share->getSharedWith() !== $group->getGID()) { |
|
103 | - continue; |
|
104 | - } |
|
105 | - |
|
106 | - if ($user->getUID() === $share->getShareOwner() || |
|
107 | - $user->getUID() === $share->getSharedBy()) { |
|
108 | - continue; |
|
109 | - } |
|
110 | - |
|
111 | - $notification = $this->instantiateNotification($share); |
|
112 | - $notification->setSubject(Notifier::INCOMING_GROUP_SHARE) |
|
113 | - ->setUser($user->getUID()); |
|
114 | - $this->notificationManager->notify($notification); |
|
115 | - } |
|
116 | - $offset += 50; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param IShare $share |
|
122 | - * @return INotification |
|
123 | - */ |
|
124 | - protected function instantiateNotification(IShare $share): INotification { |
|
125 | - $notification = $this->notificationManager->createNotification(); |
|
126 | - $notification |
|
127 | - ->setApp('files_sharing') |
|
128 | - ->setObject('share', $share->getFullId()) |
|
129 | - ->setDateTime($share->getShareTime()); |
|
130 | - |
|
131 | - return $notification; |
|
132 | - } |
|
40 | + /** @var INotificationManager */ |
|
41 | + protected $notificationManager; |
|
42 | + /** @var IShareManager */ |
|
43 | + protected $shareManager; |
|
44 | + /** @var IGroupManager */ |
|
45 | + protected $groupManager; |
|
46 | + |
|
47 | + public function __construct( |
|
48 | + INotificationManager $notificationManager, |
|
49 | + IShareManager $shareManager, |
|
50 | + IGroupManager $groupManager |
|
51 | + ) { |
|
52 | + $this->notificationManager = $notificationManager; |
|
53 | + $this->shareManager = $shareManager; |
|
54 | + $this->groupManager = $groupManager; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param GenericEvent $event |
|
59 | + */ |
|
60 | + public function shareNotification(GenericEvent $event): void { |
|
61 | + /** @var IShare $share */ |
|
62 | + $share = $event->getSubject(); |
|
63 | + $notification = $this->instantiateNotification($share); |
|
64 | + |
|
65 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
66 | + $notification->setSubject(Notifier::INCOMING_USER_SHARE) |
|
67 | + ->setUser($share->getSharedWith()); |
|
68 | + $this->notificationManager->notify($notification); |
|
69 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
70 | + $notification->setSubject(Notifier::INCOMING_GROUP_SHARE); |
|
71 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
72 | + |
|
73 | + foreach ($group->getUsers() as $user) { |
|
74 | + if ($user->getUID() === $share->getShareOwner() || |
|
75 | + $user->getUID() === $share->getSharedBy()) { |
|
76 | + continue; |
|
77 | + } |
|
78 | + |
|
79 | + $notification->setUser($user->getUID()); |
|
80 | + $this->notificationManager->notify($notification); |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param GenericEvent $event |
|
87 | + */ |
|
88 | + public function userAddedToGroup(GenericEvent $event): void { |
|
89 | + /** @var IGroup $group */ |
|
90 | + $group = $event->getSubject(); |
|
91 | + /** @var IUser $user */ |
|
92 | + $user = $event->getArgument('user'); |
|
93 | + |
|
94 | + $offset = 0; |
|
95 | + while (true) { |
|
96 | + $shares = $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_GROUP, null, 50, $offset); |
|
97 | + if (empty($shares)) { |
|
98 | + break; |
|
99 | + } |
|
100 | + |
|
101 | + foreach ($shares as $share) { |
|
102 | + if ($share->getSharedWith() !== $group->getGID()) { |
|
103 | + continue; |
|
104 | + } |
|
105 | + |
|
106 | + if ($user->getUID() === $share->getShareOwner() || |
|
107 | + $user->getUID() === $share->getSharedBy()) { |
|
108 | + continue; |
|
109 | + } |
|
110 | + |
|
111 | + $notification = $this->instantiateNotification($share); |
|
112 | + $notification->setSubject(Notifier::INCOMING_GROUP_SHARE) |
|
113 | + ->setUser($user->getUID()); |
|
114 | + $this->notificationManager->notify($notification); |
|
115 | + } |
|
116 | + $offset += 50; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param IShare $share |
|
122 | + * @return INotification |
|
123 | + */ |
|
124 | + protected function instantiateNotification(IShare $share): INotification { |
|
125 | + $notification = $this->notificationManager->createNotification(); |
|
126 | + $notification |
|
127 | + ->setApp('files_sharing') |
|
128 | + ->setObject('share', $share->getFullId()) |
|
129 | + ->setDateTime($share->getShareTime()); |
|
130 | + |
|
131 | + return $notification; |
|
132 | + } |
|
133 | 133 | } |
@@ -27,96 +27,96 @@ |
||
27 | 27 | |
28 | 28 | abstract class AbstractStringCheck implements ICheck { |
29 | 29 | |
30 | - /** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */ |
|
31 | - protected $matches; |
|
30 | + /** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */ |
|
31 | + protected $matches; |
|
32 | 32 | |
33 | - /** @var IL10N */ |
|
34 | - protected $l; |
|
33 | + /** @var IL10N */ |
|
34 | + protected $l; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param IL10N $l |
|
38 | - */ |
|
39 | - public function __construct(IL10N $l) { |
|
40 | - $this->l = $l; |
|
41 | - } |
|
36 | + /** |
|
37 | + * @param IL10N $l |
|
38 | + */ |
|
39 | + public function __construct(IL10N $l) { |
|
40 | + $this->l = $l; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - abstract protected function getActualValue(); |
|
43 | + /** |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + abstract protected function getActualValue(); |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $operator |
|
50 | - * @param string $value |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function executeCheck($operator, $value) { |
|
54 | - $actualValue = $this->getActualValue(); |
|
55 | - return $this->executeStringCheck($operator, $value, $actualValue); |
|
56 | - } |
|
48 | + /** |
|
49 | + * @param string $operator |
|
50 | + * @param string $value |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function executeCheck($operator, $value) { |
|
54 | + $actualValue = $this->getActualValue(); |
|
55 | + return $this->executeStringCheck($operator, $value, $actualValue); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $operator |
|
60 | - * @param string $checkValue |
|
61 | - * @param string $actualValue |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - protected function executeStringCheck($operator, $checkValue, $actualValue) { |
|
65 | - if ($operator === 'is') { |
|
66 | - return $checkValue === $actualValue; |
|
67 | - } elseif ($operator === '!is') { |
|
68 | - return $checkValue !== $actualValue; |
|
69 | - } else { |
|
70 | - $match = $this->match($checkValue, $actualValue); |
|
71 | - if ($operator === 'matches') { |
|
72 | - return $match === 1; |
|
73 | - } else { |
|
74 | - return $match === 0; |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
58 | + /** |
|
59 | + * @param string $operator |
|
60 | + * @param string $checkValue |
|
61 | + * @param string $actualValue |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + protected function executeStringCheck($operator, $checkValue, $actualValue) { |
|
65 | + if ($operator === 'is') { |
|
66 | + return $checkValue === $actualValue; |
|
67 | + } elseif ($operator === '!is') { |
|
68 | + return $checkValue !== $actualValue; |
|
69 | + } else { |
|
70 | + $match = $this->match($checkValue, $actualValue); |
|
71 | + if ($operator === 'matches') { |
|
72 | + return $match === 1; |
|
73 | + } else { |
|
74 | + return $match === 0; |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param string $operator |
|
81 | - * @param string $value |
|
82 | - * @throws \UnexpectedValueException |
|
83 | - */ |
|
84 | - public function validateCheck($operator, $value) { |
|
85 | - if (!in_array($operator, ['is', '!is', 'matches', '!matches'])) { |
|
86 | - throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
|
87 | - } |
|
79 | + /** |
|
80 | + * @param string $operator |
|
81 | + * @param string $value |
|
82 | + * @throws \UnexpectedValueException |
|
83 | + */ |
|
84 | + public function validateCheck($operator, $value) { |
|
85 | + if (!in_array($operator, ['is', '!is', 'matches', '!matches'])) { |
|
86 | + throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
|
87 | + } |
|
88 | 88 | |
89 | - if (in_array($operator, ['matches', '!matches']) && |
|
90 | - @preg_match($value, null) === false) { |
|
91 | - throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2); |
|
92 | - } |
|
93 | - } |
|
89 | + if (in_array($operator, ['matches', '!matches']) && |
|
90 | + @preg_match($value, null) === false) { |
|
91 | + throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - public function supportedEntities(): array { |
|
96 | - // universal by default |
|
97 | - return []; |
|
98 | - } |
|
95 | + public function supportedEntities(): array { |
|
96 | + // universal by default |
|
97 | + return []; |
|
98 | + } |
|
99 | 99 | |
100 | - public function isAvailableForScope(int $scope): bool { |
|
101 | - // admin only by default |
|
102 | - return $scope === IManager::SCOPE_ADMIN; |
|
103 | - } |
|
100 | + public function isAvailableForScope(int $scope): bool { |
|
101 | + // admin only by default |
|
102 | + return $scope === IManager::SCOPE_ADMIN; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @param string $pattern |
|
107 | - * @param string $subject |
|
108 | - * @return int|bool |
|
109 | - */ |
|
110 | - protected function match($pattern, $subject) { |
|
111 | - $patternHash = md5($pattern); |
|
112 | - $subjectHash = md5($subject); |
|
113 | - if (isset($this->matches[$patternHash][$subjectHash])) { |
|
114 | - return $this->matches[$patternHash][$subjectHash]; |
|
115 | - } |
|
116 | - if (!isset($this->matches[$patternHash])) { |
|
117 | - $this->matches[$patternHash] = []; |
|
118 | - } |
|
119 | - $this->matches[$patternHash][$subjectHash] = preg_match($pattern, $subject); |
|
120 | - return $this->matches[$patternHash][$subjectHash]; |
|
121 | - } |
|
105 | + /** |
|
106 | + * @param string $pattern |
|
107 | + * @param string $subject |
|
108 | + * @return int|bool |
|
109 | + */ |
|
110 | + protected function match($pattern, $subject) { |
|
111 | + $patternHash = md5($pattern); |
|
112 | + $subjectHash = md5($subject); |
|
113 | + if (isset($this->matches[$patternHash][$subjectHash])) { |
|
114 | + return $this->matches[$patternHash][$subjectHash]; |
|
115 | + } |
|
116 | + if (!isset($this->matches[$patternHash])) { |
|
117 | + $this->matches[$patternHash] = []; |
|
118 | + } |
|
119 | + $this->matches[$patternHash][$subjectHash] = preg_match($pattern, $subject); |
|
120 | + return $this->matches[$patternHash][$subjectHash]; |
|
121 | + } |
|
122 | 122 | } |
@@ -21,4 +21,4 @@ |
||
21 | 21 | * |
22 | 22 | */ |
23 | 23 | |
24 | - # used for Personal/Additional settings as fallback for legacy settings |
|
24 | + # used for Personal/Additional settings as fallback for legacy settings |
@@ -143,7 +143,7 @@ |
||
143 | 143 | } elseif ($existing === 'exclusive') { |
144 | 144 | return $existing; |
145 | 145 | } else { |
146 | - return $existing . ' shared locks'; |
|
146 | + return $existing.' shared locks'; |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
@@ -32,95 +32,95 @@ |
||
32 | 32 | use OCP\Lock\LockedException; |
33 | 33 | |
34 | 34 | class MemcacheLockingProvider extends AbstractLockingProvider { |
35 | - private IMemcache $memcache; |
|
35 | + private IMemcache $memcache; |
|
36 | 36 | |
37 | - public function __construct(IMemcache $memcache, int $ttl = 3600) { |
|
38 | - $this->memcache = $memcache; |
|
39 | - $this->ttl = $ttl; |
|
40 | - } |
|
37 | + public function __construct(IMemcache $memcache, int $ttl = 3600) { |
|
38 | + $this->memcache = $memcache; |
|
39 | + $this->ttl = $ttl; |
|
40 | + } |
|
41 | 41 | |
42 | - private function setTTL(string $path): void { |
|
43 | - if ($this->memcache instanceof IMemcacheTTL) { |
|
44 | - $this->memcache->setTTL($path, $this->ttl); |
|
45 | - } |
|
46 | - } |
|
42 | + private function setTTL(string $path): void { |
|
43 | + if ($this->memcache instanceof IMemcacheTTL) { |
|
44 | + $this->memcache->setTTL($path, $this->ttl); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - public function isLocked(string $path, int $type): bool { |
|
49 | - $lockValue = $this->memcache->get($path); |
|
50 | - if ($type === self::LOCK_SHARED) { |
|
51 | - return is_int($lockValue) && $lockValue > 0; |
|
52 | - } elseif ($type === self::LOCK_EXCLUSIVE) { |
|
53 | - return $lockValue === 'exclusive'; |
|
54 | - } else { |
|
55 | - return false; |
|
56 | - } |
|
57 | - } |
|
48 | + public function isLocked(string $path, int $type): bool { |
|
49 | + $lockValue = $this->memcache->get($path); |
|
50 | + if ($type === self::LOCK_SHARED) { |
|
51 | + return is_int($lockValue) && $lockValue > 0; |
|
52 | + } elseif ($type === self::LOCK_EXCLUSIVE) { |
|
53 | + return $lockValue === 'exclusive'; |
|
54 | + } else { |
|
55 | + return false; |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - public function acquireLock(string $path, int $type, ?string $readablePath = null): void { |
|
60 | - if ($type === self::LOCK_SHARED) { |
|
61 | - if (!$this->memcache->inc($path)) { |
|
62 | - throw new LockedException($path, null, $this->getExistingLockForException($path), $readablePath); |
|
63 | - } |
|
64 | - } else { |
|
65 | - $this->memcache->add($path, 0); |
|
66 | - if (!$this->memcache->cas($path, 0, 'exclusive')) { |
|
67 | - throw new LockedException($path, null, $this->getExistingLockForException($path), $readablePath); |
|
68 | - } |
|
69 | - } |
|
70 | - $this->setTTL($path); |
|
71 | - $this->markAcquire($path, $type); |
|
72 | - } |
|
59 | + public function acquireLock(string $path, int $type, ?string $readablePath = null): void { |
|
60 | + if ($type === self::LOCK_SHARED) { |
|
61 | + if (!$this->memcache->inc($path)) { |
|
62 | + throw new LockedException($path, null, $this->getExistingLockForException($path), $readablePath); |
|
63 | + } |
|
64 | + } else { |
|
65 | + $this->memcache->add($path, 0); |
|
66 | + if (!$this->memcache->cas($path, 0, 'exclusive')) { |
|
67 | + throw new LockedException($path, null, $this->getExistingLockForException($path), $readablePath); |
|
68 | + } |
|
69 | + } |
|
70 | + $this->setTTL($path); |
|
71 | + $this->markAcquire($path, $type); |
|
72 | + } |
|
73 | 73 | |
74 | - public function releaseLock(string $path, int $type): void { |
|
75 | - if ($type === self::LOCK_SHARED) { |
|
76 | - $ownSharedLockCount = $this->getOwnSharedLockCount($path); |
|
77 | - $newValue = 0; |
|
78 | - if ($ownSharedLockCount === 0) { // if we are not holding the lock, don't try to release it |
|
79 | - return; |
|
80 | - } |
|
81 | - if ($ownSharedLockCount === 1) { |
|
82 | - $removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go |
|
83 | - if (!$removed) { //someone else also has a shared lock, decrease only |
|
84 | - $newValue = $this->memcache->dec($path); |
|
85 | - } |
|
86 | - } else { |
|
87 | - // if we own more than one lock ourselves just decrease |
|
88 | - $newValue = $this->memcache->dec($path); |
|
89 | - } |
|
74 | + public function releaseLock(string $path, int $type): void { |
|
75 | + if ($type === self::LOCK_SHARED) { |
|
76 | + $ownSharedLockCount = $this->getOwnSharedLockCount($path); |
|
77 | + $newValue = 0; |
|
78 | + if ($ownSharedLockCount === 0) { // if we are not holding the lock, don't try to release it |
|
79 | + return; |
|
80 | + } |
|
81 | + if ($ownSharedLockCount === 1) { |
|
82 | + $removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go |
|
83 | + if (!$removed) { //someone else also has a shared lock, decrease only |
|
84 | + $newValue = $this->memcache->dec($path); |
|
85 | + } |
|
86 | + } else { |
|
87 | + // if we own more than one lock ourselves just decrease |
|
88 | + $newValue = $this->memcache->dec($path); |
|
89 | + } |
|
90 | 90 | |
91 | - // if we somehow release more locks then exists, reset the lock |
|
92 | - if ($newValue < 0) { |
|
93 | - $this->memcache->cad($path, $newValue); |
|
94 | - } |
|
95 | - } elseif ($type === self::LOCK_EXCLUSIVE) { |
|
96 | - $this->memcache->cad($path, 'exclusive'); |
|
97 | - } |
|
98 | - $this->markRelease($path, $type); |
|
99 | - } |
|
91 | + // if we somehow release more locks then exists, reset the lock |
|
92 | + if ($newValue < 0) { |
|
93 | + $this->memcache->cad($path, $newValue); |
|
94 | + } |
|
95 | + } elseif ($type === self::LOCK_EXCLUSIVE) { |
|
96 | + $this->memcache->cad($path, 'exclusive'); |
|
97 | + } |
|
98 | + $this->markRelease($path, $type); |
|
99 | + } |
|
100 | 100 | |
101 | - public function changeLock(string $path, int $targetType): void { |
|
102 | - if ($targetType === self::LOCK_SHARED) { |
|
103 | - if (!$this->memcache->cas($path, 'exclusive', 1)) { |
|
104 | - throw new LockedException($path, null, $this->getExistingLockForException($path)); |
|
105 | - } |
|
106 | - } elseif ($targetType === self::LOCK_EXCLUSIVE) { |
|
107 | - // we can only change a shared lock to an exclusive if there's only a single owner of the shared lock |
|
108 | - if (!$this->memcache->cas($path, 1, 'exclusive')) { |
|
109 | - throw new LockedException($path, null, $this->getExistingLockForException($path)); |
|
110 | - } |
|
111 | - } |
|
112 | - $this->setTTL($path); |
|
113 | - $this->markChange($path, $targetType); |
|
114 | - } |
|
101 | + public function changeLock(string $path, int $targetType): void { |
|
102 | + if ($targetType === self::LOCK_SHARED) { |
|
103 | + if (!$this->memcache->cas($path, 'exclusive', 1)) { |
|
104 | + throw new LockedException($path, null, $this->getExistingLockForException($path)); |
|
105 | + } |
|
106 | + } elseif ($targetType === self::LOCK_EXCLUSIVE) { |
|
107 | + // we can only change a shared lock to an exclusive if there's only a single owner of the shared lock |
|
108 | + if (!$this->memcache->cas($path, 1, 'exclusive')) { |
|
109 | + throw new LockedException($path, null, $this->getExistingLockForException($path)); |
|
110 | + } |
|
111 | + } |
|
112 | + $this->setTTL($path); |
|
113 | + $this->markChange($path, $targetType); |
|
114 | + } |
|
115 | 115 | |
116 | - private function getExistingLockForException(string $path): string { |
|
117 | - $existing = $this->memcache->get($path); |
|
118 | - if (!$existing) { |
|
119 | - return 'none'; |
|
120 | - } elseif ($existing === 'exclusive') { |
|
121 | - return $existing; |
|
122 | - } else { |
|
123 | - return $existing . ' shared locks'; |
|
124 | - } |
|
125 | - } |
|
116 | + private function getExistingLockForException(string $path): string { |
|
117 | + $existing = $this->memcache->get($path); |
|
118 | + if (!$existing) { |
|
119 | + return 'none'; |
|
120 | + } elseif ($existing === 'exclusive') { |
|
121 | + return $existing; |
|
122 | + } else { |
|
123 | + return $existing . ' shared locks'; |
|
124 | + } |
|
125 | + } |
|
126 | 126 | } |
@@ -31,44 +31,44 @@ |
||
31 | 31 | * @since 13.0.0 |
32 | 32 | */ |
33 | 33 | class SearchResultType { |
34 | - /** @var string */ |
|
35 | - protected $label; |
|
34 | + /** @var string */ |
|
35 | + protected $label; |
|
36 | 36 | |
37 | - /** |
|
38 | - * SearchResultType constructor. |
|
39 | - * |
|
40 | - * @param string $label |
|
41 | - * @since 13.0.0 |
|
42 | - */ |
|
43 | - public function __construct($label) { |
|
44 | - $this->label = $this->getValidatedType($label); |
|
45 | - } |
|
37 | + /** |
|
38 | + * SearchResultType constructor. |
|
39 | + * |
|
40 | + * @param string $label |
|
41 | + * @since 13.0.0 |
|
42 | + */ |
|
43 | + public function __construct($label) { |
|
44 | + $this->label = $this->getValidatedType($label); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return string |
|
49 | - * @since 13.0.0 |
|
50 | - */ |
|
51 | - public function getLabel() { |
|
52 | - return $this->label; |
|
53 | - } |
|
47 | + /** |
|
48 | + * @return string |
|
49 | + * @since 13.0.0 |
|
50 | + */ |
|
51 | + public function getLabel() { |
|
52 | + return $this->label; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param $type |
|
57 | - * @return string |
|
58 | - * @throws \InvalidArgumentException |
|
59 | - * @since 13.0.0 |
|
60 | - */ |
|
61 | - protected function getValidatedType($type) { |
|
62 | - $type = trim((string)$type); |
|
55 | + /** |
|
56 | + * @param $type |
|
57 | + * @return string |
|
58 | + * @throws \InvalidArgumentException |
|
59 | + * @since 13.0.0 |
|
60 | + */ |
|
61 | + protected function getValidatedType($type) { |
|
62 | + $type = trim((string)$type); |
|
63 | 63 | |
64 | - if ($type === '') { |
|
65 | - throw new \InvalidArgumentException('Type must not be empty'); |
|
66 | - } |
|
64 | + if ($type === '') { |
|
65 | + throw new \InvalidArgumentException('Type must not be empty'); |
|
66 | + } |
|
67 | 67 | |
68 | - if ($type === 'exact') { |
|
69 | - throw new \InvalidArgumentException('Provided type is a reserved word'); |
|
70 | - } |
|
68 | + if ($type === 'exact') { |
|
69 | + throw new \InvalidArgumentException('Provided type is a reserved word'); |
|
70 | + } |
|
71 | 71 | |
72 | - return $type; |
|
73 | - } |
|
72 | + return $type; |
|
73 | + } |
|
74 | 74 | } |
@@ -59,7 +59,7 @@ |
||
59 | 59 | * @since 13.0.0 |
60 | 60 | */ |
61 | 61 | protected function getValidatedType($type) { |
62 | - $type = trim((string)$type); |
|
62 | + $type = trim((string) $type); |
|
63 | 63 | |
64 | 64 | if ($type === '') { |
65 | 65 | throw new \InvalidArgumentException('Type must not be empty'); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $instance = new static(); |
52 | 52 | |
53 | 53 | foreach ($params as $key => $value) { |
54 | - $method = 'set' . ucfirst($key); |
|
54 | + $method = 'set'.ucfirst($key); |
|
55 | 55 | $instance->$method($value); |
56 | 56 | } |
57 | 57 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | foreach ($row as $key => $value) { |
71 | 71 | $prop = ucfirst($instance->columnToProperty($key)); |
72 | - $setter = 'set' . $prop; |
|
72 | + $setter = 'set'.$prop; |
|
73 | 73 | $instance->$setter($value); |
74 | 74 | } |
75 | 75 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | } |
115 | 115 | $this->$name = $args[0]; |
116 | 116 | } else { |
117 | - throw new \BadFunctionCallException($name . |
|
117 | + throw new \BadFunctionCallException($name. |
|
118 | 118 | ' is not a valid attribute'); |
119 | 119 | } |
120 | 120 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | if (property_exists($this, $name)) { |
129 | 129 | return $this->$name; |
130 | 130 | } else { |
131 | - throw new \BadFunctionCallException($name . |
|
131 | + throw new \BadFunctionCallException($name. |
|
132 | 132 | ' is not a valid attribute'); |
133 | 133 | } |
134 | 134 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } elseif ($this->isGetterForBoolProperty($methodName)) { |
150 | 150 | return $this->getter(lcfirst(substr($methodName, 2))); |
151 | 151 | } else { |
152 | - throw new \BadFunctionCallException($methodName . |
|
152 | + throw new \BadFunctionCallException($methodName. |
|
153 | 153 | ' does not exist'); |
154 | 154 | } |
155 | 155 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | if ($column === null) { |
214 | 214 | $column = $part; |
215 | 215 | } else { |
216 | - $column .= '_' . lcfirst($part); |
|
216 | + $column .= '_'.lcfirst($part); |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | // trim '-' |
260 | 260 | return trim($value, '-'); |
261 | 261 | } else { |
262 | - throw new \BadFunctionCallException($attributeName . |
|
262 | + throw new \BadFunctionCallException($attributeName. |
|
263 | 263 | ' is not a valid attribute'); |
264 | 264 | } |
265 | 265 | } |
@@ -35,254 +35,254 @@ |
||
35 | 35 | * @psalm-consistent-constructor |
36 | 36 | */ |
37 | 37 | abstract class Entity { |
38 | - /** |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - public $id; |
|
42 | - |
|
43 | - private array $_updatedFields = []; |
|
44 | - private array $_fieldTypes = ['id' => 'integer']; |
|
45 | - |
|
46 | - /** |
|
47 | - * Simple alternative constructor for building entities from a request |
|
48 | - * @param array $params the array which was obtained via $this->params('key') |
|
49 | - * in the controller |
|
50 | - * @since 7.0.0 |
|
51 | - */ |
|
52 | - public static function fromParams(array $params): static { |
|
53 | - $instance = new static(); |
|
54 | - |
|
55 | - foreach ($params as $key => $value) { |
|
56 | - $method = 'set' . ucfirst($key); |
|
57 | - $instance->$method($value); |
|
58 | - } |
|
59 | - |
|
60 | - return $instance; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Maps the keys of the row array to the attributes |
|
66 | - * @param array $row the row to map onto the entity |
|
67 | - * @since 7.0.0 |
|
68 | - */ |
|
69 | - public static function fromRow(array $row): static { |
|
70 | - $instance = new static(); |
|
71 | - |
|
72 | - foreach ($row as $key => $value) { |
|
73 | - $prop = ucfirst($instance->columnToProperty($key)); |
|
74 | - $setter = 'set' . $prop; |
|
75 | - $instance->$setter($value); |
|
76 | - } |
|
77 | - |
|
78 | - $instance->resetUpdatedFields(); |
|
79 | - |
|
80 | - return $instance; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @return array with attribute and type |
|
86 | - * @since 7.0.0 |
|
87 | - */ |
|
88 | - public function getFieldTypes() { |
|
89 | - return $this->_fieldTypes; |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Marks the entity as clean needed for setting the id after the insertion |
|
95 | - * @since 7.0.0 |
|
96 | - */ |
|
97 | - public function resetUpdatedFields() { |
|
98 | - $this->_updatedFields = []; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Generic setter for properties |
|
103 | - * @since 7.0.0 |
|
104 | - */ |
|
105 | - protected function setter(string $name, array $args): void { |
|
106 | - // setters should only work for existing attributes |
|
107 | - if (property_exists($this, $name)) { |
|
108 | - if ($this->$name === $args[0]) { |
|
109 | - return; |
|
110 | - } |
|
111 | - $this->markFieldUpdated($name); |
|
112 | - |
|
113 | - // if type definition exists, cast to correct type |
|
114 | - if ($args[0] !== null && array_key_exists($name, $this->_fieldTypes)) { |
|
115 | - $type = $this->_fieldTypes[$name]; |
|
116 | - if ($type === 'blob') { |
|
117 | - // (B)LOB is treated as string when we read from the DB |
|
118 | - if (is_resource($args[0])) { |
|
119 | - $args[0] = stream_get_contents($args[0]); |
|
120 | - } |
|
121 | - $type = 'string'; |
|
122 | - } |
|
123 | - |
|
124 | - if ($type === 'datetime') { |
|
125 | - if (!$args[0] instanceof \DateTime) { |
|
126 | - $args[0] = new \DateTime($args[0]); |
|
127 | - } |
|
128 | - } elseif ($type === 'json') { |
|
129 | - if (!is_array($args[0])) { |
|
130 | - $args[0] = json_decode($args[0], true); |
|
131 | - } |
|
132 | - } else { |
|
133 | - settype($args[0], $type); |
|
134 | - } |
|
135 | - } |
|
136 | - $this->$name = $args[0]; |
|
137 | - } else { |
|
138 | - throw new \BadFunctionCallException($name . |
|
139 | - ' is not a valid attribute'); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Generic getter for properties |
|
145 | - * @since 7.0.0 |
|
146 | - */ |
|
147 | - protected function getter(string $name): mixed { |
|
148 | - // getters should only work for existing attributes |
|
149 | - if (property_exists($this, $name)) { |
|
150 | - return $this->$name; |
|
151 | - } else { |
|
152 | - throw new \BadFunctionCallException($name . |
|
153 | - ' is not a valid attribute'); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Each time a setter is called, push the part after set |
|
160 | - * into an array: for instance setId will save Id in the |
|
161 | - * updated fields array so it can be easily used to create the |
|
162 | - * getter method |
|
163 | - * @since 7.0.0 |
|
164 | - */ |
|
165 | - public function __call(string $methodName, array $args) { |
|
166 | - if (strpos($methodName, 'set') === 0) { |
|
167 | - $this->setter(lcfirst(substr($methodName, 3)), $args); |
|
168 | - } elseif (strpos($methodName, 'get') === 0) { |
|
169 | - return $this->getter(lcfirst(substr($methodName, 3))); |
|
170 | - } elseif ($this->isGetterForBoolProperty($methodName)) { |
|
171 | - return $this->getter(lcfirst(substr($methodName, 2))); |
|
172 | - } else { |
|
173 | - throw new \BadFunctionCallException($methodName . |
|
174 | - ' does not exist'); |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @param string $methodName |
|
180 | - * @return bool |
|
181 | - * @since 18.0.0 |
|
182 | - */ |
|
183 | - protected function isGetterForBoolProperty(string $methodName): bool { |
|
184 | - if (strpos($methodName, 'is') === 0) { |
|
185 | - $fieldName = lcfirst(substr($methodName, 2)); |
|
186 | - return isset($this->_fieldTypes[$fieldName]) && strpos($this->_fieldTypes[$fieldName], 'bool') === 0; |
|
187 | - } |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Mark am attribute as updated |
|
193 | - * @param string $attribute the name of the attribute |
|
194 | - * @since 7.0.0 |
|
195 | - */ |
|
196 | - protected function markFieldUpdated(string $attribute): void { |
|
197 | - $this->_updatedFields[$attribute] = true; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Transform a database columnname to a property |
|
203 | - * @param string $columnName the name of the column |
|
204 | - * @return string the property name |
|
205 | - * @since 7.0.0 |
|
206 | - */ |
|
207 | - public function columnToProperty($columnName) { |
|
208 | - $parts = explode('_', $columnName); |
|
209 | - $property = null; |
|
210 | - |
|
211 | - foreach ($parts as $part) { |
|
212 | - if ($property === null) { |
|
213 | - $property = $part; |
|
214 | - } else { |
|
215 | - $property .= ucfirst($part); |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - return $property; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Transform a property to a database column name |
|
225 | - * @param string $property the name of the property |
|
226 | - * @return string the column name |
|
227 | - * @since 7.0.0 |
|
228 | - */ |
|
229 | - public function propertyToColumn($property) { |
|
230 | - $parts = preg_split('/(?=[A-Z])/', $property); |
|
231 | - $column = null; |
|
232 | - |
|
233 | - foreach ($parts as $part) { |
|
234 | - if ($column === null) { |
|
235 | - $column = $part; |
|
236 | - } else { |
|
237 | - $column .= '_' . lcfirst($part); |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - return $column; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @return array array of updated fields for update query |
|
247 | - * @since 7.0.0 |
|
248 | - */ |
|
249 | - public function getUpdatedFields() { |
|
250 | - return $this->_updatedFields; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Adds type information for a field so that its automatically casted to |
|
256 | - * that value once its being returned from the database |
|
257 | - * @param string $fieldName the name of the attribute |
|
258 | - * @param string $type the type which will be used to call settype() |
|
259 | - * @since 7.0.0 |
|
260 | - */ |
|
261 | - protected function addType($fieldName, $type) { |
|
262 | - $this->_fieldTypes[$fieldName] = $type; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * Slugify the value of a given attribute |
|
268 | - * Warning: This doesn't result in a unique value |
|
269 | - * @param string $attributeName the name of the attribute, which value should be slugified |
|
270 | - * @return string slugified value |
|
271 | - * @since 7.0.0 |
|
272 | - * @deprecated 24.0.0 |
|
273 | - */ |
|
274 | - public function slugify($attributeName) { |
|
275 | - // toSlug should only work for existing attributes |
|
276 | - if (property_exists($this, $attributeName)) { |
|
277 | - $value = $this->$attributeName; |
|
278 | - // replace everything except alphanumeric with a single '-' |
|
279 | - $value = preg_replace('/[^A-Za-z0-9]+/', '-', $value); |
|
280 | - $value = strtolower($value); |
|
281 | - // trim '-' |
|
282 | - return trim($value, '-'); |
|
283 | - } else { |
|
284 | - throw new \BadFunctionCallException($attributeName . |
|
285 | - ' is not a valid attribute'); |
|
286 | - } |
|
287 | - } |
|
38 | + /** |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + public $id; |
|
42 | + |
|
43 | + private array $_updatedFields = []; |
|
44 | + private array $_fieldTypes = ['id' => 'integer']; |
|
45 | + |
|
46 | + /** |
|
47 | + * Simple alternative constructor for building entities from a request |
|
48 | + * @param array $params the array which was obtained via $this->params('key') |
|
49 | + * in the controller |
|
50 | + * @since 7.0.0 |
|
51 | + */ |
|
52 | + public static function fromParams(array $params): static { |
|
53 | + $instance = new static(); |
|
54 | + |
|
55 | + foreach ($params as $key => $value) { |
|
56 | + $method = 'set' . ucfirst($key); |
|
57 | + $instance->$method($value); |
|
58 | + } |
|
59 | + |
|
60 | + return $instance; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Maps the keys of the row array to the attributes |
|
66 | + * @param array $row the row to map onto the entity |
|
67 | + * @since 7.0.0 |
|
68 | + */ |
|
69 | + public static function fromRow(array $row): static { |
|
70 | + $instance = new static(); |
|
71 | + |
|
72 | + foreach ($row as $key => $value) { |
|
73 | + $prop = ucfirst($instance->columnToProperty($key)); |
|
74 | + $setter = 'set' . $prop; |
|
75 | + $instance->$setter($value); |
|
76 | + } |
|
77 | + |
|
78 | + $instance->resetUpdatedFields(); |
|
79 | + |
|
80 | + return $instance; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @return array with attribute and type |
|
86 | + * @since 7.0.0 |
|
87 | + */ |
|
88 | + public function getFieldTypes() { |
|
89 | + return $this->_fieldTypes; |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Marks the entity as clean needed for setting the id after the insertion |
|
95 | + * @since 7.0.0 |
|
96 | + */ |
|
97 | + public function resetUpdatedFields() { |
|
98 | + $this->_updatedFields = []; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Generic setter for properties |
|
103 | + * @since 7.0.0 |
|
104 | + */ |
|
105 | + protected function setter(string $name, array $args): void { |
|
106 | + // setters should only work for existing attributes |
|
107 | + if (property_exists($this, $name)) { |
|
108 | + if ($this->$name === $args[0]) { |
|
109 | + return; |
|
110 | + } |
|
111 | + $this->markFieldUpdated($name); |
|
112 | + |
|
113 | + // if type definition exists, cast to correct type |
|
114 | + if ($args[0] !== null && array_key_exists($name, $this->_fieldTypes)) { |
|
115 | + $type = $this->_fieldTypes[$name]; |
|
116 | + if ($type === 'blob') { |
|
117 | + // (B)LOB is treated as string when we read from the DB |
|
118 | + if (is_resource($args[0])) { |
|
119 | + $args[0] = stream_get_contents($args[0]); |
|
120 | + } |
|
121 | + $type = 'string'; |
|
122 | + } |
|
123 | + |
|
124 | + if ($type === 'datetime') { |
|
125 | + if (!$args[0] instanceof \DateTime) { |
|
126 | + $args[0] = new \DateTime($args[0]); |
|
127 | + } |
|
128 | + } elseif ($type === 'json') { |
|
129 | + if (!is_array($args[0])) { |
|
130 | + $args[0] = json_decode($args[0], true); |
|
131 | + } |
|
132 | + } else { |
|
133 | + settype($args[0], $type); |
|
134 | + } |
|
135 | + } |
|
136 | + $this->$name = $args[0]; |
|
137 | + } else { |
|
138 | + throw new \BadFunctionCallException($name . |
|
139 | + ' is not a valid attribute'); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Generic getter for properties |
|
145 | + * @since 7.0.0 |
|
146 | + */ |
|
147 | + protected function getter(string $name): mixed { |
|
148 | + // getters should only work for existing attributes |
|
149 | + if (property_exists($this, $name)) { |
|
150 | + return $this->$name; |
|
151 | + } else { |
|
152 | + throw new \BadFunctionCallException($name . |
|
153 | + ' is not a valid attribute'); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Each time a setter is called, push the part after set |
|
160 | + * into an array: for instance setId will save Id in the |
|
161 | + * updated fields array so it can be easily used to create the |
|
162 | + * getter method |
|
163 | + * @since 7.0.0 |
|
164 | + */ |
|
165 | + public function __call(string $methodName, array $args) { |
|
166 | + if (strpos($methodName, 'set') === 0) { |
|
167 | + $this->setter(lcfirst(substr($methodName, 3)), $args); |
|
168 | + } elseif (strpos($methodName, 'get') === 0) { |
|
169 | + return $this->getter(lcfirst(substr($methodName, 3))); |
|
170 | + } elseif ($this->isGetterForBoolProperty($methodName)) { |
|
171 | + return $this->getter(lcfirst(substr($methodName, 2))); |
|
172 | + } else { |
|
173 | + throw new \BadFunctionCallException($methodName . |
|
174 | + ' does not exist'); |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @param string $methodName |
|
180 | + * @return bool |
|
181 | + * @since 18.0.0 |
|
182 | + */ |
|
183 | + protected function isGetterForBoolProperty(string $methodName): bool { |
|
184 | + if (strpos($methodName, 'is') === 0) { |
|
185 | + $fieldName = lcfirst(substr($methodName, 2)); |
|
186 | + return isset($this->_fieldTypes[$fieldName]) && strpos($this->_fieldTypes[$fieldName], 'bool') === 0; |
|
187 | + } |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Mark am attribute as updated |
|
193 | + * @param string $attribute the name of the attribute |
|
194 | + * @since 7.0.0 |
|
195 | + */ |
|
196 | + protected function markFieldUpdated(string $attribute): void { |
|
197 | + $this->_updatedFields[$attribute] = true; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Transform a database columnname to a property |
|
203 | + * @param string $columnName the name of the column |
|
204 | + * @return string the property name |
|
205 | + * @since 7.0.0 |
|
206 | + */ |
|
207 | + public function columnToProperty($columnName) { |
|
208 | + $parts = explode('_', $columnName); |
|
209 | + $property = null; |
|
210 | + |
|
211 | + foreach ($parts as $part) { |
|
212 | + if ($property === null) { |
|
213 | + $property = $part; |
|
214 | + } else { |
|
215 | + $property .= ucfirst($part); |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + return $property; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Transform a property to a database column name |
|
225 | + * @param string $property the name of the property |
|
226 | + * @return string the column name |
|
227 | + * @since 7.0.0 |
|
228 | + */ |
|
229 | + public function propertyToColumn($property) { |
|
230 | + $parts = preg_split('/(?=[A-Z])/', $property); |
|
231 | + $column = null; |
|
232 | + |
|
233 | + foreach ($parts as $part) { |
|
234 | + if ($column === null) { |
|
235 | + $column = $part; |
|
236 | + } else { |
|
237 | + $column .= '_' . lcfirst($part); |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + return $column; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @return array array of updated fields for update query |
|
247 | + * @since 7.0.0 |
|
248 | + */ |
|
249 | + public function getUpdatedFields() { |
|
250 | + return $this->_updatedFields; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Adds type information for a field so that its automatically casted to |
|
256 | + * that value once its being returned from the database |
|
257 | + * @param string $fieldName the name of the attribute |
|
258 | + * @param string $type the type which will be used to call settype() |
|
259 | + * @since 7.0.0 |
|
260 | + */ |
|
261 | + protected function addType($fieldName, $type) { |
|
262 | + $this->_fieldTypes[$fieldName] = $type; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * Slugify the value of a given attribute |
|
268 | + * Warning: This doesn't result in a unique value |
|
269 | + * @param string $attributeName the name of the attribute, which value should be slugified |
|
270 | + * @return string slugified value |
|
271 | + * @since 7.0.0 |
|
272 | + * @deprecated 24.0.0 |
|
273 | + */ |
|
274 | + public function slugify($attributeName) { |
|
275 | + // toSlug should only work for existing attributes |
|
276 | + if (property_exists($this, $attributeName)) { |
|
277 | + $value = $this->$attributeName; |
|
278 | + // replace everything except alphanumeric with a single '-' |
|
279 | + $value = preg_replace('/[^A-Za-z0-9]+/', '-', $value); |
|
280 | + $value = strtolower($value); |
|
281 | + // trim '-' |
|
282 | + return trim($value, '-'); |
|
283 | + } else { |
|
284 | + throw new \BadFunctionCallException($attributeName . |
|
285 | + ' is not a valid attribute'); |
|
286 | + } |
|
287 | + } |
|
288 | 288 | } |
@@ -33,27 +33,27 @@ |
||
33 | 33 | * @since 7.0.0 |
34 | 34 | */ |
35 | 35 | class RedirectResponse extends Response { |
36 | - private $redirectURL; |
|
36 | + private $redirectURL; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Creates a response that redirects to a url |
|
40 | - * @param string $redirectURL the url to redirect to |
|
41 | - * @since 7.0.0 |
|
42 | - */ |
|
43 | - public function __construct($redirectURL) { |
|
44 | - parent::__construct(); |
|
38 | + /** |
|
39 | + * Creates a response that redirects to a url |
|
40 | + * @param string $redirectURL the url to redirect to |
|
41 | + * @since 7.0.0 |
|
42 | + */ |
|
43 | + public function __construct($redirectURL) { |
|
44 | + parent::__construct(); |
|
45 | 45 | |
46 | - $this->redirectURL = $redirectURL; |
|
47 | - $this->setStatus(Http::STATUS_SEE_OTHER); |
|
48 | - $this->addHeader('Location', $redirectURL); |
|
49 | - } |
|
46 | + $this->redirectURL = $redirectURL; |
|
47 | + $this->setStatus(Http::STATUS_SEE_OTHER); |
|
48 | + $this->addHeader('Location', $redirectURL); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @return string the url to redirect |
|
54 | - * @since 7.0.0 |
|
55 | - */ |
|
56 | - public function getRedirectURL() { |
|
57 | - return $this->redirectURL; |
|
58 | - } |
|
52 | + /** |
|
53 | + * @return string the url to redirect |
|
54 | + * @since 7.0.0 |
|
55 | + */ |
|
56 | + public function getRedirectURL() { |
|
57 | + return $this->redirectURL; |
|
58 | + } |
|
59 | 59 | } |
@@ -34,57 +34,57 @@ |
||
34 | 34 | * @package OC\IntegrityCheck\Helpers |
35 | 35 | */ |
36 | 36 | class FileAccessHelper { |
37 | - /** |
|
38 | - * Wrapper around file_get_contents($filename, $data) |
|
39 | - * |
|
40 | - * @param string $filename |
|
41 | - * @return string|false |
|
42 | - */ |
|
43 | - public function file_get_contents(string $filename) { |
|
44 | - return file_get_contents($filename); |
|
45 | - } |
|
37 | + /** |
|
38 | + * Wrapper around file_get_contents($filename, $data) |
|
39 | + * |
|
40 | + * @param string $filename |
|
41 | + * @return string|false |
|
42 | + */ |
|
43 | + public function file_get_contents(string $filename) { |
|
44 | + return file_get_contents($filename); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Wrapper around file_exists($filename) |
|
49 | - * |
|
50 | - * @param string $filename |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function file_exists(string $filename): bool { |
|
54 | - return file_exists($filename); |
|
55 | - } |
|
47 | + /** |
|
48 | + * Wrapper around file_exists($filename) |
|
49 | + * |
|
50 | + * @param string $filename |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function file_exists(string $filename): bool { |
|
54 | + return file_exists($filename); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Wrapper around file_put_contents($filename, $data) |
|
59 | - * |
|
60 | - * @param string $filename |
|
61 | - * @param string $data |
|
62 | - * @return int |
|
63 | - * @throws \Exception |
|
64 | - */ |
|
65 | - public function file_put_contents(string $filename, string $data): int { |
|
66 | - $bytesWritten = @file_put_contents($filename, $data); |
|
67 | - if ($bytesWritten === false || $bytesWritten !== \strlen($data)) { |
|
68 | - throw new \Exception('Failed to write into ' . $filename); |
|
69 | - } |
|
70 | - return $bytesWritten; |
|
71 | - } |
|
57 | + /** |
|
58 | + * Wrapper around file_put_contents($filename, $data) |
|
59 | + * |
|
60 | + * @param string $filename |
|
61 | + * @param string $data |
|
62 | + * @return int |
|
63 | + * @throws \Exception |
|
64 | + */ |
|
65 | + public function file_put_contents(string $filename, string $data): int { |
|
66 | + $bytesWritten = @file_put_contents($filename, $data); |
|
67 | + if ($bytesWritten === false || $bytesWritten !== \strlen($data)) { |
|
68 | + throw new \Exception('Failed to write into ' . $filename); |
|
69 | + } |
|
70 | + return $bytesWritten; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $path |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function is_writable(string $path): bool { |
|
78 | - return is_writable($path); |
|
79 | - } |
|
73 | + /** |
|
74 | + * @param string $path |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function is_writable(string $path): bool { |
|
78 | + return is_writable($path); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param string $path |
|
83 | - * @throws \Exception |
|
84 | - */ |
|
85 | - public function assertDirectoryExists(string $path) { |
|
86 | - if (!is_dir($path)) { |
|
87 | - throw new \Exception('Directory ' . $path . ' does not exist.'); |
|
88 | - } |
|
89 | - } |
|
81 | + /** |
|
82 | + * @param string $path |
|
83 | + * @throws \Exception |
|
84 | + */ |
|
85 | + public function assertDirectoryExists(string $path) { |
|
86 | + if (!is_dir($path)) { |
|
87 | + throw new \Exception('Directory ' . $path . ' does not exist.'); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | public function file_put_contents(string $filename, string $data): int { |
66 | 66 | $bytesWritten = @file_put_contents($filename, $data); |
67 | 67 | if ($bytesWritten === false || $bytesWritten !== \strlen($data)) { |
68 | - throw new \Exception('Failed to write into ' . $filename); |
|
68 | + throw new \Exception('Failed to write into '.$filename); |
|
69 | 69 | } |
70 | 70 | return $bytesWritten; |
71 | 71 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function assertDirectoryExists(string $path) { |
86 | 86 | if (!is_dir($path)) { |
87 | - throw new \Exception('Directory ' . $path . ' does not exist.'); |
|
87 | + throw new \Exception('Directory '.$path.' does not exist.'); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -34,27 +34,27 @@ |
||
34 | 34 | * @package OC\IntegrityCheck\Helpers |
35 | 35 | */ |
36 | 36 | class AppLocator { |
37 | - /** |
|
38 | - * Provides \OC_App::getAppPath($appId) |
|
39 | - * |
|
40 | - * @param string $appId |
|
41 | - * @return string |
|
42 | - * @throws \Exception If the app cannot be found |
|
43 | - */ |
|
44 | - public function getAppPath(string $appId): string { |
|
45 | - $path = \OC_App::getAppPath($appId); |
|
46 | - if ($path === false) { |
|
47 | - throw new \Exception('App not found'); |
|
48 | - } |
|
49 | - return $path; |
|
50 | - } |
|
37 | + /** |
|
38 | + * Provides \OC_App::getAppPath($appId) |
|
39 | + * |
|
40 | + * @param string $appId |
|
41 | + * @return string |
|
42 | + * @throws \Exception If the app cannot be found |
|
43 | + */ |
|
44 | + public function getAppPath(string $appId): string { |
|
45 | + $path = \OC_App::getAppPath($appId); |
|
46 | + if ($path === false) { |
|
47 | + throw new \Exception('App not found'); |
|
48 | + } |
|
49 | + return $path; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Providers \OC_App::getAllApps() |
|
54 | - * |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function getAllApps(): array { |
|
58 | - return \OC_App::getAllApps(); |
|
59 | - } |
|
52 | + /** |
|
53 | + * Providers \OC_App::getAllApps() |
|
54 | + * |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function getAllApps(): array { |
|
58 | + return \OC_App::getAllApps(); |
|
59 | + } |
|
60 | 60 | } |