1
0
Fork 0
mirror of https://github.com/archtechx/livewire-access.git synced 2025-12-12 04:14:03 +00:00
Control frontend access to properties/methods in Livewire using PHP 8 attributes.
Find a file
Samuel Štancl a5e58a14d8 clean up
2021-03-17 17:30:10 +01:00
.github Merge branch 'master' of github.com:LeanAdmin/explicit-frontend-access 2021-03-17 17:28:52 +01:00
src initial 2021-03-17 17:28:17 +01:00
tests initial 2021-03-17 17:28:17 +01:00
.gitattributes Initial commit 2021-03-17 17:02:28 +01:00
.gitignore Initial commit 2021-03-17 17:02:28 +01:00
.php_cs.php Initial commit 2021-03-17 17:02:28 +01:00
check initial 2021-03-17 17:28:17 +01:00
composer.json initial 2021-03-17 17:28:17 +01:00
phpunit.xml Initial commit 2021-03-17 17:02:28 +01:00
README.md clean up 2021-03-17 17:30:10 +01:00

Explicit property/method access for Livewire

This package adds PHP 8.0 attribute support to Livewire. In specific, the attributes are used for flagging component properties and methods as frontend-accessible.

Components which implement the trait provided by this package will implicitly deny access to all properties and methods if they don't have the #[FrontendAccess] attribute, regardless of their visibility.

Installation

composer require leanadmin/livewire-access

Usage

use Livewire\Component;
use Lean\LivewireAccess\WithExplicitAccess;
use Lean\LivewireAccess\FrontendAccess;

class MyComponent extends Component
{
    // Use the trait on your component to enable this functionality
    use WithExplicitAccess;

    // Accessing this from the frontend will throw an exception
    public string $inaccessible;

    #[FrontendAccess]
    public string $accessible; // This property allows frontend access

    public function secretMethod()
    {
        // Calling this from the frontend will throw an exception
    }

    #[FrontendAccess]
    public function secretMethod()
    {
        // This method allows frontend access
    }
}

The properties still need to be public to be accessible.

The thrown exceptions are identical to those that Livewire would throw if the properties/methods were not public.

Development

Running all checks locally:

./check

Running tests:

phpunit

Code style will be automatically fixed by php-cs-fixer.