Commit graph

105 commits

Author SHA1 Message Date
Marc Würth
1258739411 Replace Set by Hash
References to the deprecated Set class don't make much sense.
2016-02-23 13:09:03 +01:00
mark_story
8a57d78dba Merge branch '2.7' into 2.8 2015-09-27 11:12:55 -04:00
Marc Würth
e690662f0e Various improvments to the CakePH Plib files
Mostly CS, doc blocks and explicit returning nulls.
2015-09-25 17:11:20 +02:00
mark_story
77f2c8cb42 Use mb_strtolower in case-insensitive sorting.
We should try to support unicode everywhere people might use it.
2015-08-25 21:49:10 -04:00
mark_story
a9ef1f8aea Simplify branching and add default options.
Use fewer conditionals by merging defaults and avoid exceptions
by setting defaults as well.

Refs #7217
2015-08-25 21:39:02 -04:00
Adrian Gunawan
12e5719aad Remove whitespace at end of line 2015-08-14 17:05:59 +10:00
Adrian Gunawan
80f6a97d93 Check === 'natural' was inadvertently removed 2015-08-14 15:32:23 +10:00
Adrian Gunawan
b89d8d5efa Use array() instead of the short notation [] 2015-08-14 14:15:00 +10:00
Adrian Gunawan
f23e6589d0 Overload $type parameter instead of adding another parameter for case insensitive sort 2015-08-13 11:16:32 +10:00
Adrian Gunawan
a217556c13 Ability for Hash::sort to sort case-insensitively 2015-08-12 14:35:11 +10:00
Mark Story
de4b44a37b Merge pull request #7077 from dereuromark/2.7-static
Replacing self with static due to PHP5.3+. Following #7040.
2015-07-23 22:27:37 -04:00
mark_story
e4b2428735 Fix PHPCS errors. 2015-07-21 16:28:17 -04:00
Mark Scherer
52e79987a2 Replacing self with static due to PHP5.3+. Following #7040. 2015-07-21 10:22:53 +02:00
mark_story
bd23fdeebf Simplify code and reduce test redundancy.
We don't need the additional parameter, and some of the tests weren't
covering unique scenarios.

Refs #7040
2015-07-20 22:16:50 -04:00
Chris Valliere
64f0ca0028 Fix Hash::maxDimensions
The current Hash::maxDimensions function calls Hash::dimensions to try
to get the maximum depth of the passed in array.  However, this ends up
only getting the depth of the first element of each 1st dimension
element in the array passed to maxDimensions.  The function needs to be
called recursively in order to get the depth of ALL of the elements in
all of the dimensions of the passed in array.

I made the maxDimensions function more closely resemble the deprecated
Set::countDim function in order to restore the correct functionality.
2015-07-20 22:07:58 -04:00
mark_story
5e9d4893a8 Add the {*} matcher to Hash::extract()
This matcher will match anything and is useful when you just want to
traverse through data and you're not too picky.

I've also refactored the conditions to use a case as it is slightly more
readable and uses fewer lines of code.

Refs #6447
2015-05-01 22:03:40 -04:00
mark_story
096a2ebb72 Merge branch '2.6' into 2.7
Conflicts:
	lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
	lib/Cake/VERSION.txt
2015-04-20 15:42:54 -04:00
Marc Würth
b19b76b9f2 Fix parameter type annotation
https://github.com/cakephp/cakephp/blob/2.6.3/lib/Cake/Utility/Hash.php#L265
https://github.com/cakephp/cakephp/blob/2.6.3/lib/Cake/Utility/Hash.php#L293
2015-04-13 18:20:16 +02:00
mark_story
a6aefdd4d3 Fix null path in Hash::get() causing exceptions.
This was a regression introduced in 2.6.x

Refs #6297
2015-04-09 07:50:29 -04:00
mark_story
69971505a2 Fix maxDimensions() for empty/1 dimensional arrays.
maxDimensions() should not emit warnings or mis-calculate an array's
dimensions.

Fixes #6224
2015-03-31 22:21:15 -04:00
mark_story
ac9a212d44 Merge branch 'master' into 2.7
Conflicts:
	lib/Cake/Utility/String.php
2015-01-11 15:25:18 -05:00
antograssiot
c2f298a8b7 Replace our custom code fence with markdown standard fence 2015-01-09 13:47:25 +01:00
euromark
52ecccb1a2 App::uses and usage replacements for String => CakeText. 2015-01-05 01:00:57 +01:00
mark_story
4d6611b328 Merge branch 'master' into 2.6
Conflicts:
	lib/Cake/VERSION.txt
2014-12-17 21:38:32 -05:00
euromark
e1c128bb99 Consolidate with conditions sniff. 2014-12-09 03:17:35 +01:00
mark_story
87fcc9f0b9 Merge branch 'master' into 2.6
Conflicts:
	lib/Cake/VERSION.txt
