public function show($id)
 {
     $user = User::findOrFail($id);
     if (\Auth::guest() && $user->profile_private) {
         return \Response::make('', 404);
     }
     $profileData = $this->profileRepo->getUserProfile($id);
     $userSkills = array_intersect_ukey($this->profileSkillsRepository->getAll(), array_flip($profileData->skills), [$this, 'key_compare_func']);
     return \View::make('members.show')->with('user', $user)->with('profileData', $profileData)->with('userSkills', $userSkills);
 }
Пример #2
0
    echo "<p class=\"alert alert-danger\">{$error}</p>";
    exit;
}
?>
<h3><?php 
printf('%s "%s"', _("Rights for user"), $user_name);
?>
</h3>
<?php 
$raw_sites = $piwik->get_site_list();
$piwik_sites = array();
foreach ($raw_sites as $site) {
    $piwik_sites[$site->idsite] = array('name' => $site->name, 'url' => $site->main_url);
}
$raw_access = $piwik->get_site_access($user_name);
$piwik_user_sites = array_intersect_ukey($piwik_sites, $user_piwik_sites, "strcmp");
$available_user_sites = $piwik_user_sites;
echo '<ul>';
foreach ($raw_access as $access) {
    unset($available_user_sites[$access->site]);
    printf("<li>%s -> %s</li>\n", $piwik_sites[$access->site]['name'], $access->access);
}
echo '</ul>';
if (count($available_user_sites) > 0) {
    ?>
<h3><?php 
    printf('%s "%s"', _("Add rights to user"), $user_name);
    ?>
</h3>
<ul>
<?php 
Пример #3
0
    return $a > $b;
})), array_key_exists((int) array_walk($names, function ($v, $k) {
    return $k;
}), $names), array_walk_recursive($names, function ($v, $k) {
    return $k;
}))))), $names))), function ($a, $b) {
    return $a > $b;
}), function ($a, $b) {
    return $b > $a;
}, function ($a, $b) {
    return $b > $a;
})), array_splice($names, array_multisort(array_map(function ($v) {
    return $v;
}, array_intersect_ukey(array_diff_key($names, array_udiff_assoc($names, $names, function ($a, $b) {
    return $a > $b;
})), $names, function ($a, $b) use($names) {
    return array_push($names, $a) === $b;
})))), function ($a, $b) {
    return $a;
})))), function ($v) {
    if ($v !== '' && $v !== 'Rick Astley') {
        return true;
    }
    return false;
}))) . "!\n";
/*
  Step 1: separate the functions by return value scalar/array
  Step 2: further separate by type, and type of array
  Step 3: pair similar functions together
  Step 4: tackle the hard functions first (indicated with *)
  Step 5: make small blocks that 'return original input', 'return empty array', 'return scalar value'
<?php

/* Prototype  : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func)
 * Description: Computes the intersection of arrays using a callback function on the keys for comparison. 
 * Source code: ext/standard/array.c
 */
