Skip to content

Commit

Permalink
Merge pull request #4148 from cakephp/3.0-global-func
Browse files Browse the repository at this point in the history
Another round of global functions purging.
  • Loading branch information
markstory committed Aug 2, 2014
2 parents 6eec44c + 1381344 commit 0208da7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 143 deletions.
82 changes: 0 additions & 82 deletions src/basics.php
Expand Up @@ -121,41 +121,6 @@ function stackTrace(array $options = array()) {

}

if (!function_exists('sortByKey')) {

/**
* Sorts given $array by key $sortBy.
*
* @param array &$array Array to sort
* @param string $sortBy Sort by this key
* @param string $order Sort order asc/desc (ascending or descending).
* @param int $type Type of sorting to perform
* @return mixed Sorted array
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#sortByKey
*/
function sortByKey(&$array, $sortBy, $order = 'asc', $type = SORT_NUMERIC) {
if (!is_array($array)) {
return null;
}

foreach ($array as $key => $val) {
$sa[$key] = $val[$sortBy];
}

if ($order === 'asc') {
asort($sa, $type);
} else {
arsort($sa, $type);
}

foreach ($sa as $key => $val) {
$out[] = $array[$key];
}
return $out;
}

}

if (!function_exists('h')) {

/**
Expand Down Expand Up @@ -273,28 +238,6 @@ function pr($var) {

}

if (!function_exists('am')) {

/**
* Merge a group of arrays, accepts an unlimited amount of parameters
*
* @return array All array parameters merged into one
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#am
*/
function am() {
$r = array();
$args = func_get_args();
foreach ($args as $a) {
if (!is_array($a)) {
$a = array($a);
}
$r = array_merge($r, $a);
}
return $r;
}

}

if (!function_exists('env')) {

/**
Expand Down Expand Up @@ -627,28 +570,3 @@ function __x($context, $singular, $args = null) {
}

}

if (!function_exists('fileExistsInPath')) {

/**
* Searches include path for files.
*
* @param string $file File to look for
* @return bool|string Full path to file if exists, otherwise false
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#fileExistsInPath
*/
function fileExistsInPath($file) {
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($paths as $path) {
$fullPath = $path . DS . $file;

if (file_exists($fullPath)) {
return $fullPath;
} elseif (file_exists($file)) {
return $file;
}
}
return false;
}

}
61 changes: 0 additions & 61 deletions tests/TestCase/BasicsTest.php
Expand Up @@ -244,21 +244,6 @@ public function testH() {
$this->assertEquals('Body content', $result);
}

/**
* Test am()
*
* @return void
*/
public function testAm() {
$result = am(array('one', 'two'), 2, 3, 4);
$expected = array('one', 'two', 2, 3, 4);
$this->assertEquals($expected, $result);

$result = am(array('one' => array(2, 3), 'two' => array('foo')), array('one' => array(4, 5)));
$expected = array('one' => array(4, 5), 'two' => array('foo'));
$this->assertEquals($expected, $result);
}

/**
* test __()
*
Expand Down Expand Up @@ -677,52 +662,6 @@ public function testTranslateDomainCategoryPlural() {
$this->assertEquals($expected, $result);
}

/**
* test fileExistsInPath()
*
* @return void
*/
public function testFileExistsInPath() {
if (!function_exists('ini_set')) {
$this->markTestSkipped('%s ini_set function not available');
}

$_includePath = ini_get('include_path');

$path = TMP . 'basics_test';
$folder1 = $path . DS . 'folder1';
$folder2 = $path . DS . 'folder2';
$file1 = $path . DS . 'file1.php';
$file2 = $folder1 . DS . 'file2.php';
$file3 = $folder1 . DS . 'file3.php';
$file4 = $folder2 . DS . 'file4.php';

new Folder($path, true);
new Folder($folder1, true);
new Folder($folder2, true);
touch($file1);
touch($file2);
touch($file3);
touch($file4);

ini_set('include_path', $path . PATH_SEPARATOR . $folder1);

$this->assertEquals(fileExistsInPath('file1.php'), $file1);
$this->assertEquals(fileExistsInPath('file2.php'), $file2);
$this->assertEquals(fileExistsInPath('folder1' . DS . 'file2.php'), $file2);
$this->assertEquals(fileExistsInPath($file2), $file2);
$this->assertEquals(fileExistsInPath('file3.php'), $file3);
$this->assertEquals(fileExistsInPath($file4), $file4);

$this->assertFalse(fileExistsInPath('file1'));
$this->assertFalse(fileExistsInPath('file4.php'));

$Folder = new Folder($path);
$Folder->delete();

ini_set('include_path', $_includePath);
}

/**
* test debug()
*
Expand Down

0 comments on commit 0208da7

Please sign in to comment.