generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
7 changed files
with
106 additions
and
68 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,78 @@ | ||
<?php | ||
|
||
namespace Kanuni\LaravelBladeAnchor; | ||
|
||
use Illuminate\Support\Facades\View; | ||
use Kanuni\LaravelBladeAnchor\Contracts\AnchorExtender; | ||
|
||
class BladeAnchorsManager | ||
{ | ||
private static array $extenders = []; | ||
|
||
/** | ||
* Register anchor extender class on specified anchor | ||
* | ||
* @param string $view | ||
* @param string $anchor | ||
* @param string $extenderClass | ||
* @return boolean | ||
*/ | ||
public function registerExtender(string $view, string $anchor, string $extenderClass): bool | ||
{ | ||
if (! View::exists($view)) return false; | ||
if (! class_exists($extenderClass)) return false; | ||
if (! in_array(AnchorExtender::class, class_implements($extenderClass))) return false; | ||
|
||
$anchorPath = $this->getExtendersPath($view, $anchor); | ||
|
||
if (array_key_exists($anchorPath, static::$extenders)) { | ||
// Push extender to extenders array | ||
static::$extenders[$anchorPath][] = $extenderClass; | ||
} else { | ||
// Create new array for the path and add extender to it | ||
static::$extenders[$anchorPath] = [$extenderClass]; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Get all registered extenders for specified anchor. | ||
* | ||
* @param string $view | ||
* @param string $anchor | ||
* @return array | ||
*/ | ||
public function getExtenders(string $view, string $anchor): array | ||
{ | ||
$path = $this->getExtendersPath($view, $anchor); | ||
|
||
return array_key_exists($path, static::$extenders) | ||
? static::$extenders[$path] | ||
: []; | ||
} | ||
|
||
/** | ||
* Check if specified anchor has registered extenders | ||
* | ||
* @param string $view | ||
* @param string $anchor | ||
* @return boolean | ||
*/ | ||
public function hasExtenders(string $view, string $anchor): bool | ||
{ | ||
return count($this->getExtenders($view, $anchor)) > 0; | ||
} | ||
|
||
/** | ||
* Returns string path for specified anchor to be used in extenders registry | ||
* | ||
* @param string $view | ||
* @param string $anchor | ||
* @return string | ||
*/ | ||
protected function getExtendersPath(string $view, string $anchor): string | ||
{ | ||
return "$view#$anchor"; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Kanuni\LaravelBladeAnchor\Commands; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
|
||
class MakeAnchorExtenderCommand extends GeneratorCommand | ||
{ | ||
public $signature = 'make:anchor-extender {name}'; | ||
|
||
public $description = 'Create a new extender class that can be attached to anchor defined in laravel blade template.'; | ||
|
||
public function getStub(): string | ||
{ | ||
return __DIR__ . '../../stubs/anchor-extender.stub'; | ||
} | ||
|
||
public function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace . '\BladeExtenders'; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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