echo "*** Testing array_intersect_ukey() : usage variation ***\n";
//Initialize variables
$arr_float = array(0.0 => 1.0, 1.0 => 2.0);
$arr_string = array('0' => '1', '1' => '2', '2' => '3');
$arr_string_float = array('0.00' => '1.00', '1.00' => '2.00');
//Call back function
function key_compare_func($key1, $key2)
{
    if ($key1 == $key2) {
        return 0;
    } else {
        return $key1 > $key2 ? 1 : -1;
    }
}
echo "\n-- Result of floating points and strings containing integers intersection --\n";
var_dump(array_intersect_ukey($arr_float, $arr_string, 'key_compare_func'));
echo "\n-- Result of floating points and strings containing floating point intersection --\n";
var_dump(array_intersect_ukey($arr_float, $arr_string_float, 'key_compare_func'));
?>
===DONE===
Пример #5
0
 public static function update_table_options($ofs1, $ofs3, $old_schema, $old_table, $new_schema, $new_table)
 {
     if (strcasecmp(dbsteward::get_sql_format(), 'mssql10') === 0) {
         dbsteward::warning("mssql10 tableOptions are not implemented yet");
         return;
     }
     if ($new_schema && $new_table) {
         $alter_options = array();
         $create_options = array();
         $drop_options = array();
         $old_options = format_table::get_table_options($old_schema, $old_table);
         $new_options = format_table::get_table_options($new_schema, $new_table);
         // dropped options are those present in the old table, but not in the new
         $drop_options = array_diff_key($old_options, $new_options);
         // added options are those present in the new table but not in the old
         $create_options = array_diff_key($new_options, $old_options);
         // altered options are those present in both but with different values
         $alter_options = array_intersect_ukey($new_options, $old_options, function ($new_key, $old_key) use($new_options, $old_options) {
             if ($new_key == $old_key && strcasecmp($new_options[$new_key], $old_options[$old_key]) !== 0) {
                 return 0;
             } else {
                 return -1;
             }
         });
         static::apply_table_options_diff($ofs1, $ofs3, $new_schema, $new_table, $alter_options, $create_options, $drop_options);
     }
 }
Пример #6
0
 /**
  * (PHP 5 &gt;= 5.1.0)<br/>
  * Computes the intersection of arrays using a callback function on the keys for comparison
  * @link http://php.net/manual/en/function.array-intersect-ukey.php
  * @param array $array2 <p>
  * First array to compare keys against.
  * </p>
  * @param array $_ [optional] <p>
  * Variable list of array arguments to compare keys against.
  * </p>
  * @param callable $key_compare_func <p>
  * The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
  * </p>
  * int<b>callback</b><b>mixed<i>a</i></b><b>mixed<i>b</i></b>
  * @return array the values of <i>array1</i> whose keys exist
  * in all the arguments.
  */
 public function intersect_ukey(array $array2, array $_ = null, callable $key_compare_func)
 {
     // TODO: use func_get_args() for multiple arguments, like Arr($array)->function($v1, $v2, $v3)
     return array_intersect_ukey($this->array, $array2, $key_compare_func);
 }
Пример #7
0
 /**
  * Get key-value pairs which exist in both of two arrays, where keys
  * alone determine uniqueness.
  *
  * Returns an associative array containing all key-value pairs in the
  * first array whose keys exist in the second. Optionally provide a
  * key comparison function.
  *
  * @param array $array1
  * @param array $array2
  * @param callable|null $key_cmp
  * @return array
  */
 public static function keyIntersection($array1, $array2, $key_cmp = null)
 {
     if ($key_cmp === null) {
         return array_intersect_key($array1, $array2);
     } else {
         return array_intersect_ukey($array1, $array2, $key_cmp);
     }
 }
Пример #8
0
 /**
  * Get all public fields from model
  *
  * @param bool $getColumns
  *
  * @return array
  */
 private function getPropertiesAndValuesChildClass($getColumns = false)
 {
     $reflection = new \ReflectionClass($this->pathNamespace);
     $classVars = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
     $data = array_intersect_ukey($this->dataModel, $classVars, function ($key1, $key2) {
         if ($key1 === $key2) {
             return 0;
         }
     });
     if ($getColumns) {
         $columns = [];
         foreach ($data as $column => $value) {
             $columns[] = $column;
         }
         return $columns;
     }
     return $data;
 }
<?php

/* Prototype  : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func)
 * Description: Computes the intersection of arrays using a callback function on the keys for comparison. 
 * Source code: ext/standard/array.c
 */
