-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80784a2
commit 305a513
Showing
4 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ composer.lock | |
mix-manifest.json | ||
package-lock.json | ||
yarn.lock | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace StatamicRadPack\Mailchimp; | ||
|
||
use Illuminate\Support\Collection; | ||
use Statamic\Facades\Blink; | ||
use Statamic\Facades\File; | ||
use Statamic\Facades\YAML; | ||
|
||
class UserConfig extends Collection | ||
{ | ||
private array $config; | ||
|
||
/** | ||
* Load user config defaults collection. | ||
* | ||
* @param array|Collection|null $config | ||
*/ | ||
public function __construct($config = null) | ||
{ | ||
if (! is_null($config)) { | ||
$config = collect($config)->all(); | ||
} | ||
|
||
$this->config = $config ?? $this->getSavedSettings(); | ||
} | ||
|
||
/** | ||
* Load user config collection. | ||
* | ||
* @param array|Collection|null $config | ||
* @return static | ||
*/ | ||
public static function load($config = null) | ||
{ | ||
$class = app(UserConfig::class); | ||
|
||
return new $class($config); | ||
} | ||
|
||
/** | ||
* Save user config to yaml. | ||
*/ | ||
public function config() | ||
{ | ||
return $this->config; | ||
} | ||
|
||
/** | ||
* Save user config to yaml. | ||
*/ | ||
public function save() | ||
{ | ||
File::put($this->path(), YAML::dump(['users' => $this->config])); | ||
} | ||
|
||
/** | ||
* Get user config from yaml | ||
* | ||
* @return array | ||
*/ | ||
protected function getSavedSettings() | ||
{ | ||
return Blink::once('statamic-mailchimp::user-config', function () { | ||
return collect(YAML::file($this->path())->parse()) | ||
->all()['users'] ?? []; | ||
}); | ||
} | ||
|
||
/** | ||
* Get site defaults yaml path. | ||
* | ||
* @return string | ||
*/ | ||
protected function path() | ||
{ | ||
return resource_path('mailchimp.yaml'); | ||
} | ||
} |