/**
* @param WithInterface|DataInterface|ModelInterface $config
* @return mixed
*/
public function apply($config)
{
if (!($config instanceof WithInterface && $config instanceof DataInterface && $config instanceof ModelInterface)) {
return;
}
if ($config->with()->isEmpty()) {
return;
}
$this->config = $config;
$this->allowed = $config->with();
foreach ($this->allowed as $key => $value) {
if (is_numeric($key)) {
$this->allowed->forget($key)->put($value, '*');
}
}
foreach (explode('|', $config->data()->get('with', '')) as $with) {
$parts = explode(':', $with);
if (count($parts) == 0) {
continue;
}
if (!$this->allowed->has($parts[0])) {
continue;
}
$this->processWith($parts[0], isset($parts[1]) ? $parts[1] : '');
}
if (count($this->approved) > 0) {
$config->model($config->model()->with($this->approved));
}
}