echo "*** Testing array_intersect_ukey() : usage variation ***\n";
//Initialise arguments
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
//function name within double quotes
var_dump(array_intersect_ukey($array1, $array2, "unknown_function"));
//function name within single quotes
var_dump(array_intersect_ukey($array1, $array2, 'unknown_function'));
//function name without quotes
var_dump(array_intersect_ukey($array1, $array2, unknown_function));
?>
===DONE===
Пример #10
0
 /**
  * Returns a Collection containing all the values of this Collection that are present
  * in the other Collection. Keys are used for comparison
  *
  * If the optional comparison function is supplied it must have signature
  * function(mixed $a, mixed $b){}. The comparison function must return an integer
  * less than, equal to, or greater than zero if the first argument is considered
  * to be respectively less than, equal to, or greater than the second.
  *
  * @param Collection $other
  * @param \Closure $function Optional function to compare values
  *
  * @return Collection
  */
 public function kIntersect(Collection $other, \Closure $function = null)
 {
     return new static(Match::on(Option::create($function))->Monad_Option_Some(function () use($other, $function) {
         return \array_intersect_ukey($this->getArrayCopy(), $other->getArrayCopy(), $function);
     })->Monad_Option_None(function () use($other) {
         return \array_intersect_key($this->getArrayCopy(), $other->getArrayCopy());
     })->value(), $this->type);
 }
Пример #11
0
function compArray($val1, $val2)
{
    if (is_array($val1) && is_array($val2)) {
        return array_intersect_ukey($val1, $val2, 'compArray');
    } else {
        return strcasecmp($val1, $val2);
    }
}
// [] ==>> E_NOTICE
$array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red");
var_dump(array_intersect_uassoc($array1, $array2, "strcasecmp"));
//			var_dump(array_intersect_assoc($array1, $array2));
?>
</div>
		
		
		
		<h3><code>array</code> array_intersect_ukey(<code>array $array1, array $array2 [, array $...], callable $key_compare_func</code>) <span class="badge">5.1+</span></h3>
		<div><?php 
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4, []);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8, []);
var_dump(array_intersect_ukey($array1, $array2, function ($k1, $k2) {
    if ($k1 == $k2) {
        return 0;
    }
    return $k1 > $k2 ? 1 : -1;
}));
?>
</div>
		
		
		
		<h3><code>array</code> array_intersect(<code>array $array1, array $array2 [, array $...]</code>) <span class="badge">4.0.1+</span></h3>
		<div><?php 
$array1 = array("a" => "green", "red", "blue");
// [] ==>> E_NOTICE
$array2 = array("b" => "green", "yellow", "red");
var_dump(array_intersect($array1, $array2));
?>
</div>
Пример #13
0
 /**
  * @param HTArray $array2
  * @param $key_compare_func
  * @return $this
  * @desc 用回调函数比较键名来计算数组的交集。
  */
 public function array_intersect_ukey(HTArray $array2, $key_compare_func)
 {
     $this->current = array_intersect_ukey($this->current, (array) $array2, $key_compare_func);
     return $this;
 }
Пример #14
0
 /**
  * @dataProvider arraySet1
  */
 public function testIntersectKey2($array)
 {
     $compare = ['k1' => 'v1'];
     // callback function used for filtering
     $callable = function ($a, $b) {
         if ($a == $b) {
             return 0;
         }
         return 1;
     };
     $a = new ArrayObject($array);
     @$a->intersectKey($compare, $callable);
     @($array = array_intersect_ukey($array, $compare, $callable));
     $this->assertSame($array, $a->val());
 }
Пример #15
0
 public function intersect_ukey($aArray, $callback)
 {
     if ($aArray instanceof MF_PHP_Array) {
         $aArray =& $aArray->to_array();
     }
     $oReturn = new MF_PHP_Array(array_intersect_ukey($this->__data, $aArray, $callback));
     return $oReturn;
 }
