2018-12-03 12:33:00 +00:00
< ? php
2020-09-10 19:59:26 +00:00
namespace BeyondCode\LaravelWebSockets\Rules ;
2018-12-03 12:33:00 +00:00
2020-09-10 19:59:26 +00:00
use BeyondCode\LaravelWebSockets\Contracts\AppManager ;
2022-10-06 11:46:54 +00:00
use function Clue\React\Block\await ;
2020-03-04 09:58:39 +00:00
use Illuminate\Contracts\Validation\Rule ;
2022-10-06 11:46:54 +00:00
use React\EventLoop\Factory ;
2018-12-03 12:33:00 +00:00
class AppId implements Rule
{
2020-08-18 17:21:22 +00:00
/**
* Create a new rule .
*
* @ param mixed $attribute
* @ param mixed $value
* @ return bool
*/
2018-12-03 12:33:00 +00:00
public function passes ( $attribute , $value )
{
2020-08-13 11:51:18 +00:00
$manager = app ( AppManager :: class );
2018-12-03 12:33:00 +00:00
2022-10-06 11:46:54 +00:00
return await ( $manager -> findById ( $value ), Factory :: create ()) ? true : false ;
2018-12-03 12:33:00 +00:00
}
2020-08-18 17:21:22 +00:00
/**
* The validation message .
*
* @ return string
*/
2018-12-03 12:33:00 +00:00
public function message ()
{
2020-08-13 11:51:18 +00:00
return 'There is no app registered with the given id. Make sure the websockets config file contains an app for this id or that your custom AppManager returns an app for this id.' ;
2018-12-04 21:22:33 +00:00
}
}