diff --git a/composer.json b/composer.json index 3d08001..e83829f 100644 --- a/composer.json +++ b/composer.json @@ -16,18 +16,11 @@ "Incognito\\": "src/" } }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" - } - }, + "autoload-dev": {}, "require": { "iamfredric/modest": "^1.0", "iamfredric/instantiator": "^1.0", - "duncan3dc/blade": "^4.5" + "duncan3dc/blade": "^4.8" }, - "require-dev": { - "phpunit/phpunit": "^6.2", - "mockery/mockery": "^0.9.9" - } + "require-dev": {} } diff --git a/src/Components/Components.php b/src/Components/Components.php index 93b0e44..465cb56 100644 --- a/src/Components/Components.php +++ b/src/Components/Components.php @@ -69,7 +69,9 @@ protected function resolveComponents($components) */ protected function resolveClassname($name) { - $name = ucfirst($name); + $name = collect(explode('-', $name))->map(function ($name) { + return ucfirst($name); + })->implode(''); if (! $this->prefix) { return "\\App\\Components\\{$name}Component"; diff --git a/src/Utilities/Transformer.php b/src/Utilities/Transformer.php index 4ff9131..0952feb 100644 --- a/src/Utilities/Transformer.php +++ b/src/Utilities/Transformer.php @@ -3,6 +3,7 @@ namespace Incognito\Utilities; use Incognito\Utilities\Wordpress\Image; +use Incognito\Utilities\Wordpress\Link; trait Transformer { @@ -31,6 +32,10 @@ protected function transform($data = []) $item = new Image($item); } + if (is_array($item) && isset($item['url']) && isset($item['title']) && isset($item['target'])) { + $item = new Link($item); + } + $key = dash_to_camel($key); // Casts item if defined diff --git a/src/Utilities/Wordpress/Link.php b/src/Utilities/Wordpress/Link.php new file mode 100644 index 0000000..4cf4388 --- /dev/null +++ b/src/Utilities/Wordpress/Link.php @@ -0,0 +1,60 @@ +attributes = $attributes; + } + + /** + * @return bool + */ + public function exists() + { + return $this->has('url'); + } + + /** + * @param string $class + * + * @return string + */ + public function render($class = '') + { + return '' . $this->get('title') . ''; + } + + /** + * @param $key + * @param null $default + * + * @return mixed|null + */ + public function get($key, $default = null) + { + return $this->has($key) ? $this->attributes[$key] : $default; + } + + /** + * @param $key + * + * @return bool + */ + public function has($key) + { + return isset($this->attributes[$key]); + } +}