-
Notifications
You must be signed in to change notification settings - Fork 613
Expand file tree
/
Copy pathUtils.php
More file actions
126 lines (104 loc) · 3.25 KB
/
Copy pathUtils.php
File metadata and controls
126 lines (104 loc) · 3.25 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
declare(strict_types=1);
/**
* This file is part of the Phalcon Developer Tools.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Phalcon\DevTools;
use InvalidArgumentException;
use Phalcon\Config\Config;
class Utils
{
const DB_ADAPTER_POSTGRESQL = 'postgresql';
const DB_ADAPTER_SQLITE = 'sqlite';
/**
* Converts the underscore_notation to the UpperCamelCase
*
* @param string $string
* @param string $delimiter
* @return string
*/
public static function camelize($string, $delimiter = '_')
{
if (empty($delimiter)) {
throw new InvalidArgumentException('Please, specify the delimiter');
}
$delimiterArray = str_split($delimiter);
foreach ($delimiterArray as $delimiter) {
$stringParts = explode($delimiter, $string);
$stringParts = array_map('ucfirst', $stringParts);
$string = implode('', $stringParts);
}
return $string;
}
/**
* Convert string foo_bar to FooBar or fooBar
*
* <code>
* echo Phalcon\Utils::lowerCamelizeWithDelimiter('coco_bongo'); // coco_bongo
* echo Phalcon\Utils::lowerCamelizeWithDelimiter('coco_bongo', '_'); // CocoBongo
* echo Phalcon\Utils::lowerCamelizeWithDelimiter('coco_bongo', '_', true); // cocoBongo
* </code>
*
* @param string $string
* @param string $delimiter
* @param boolean $useLow
* @return string
*/
public static function lowerCamelizeWithDelimiter($string, $delimiter = '', $useLow = false)
{
if (empty($string)) {
throw new InvalidArgumentException('Please, specify the string');
}
if (!empty($delimiter)) {
$delimiterArray = str_split($delimiter);
foreach ($delimiterArray as $delimiter) {
$stringParts = explode($delimiter, $string);
$stringParts = array_map('ucfirst', $stringParts);
$string = implode('', $stringParts);
}
}
if ($useLow) {
$string = lcfirst($string);
}
return $string;
}
/**
* Converts the underscore_notation to the lowerCamelCase
*
* @param string $string
* @return string
*/
public static function lowerCamelize($string)
{
return lcfirst(self::camelize($string));
}
/**
* Resolves the DB Schema
*
* @param Config $config
* @return null|string
*/
public static function resolveDbSchema(Config $config)
{
if ($config->offsetExists('schema')) {
return $config->get('schema');
}
if (self::DB_ADAPTER_POSTGRESQL === strtolower($config->get('adapter'))) {
return 'public';
}
if (self::DB_ADAPTER_SQLITE === strtolower($config->get('adapter'))) {
// SQLite only supports the current database, unless one is
// attached. This is not the case, so don't return a schema.
return null;
}
if ($config->offsetExists('dbname')) {
return $config->get('dbname');
}
return null;
}
}