Skip to content

Commit 31c84eb

Browse files
committed
first commit
0 parents  commit 31c84eb

21 files changed

+1657
-0
lines changed

.buildpath

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<buildpath>
3+
<buildpathentry kind="src" path=""/>
4+
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
5+
</buildpath>

.htaccess

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<IfModule mod_rewrite.c>
2+
3+
RewriteEngine On
4+
5+
RewriteBase /oop
6+
#RewriteBase /new
7+
8+
9+
10+
#Removes access to the system folder by users.
11+
12+
#Additionally this will allow you to create a System.php controller,
13+
14+
#previously this would not have been possible.
15+
16+
#\u2018system\u2019 can be replaced if you have renamed your system folder.
17+
18+
#RewriteCond %{REQUEST_URI} ^system.*
19+
20+
RewriteRule ^show$ display.php
21+
22+
23+
#Checks to see if the user is attempting to access a valid file,
24+
25+
#such as an image or css document, if this isn\u2019t true it sends the
26+
27+
#request to index.php
28+
29+
RewriteCond %{REQUEST_FILENAME} !-f
30+
31+
RewriteCond %{REQUEST_FILENAME} !-d
32+
33+
#This last condition enables access to the images and css folders, and the robots.txt file
34+
35+
#Submitted by Michael Radlmaier (mradlmaier)
36+
37+
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
38+
RewriteRule ^(.*)$ index.php/$1 [L]
39+
40+
</IfModule>
41+
42+
<IfModule !mod_rewrite.c>
43+
44+
# If we don\u2019t have mod_rewrite installed, all 404\u2019s
45+
46+
# can be sent to index.php, and everything works as normal.
47+
48+
# Submitted by: ElliotHaughin
49+
50+
ErrorDocument 404 /index.php
51+
52+
</IfModule>

.project

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>OOP</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.validation.validationbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.dltk.core.scriptbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.php.core.PHPNature</nature>
21+
</natures>
22+
</projectDescription>

.settings/org.eclipse.php.core.prefs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Fri Apr 27 10:16:43 NPT 2012
2+
eclipse.preferences.version=1
3+
include_path=0;/OOP

DB.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
class DB {
4+
5+
/**
6+
* private variables
7+
*/
8+
private $user;
9+
private $password;
10+
private $database;
11+
private $server;
12+
13+
private $_handle = NULL;
14+
15+
/**
16+
* public variables
17+
*/
18+
public $error;
19+
public $sql;
20+
public $result;
21+
22+
23+
/*
24+
* this is a constructor, a function
25+
* that loads when an object of a class is created
26+
* here constructor initializes the database connectivity variables
27+
*/
28+
/*
29+
function __construct($server, $user, $password, $database) {
30+
31+
$this->server = $server;
32+
$this->user = $user;
33+
$this->password = $password;
34+
$this->database = $database;
35+
36+
37+
if(!$this->connection = mysql_connect($this->server,$this->user,$this->password)) {
38+
throw new Exception('<font color="red">ERROR :: COULD NOT ESTABLISH A CONNECTION: '.mysql_error().'</font>', self::CONNECTION_ERROR);
39+
}else {
40+
if(!mysql_select_db($this->database)) {
41+
throw new Exception('<font color="red">ERROR :: COULD NOT FIND A DATABASE : '.mysql_error().'</font>', self::CONNECTION_ERROR);
42+
}
43+
}
44+
}
45+
*/
46+
47+
function Connect($server, $user, $password, $database) {
48+
49+
$this->server = $server;
50+
$this->user = $user;
51+
$this->password = $password;
52+
$this->database = $database;
53+
54+
55+
if(!$this->connection = mysql_connect($this->server,$this->user,$this->password,$this->database)) {
56+
throw new Exception('<font color="red">ERROR :: COULD NOT ESTABLISH A CONNECTION: '.mysql_error().'</font>', self::CONNECTION_ERROR);
57+
}else {
58+
if(!mysql_select_db($this->database)) {
59+
throw new Exception('<font color="red">ERROR :: COULD NOT FIND A DATABASE : '.mysql_error().'</font>', self::CONNECTION_ERROR);
60+
}else return mysql_select_db($this->database);
61+
}
62+
}
63+
64+
private function __construct($server,$user,$password, $database) {
65+
66+
//$dsn = 'mysql://root:password@localhost/photos'; die;
67+
$this->_handle =& DB::Connect($server,$user,$password, $database);
68+
}
69+
70+
public static function get() {
71+
$user = "root";
72+
$password = "";
73+
$database= "db_pyrocms";
74+
$server = "localhost";
75+
76+
static $db = null;
77+
if ( $db == null )
78+
$db = new DB($server,$user,$password, $database);
79+
return $db;
80+
}
81+
82+
public function handle() {
83+
echo $this->_handle;
84+
}
85+
function __destruct(){}
86+
}
87+
88+
?>

abstract_factory.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/*
3+
switch ($etfType) {
4+
case ETF_VIRTUALCHECK :
5+
$etf = new VirtualCheck();
6+
$etf->processCheck();
7+
break;
8+
case ETF_CREDITCARD :
9+
$etf = new CreditCard();
10+
$etf->chargeCard();
11+
break;
12+
case ETF_WIRETRANSFER :
13+
$etf = new WireTransfer();
14+
$etf->chargeCard();
15+
break;
16+
}
17+
//Read more at http://www.devshed.com/c/a/PHP/Design-Patterns-in-PHP-Factory-Method-and-Abstract-Factory/1/#sKgeCmLSMzI4B5KQ.99
18+
*/
19+
20+
class ETF {
21+
var $data;
22+
function ETF($data) {
23+
$this->data = $data;
24+
}
25+
function process() {}
26+
function getResult() {}
27+
}
28+
29+
class VirtualCheck extends ETF {}
30+
class WireTransfer extends ETF {}
31+
32+
class ETFFactory {
33+
function createETF($data) {
34+
switch ($data['etfType']) {
35+
case ETF_VIRTUALCHECK :
36+
return new VirtualCheck($data);;
37+
case ETF_WIRETRANSFER :
38+
return new WireTransfer($data);
39+
default :
40+
return new ETF($data);
41+
}
42+
}
43+
}
44+
45+
$data = $_POST;
46+
$etf = ETFFactory::createETF($data);
47+
$etf->process();
48+
49+
//Read more at http://www.devshed.com/c/a/PHP/Design-Patterns-in-PHP-Factory-Method-and-Abstract-Factory/1/#sKgeCmLSMzI4B5KQ.99

abstract_factory2.php

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
namespace Library\Helper;
4+
5+
class Validator
6+
{
7+
private function __construct(){}
8+
9+
/**
10+
* Validate an email address
11+
*/
12+
public static function validateEmail($email)
13+
{
14+
return filter_var($email, FILTER_VALIDATE_EMAIL);
15+
}
16+
17+
/**
18+
* Validate a URL
19+
*/
20+
public static function validateUrl($url)
21+
{
22+
return filter_var($url, FILTER_VALIDATE_URL);
23+
}
24+
25+
/**
26+
* Validate a float number
27+
*/
28+
public static function validateFloat($value)
29+
{
30+
return filter_var($value, FILTER_VALIDATE_FLOAT);
31+
}
32+
33+
/**
34+
* Validate an integer number
35+
*/
36+
public static function validateInteger($value)
37+
{
38+
return filter_var($value, FILTER_VALIDATE_INT);
39+
}
40+
}
41+
//Read more at http://www.devshed.com/c/a/PHP/PHP-Effects-of-Wrapping-Code-in-Class-Constructs/#TAxCLtYVsdVRXVRp.99
42+
43+
// include the validator helper
44+
//require_once __DIR__ . '/Helper/Validator.php';
45+
46+
use Library\Helper\Validator as Validator;
47+
48+
// validate a URL
49+
if (!Validator::validateUrl('http://www.devshed.com')) {
50+
echo 'The supplied URL is invalid';
51+
}
52+
53+
// validate an email address
54+
if (!Validator::validateEMail('[email protected]')) {
55+
echo 'The supplied email address is invalid.';
56+
}
57+
58+
// validate a float number
59+
if (!Validator::validateFloat(2.5)) {
60+
echo 'The supplied value is an invalid float number.';
61+
}
62+
63+
// validate an integer number
64+
if (!Validator::validateInteger(10.5)) {
65+
echo 'The supplied value is an invalid integer number.';
66+
}
67+
68+
/* displays the following
69+
70+
The supplied value is an invalid integer number.
71+
72+
*/
73+
//Read more at http://www.devshed.com/c/a/PHP/PHP-Effects-of-Wrapping-Code-in-Class-Constructs/#TAxCLtYVsdVRXVRp.99
74+
75+
?>
76+
<?php
77+
78+
79+
namespace Library\Helper;
80+
81+
interface ValidatorInterface
82+
{
83+
/**
84+
* Validate the given value
85+
*/
86+
public function validate();
87+
}
88+
//Read more at http://www.devshed.com/c/a/PHP/PHP-Effects-of-Wrapping-Code-in-Class-Constructs/1/#3U5hfgYAl7RKFcHh.99
89+
90+
91+
namespace Library\Helper;
92+
93+
abstract class AbstractValidator
94+
{
95+
const DEFAULT_ERROR_MESAGE = 'The supplied value is invalid.';
96+
protected $_value;
97+
protected $_errorMessage = self::DEFAULT_ERROR_MESAGE;
98+
99+
/**
100+
* Constructor
101+
*/
102+
public function __construct($value = null, $errorMessage = null)
103+
{
104+
if ($value !== null) {
105+
$this->setValue($value);
106+
}
107+
if ($errorMessage !== null) {
108+
$this->setErrorMessage($errorMessage);
109+
}
110+
}
111+
112+
/**
113+
* Set the value to be validated
114+
*/
115+
public function setValue($value)
116+
{
117+
$this->_value = $value;
118+
}
119+
120+
/**
121+
* Get the inputted value
122+
*/
123+
public function getValue()
124+
{
125+
return $this->_value;
126+
}
127+
128+
/**
129+
* Set the error message
130+
*/
131+
public function setErrorMessage($errorMessage)
132+
{
133+
if (!is_string($errorMessage) || empty($errorMessage)) {
134+
throw new \InvalidArgumentException('The error message is invalid. It must be a non-empty string.');
135+
}
136+
$this->_errorMessage = $errorMessage;
137+
}
138+
139+
/**
140+
* Get the error message
141+
*/
142+
public function getErrorMessage()
143+
{
144+
return $this->_errorMessage;
145+
}
146+
147+
/**
148+
* Reset the error message to the default value
149+
*/
150+
public function resetErrorMessage()
151+
{
152+
$this->_errorMessage = self::DEFAULT_ERROR_MESAGE;
153+
}
154+
}
155+
//Read more at http://www.devshed.com/c/a/PHP/PHP-Effects-of-Wrapping-Code-in-Class-Constructs/1/#3U5hfgYAl7RKFcHh.99
156+
157+
158+
?>

0 commit comments

Comments
 (0)