$unset_var = 10;
unset($unset_var);
//resource variable
$fp = fopen(__FILE__, "r");
// define some classes
class classWithToString
{
    public function __toString()
    {
        return "Class A object";
    }
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
//array of values to iterate over
$inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -12345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float 12.3456789000e10' => 123456789000.0, 'float -12.3456789000e10' => -123456789000.0, 'float .5' => 0.5, 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'empty string DQ' => "", 'empty string SQ' => '', 'string DQ' => "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var, 'resource var' => $fp);
// loop through each element of the array for arr1
foreach ($inputs as $key => $value) {
    echo "\n--{$key}--\n";
    var_dump(array_intersect_ukey($value, $array2, 'key_compare_func'));
    var_dump(array_intersect_ukey($value, $array2, $array3, 'key_compare_func'));
}
fclose($fp);
?>
===DONE===
Пример #17
0
<?php

/*
* proto array array_intersect_ukey ( array $array1, array $array2 [, array $ ..., callback $key_compare_func] )
* Function is implemented in ext/standard/array.c
*/
function key_compare_func($key1, $key2)
{
    if ($key1 == $key2) {
        return 0;
    } else {
        if ($key1 > $key2) {
            return 1;
        } else {
            return -1;
        }
    }
}
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
var_dump(array_intersect_ukey($array1, $array2, 'key_compare_func'));
Пример #18
0
// -20
__var_dump(array_intersect_key($a_f, $b_f, $c_f, $d_f));
// -20
__var_dump(array_intersect_ukey($a_f, $b_f, $c_f, $d_f, "comp_func"));
//-20
__var_dump(array_intersect_key($b_f, $c_f));
// 0, 2, -20, -2500
__var_dump(array_intersect_ukey($b_f, $c_f, "comp_func"));
//0, 2, -20, 2500
__var_dump(array_intersect_key($b_f, $d_f));
// -20
__var_dump(array_intersect_ukey($b_f, $d_f, "comp_func"));
// -20
__var_dump(array_intersect_key($b_f, $c_f, $d_f));
// -20
__var_dump(array_intersect_ukey($b_f, $c_f, $d_f, "comp_func"));
// -20
echo "----- Now testing array_intersect() ------- \n";
__var_dump(array_intersect($a, $b_f));
__var_dump(array_uintersect($a, $b, "comp_func"));
__var_dump(array_intersect($a, $b, $c));
__var_dump(array_uintersect($a, $b, $c, "comp_func"));
__var_dump(array_intersect($a, $b, $c, $d));
__var_dump(array_uintersect($a, $b, $c, $d, "comp_func"));
///////////////////////////////////////////////////////////////////////
function comp_func($a, $b)
{
    if ($a === $b) {
        return 0;
    }
    return $a > $b ? 1 : -1;
<?php

/* Prototype  : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func)
 * Description: Computes the intersection of arrays using a callback function on the keys for comparison. 
 * Source code: ext/standard/array.c
 */
echo "*** Testing array_intersect_ukey() : usage variation ***\n";
//Initialize variables
$arr_default_int = array(1, 2);
$arr_float = array(0 => 1.0, 1.0 => 2.0, 2.0 => 3.0);
$arr_string = array('0' => '1', '1' => '2', '2' => '3');
$arr_string_float = array('0.00' => '1.00', '1.00' => '2.00');
//Call back function
function key_compare_func($key1, $key2)
{
    if ($key1 == $key2) {
        return 0;
    } else {
        return $key1 > $key2 ? 1 : -1;
    }
}
echo "\n-- Result of integers and floating point intersection --\n";
var_dump(array_intersect_ukey($arr_default_int, $arr_float, "key_compare_func"));
echo "\n-- Result of integers and strings containing integers intersection --\n";
var_dump(array_intersect_ukey($arr_default_int, $arr_string, "key_compare_func"));
echo "\n-- Result of integers and strings containing floating points intersection --\n";
var_dump(array_intersect_ukey($arr_default_int, $arr_string_float, "key_compare_func"));
?>
===DONE===
//get an unset variable
$unset_var = 10;
unset($unset_var);
//resource variable
$fp = fopen(__FILE__, "r");
// define some classes
class classWithToString
{
    public function __toString()
    {
        return "Class A object";
    }
}
class classWithoutToString
{
}
// add arrays
$index_array = array(1, 2, 3);
$assoc_array = array('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -12345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float 12.3456789000e10' => 123456789000.0, 'float -12.3456789000e10' => -123456789000.0, 'float .5' => 0.5, 'empty array' => array(), 'int indexed array' => $index_array, 'associative array' => $assoc_array, 'nested arrays' => array('foo', $index_array, $assoc_array), 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var, 'resource var' => $fp);
// loop through each element of the array for key_compare_func
foreach ($inputs as $key => $value) {
    echo "\n--{$key}--\n";
    var_dump(array_intersect_ukey($array1, $array2, $value));
    var_dump(array_intersect_ukey($array1, $array2, $array3, $value));
}
fclose($fp);
?>
===DONE===
Пример #21
0
 /**
  * {@inheritdoc}
  */
 public function ukeyIntersect(CollectionInterface $collection, callable $intersecter) : CollectionInterface
 {
     return new self(array_intersect_ukey($this->values, $collection->toPrimitive(), $intersecter));
 }
Пример #22
0
/* Prototype  : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func)
 * Description: Computes the intersection of arrays using a callback function on the keys for comparison. 
 * Source code: ext/standard/array.c
 */
echo "*** Testing array_intersect_ukey() : error conditions ***\n";
//Initialise arguments
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
//Call back function
function key_compare_func($key1, $key2)
{
    if ($key1 == $key2) {
        return 0;
    } else {
        return $key1 > $key2 ? 1 : -1;
    }
}
//Test array_intersect_ukey with one more than the expected number of arguments
echo "\n-- Testing array_intersect_ukey() function with more than expected no. of arguments --\n";
$extra_arg = 10;
var_dump(array_intersect_ukey($array1, $array2, 'key_compare_func', $extra_arg));
// Testing array_intersect_ukey with one less than the expected number of arguments
echo "\n-- Testing array_intersect_ukey() function with less than expected no. of arguments --\n";
var_dump(array_intersect_ukey($array1, $array2));
// Testing array_intersect_ukey with no arguments
echo "\n-- Testing array_intersect_ukey() function with no arguments --\n";
var_dump(array_intersect_ukey());
?>
===DONE===
Пример #23
0
 /**
  * Remove all elements from the current array that are not present in the given $array.
  * This function compares ONLY array keys.
  *
  * @param array  $array Array for comparison
  * @param string $callable Optional callback function that can be uses for comparison.
  *
  * @return $this
  * @throws ArrayObjectException
  */
 public function intersectKey($array, $callable = '')
 {
     if ($callable != '') {
         if (!$this->isCallable($callable)) {
             throw new ArrayObjectException(ArrayObjectException::MSG_INVALID_PARAM, ['$callable', 'a callable function or method']);
         }
         $this->val(array_intersect_ukey($this->val(), $array, $callable));
     } else {
         $this->val(array_intersect_key($this->val(), $array));
     }
     return $this;
 }
Пример #24
0
<?php

$array1 = array("blue" => 1, "red" => 2, "green" => 3, "purple" => 4);
$array2 = array("green" => 5, "blue" => 6, "yellow" => 7, "cyan" => 8);
var_dump(array_intersect_ukey($array1, $array2, 'strcasecmp'));
<?php

/* Prototype  : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func)
 * Description: Computes the intersection of arrays using a callback function on the keys for comparison. 
 * Source code: ext/standard/array.c
 */
echo "*** Testing array_intersect_ukey() : usage variation ***\n";
//Initialise arguments
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
class MyClass
{
    static function static_compare_func($key1, $key2)
    {
        return strcasecmp($key1, $key2);
    }
    public function class_compare_func($key1, $key2)
    {
        return strcasecmp($key1, $key2);
    }
}
echo "\n-- Testing array_intersect_ukey() function using class with static method as callback --\n";
var_dump(array_intersect_ukey($array1, $array2, array('MyClass', 'static_compare_func')));
var_dump(array_intersect_ukey($array1, $array2, 'MyClass::static_compare_func'));
echo "\n-- Testing array_intersect_uassoc() function using class with regular method as callback --\n";
$obj = new MyClass();
var_dump(array_intersect_ukey($array1, $array2, array($obj, 'class_compare_func')));
?>
===DONE===
Пример #26
0
 public function runAction()
 {
     $sm = $this->getServiceLocator();
     /* @var $console AdapterInterface */
     /* @var $config array */
     /* @var $mm ModuleManager */
     $console = $sm->get('console');
     $config = $sm->get('Configuration');
     $mm = $sm->get('ModuleManager');
     $verbose = $this->params()->fromRoute('verbose', false);
     $debug = $this->params()->fromRoute('debug', false);
     $quiet = !$verbose && !$debug && $this->params()->fromRoute('quiet', false);
     $breakOnFailure = $this->params()->fromRoute('break', false);
     $checkGroupName = $this->params()->fromRoute('filter', false);
     // Get basic diag configuration
     $config = isset($config['diagnostics']) ? $config['diagnostics'] : array();
     // Collect diag tests from modules
     $modules = $mm->getLoadedModules(false);
     foreach ($modules as $moduleName => $module) {
         if (is_callable(array($module, 'getDiagnostics'))) {
             $checks = $module->getDiagnostics();
             if (is_array($checks)) {
                 $config[$moduleName] = $checks;
             }
             // Exit the loop early if we found check definitions for
             // the only check group that we want to run.
             if ($checkGroupName && $moduleName == $checkGroupName) {
                 break;
             }
         }
     }
     // Filter array if a check group name has been provided
     if ($checkGroupName) {
         $config = array_intersect_ukey($config, array($checkGroupName => 1), 'strcasecmp');
         if (empty($config)) {
             $m = new ConsoleModel();
             $m->setResult($console->colorize(sprintf("Unable to find a group of diagnostic checks called \"%s\". Try to use module name (i.e. \"%s\").\n", $checkGroupName, 'Application'), ColorInterface::YELLOW));
             $m->setErrorLevel(1);
             return $m;
         }
     }
     // Check if there are any diagnostic checks defined
     if (empty($config)) {
         $m = new ConsoleModel();
         $m->setResult($console->colorize("There are no diagnostic checks currently enabled for this application - please add one or more " . "entries into config \"diagnostics\" array or add getDiagnostics() method to your Module class. " . "\n\nMore info: https://github.com/zendframework/ZFTool/blob/master/docs/" . "DIAGNOSTICS.md#adding-checks-to-your-module\n", ColorInterface::YELLOW));
         $m->setErrorLevel(1);
         return $m;
     }
     // Analyze check definitions and construct check instances
     $checkCollection = array();
     foreach ($config as $checkGroupName => $checks) {
         foreach ($checks as $checkLabel => $check) {
             // Do not use numeric labels.
             if (!$checkLabel || is_numeric($checkLabel)) {
                 $checkLabel = false;
             }
             // Handle a callable.
             if (is_callable($check)) {
                 $check = new Callback($check);
                 if ($checkLabel) {
                     $check->setLabel($checkGroupName . ': ' . $checkLabel);
                 }
                 $checkCollection[] = $check;
                 continue;
             }
             // Handle check object instance.
             if (is_object($check)) {
                 if (!$check instanceof CheckInterface) {
                     throw new RuntimeException('Cannot use object of class "' . get_class($check) . '" as check. ' . 'Expected instance of ZendDiagnostics\\Check\\CheckInterface');
                 }
                 // Use duck-typing for determining if the check allows for setting custom label
                 if ($checkLabel && is_callable(array($check, 'setLabel'))) {
                     $check->setLabel($checkGroupName . ': ' . $checkLabel);
                 }
                 $checkCollection[] = $check;
                 continue;
             }
             // Handle an array containing callback or identifier with optional parameters.
             if (is_array($check)) {
                 if (!count($check)) {
                     throw new RuntimeException('Cannot use an empty array() as check definition in "' . $checkGroupName . '"');
                 }
                 // extract check identifier and store the remainder of array as parameters
                 $testName = array_shift($check);
                 $params = $check;
             } elseif (is_scalar($check)) {
                 $testName = $check;
                 $params = array();
             } else {
                 throw new RuntimeException('Cannot understand diagnostic check definition "' . gettype($check) . '" in "' . $checkGroupName . '"');
             }
             // Try to expand check identifier using Service Locator
             if (is_string($testName) && $sm->has($testName)) {
                 $check = $sm->get($testName);
                 // Try to use the ZendDiagnostics namespace
             } elseif (is_string($testName) && class_exists('ZendDiagnostics\\Check\\' . $testName)) {
                 $class = new \ReflectionClass('ZendDiagnostics\\Check\\' . $testName);
                 $check = $class->newInstanceArgs($params);
                 // Try to use the ZFTool namespace
             } elseif (is_string($testName) && class_exists('ZFTool\\Diagnostics\\Check\\' . $testName)) {
                 $class = new \ReflectionClass('ZFTool\\Diagnostics\\Check\\' . $testName);
                 $check = $class->newInstanceArgs($params);
                 // Check if provided with a callable inside an array
             } elseif (is_callable($testName)) {
                 $check = new Callback($testName, $params);
                 if ($checkLabel) {
                     $check->setLabel($checkGroupName . ': ' . $checkLabel);
                 }
                 $checkCollection[] = $check;
                 continue;
                 // Try to expand check using class name
             } elseif (is_string($testName) && class_exists($testName)) {
                 $class = new \ReflectionClass($testName);
                 $check = $class->newInstanceArgs($params);
             } else {
                 throw new RuntimeException('Cannot find check class or service with the name of "' . $testName . '" (' . $checkGroupName . ')');
             }
             if (!$check instanceof CheckInterface) {
                 // not a real check
                 throw new RuntimeException('The check object of class ' . get_class($check) . ' does not implement ' . 'ZendDiagnostics\\Check\\CheckInterface');
             }
             // Use duck-typing for determining if the check allows for setting custom label
             if ($checkLabel && is_callable(array($check, 'setLabel'))) {
                 $check->setLabel($checkGroupName . ': ' . $checkLabel);
             }
             $checkCollection[] = $check;
         }
     }
     // Configure check runner
     $runner = new Runner();
     $runner->addChecks($checkCollection);
     $runner->getConfig()->setBreakOnFailure($breakOnFailure);
     if (!$quiet && $this->getRequest() instanceof ConsoleRequest) {
         if ($verbose || $debug) {
             $runner->addReporter(new VerboseConsole($console, $debug));
         } else {
             $runner->addReporter(new BasicConsole($console));
         }
     }
     // Run tests
     $results = $runner->run();
     $request = $this->getRequest();
     // Return result
     if ($request instanceof ConsoleRequest) {
         return $this->processConsoleRequest($results);
     }
     if ($request instanceof Request) {
         return $this->processHttpRequest($request, $results);
     }
 }
Пример #27
0
<?php

// array_intersect_ukey.php
$week = ["Monday" => "Rāhina", "Tuesday" => "Rātū", "Wednesday" => "Rāapa", "Thursday" => "Rāpare", "Friday" => "Rāmere", "Saturday" => "Rāhoroi", "Sunday" => "Rātapu"];
$weekend = ["Saturday" => "Rāhoroi", "Sunday" => "Rātapu"];
$weekendDays = array_intersect_ukey($week, $weekend, function ($v1, $v2) {
    echo "{$v1}:{$v2}<br>";
    if ($v1 == $v2) {
        return 0;
    }
    return $v1 > $v2 ? 1 : -1;
});
echo "<pre>";
var_dump($weekendDays);
echo "</pre>";