2014-10-13 21:11:38 -04:00
Hunter Perrin
be8c591dd8 Fixed coding standard violations. 2014-10-01 12:40:22 -07:00
Hunter Perrin
050e368bd0 Improvements to Hash::expand and Hash::merge.
Because of the recursion in these functions, processing very large
arrays would take a very long time. I rewrote the functions to
eliminate any unnecessary recursion and function calls. Large arrays
are now processed much faster.
2014-10-01 12:08:43 -07:00
mark_story
af43bc1706 Merge branch 'master' into 2.6 2014-09-25 22:39:51 -04:00
Yves
b70cb132fd Fix Hash::remove() removing data even if the path is not matched 2014-09-23 22:00:49 +02:00
ADmad
3fb252ad2f Merge branch 'master' into 2.6 2014-09-13 00:37:16 +05:30
Yves
90ad813b40 Fix Hash not returning correct value with special paths
When doing a Hash::insert() with a part of the path starting with a '0', Hash::get() returned null even if the same path was used.
2014-09-10 22:47:25 +02:00
euromark
e77f96d8b7 Use (int) cast instead of intval() function for performance reasons and to unify it. 2014-09-10 15:52:57 +02:00
Marc Würth
c321a8fa93 Hash::nest() should throw an exception instead of returning an empty array
Refs: https://github.com/cakephp/cakephp/pull/3498#issuecomment-48316204
2014-07-08 13:01:02 +02:00
ADmad
e410501791 Fix CS errors. 2014-07-03 23:13:55 +05:30
mark_story
2bcd817367 Merge branch 'master' into 2.6 2014-07-03 11:13:06 -04:00
euromark
974ca851c2 Correct doc blocks according to cs guidelines.
Remove superfluous empty lines.
2014-07-03 15:36:42 +02:00
Dan Voyce
239af0322e Raise an exception when Hash::get() receives invalid parameters
I'm not sure on whether this is a problem with my local app but I have
seen it a couple of times in a couple of projects: Warning (2): Invalid
argument supplied for foreach() [CORE/Cake/Utility/Hash.php, line 52]

I think Hash::get should be able to handle this better rather than
throwing an error in a core Util file.

Refs #3754
2014-06-25 09:15:46 -04:00
mark_story
fa19c34580 Fix Hash::extract() not matching 1/0 to true/false.
Historically [prop=1] has matched prop=true as well. This restores that
and also fixes [prop=0] not finding falsey values.

This makes the typing less strict in Hash::extract() but I don't think
it is unreasonable given PHP's type juggling.

Refs #3288
2014-06-12 11:30:48 -04:00
ADmad
543066f34a Set default sort direction to 'asc'. 2014-05-30 19:43:09 +05:30
ADmad
7a4244d0a6 More docblock CS fixes. 2014-05-28 22:09:54 +05:30
euromark
143e8e4c56 Make sure invalid arrays return empty array instead of throwing notices. 2014-05-14 23:53:58 +02:00
mark_story
bf9c3029cb Merge branch 'master' into 2.5 2014-04-10 20:51:49 -04:00
mark_story
c6173a0054 Add tests for #3288 and remove nested ternaries.
Nested ternaries are complicated to maintain and hard to read. Break
down the nested ternary into two conditionals.
2014-04-10 20:37:08 -04:00
Guillaume Lafarge
db450a96e9 Fix Hash type casting
When using comparison with a boolean, as the filter is a string, we have to convert the data boolean to "boolean string" to avoid type-casting troubles.

## Example
```php
$users = [
    [
        'id' => 2,
        'username' => 'johndoe',
        'active' => true
    ],
    [   'id' => 5,
        'username' => 'kevin',
        'active' => true
    ],
    [
        'id' => 9,
        'username' => 'samantha',
        'active' => false
    ],
];
$unactiveUsers = Hash::extract($users, '{n}[active=false]');
print_r($unactiveUsers);
```

This example returns the two unwanted active users because `"false"` is `true` but not `false` :)

I think this pull request will fix this issue by converting true/false boolean to string (to match with our filter).
2014-04-10 20:19:32 +02:00
mark_story
99e4dbd827 Merge branch 'master' into 2.5 2013-12-23 11:58:07 -05:00
Saleh Souzanchi
328125ad43 Merge branch 'master' into master-phpcs-error-fix 2013-12-23 11:43:54 +03:30
Mark Story
321347e52b Merge pull request #2532 from bar/patch-2
Trivial continue.

fix phpcs error "Missing @throws tag in function comment"
2013-12-23 11:21:18 +03:30
mark_story
62e89734ab Throw exceptions from Hash::combine()
When the key + value counts do not match Hash should throw an exception.
Silently doing the wrong thing is generally not a good idea. While this
change could break existing applications, those applications were
probably behaving incorrectly anyways.

Fixes #2470
2013-12-21 17:46:05 -05:00
mark_story
c2b8778ce8 Merge branch 'master' into 2.5 2013-12-14 17:45:49 -05:00