<?php /* Prototype : int ArrayObject::ksort() * Description: proto int ArrayIterator::ksort() * Sort the entries by key. * Source code: ext/spl/spl_array.c * Alias to functions: */ echo "*** Testing ArrayObject::ksort() : basic functionality ***\n"; class C { public $x = 'prop1'; public $z = 'prop2'; public $a = 'prop3'; private $b = 'prop4'; } $c = new C(); $ao1 = new ArrayObject($c); var_dump($ao1->ksort()); var_dump($ao1, $c); ?> ===DONE===
function getTableContent($headers, $param) { $paramArrayObject = new ArrayObject($param); $paramArrayObject->ksort(); $o = "<table>"; $o .= "<tr>"; foreach ($headers as $header) { $o .= "<th>" . $header . "</th>"; } $o .= "</tr>"; if (is_array($param)) { foreach ($paramArrayObject as $key => $value) { $restrictedAvailability = false; $o .= '<tr class="linkable" id="' . $key . '">'; $o .= "<td>" . $key; foreach ($value as $val => $value1) { if ($val == 'availability' && $value1 == 'kdp') { $o .= '<br><span class="label label-warning">Legacy Only</span>'; $restrictedAvailability = true; } } //if (!$restrictedAvailability) // $o.= '<br><span class="label label-success">Legacy / Universal</span>'; $o .= "</td>"; foreach ($value as $val => $value) { if ($val != 'availability' && $val != 'example') { $o .= "<td>" . $value . "</td>"; } if ($val == 'example') { if ($value != '') { $o .= '<td><a href="' . $value . '" target="_blank">Example</a></td>'; } else { $o .= '<td>-</td>'; } } } /* foreach( $value as $val){ $o.= "<td>".$val."</td>"; } $o.= "</tr>";*/ } } $o .= "</table>"; return $o; }
/** * Return the list of available modules, including uninstalled modules * * @uses Message::warn * @uses HTML::anchor * @uses Route::get * @uses Route::uri */ public static function available() { if (empty(self::$available)) { $upgrade = FALSE; $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); $paths = (array) Config::get('site.module_paths', array(MODPATH)); // Make sure MODPATH is set else add last if (!in_array(MODPATH, $paths)) { array_push($paths, MODPATH); } // Iterate over each config path foreach ($paths as $name => $path) { foreach (glob($path . "*/module.info") as $file) { $name = basename(dirname($file)); $modules->{$name} = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); $m =& $modules->{$name}; $m->active = self::is_active($name); $m->title = isset($m->title) ? (string) $m->title : $name; $m->code_version = $m->version; $m->version = self::get_version($name); $m->locked = false; $m->visible = isset($m->visible) ? (bool) $m->visible : true; $m->author = isset($m->author) ? (string) $m->author : 'Gleez Team'; $m->authorURL = isset($m->authorURL) ? (string) $m->authorURL : 'http://gleezcms.org/'; $m->path = realpath(dirname($file)) . DS; // Skip this module in list if the module is hidden if ($m->visible === false && isset($modules[$name])) { unset($modules[$name]); } // Check installed and available version and set message if ($m->active and $m->version != $m->code_version) { $upgrade = TRUE; } } } if ($upgrade) { Message::warn(__('Some of your modules are out of date. :upgrade_url', array(':upgrade_url' => HTML::anchor(Route::get('admin/module')->uri(array('action' => 'upgrade')), __('Upgrade now!'))))); } // Lock certain modules $modules->user->locked = TRUE; $modules->ksort(); self::$available = $modules; } return self::$available; }
public function getFiles($return_as_array = false) { // compose the full name of the filter class $classname = 'Koch_' . $this->filtername . 'FilterIterator'; // wrap the iterator in a filter class, when looking for a specific file type, like imagesOnly' $iterator = new $classname(new DirectoryIterator($this->getDirectory())); // return objects if ($return_as_array === false) { // create new array to take the SPL FileInfo Objects $data = new ArrayObject(); // while iterating foreach ($iterator as $file) { /** * push the SPL FileInfo Objects into the array * @see http://www.php.net/~helly/php/ext/spl/classSplFileInfo.html */ $data[$file->getFilename()] = $file->getFileInfo(); } $data->ksort(); } else { // return array // create array $data = array(); // while iterating foreach ($iterator as $file) { $wwwpath = WWW_ROOT . DIRECTORY_SEPARATOR . $this->getDirectory() . DIRECTORY_SEPARATOR . $file->getFilename(); $wwwpath = str_replace('//', '/', $wwwpath); $data[$wwwpath] = $file->getFilename(); } } // return the array with SPL FileInfo Objects return $data; }
/** * Return the list of available modules, including uninstalled modules. */ static function available() { if (empty(self::$available)) { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); foreach (glob(MODPATH . "*/module.info") as $file) { $module_name = basename(dirname($file)); $modules->{$module_name} = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); $m =& $modules->{$module_name}; $m->installed = self::is_installed($module_name); $m->active = self::is_active($module_name); $m->code_version = $m->version; $m->version = self::get_version($module_name); $m->locked = false; } // Lock certain modules $modules->gallery->locked = true; $modules->user->locked = true; $modules->ksort(); self::$available = $modules; } return self::$available; }
<?php /* Prototype : int ArrayObject::ksort() * Description: proto int ArrayIterator::ksort() * Sort the entries by key. * Source code: ext/spl/spl_array.c * Alias to functions: */ echo "*** Testing ArrayObject::ksort() : basic functionality ***\n"; $ao1 = new ArrayObject(array(4, 2, 3)); $ao2 = new ArrayObject(array('b' => 4, 'a' => 2, 'q' => 3, 99 => 'x')); var_dump($ao1->ksort()); var_dump($ao1); var_dump($ao2->ksort('blah')); var_dump($ao2); var_dump($ao2->ksort(SORT_STRING)); var_dump($ao2); ?> ===DONE===
) */ /* ksort($aa); print_r($aa); */ /* asort($aa); print_r($aa);*/ ?> <?php $name = array("d" => "Mark", "a" => "David", "b" => "Peter", "c" => "Martha"); $nameArrayObject = new ArrayObject($name); $nameArrayObject->ksort(); foreach ($nameArrayObject as $key => $val) { echo "$key = $val\n"; } ?> <?php $foofa = function ($x){ return $x*$x; }; $foo = create_function('$x', 'return $x*$x;'); $bar = create_function("\$x", "return \$x*\$x;"); echo $foo(10) . PHP_EOL; echo $bar(5). PHP_EOL;
<?php $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); $fruitArrayObject = new ArrayObject($fruits); $fruitArrayObject->ksort(); foreach ($fruitArrayObject as $key => $val) { echo "{$key} = {$val}\n"; }
/** * Return the list of available modules, including uninstalled modules. */ static function available() { if (empty(self::$available)) { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); foreach (glob(MODPATH . "*/module.info") as $file) { $module_name = basename(dirname($file)); $modules->{$module_name} = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); $m =& $modules->{$module_name}; $m->installed = module::is_installed($module_name); $m->active = module::is_active($module_name); $m->code_version = $m->version; $m->version = module::get_version($module_name); $m->locked = false; if ($m->active && $m->version != $m->code_version) { site_status::warning(t("Some of your modules are out of date. <a href=\"%upgrader_url\">Upgrade now!</a>", array("upgrader_url" => url::site("upgrader"))), "upgrade_now"); } } // Lock certain modules $modules->gallery->locked = true; $identity_module = module::get_var("gallery", "identity_provider", "user"); $modules->{$identity_module}->locked = true; $modules->ksort(); self::$available = $modules; } return self::$available; }
/** * @param \ArrayObject $project The project */ public function applyPermissions(\ArrayObject $project) { if ($this->app["config"]["develmode"] || !$this->processProvider->commandExists("setfacl")) { if (!file_exists($this->fileSystemProvider->getProjectDirectory($project["name"]))) { $this->dialogProvider->logNotice($this->fileSystemProvider->getProjectDirectory($project["name"]) . " does not exist, do not chmod"); } else { $this->processProvider->executeSudoCommand('chmod -R 777 ' . $this->fileSystemProvider->getProjectDirectory($project["name"])); } if (!file_exists($this->fileSystemProvider->getProjectDirectory($project["name"]) . '/.ssh/')) { $this->dialogProvider->logNotice($this->fileSystemProvider->getProjectDirectory($project["name"]) . '/.ssh/' . " does not exist, do not chmod"); } else { $this->processProvider->executeSudoCommand('chmod -R 700 ' . $this->fileSystemProvider->getProjectDirectory($project["name"]) . '/.ssh/'); } } else { $permissions_sorted = new \ArrayObject($project["permissions"]); $permissions_sorted->ksort(); /** @var PermissionDefinition $pd */ foreach ($permissions_sorted as $pd) { $path = $this->fileSystemProvider->getProjectDirectory($project["name"]) . $pd->getPath(); foreach ($pd->getAcl() as $acl) { if (file_exists($path)) { $this->processProvider->executeSudoCommand('setfacl ' . $this->projectConfigProvider->searchReplacer($acl, $project) . ' ' . $path, true); } else { $this->dialogProvider->logNotice($path . " does not exist, do not chmod"); } } } } $this->processProvider->executeSudoCommand('find ' . $this->fileSystemProvider->getProjectDirectory($project["name"]) . '/ -type d -exec chmod o+rx {} \\;'); }
<?php // SPL stands for Standard PHP Library $fruits = ["dollar" => 10, "sterlin" => 5, "euro" => 25]; $obj = new ArrayObject($fruits); foreach ($obj as $key => $value) { echo "{$key} ... {$value}" . PHP_EOL; } $obj->asort(); foreach ($obj as $key => $value) { echo "{$key} ... {$value}" . PHP_EOL; } $obj->ksort(); foreach ($obj as $key => $value) { echo "{$key} ... {$value}" . PHP_EOL; } /* Flag Effect ArrayObject::STD_PROP_LIST Properties of the object have their normal functionality when accessed as list (var_dump, foreach, etc.). ArrayObject::ARRAY_AS_PROPS Entries can be accessed as properties (read and write). */ var_dump($obj->dollar); $obj->setFlags(ArrayObject::ARRAY_AS_PROPS); var_dump($obj->dollar); foreach ($obj as $key => $value) { echo "{$key} => {$value}" . PHP_EOL; }
/** * Provide PHP5.1 compat for object ksort() * * @return object */ public function ksort() { if (method_exists('ArrayObject', 'ksort')) { parent::ksort(); } else { $tmp = $this->getArrayCopy(); ksort($tmp); $this->exchangeArray($tmp); } return $this; }
/** * ksort * * @return BEAR_Ro * @ignore */ public function ksort() { parent::ksort(); return $this; }
public function ksort() { $this->lazyLoadArray(); parent::ksort(); }
/** * Return the list of available modules. */ static function available() { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); foreach (array_merge(array("core/module.info"), glob(MODPATH . "*/module.info")) as $file) { $module_name = basename(dirname($file)); $modules->{$module_name} = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); $modules->{$module_name}->installed = empty(self::$modules[$module_name]) ? null : self::$modules[$module_name]->version; $modules->{$module_name}->locked = false; } // Lock certain modules $modules->core->locked = true; $modules->user->locked = true; $modules->ksort(); return $modules; }
/** * Implementation of ArrayObject::ksort(). * * Sorts the entries by key, maintaining key to entry correlations. This is * useful mainly for associative arrays. * * No value is returned. */ public function ksort() { $this->arrayObject->ksort(); }