Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webbasics
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
webbasics
Commits
a733b45e
Commit
a733b45e
authored
Oct 06, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added utilities file with camelize() function
parent
b09f6f6c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
0 deletions
+53
-0
base.php
base.php
+1
-0
tests/test_utils.php
tests/test_utils.php
+22
-0
utils.php
utils.php
+30
-0
No files found.
base.php
View file @
a733b45e
...
...
@@ -8,6 +8,7 @@
namespace
webbasics
;
require_once
'utils.php'
;
require_once
'logger.php'
;
/**
...
...
tests/test_utils.php
0 → 100644
View file @
a733b45e
<?php
require_once
'utils.php'
;
use
webbasics
as
wb
;
class
UtilsTest
extends
PHPUnit_Framework_TestCase
{
function
testCamelize
()
{
$this
->
assertEquals
(
'fooBarBaz'
,
wb\camelize
(
'foo bar baz'
));
$this
->
assertEquals
(
'fooBarBaz'
,
wb\camelize
(
'foo_bar_baz'
));
$this
->
assertEquals
(
'fooBarBaz'
,
wb\camelize
(
'foo-bar-baz'
));
$this
->
assertEquals
(
'fooBarBaz'
,
wb\camelize
(
'foo_barBaz'
));
}
/*
* @depends testCamelize
*/
function
testCamelizePascalCase
()
{
$this
->
assertEquals
(
'FooBarBaz'
,
wb\camelize
(
'foo_bar_baz'
,
true
));
}
}
?>
\ No newline at end of file
utils.php
0 → 100644
View file @
a733b45e
<?php
/**
* Utility functions for WebBasics library.
*
* @author Taddeus Kroes
* @date 05-10-2012
* @since 0.2
*/
namespace
webbasics
;
/**
* Camelize a string.
*
* @param string $string The string to camelize.
* @param bool $upper Whether to make the first character uppercase (defaults to FALSE).
* @return string The camelized string.
*/
function
camelize
(
$string
,
$upper
=
false
)
{
$camel
=
preg_replace_callback
(
'/[_ -]([a-z])/'
,
function
(
$matches
)
{
return
strtoupper
(
$matches
[
1
]);
},
$string
);
if
(
$upper
)
return
ucfirst
(
$camel
);
return
$camel
;
}
?>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment