Skip to content

Commit 64e3003

Browse files
committed
New BFPsqlSecureString type
1 parent c06ffc8 commit 64e3003

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

Vartypes/BFPsqlSecureString.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/**
4+
* GNU General Public License (Version 2, June 1991)
5+
*
6+
* This program is free software; you can redistribute
7+
* it and/or modify it under the terms of the GNU
8+
* General Public License as published by the Free
9+
* Software Foundation; either version 2 of the License,
10+
* or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will
13+
* be useful, but WITHOUT ANY WARRANTY; without even the
14+
* implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU General Public License
16+
* for more details.
17+
*/
18+
19+
namespace Beeflow\SQLQueryManager\Vartypes;
20+
21+
/**
22+
* Class BFPsqlSecureString
23+
*
24+
* @author Rafal Przetakowski <[email protected]>
25+
* @package Beeflow\SQLQueryManager\Vartypes
26+
*/
27+
class BFPsqlSecureString
28+
{
29+
/**
30+
* Wartość zmienej
31+
*
32+
* @var Mixed
33+
*/
34+
private $value;
35+
36+
/**
37+
* BFPsqlSecureString constructor.
38+
*
39+
* @param $value
40+
*
41+
* @throws \Exception
42+
*/
43+
public function __construct($value)
44+
{
45+
$value = strtr(strip_tags($value),
46+
array(
47+
"'" => "''",
48+
"\0" => "",
49+
"--" => "",
50+
");" => "",
51+
")" => "",
52+
"}" => "",
53+
"(" => "",
54+
"(" => "",
55+
"<!--" => "",
56+
"<" => "&lt;",
57+
">" => "&gt;"
58+
// more secure
59+
));
60+
61+
if (gettype($value) == 'string') {
62+
$this->value = $value;
63+
} else {
64+
throw new \Exception('Value must be ' . __CLASS__ . ' type but is ' . gettype($value));
65+
}
66+
}
67+
68+
/**
69+
* @return String
70+
*/
71+
public function val()
72+
{
73+
return $this->__toString();
74+
}
75+
76+
/**
77+
* @return string
78+
*/
79+
public function __toString()
80+
{
81+
return (string)$this->value;
82+
}
83+
}

0 commit comments

Comments
 (0)