PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.21
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.21
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
fluent-booking / vendor / wpfluent / framework / src / WPFluent / Database / Orm / ResourceAbleTrait.php

ResourceAbleTrait.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.21, at vendor/wpfluent/framework/src/WPFluent/Database/Orm/ResourceAbleTrait.php

59 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\Framework\Database\Orm;
4
5 use BadMethodCallException;
6 use FluentBooking\Framework\Support\Collection;
7
8 trait ResourceAbleTrait
9 {
10 /**
11 * Transforms a resource
12 *
13 * @param array $excludes
14 * @return mixed
15 */
16 public function toResource($excludes = [])
17 {
18 if ($this instanceof Model) {
19 throw new BadMethodCallException(
20 'Implement ' . __FUNCTION__ .' method in you ' . get_class($this) . ' Model.'
21 );
22 }
23
24 $items = [];
25
26 foreach ($this->all() as $item) {
27 $items[] = $item->toResource($excludes);
28 }
29
30 $collection = new Collection($items);
31
32 if ($this instanceof Collection) {
33 return $collection;
34 }
35
36 return $this->setCollection($collection);
37 }
38
39 /**
40 * Filter the resource to exclude properties
41 *
42 * @param array $resource
43 * @param array $excludes
44 * @return array
45 */
46 public function filterResource($resource, $excludes)
47 {
48 if ($excludes) {
49 foreach ($resource as $key => $value) {
50 if (in_array($key, $excludes)) {
51 unset($resource[$key]);
52 }
53 }
54 }
55
56 return $resource;
57 }
58 }
59