laravel.com
의 문서로 충분하지 않습니다. 어느 누구도 처음부터 Laravel
에 계약서 작성 방법을 안내해 줄 수 있습니까?laravel의 계약 생성 5.4
Laravel
에 계약 구현이 필요합니다. 지금은 사용하고 있습니다 Laravel 5.4
laravel.com
의 문서로 충분하지 않습니다. 어느 누구도 처음부터 Laravel
에 계약서 작성 방법을 안내해 줄 수 있습니까?laravel의 계약 생성 5.4
Laravel
에 계약 구현이 필요합니다. 지금은 사용하고 있습니다 Laravel 5.4
Contract은 php interfaces
의 멋진 이름입니다. 우리는 그들 모두를 사용하고 있으며, 새로운 것을 사용하지 않고 있습니다.
Contracts/Interfaces
느슨하게 결합 된 코드 기반을 유지하는 데 도움이됩니다. 아래 문서의 예를 참조하십시오. 이제까지 Repository
인스턴스화 우리가 코드가 작동하려면에 \SomePackage\Cache\Memcached
인스턴스를 제공해야합니다 여기
<?php
namespace App\Orders;
class Repository
{
/**
* The cache instance.
*/
protected $cache;
/**
* Create a new repository instance.
*
* @param \SomePackage\Cache\Memcached $cache
* @return void
*/
public function __construct(\SomePackage\Cache\Memcached $cache)
{
$this->cache = $cache;
}
/**
* Retrieve an Order by ID.
*
* @param int $id
* @return Order
*/
public function find($id)
{
if ($this->cache->has($id)) {
//
}
}
}
. 따라서 우리 코드는 \SomePackage\Cache\Memcached
과 밀접하게 결합됩니다. 이제 아래 코드를 살펴보십시오.
<?php
namespace App\Orders;
use Illuminate\Contracts\Cache\Repository as Cache;
class Repository
{
/**
* The cache instance.
*/
protected $cache;
/**
* Create a new repository instance.
*
* @param Cache $cache
* @return void
*/
public function __construct(Cache $cache)
{
$this->cache = $cache;
}
}
똑같은하지만 지금 우리는 단지 일부 캐시 인터페이스를 제공해야합니다. 그리고 그 장면 뒤에 당신은 이런 식으로 할 수있었습니다.
<?php
namespace App\Orders;
use Illuminate\Contracts\Cache\Repository as Cache;
class RedisCache implements Cache {
//
}
Repository
인스턴스화 위, PHP는 Illuminate\Contracts\Cache\Repository
볼 것이며, 그것은 RedisCache
클래스에서 구현 된 경우.