Skip to content

Commit 8f6039e

Browse files
author
Craig Manley
committed
Replace old // comment prefixes with #
1 parent e99c094 commit 8f6039e

10 files changed

+84
-84
lines changed

eg/spec.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
* The Spec class is rarely used stand-alone as it is only able to validate a single value.
77
*
88
* @author Craig Manley
9-
* @version $Id: spec.php,v 1.3 2016/06/13 20:04:08 cmanley Exp $
9+
* @version $Id: spec.php,v 1.4 2018/05/26 22:55:49 cmanley Exp $
1010
* @package Validate
1111
*/
1212
require_once(__DIR__ . '/../src/Spec.php');
1313

14-
// A Spec object can be created in 3 possible ways, all having the same effect.
14+
# A Spec object can be created in 3 possible ways, all having the same effect.
1515
$specs = array();
1616

1717

18-
// This is the proper way to create a Spec object with it's embedded Validation object.
18+
# This is the proper way to create a Spec object with it's embedded Validation object.
1919
$specs []= new Validate\Spec(array(
2020
'allow_empty' => false,
2121
'description' => 'String with a lowercase "a"',
@@ -30,7 +30,7 @@
3030
));
3131

3232

33-
// This is the lazy way to create a Spec object. It'll automatically convert the 'validation' array into a Validation object internally.
33+
# This is the lazy way to create a Spec object. It'll automatically convert the 'validation' array into a Validation object internally.
3434
$specs []= new Validate\Spec(array(
3535
'allow_empty' => false,
3636
'description' => 'String with a lowercase "a"',
@@ -45,14 +45,14 @@
4545
));
4646

4747

