Answer the question
In order to leave comments, you need to log in
Php Laravel, why give contract to class constructor?
I'm studying laravel->contracts and the following question arose:
<?php
namespace App\Orders;
use Illuminate\Contracts\Cache\Repository as Cache;
class Repository
{
/**
* Экземпляр кэша.
*/
protected $cache;
/**
* Создание нового экземпляра репозитория.
*
* @param Cache $cache
* @return void
*/
public function __construct(Cache $cache)
{
$this->cache = $cache;
}
}
Answer the question
In order to leave comments, you need to log in
The contract implies that it has one main released class. But we can also change it.
For example, with the mysql database, the main one, if it is registered in the config. There are also other database drivers working on a contract basis. Mail, cache, repositories and much more work the same
If you had to implement a contract, then it would be indicated in the class declaration, for example:
class Repository implements RepositoryInterface
или
class Repository extends AbstractRepository
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question