I have class with only static method
<?phpThis text will be hidden
use Carbon\Carbon;
use Respect\Validation\Validator as r;
class ClientService {
private static $container;
public static function init($container) {
self::$container = $container;
}
public static function getContainer() {
return self::$container;
}
public static function create($params) {
$data['user'] = [
'email' => $params['email'],
'password' => password_hash($params['password'], PASSWORD_DEFAULT)
];
$data['client'] = [
'firstname' => $params['firstname'],
'secondname' => $params['secondname'],
'thirdname' => $params['thirdname']
];
$client = Client::create($data['client']);
$data['user']['password'] = password_hash($data['user']['password'], PASSWORD_DEFAULT);
$user = User::create($data['user']);
$client->user()->save($user);
return $client;
}
public static function isValid($request) {
// to do form validation
}
}
I implemented the transfer of the container by writing to the static variable of the class through calling the static method, I do not want to initiate this class anywhere through the constructor, I want to work with it as with a static one.
Is it implemented correctly or is there a more correct way?