Get the applicable resource methods.

@param  array  $defaults
@param  array  $options
@return array
160717
protected function getResourceMethods($defaults, $options)
	{
		if (isset($options['only']))
		{
			return array_intersect($defaults, $options['only']);
		}
		elseif (isset($options['except']))
		{
			return array_diff($defaults, $options['except']);
		}

		return $defaults;
	}
119572
protected function getAuthorizedResources($methods = null)
    {
        $resources = [];

        if ($this->auth instanceof Authentication) {
            $allow = (array) ($methods ?? $this->method);

            $authorizations = Authorization::dump(
                [
                    'user' => $this->auth->id,
                ],
                [
                    'resource',
                    'methods',
                    'filter',
                ]
            );

            foreach ($authorizations as $authorization) {
                $resource = $authorization['resource'];
                if (array_key_exists($resource, $this->resources)) {
                    if ($this->isPublic($resource, $methods)) {
                        $resources[$resource] = null;
                    } elseif (!empty(array_intersect(
                        $this->getAllowedMethods($resource),
                        array_merge(
                            $authorization['methods'] ?? [],
                            $allow
                        )
                    ))) {
                        $resources[$resource] = $authorization['filter'];
                    }
                }
            }
        } else {
            $resources = array_keys($this->resources);

            if ($this->auth === false) {
                foreach ($resources as $id => $resource) {
                    if (!$this->isPublic($resource, $methods)) {
                        unset($resources[$id]);
                    }
                }
            }

            $resources = array_fill_keys(array_values($resources), null);
        }

        return $resources;
    }
776536
private static function getQueriableResource($type, array $options = [])
    {
        if (!array_key_exists($type, self::$cache['resources']) || self::haveOptionsBeenUpdated($type, $options)) {
            self::$cache['options'][$type] = $options;
            self::$cache['resources'][$type] = new QueriableResource($type, $options);
        }
        return self::$cache['resources'][$type];
    }
1076197
public function get($options = []) {
		// get available data types
		if (get_called_class() == 'Object\Data\Types') {
			$types = $this->data;
		} else {
			$types = \Object\Data\Types::getStatic();
		}
		// transform data
		$result = [];
		foreach ($this->data as $k => $v) {
			foreach ($this->columns as $k2 => $v2) {
				if ($this->column_key == $k2) {
					$result[$k][$k2] = $k;
				} else if (!array_key_exists($k2, $v)) {
					$result[$k][$k2] = $v2['default'] ?? $types[$v2['type']]['no_data_type_default'] ?? null;
				} else {
					$result[$k][$k2] = $v[$k2];
				}
			}
		}
		// filtering
		if (!empty($options['where'])) {
			foreach ($result as $k => $v) {
				$found = true;
				foreach ($options['where'] as $k2 => $v2) {
					// todo: add options ad in query
					if (array_key_exists($k2, $v) && $v[$k2] != $v2) {
						$found = false;
						break;
					}
				}
				if (!$found) {
					unset($result[$k]);
				}
			}
		}
		// sorting, if none specified we sort by name if its in columns
		$orderby = null;
		if (isset($options['orderby'])) {
			$orderby = $options['orderby'];
		} else if (isset($this->orderby)) {
			$orderby = $this->orderby;
		} else if (isset($this->columns[$this->column_prefix . 'name'])) {
			$orderby = [$this->column_prefix . 'name' => SORT_ASC];
		}
		if (!empty($orderby)) {
			$method = [];
			foreach ($orderby as $k => $v) {
				$type = $types[$this->columns[$k]['type']]['php_type'];
				if ($type == 'integer' || $type == 'float') {
					$method[$k] = SORT_NUMERIC;
				}
			}
			array_key_sort($result, $orderby, $method);
		}
		// if we have primary key
		$pk = $options['pk'] ?? $this->pk;
		if (!empty($pk)) {
			pk($pk, $result);
		}
		// single row
		if (!empty($options['single_row'])) {
			return current($result);
		}
		return $result;
	}
333198
protected function resolveOptions(array $options = array())
    {
        $resolver = new OptionsResolver;
        $this->setDefaultOptions($resolver);

        if (!empty($this->options)) {
            $resolver->setDefaults($this->options);
        }

        return $resolver->resolve($options);
    }
