Skip to content

Commit fe87276

Browse files
committed
Codes for adapter patter using comosition.
1 parent c06f005 commit fe87276

File tree

12 files changed

+233
-16
lines changed

12 files changed

+233
-16
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
include_once('Mobile.php');
3+
include_once('MobileAdapter.php');
4+
class Client
5+
{
6+
private $mobile;
7+
private $mobileAdapter;
8+
public function __construct()
9+
{
10+
$this->mobile = new Mobile();
11+
$this->mobileAdapter = new MobileAdapter($this->mobile);
12+
$this->mobileAdapter->formatCSS();
13+
$this->mobileAdapter->formatGraphics();
14+
$this->mobileAdapter->horizontalLayout();
15+
$this->mobile->closeHTML();
16+
17+
}
18+
}
19+
$worker=new Client();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* To change this license header, choose License Headers in Project Properties.
5+
* To change this template file, choose Tools | Templates
6+
* and open the template in the editor.
7+
*/
8+
9+
/**
10+
* Description of Desktop
11+
*
12+
* @author Anit Shrestha
13+
*/
14+
15+
include_once("IFormat.php");
16+
17+
class Desktop implements IFormat
18+
{
19+
private $head="<!doctype html><html><head>";
20+
private $headClose="<meta charset='UTF-8'>
21+
<title>Desktop</title></head><body>";
22+
private $cap="</body></html>";
23+
private $sampleText;
24+
public function formatCSS()
25+
{
26+
echo $this->head;
27+
echo "<link rel='stylesheet' href='desktop.css'>";
28+
echo $this->headClose;
29+
echo "<h1>Hello, Everyone!</h1>";
30+
}
31+
public function formatGraphics()
32+
{
33+
echo "<img class='pixRight' src='pix/NationalFlag.jpg' width='720'
34+
height='480' alt='river'>";
35+
}
36+
public function horizontalLayout()
37+
{
38+
$textFile = "text/lorem.txt";
39+
$openText = fopen($textFile, 'r');
40+
$textInfo = fread($openText, filesize($textFile));
41+
fclose($openText);
42+
$this->sampleText=$textInfo;
43+
echo "<div>" . $this->sampleText . "</div>";
44+
echo "<p/><div>" . $this->sampleText . "</div>";
45+
}
46+
public function closeHTML()
47+
{
48+
echo $this->cap;
49+
}
50+
}
51+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
interface IFormat {
3+
public function formatCSS();
4+
public function formatGraphics();
5+
public function horizontalLayout();
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* To change this license header, choose License Headers in Project Properties.
5+
* To change this template file, choose Tools | Templates
6+
* and open the template in the editor.
7+
*/
8+
9+
/**
10+
* Description of IMobile
11+
*
12+
* @author Anit Shrestha
13+
*/
14+
//put your code here
15+
interface IMobileFormat
16+
{
17+
public function formatCSS();
18+
public function formatGraphics();
19+
public function verticalLayout();
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
include_once('IMobileFormat.php');
3+
class Mobile implements IMobileFormat
4+
{
5+
private $head="<!doctype html><html><head>";
6+
private $headClose="<meta charset='UTF-8'>
7+
<title>Mobile</title></head><body>";
8+
private $cap="</body></html>";
9+
private $sampleText;
10+
public function formatCSS()
11+
{
12+
echo $this->head;
13+
echo "<link rel='stylesheet' href='mobile.css'>";
14+
echo $this->headClose;
15+
echo "<h1>Hello, Everyone!</h1>";
16+
}
17+
public function formatGraphics()
18+
{
19+
echo "<img src='pix/Nationalflag.jpg' width=device-width
20+
height=device-height alt='river'>";
21+
}
22+
public function verticalLayout()
23+
{
24+
$textFile = "text/lorem.txt";
25+
$openText = fopen($textFile, 'r');
26+
$textInfo = fread($openText, filesize($textFile));
27+
fclose($openText);
28+
$this->sampleText=$textInfo;
29+
echo "<p/><div>" . $this->sampleText . "</div>";
30+
echo "<p/><div>" . $this->sampleText . "</div>";
31+
}
32+
public function closeHTML()
33+
{
34+
echo $this->cap;
35+
}
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
include_once("IFormat.php");
3+
include_once("Mobile.php");
4+
class MobileAdapter implements IFormat
5+
{
6+
private $mobile;
7+
public function __construct(IMobileFormat $mobileNow)
8+
{
9+
$this->mobile = $mobileNow;
10+
}
11+
public function formatCSS()
12+
{
13+
$this->mobile->formatCSS();
14+
}
15+
public function formatGraphics()
16+
{
17+
$this->mobile->formatGraphics();
18+
}
19+
public function horizontalLayout()
20+
{
21+
$this->mobile->verticalLayout();
22+
}
23+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
To change this license header, choose License Headers in Project Properties.
3+
To change this template file, choose Tools | Templates
4+
and open the template in the editor.
5+
*/
6+
/*
7+
Created on : Jan 3, 2014, 8:58:09 AM
8+
Author : Anit Shrestha
9+
*/
10+
11+
@charset "UTF-8";
12+
//desktop.css
13+
/* CSS Document */
14+
/*DDDCC5,958976,611427,1D2326,6A6A61*/
15+
@media only screen and (min-device-width : 800px) {
16+
}
17+
body
18+
{
19+
font-family:Verdana, Geneva, sans-serif;
20+
color:#1D2326;
21+
font-size:12px;
22+
background-color:#DDDCC5;
23+
}
24+
h1
25+
{
26+
font-family:"Arial Black", Gadget, sans-serif;
27+
font-size:24px;
28+
color:#611427;
29+
}
30+
.pixRight
31+
{
32+
float:right; margin: 0px 0px 5px 5px;
33+
}
34+
image
35+
{
36+
padding: 10px 10px 10px 0px;
37+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
To change this license header, choose License Headers in Project Properties.
3+
To change this template file, choose Tools | Templates
4+
and open the template in the editor.
5+
*/
6+
/*
7+
Created on : Jan 3, 2014, 9:03:19 AM
8+
Author : Anit Shrestha
9+
*/
10+
11+
@charset "UTF-8";
12+
/* CSS Document */
13+
/*DDDCC5,958976,611427,1D2326,6A6A61*/
14+
@media only screen and (min-device-width : 640px) and (max-device-width : 960px)
15+
{
16+
img { max-width: 100%; }
17+
}
18+
body
19+
{
20+
font-family:Verdana, Geneva, sans-serif;
21+
color:#1D2326;
22+
font-size:24px;
23+
background-color:#DDDCC5;
24+
}
25+
h1
26+
{
27+
font-family:"Arial Black", Gadget, sans-serif;
28+
font-size:48px;
29+
color:#611427;
30+
}
31+
image
32+
{
33+
padding: 5px 5px 5px 0px;
34+
}
8.96 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This will tell the component that you want to re-use a CSRF token until it expires - which is controlled by the csrfExpires value. If you are having issues with expired tokens, this is a good balance between security and ease of use.
2+
3+
Disabling the CSRF protection
4+
There may be cases where you want to disable CSRF protection on your forms for some reason. If you do want to disable this feature, you can set $this->Security->csrfCheck = false; in your beforeFilter or use the components array. By default CSRF protection is enabled, and configured to use one-use tokens.
5+
6+
Disabling Security Component For Specific Actions
7+
There may be cases where you want to disable all security checks for an action (ex. AJAX requests). You may “unlock” these actions by listing them in $this->Security->unlockedActions in your beforeFilter.

0 commit comments

Comments
 (0)