48-
// This is the very lazy way to create a Spec object. It'll automatically create a Validation object internally.
48+
# This is the very lazy way to create a Spec object. It'll automatically create a Validation object internally.
4949
$specs []= new Validate\Spec(array(
50-
// Spec options:
50+
# Spec options:
5151
'allow_empty' => false,
5252
'description' => 'String with a lowercase "a"',
5353
'optional' => false,
5454

55-
// Validation options:
55+
# Validation options:
5656
'mb_max_length' => 10,
5757
'regex' => '/a/',
5858
'callbacks' => array(
@@ -61,7 +61,7 @@
6161
));
6262

6363

64-
// Check if all the Spec objects are indeed identical:
64+
# Check if all the Spec objects are indeed identical:
6565
if (count(array_unique(array_map(function($spec) { return var_export($spec,true); }, $specs))) != 1) {
6666
die("The Spec objects are not identical!\n");
6767
}

eg/specs.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
* Specs objects can be used as arrays since they implement the Countable, IteratorAggregate, and ArrayAccess interfaces.
66
*
77
* @author Craig Manley
8-
* @version $Id: specs.php,v 1.3 2016/06/13 20:04:08 cmanley Exp $
8+
* @version $Id: specs.php,v 1.4 2018/05/26 22:55:49 cmanley Exp $
99
* @package Validate
1010
*/
1111
require_once(__DIR__ . '/../src/Specs.php');
1212

1313

14-
// A Specs object can be created in 3 possible ways, all having the same effect.
15-
// The contructor is given an associative array of name => Spec pairs
14+
# A Specs object can be created in 3 possible ways, all having the same effect.
15+
# The contructor is given an associative array of name => Spec pairs
1616

1717

18-
// This is the easy/lazy and my preferred way to create a Specs object with it's embedded Spec objects.
18+
# This is the easy/lazy and my preferred way to create a Specs object with it's embedded Spec objects.
1919
$specs_easy = new Validate\Specs(array(
2020
'firstname' => array(
2121
'description' => 'First name',
2222
'mb_max_length' => 10,
2323
'regex' => '/^[A-Z][a-z]+$/',
2424
'type' => 'string',
2525
),
26-
'surname' => 1, // shortcut for Spec with 'optional' => !value
26+
'surname' => 1, # shortcut for Spec with 'optional' => !value
2727
'age' => array(
2828
'optional' => true,
2929
'mb_max_length' => 3,
@@ -33,7 +33,7 @@
3333
));
3434

3535

36-
// This is the less lazy way to create a Specs object with it's embedded Spec objects.
36+
# This is the less lazy way to create a Specs object with it's embedded Spec objects.
3737
$specs_lazy = new Validate\Specs(array(
3838
'firstname' => (new Validate\Spec(array(
3939
'description' => 'First name',
@@ -43,7 +43,7 @@
4343
'types' => array('string'),
4444
),
4545
))),
46-
'surname' => true, // shortcut for Spec with 'optional' => !value
46+
'surname' => true, # shortcut for Spec with 'optional' => !value
4747
'age' => (new Validate\Spec(array(
4848
'optional' => true,
4949
'validation' => array(
@@ -55,7 +55,7 @@
5555
));
5656

5757

58-
// This is the proper and most verbose way to create a Specs object with it's embedded Spec objects.
58+
# This is the proper and most verbose way to create a Specs object with it's embedded Spec objects.
5959
$specs_proper = new Validate\Specs(array(
6060
'firstname' => (new Validate\Spec(array(
6161
'description' => 'First name',
@@ -82,7 +82,7 @@
8282

8383

8484

85-
// Check if all the Spec objects are indeed identical:
85+
# Check if all the Spec objects are indeed identical:
8686
if (count(array_unique(array_map(function($specs) { return var_export($specs,true); }, array($specs_easy, $specs_lazy, $specs_proper) ))) != 1) {
8787
die("The Specs objects are not identical!\n");
8888
}

eg/validator_after.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The 'after' function is executed after other spec validations have been performed.
55
*
66
* @author Craig Manley
7-
* @version $Id: validator_after.php,v 1.3 2016/06/13 20:04:08 cmanley Exp $
7+
* @version $Id: validator_after.php,v 1.4 2018/05/26 22:55:49 cmanley Exp $
88
* @package Validate
99
*/
1010
require_once(__DIR__ . '/../src/Validator.php');
@@ -19,8 +19,8 @@
1919
),
2020
'birthdate' => array(
2121
'type' => 'string',
22-
'regex' => '#^[0-3]\d/[01]\d/\d{4}$#', // expect dd/mm/yyyy
23-
'after' => function(&$value) { // want yyyy-mm-dd
22+
'regex' => '#^[0-3]\d/[01]\d/\d{4}$#', # expect dd/mm/yyyy
23+
'after' => function(&$value) { # want yyyy-mm-dd
2424
if (is_string($value) && preg_match('#^(\d{2})/(\d{2})/(\d{4})$#', $value, $matches)) {
2525
$value = $matches[3] . '-' . $matches[2] . '-' . $matches[1];
2626
}

eg/validator_before.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The 'before' function is executed before other spec validations have been performed.
55
*
66
* @author Craig Manley
7-
* @version $Id: validator_before.php,v 1.3 2016/06/13 20:04:08 cmanley Exp $
7+
* @version $Id: validator_before.php,v 1.4 2018/05/26 22:55:49 cmanley Exp $
88
* @package Validate
99
*/
1010
require_once(__DIR__ . '/../src/Validator.php');
@@ -19,8 +19,8 @@
1919
),
2020
'birthdate' => array(
2121
'type' => 'string',
22-
'regex' => '/^\d{4}-[01]\d-[0-3]\d$/', // should be yyyy-mm-dd
23-
'before' => function(&$value) { // expect dd/mm/yyyy
22+
'regex' => '/^\d{4}-[01]\d-[0-3]\d$/', # should be yyyy-mm-dd
23+
'before' => function(&$value) { # expect dd/mm/yyyy
2424
if (is_string($value) && preg_match('#^([0-3]\d)/([01]\d)/(\d{4})$#', $value, $matches)) {
2525
$value = $matches[3] . '-' . $matches[2] . '-' . $matches[1];
2626
}

src/Specs.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @author Craig Manley
1111
* @copyright Copyright © 2016, Craig Manley (www.craigmanley.com)
1212
* @license http://www.opensource.org/licenses/mit-license.php Licensed under MIT
13-
* @version $Id: Specs.php,v 1.3 2018/05/26 22:51:21 cmanley Exp $
13+
* @version $Id: Specs.php,v 1.4 2018/05/26 22:55:49 cmanley Exp $
1414
* @package cmanley
1515
*/
1616
namespace Validate;
@@ -29,7 +29,7 @@
2929
*/
3030
class Specs implements \Countable, \IteratorAggregate, \ArrayAccess {
3131

32-
private $pairs; // map of name => Spec pairs
32+
private $pairs; # map of name => Spec pairs
3333
static private $boolean_spec_true;
3434
static private $boolean_spec_false;
3535

src/Validation.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @author Craig Manley
1111
* @copyright Copyright © 2016, Craig Manley (www.craigmanley.com)
1212
* @license http://www.opensource.org/licenses/mit-license.php Licensed under MIT
13-
* @version $Id: Validation.php,v 1.2 2018/05/26 22:51:21 cmanley Exp $
13+
* @version $Id: Validation.php,v 1.3 2018/05/26 22:55:49 cmanley Exp $
1414
* @package Validate
1515
*/
1616
namespace Validate;
@@ -31,9 +31,9 @@
3131
*/
3232
class Validation {
3333

34-
// validations:
35-
protected $allowed_values; // array of scalars
36-
protected $callbacks; // associative array of key => callback pairs
34+
# validations:
35+
protected $allowed_values; # array of scalars
36+
protected $callbacks; # associative array of key => callback pairs
3737
protected $callback;
3838
protected $isa;
3939
protected $mb_max_length;
@@ -46,10 +46,10 @@ class Validation {
4646
protected $resource_type;
4747
protected $types;
4848

49-
// options:
49+
# options:
5050
protected $nocase;
5151

52-
// other:
52+
# other:
5353
protected $last_failure;
5454

5555
/**
@@ -85,7 +85,7 @@ class Validation {
8585
public function __construct(array $args = null) {
8686
if ($args) {
8787
foreach ($args as $key => $value) {
88-
// Process validations:
88+
# Process validations:
8989
if ($key == 'allowed_values') {
9090
if (!(is_array($value) && count($value))) {
9191
throw new \InvalidArgumentException("The \"$key\" argument must be an array containing at least 1 value.");
@@ -154,7 +154,7 @@ public function __construct(array $args = null) {
154154
elseif ($value == 'float') {
155155
$value = 'double';
156156
}
157-
if (is_array($this->types)) { // because 'types' was given
157+
if (is_array($this->types)) { # because 'types' was given
158158
$this->types []= $value;
159159
}
160160
else {
@@ -171,16 +171,16 @@ public function __construct(array $args = null) {
171171
}
172172
/*
173173
'boolean',
174-
'integer', // Be careful with integers > 2147483647 (0x7FFFFFFF) or < -2147483648 (0x8000000) as these automatically become floats in PHP.
175-
'double', // (for historical reasons "double" is returned in case of a float, and not simply "float")
174+
'integer', # Be careful with integers > 2147483647 (0x7FFFFFFF) or < -2147483648 (0x8000000) as these automatically become floats in PHP.
175+
'double', # (for historical reasons "double" is returned in case of a float, and not simply "float")
176176
'string',
177177
'array',
178178
'object',
179179
'resource',
180180
'NULL',
181181
'unknown type',
182182
*/
183-
// Handle some common type aliases too:
183+
# Handle some common type aliases too:
184184
if ($type == 'int') {
185185
$type = 'integer';
186186
}
@@ -189,21 +189,21 @@ public function __construct(array $args = null) {
189189
}
190190
unset($type);
191191
}
192-
if (is_array($this->$key)) { // because 'type' was given
192+
if (is_array($this->$key)) { # because 'type' was given
193193
$this->$key = array_merge($this->$key, $value);
194194
}
195195
else {
196196
$this->$key = $value;
197197
}
198198
}
199199

200-
// Process boolean options
200+
# Process boolean options
201201
elseif (in_array($key, array('nocase'))) {
202202
$this->$key = (boolean) $value;
203203
}
204204

205205
elseif (substr($key,0,1) === '_') {
206-
// Silently ignore options prefixed with underscore.
206+
# Silently ignore options prefixed with underscore.
207207
}
208208
else {
209209
throw new \InvalidArgumentException("Unknown argument \"$key\".");
@@ -218,18 +218,18 @@ public function __construct(array $args = null) {
218218
* All options passed into the constructor can be read using property accessors, e.g. print $validation->regex . "\n";
219219
*/
220220
public function __get($key) {
221-
// TODO: perhaps replace this reflection code with some simple hash access code. See the comments below why.
221+
# TODO: perhaps replace this reflection code with some simple hash access code. See the comments below why.
222222
$r = new \ReflectionObject($this);
223223
$p = null;
224224
try {
225225
$p = $r->getProperty($key);
226226
}
227227
catch (\ReflectionException $e) {
228-
// snuff unknown properties with exception message 'Property x does not exist'
228+
# snuff unknown properties with exception message 'Property x does not exist'
229229
}
230230
if ($p && ($p->isProtected() || $p->isPublic()) && !$p->isStatic()) {
231-
$p->setAccessible(true); // Allow access to non-public members.
232-
return $p->getValue($this); // This design breaks mirrors. Surely the reflection property should know what object was given to ReflectionObject.
231+
$p->setAccessible(true); # Allow access to non-public members.
232+
return $p->getValue($this); # This design breaks mirrors. Surely the reflection property should know what object was given to ReflectionObject.
233233
}
234234
throw new \BadMethodCallException('Attempt to read undefined property ' . get_class($this) . '->' . $key);
235235
}

0 commit comments

Comments
 (0)