-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha_w_s_app_model.php
91 lines (77 loc) · 2.66 KB
/
a_w_s_app_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* AWS App Controller File
*
* Copyright (c) 2011 Anthony Putignano
*
* Distributed under the terms of the MIT License.
* Redistributions of files must retain the above copyright notice.
*
* PHP version 5.3
* CakePHP version 1.3
*
* @package aws
* @since 0.1
* @copyright 2011 Anthony Putignano <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @link http://github.com/anthonyp/CakePHP-AWS-Plugin
*/
class AWSAppModel extends AppModel {
/**
* Validation for bucket names
*
* @author Anthony Putignano <[email protected]>
* @since 0.1
* @param array $check
* @return bool
*/
public function isValidBucketName ($check=array()) {
$bucket = array_shift($check);
if (
($bucket === null || $bucket === false) || // Must not be null or false
preg_match('/[^(a-z0-9\-\.)]/', $bucket) || // Must be in the lowercase Roman alphabet, period or hyphen
!preg_match('/^([a-z]|\d)/', $bucket) || // Must start with a number or letter
!(strlen($bucket) >= 3 && strlen($bucket) <= 63) || // Must be between 3 and 63 characters long
(strpos($bucket, '..') !== false) || // Bucket names cannot contain two, adjacent periods
(strpos($bucket, '-.') !== false) || // Bucket names cannot contain dashes next to periods
(strpos($bucket, '.-') !== false) || // Bucket names cannot contain dashes next to periods
preg_match('/(-|\.)$/', $bucket) || // Bucket names should not end with a dash or period
preg_match('/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/', $bucket) // Must not be formatted as an IP address
) {
return false;
}
return true;
}
/**
* beforeSave
*
* @author Anthony Putignano <[email protected]>
* @since 0.1
* @param array $options
* @return bool
*/
public function beforeSave ($options=array()) {
$this->_tmp_schema = $this->_schema;
foreach ($this->_tmp_schema as $field => $properties) {
if (!empty($properties['type']) && in_array($properties['type'], array('date', 'datetime'))) {
unset($this->_tmp_schema[$field]);
}
}
return true;
}
/**
* afterSave
*
* @author Anthony Putignano <[email protected]>
* @since 0.1
* @param bool $created
* @return bool
*/
public function afterSave ($created=false) {
if (isset($this->_tmp_schema)) {
$this->_schema = $this->_tmp_schema;
}
return true;
}
}
?>