Skip to content

Commit 444bf98

Browse files
committed
Add DefaultNormalizerTypeEnum
1 parent c8f7d55 commit 444bf98

File tree

5 files changed

+63
-21
lines changed

5 files changed

+63
-21
lines changed

app/Model/Behavior/NormalizationBehavior.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public function normalize(Model $model, $data, $coId = false, $options = array()
5858

5959
// Are there any types of normalization that we need to skip
6060
$normalization_dis = array();
61-
if(isset($options['mixCase']) && !$options['mixCase']) {
62-
$normalization_dis[] = 'mixCase';
63-
}
64-
if(isset($options['trimWhitespace']) && !$options['trimWhitespace']) {
65-
$normalization_dis[] = 'trimWhitespace';
61+
foreach (DefaultNormalizerTypeEnum::$type as $key => $value) {
62+
if(isset($options[$key]) && !$options[$key]) {
63+
$normalization_dis[] = $key;
64+
}
6665
}
66+
6767
// If $coId is false, look for a CO ID. If we don't find one or if $coId is null,
6868
// we're dealing with org identity data, which normalizations don't currently support.
6969

app/Model/CoPipeline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ protected function syncOrgIdentityToCoPerson($coPipeline,
10201020

10211021
if(!$this->Co->CoPerson->CoPersonRole->save($newCoPersonRole, array("provision" => false,
10221022
"safeties" => $safeties,
1023-
"mixCase" => false))) {
1023+
DefaultNormalizerTypeEnum::MixCase => false))) {
10241024
throw new RuntimeException(_txt('er.db.save-a', array('CoPersonRole')));
10251025
}
10261026

@@ -1249,7 +1249,7 @@ protected function syncOrgIdentityToCoPerson($coPipeline,
12491249
if(!$model->save($nr, array("provision" => false,
12501250
"safeties" => $safeties,
12511251
"skipAvailability" => true,
1252-
"mixCase" => !in_array($model, array('CoPersonRole', 'EnrolleeCoPersonRole')),
1252+
DefaultNormalizerTypeEnum::MixCase => !in_array($model, array('CoPersonRole', 'EnrolleeCoPersonRole')),
12531253
"trustVerified" => $trustVerified))) {
12541254

12551255
throw new RuntimeException(_txt('er.db.save-a',

app/Plugin/DefaultNormalizer/Lib/empty

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* COmanage Registry Default Normalizer Enumerations
4+
*
5+
* Portions licensed to the University Corporation for Advanced Internet
6+
* Development, Inc. ("UCAID") under one or more contributor license agreements.
7+
* See the NOTICE file distributed with this work for additional information
8+
* regarding copyright ownership.
9+
*
10+
* UCAID licenses this file to you under the Apache License, Version 2.0
11+
* (the "License"); you may not use this file except in compliance with the
12+
* License. You may obtain a copy of the License at:
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*
22+
* @link http://www.internet2.edu/comanage COmanage Project
23+
* @package registry-plugin DefaultNormalizer
24+
* @since COmanage Registry v4.0.1
25+
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
26+
*/
27+
28+
29+
class DefaultNormalizerTypeEnum
30+
{
31+
const TrimWhitespace = 'TW';
32+
const MixCase = 'MC';
33+
const PunctuationToSpace = 'PS';
34+
35+
// Each type maps to a function having the first letter lowercase
36+
public static $type = array(
37+
DefaultNormalizerTypeEnum::TrimWhitespace => 'TrimWhitespace',
38+
DefaultNormalizerTypeEnum::MixCase => 'MixCase',
39+
DefaultNormalizerTypeEnum::PunctuationToSpace => 'PunctuationToSpace'
40+
);
41+
}

app/Plugin/DefaultNormalizer/Model/DefaultNormalizer.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,43 @@ public function normalize($data, $normalization_dis = array()) {
6161

6262
$normalizations = array(
6363
'Address' => array(
64-
'mixCase' => array('street', 'locality', 'state', 'country'),
65-
'trimWhitespace' => array('street', 'locality', 'state', 'postal_code', 'country')
64+
DefaultNormalizerTypeEnum::MixCase => array('street', 'locality', 'state', 'country'),
65+
DefaultNormalizerTypeEnum::TrimWhitespace => array('street', 'locality', 'state', 'postal_code', 'country')
6666
),
6767
'CoPersonRole' => array(
68-
'mixCase' => array('title', 'o', 'ou'),
69-
'trimWhitespace' => array('title', 'o', 'ou')
68+
DefaultNormalizerTypeEnum::MixCase => array('title', 'o', 'ou'),
69+
DefaultNormalizerTypeEnum::TrimWhitespace => array('title', 'o', 'ou')
7070
),
7171
// We get passed the alias, not the model name during enrollment.
7272
// There's not an obvious generic way to figure the out, but for now this
7373
// only happens here, so we simply duplicate the rules. (CO-1550)
7474
'EnrolleeCoPersonRole' => array(
75-
'mixCase' => array('title', 'o', 'ou'),
76-
'trimWhitespace' => array('title', 'o', 'ou')
75+
DefaultNormalizerTypeEnum::MixCase => array('title', 'o', 'ou'),
76+
DefaultNormalizerTypeEnum::TrimWhitespace => array('title', 'o', 'ou')
7777
),
7878
'EmailAddress' => array(
7979
// Note cake validation will likely prevent this from being called
80-
'trimWhitespace' => array('mail')
80+
DefaultNormalizerTypeEnum::TrimWhitespace => array('mail')
8181
),
8282
'Identifier' => array(
83-
'trimWhiteSpace' => array('identifier')
83+
DefaultNormalizerTypeEnum::TrimWhitespace => array('identifier')
8484
),
8585
'Name' => array(
8686
// For now, we don't mix case to avoid dealing with issues like people who
8787
// go by lowercase names, or McPherson-style capitalization
88-
'trimWhitespace' => array('honorific', 'given', 'middle', 'family', 'suffix')
88+
DefaultNormalizerTypeEnum::TrimWhitespace => array('honorific', 'given', 'middle', 'family', 'suffix')
8989
),
9090
'TelephoneNumber' => array(
9191
// Following E.123 format, we only use spaces in telephone numbers
9292
// (the + and extension label get added by formatTelephone at rendering time)
93-
'punctuationToSpace' => array('country_code', 'area_code', 'number', 'extension'),
94-
'trimWhitespace' => array('country_code', 'area_code', 'number', 'extension')
93+
DefaultNormalizerTypeEnum::PunctuationToSpace => array('country_code', 'area_code', 'number', 'extension'),
94+
DefaultNormalizerTypeEnum::TrimWhitespace => array('country_code', 'area_code', 'number', 'extension')
9595
),
9696
'Url' => array(
9797
// We don't normalize an http:// prefix because cake validation will prevent
9898
// a URL from being submitted without a prefix (and we wouldn't know the
9999
// protocol anyway).
100-
'trimWhitespace' => array('url')
100+
DefaultNormalizerTypeEnum::TrimWhitespace => array('url')
101101
)
102102
);
103103

@@ -135,7 +135,7 @@ public function normalize($data, $normalization_dis = array()) {
135135
// We only trim whitespace since we can't say too much about the contents
136136
// of the extended attribute.
137137

138-
$normalizations[$model]['trimWhitespace'][] = $name;
138+
$normalizations[$model][DefaultNormalizerTypeEnum::TrimWhitespace][] = $name;
139139
}
140140
}
141141
}
@@ -154,7 +154,8 @@ public function normalize($data, $normalization_dis = array()) {
154154
}
155155
foreach($normalizations[$model][$normalization] as $field) {
156156
if(!empty($ret[$model][$field])) {
157-
$ret[$model][$field] = $this->$normalization($ret[$model][$field], $field);
157+
$func = lcfirst( (DefaultNormalizerTypeEnum::$type)[$normalization] );
158+
$ret[$model][$field] = $this->$func($ret[$model][$field], $field);
158159
}
159160
}
160161
}

0 commit comments

Comments
 (0)