커뮤니티

고용노동부, 산업인력공단과 함께하는 강원도 유일한 기업중심 IT전문교육기관 ICT융합캠퍼스만의 특별한교육입니다.
공인 IT숙련기술인의 다양한 접근방법으로 전문가다운 실무교육을 받을 수 있습니다.

Category

교육강좌

언어 PHP - Interface

페이지 정보

작성자 관리자 댓글 0건 조회 2,319회 작성일 20-06-10 13:47

본문

Interface

수업소개

인터페이스는 서로 다른 시스템이 결합되는 접점을 의미합니다. 이 때 서로 시스템이 잘 결합하기 위해서는 상호간에 엄격한 약속이 필요합니다. 프로그래밍에서의 인터페이스도 마찬가지입니다. 이 수업에서는 프로그래밍에서는 어떻게 인터페이스를 구현하는가를 알아보겠습니다. 

수업

소개

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
interface ContractInterface
{
public function promiseMethod(array $param):int;
}
interface ContractInterface2
{
public function promiseMethod2(array $param):int;
}
class ConcreateClass implements ContractInterface, ContractInterface2
{
public function promiseMethod(array $param):int
{
return 1;
}
public function promiseMethod2(array $param):int
{
return 1;
}
}
$obj = new ConcreateClass();
$obj->promiseMethod([1,2]);

사례

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
interface ContractInterface
{
public function compare(string $str1, string $str2):bool;
}
class Concreate implements ContractInterface
{
public function compare(string $str1, string $str2):bool
{
if($str1 === $str2)
return true;
else
return false;
}
}
class Dummy implements ContractInterface
{
public function compare(string $str1, string $str2):bool
{
return true;
}
}
$obj = new Concreate();
if ($obj->compare('test1', 'test2')) {
echo '<h1>same</h1>';
} else {
echo '<h1>different</h1>';
}

사례

모노로그에서 인터페이스를 사용하는 사례를 살펴봅니다. monolog에 대한 자세한 설명은 아래 수업을 참고하세요. https://opentutorials.org/module/6/15756

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\NativeMailerHandler;
$log = new Logger('name');
$log->pushHandler(new StreamHandler(__DIR__ . '/app.log', Logger::ERROR));
$log->pushHandler(new NativeMailerHandler(
'egoing@gmail.com',
'Emergence!!!!',
'out@system.com',
Logger::EMERGENCY));
$log->warning('EGO');
$log->error('ING');
$log->emergency('emergency');
  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기

답변목록

등록된 답변이 없습니다.