Skip to content

Commit fd6a1b1

Browse files
committed
Strategy implementation complete
1 parent 7996102 commit fd6a1b1

16 files changed

+331
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
class Client
10+
{
11+
public function insertData()
12+
{
13+
$context=new Context(new DataEntry());
14+
$context->algorithm();
15+
}
16+
public function findData()
17+
{
18+
$context=new Context(new SearchData());
19+
$context->algorithm();
20+
}
21+
public function showAll()
22+
{
23+
$context=new Context(new DisplayData());
24+
$context->algorithm();
25+
}
26+
public function changeData()
27+
{
28+
$context=new Context(new UpdateData());
29+
$context->algorithm();
30+
}
31+
public function killer()
32+
{
33+
$context=new Context(new DeleteRecord());
34+
$context->algorithm();
35+
}
36+
}
37+
?>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
class Context
10+
{
11+
private $strategy;
12+
public function __construct(IStrategy $strategy)
13+
{
14+
$this->strategy = $strategy;
15+
}
16+
public function algorithm()
17+
{
18+
$this->strategy->algorithm();
19+
}
20+
}
21+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
class DataEntry implements IStrategy
10+
//DataEntry.php
11+
{
12+
public function algorithm(){
13+
$hookup=UniversalConnect::doConnect();
14+
$test = $hookup->real_escape_string($_POST['data']);
15+
echo "This data has been entered: " . $test . "<br/>";
16+
}
17+
}
18+
?>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
//DeleteRecord.php
10+
class DeleteRecord implements IStrategy
11+
{
12+
public function algorithm()
13+
{
14+
$hookup=UniversalConnect::doConnect();
15+
$test = $hookup->real_escape_string($_POST['data']);
16+
echo "The record " . $test . "has been deleted.<br/>";
17+
}
18+
}
19+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
class DisplayData implements IStrategy
10+
{
11+
public function algorithm()
12+
{
13+
$hookup=UniversalConnect::doConnect();
14+
$test = "Here's all the data!!";
15+
echo $test . "<br/>";
16+
}
17+
}
18+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
interface IConnectInfo
10+
{
11+
const HOST ="localhost";
12+
const UNAME ="root";
13+
const PW ="";
14+
const DBNAME = "practise";
15+
16+
public function doConnect();
17+
}
18+
?>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
interface IStrategy
10+
{
11+
public function algorithm();
12+
}
13+
?>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
//SearchData.php
10+
class SearchData implements IStrategy
11+
{
12+
public function algorithm()
13+
{
14+
$hookup=UniversalConnect::doConnect();
15+
$test = $hookup->real_escape_string($_POST['data']);
16+
echo "Here's what you were looking for " . $test . "<br/>";
17+
}
18+
}
19+
?>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
include_once('IConnectInfo.php');
10+
class UniversalConnect implements IConnectInfo
11+
{
12+
private static $server=IConnectInfo::HOST;
13+
private static $currentDB= IConnectInfo::DBNAME;
14+
private static $user= IConnectInfo::UNAME;
15+
private static $pass= IConnectInfo::PW;
16+
private static $hookup;
17+
public function doConnect()
18+
{
19+
self::$hookup=mysqli_connect(self::$server, self::$user, self::$pass,
20+
self::$currentDB);
21+
if(self::$hookup)
22+
{
23+
echo "Successful connection to MySQL:<br/>";
24+
}
25+
elseif (mysqli_connect_error(self::$hookup))
26+
{
27+
echo('Here is why it failed: ' . mysqli_connect_error());
28+
}
29+
return self::$hookup;
30+
}
31+
}
32+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
class UpdateData implements IStrategy
10+
{
11+
public function algorithm()
12+
{
13+
$hookup=UniversalConnect::doConnect();
14+
$test = $hookup->real_escape_string($_POST['data']);
15+
echo "Your new data is now " . $test . "<br/>";
16+
}
17+
}
18+
?>

0 commit comments

Comments
 (0)