807057
protected function getServers(array $options)
    {
        if (! array_key_exists('on', $options)) {
            $options['on'] = [];
        }

        return Arr::flatten(array_map(function ($name) {
            return $this->getServer($name);
        }, (array) $options['on']));
    }
643052
protected function getConvertOptions(array $options)
    {
        if ($this->arrHas($options, 'convertOptions')) {
            return $this->arrGet($options, 'convertOptions', []);
        }

        return $this->arrGet($options, 'convert_options', []);
    }
119677
protected function mergeDefaultOptions($options = [])
    {
        $defaults = $this->getDefaultOptions();

        foreach (array_keys($defaults) as $key) {
            if (!isset($options[$key])) {
                $options[$key] = [];
            }
            $options[$key] += $defaults[$key];
        }

        return $options;
    }
364419
private static function _getOptions($options, $default)
    {
        if (is_array($options)) {
            foreach ($default as $key => $value) {
                if (isset($options[$key])) {
                    $default[$key] = $options[$key];
                }
            }
        }

        return $default;
    }
167555
protected function getMethods($options)
	{
		if (isset($options['only']) && count($options['only']) > 0)
		{
			return $options['only'];
		}
		elseif (isset($options['except']) && count($options['except']) > 0)
		{
			return array_diff($this->defaults, $options['except']);
		}

		return $this->defaults;
	}
518091
protected function mapResourceAbilities(): array
    {
        // Reflect calling controller
        $controller = new ReflectionClass(static::class);

        // Get public methods and filter magic methods
        $methods = array_filter($controller->getMethods(ReflectionMethod::IS_PUBLIC), function ($item) use ($controller) {
            return $item->class === $controller->name && mb_substr($item->name, 0, 2) !== '__' && ! in_array($item->name, $this->resourceActionWhitelist);
        });

        // Get controller actions
        $actions = array_combine($items = array_map(function ($action) {
            return $action->name;
        }, $methods), $items);

        // Map resource actions to resourse abilities
        array_walk($actions, function ($value, $key) use (&$actions) {
            $actions[$key] = array_get($this->resourceAbilityMap(), $key, $value);
        });

        return $actions;
    }
807235
protected function prepareResourceSettings(ResourceSettings $settings) : ?ResourceSettings
    {
        if ($settings->order === -1) {
            $settings->order = $this->order;
        }

        if ($settings->url !== null) {
            return $settings;
        }

        $settings->resourcePath = $this->getResourcePath($settings->filename, $settings->theme);
        $settings->exists       = is_file($settings->resourcePath);

        if ($settings->automin) {
            $settings->filename = $this->searchForMinifiedResource($settings);
        }

        if (!$settings->exists) {
            if ($settings->defaultFallback && !$this->themeIsDefault($settings->theme)) {
                $settings->theme = $this->getDefaultTheme();

                return $this->prepareResourceSettings($settings);
            }

            $this->missing($settings->filename, $settings->theme);

            return null;
        }

        $settings->mtime = filemtime($this->getResourcePath($settings->filename, $settings->theme));

        return $settings;
    }
802132
public function getPopular(array $options = [], array $headers = [])
    {
        return $this->getFactory()->createResultCollection(
            $this->getApi()->getPopular($options, $headers)
        );
    }
590173
public function setOptions(array $options, array $defaults = [])
    {
        $options = array_merge($defaults, $options);
        $this->options = $options;

        return $this;
    }
1060236
private function getFormat(array $options)
    {
        if (isset($options[self::PARAM_FORMAT])) {
            return $options[self::PARAM_FORMAT];
        } else {
            return $this->defaultFormat;
        }
    }
379868
public function themeSettingsDefaults($defaults): array
    {
        $defaultsConfig = $this->config->getSubConfig(self::DEFAULTS);
        foreach ($defaultsConfig->getArrayCopy() as $key => $value) {
            $defaults[$key] = $value;
        }

        return $defaults;
    }
491346
public function getOptions(array $defaultOptions = []): array
    {
        $options = $this->options;
        $options['TTL'] = array_key_exists('TTL', $options) ? $options['TTL'] : $defaultOptions['TTL'];
        $options['urgency'] = array_key_exists('urgency', $options) ? $options['urgency'] : $defaultOptions['urgency'];
        $options['topic'] = array_key_exists('topic', $options) ? $options['topic'] : $defaultOptions['topic'];

        return $options;
    }