Example #1
0
 /**
  * Scans and parses PHP files.
  *
  * @return array
  * @throws \RuntimeException If no PHP files have been found.
  */
 public function parse()
 {
     $files = array();
     $flags = \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO | \RecursiveDirectoryIterator::SKIP_DOTS;
     if (defined('\\RecursiveDirectoryIterator::FOLLOW_SYMLINKS')) {
         // Available from PHP 5.3.1
         $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
     }
     foreach ($this->config->source as $source) {
         $entries = array();
         if (is_dir($source)) {
             foreach (new \RecursiveIteratorIterator(new SourceFilesFilterIterator(new \RecursiveDirectoryIterator($source, $flags), $this->config->exclude)) as $entry) {
                 if (!$entry->isFile()) {
                     continue;
                 }
                 $entries[] = $entry;
             }
         } elseif ($this->isPhar($source)) {
             if (!extension_loaded('phar')) {
                 throw new RuntimeException('Phar extension is not loaded');
             }
             foreach (new \RecursiveIteratorIterator(new \Phar($source, $flags)) as $entry) {
                 if (!$entry->isFile()) {
                     continue;
                 }
                 $entries[] = $entry;
             }
         } else {
             $entries[] = new \SplFileInfo($source);
         }
         $regexp = '~\\.' . implode('|', $this->config->extensions->toArray()) . '$~i';
         foreach ($entries as $entry) {
             if (!preg_match($regexp, $entry->getFilename())) {
                 continue;
             }
             $pathName = $this->normalizePath($entry->getPathName());
             $files[$pathName] = $entry->getSize();
             if (false !== $entry->getRealPath() && $pathName !== $entry->getRealPath()) {
                 $this->symlinks[$entry->getRealPath()] = $pathName;
             }
         }
     }
     if (empty($files)) {
         throw new RuntimeException('No PHP files found');
     }
     $this->fireEvent('parseStart', array_sum($files));
     $broker = new Broker(new Backend($this, !empty($this->config->report)), Broker::OPTION_DEFAULT & ~(Broker::OPTION_PARSE_FUNCTION_BODY | Broker::OPTION_SAVE_TOKEN_STREAM));
     $errors = array();
     foreach ($files as $filePath => $size) {
         $content = $this->charsetConvertor->convertFile($filePath);
         try {
             $broker->processString($content, $filePath);
         } catch (\Exception $e) {
             $errors[] = $e;
         }
         $this->fireEvent('parseProgress', $size);
     }
     // Classes
     $this->parsedClasses->exchangeArray($broker->getClasses(Backend::TOKENIZED_CLASSES | Backend::INTERNAL_CLASSES | Backend::NONEXISTENT_CLASSES));
     $this->parsedClasses->uksort('strcasecmp');
     // Constants
     $this->parsedConstants->exchangeArray($broker->getConstants());
     $this->parsedConstants->uksort('strcasecmp');
     // Functions
     $this->parsedFunctions->exchangeArray($broker->getFunctions());
     $this->parsedFunctions->uksort('strcasecmp');
     $documentedCounter = function ($count, $element) {
         return $count += (int) $element->isDocumented();
     };
     return (object) array('classes' => count($broker->getClasses(Backend::TOKENIZED_CLASSES)), 'constants' => count($this->parsedConstants), 'functions' => count($this->parsedFunctions), 'internalClasses' => count($broker->getClasses(Backend::INTERNAL_CLASSES)), 'documentedClasses' => array_reduce($broker->getClasses(Backend::TOKENIZED_CLASSES), $documentedCounter), 'documentedConstants' => array_reduce($this->parsedConstants->getArrayCopy(), $documentedCounter), 'documentedFunctions' => array_reduce($this->parsedFunctions->getArrayCopy(), $documentedCounter), 'documentedInternalClasses' => array_reduce($broker->getClasses(Backend::INTERNAL_CLASSES), $documentedCounter), 'errors' => $errors);
 }
<?php

/* Prototype  : int ArrayObject::uksort(callback cmp_function)
 * Description: proto int ArrayIterator::uksort(callback cmp_function)
 Sort the entries by key using user defined function.
 * Source code: ext/spl/spl_array.c
 * Alias to functions: 
 */
$ao = new ArrayObject();
try {
    $ao->uksort();
} catch (BadMethodCallException $e) {
    echo $e->getMessage() . "\n";
}
try {
    $ao->uksort(1, 2);
} catch (BadMethodCallException $e) {
    echo $e->getMessage() . "\n";
}
?>
===DONE===
Example #3
0
<?php

function cmp($a, $b)
{
    $a = preg_replace('@^(a|an|the) @', '', $a);
    $b = preg_replace('@^(a|an|the) @', '', $b);
    return strcasecmp($a, $b);
}
$array = array("John" => 1, "the Earth" => 2, "an apple" => 3, "a banana" => 4);
$arrayObject = new ArrayObject($array);
$arrayObject->uksort('cmp');
foreach ($arrayObject as $key => $value) {
    echo "{$key}: {$value}\n";
}
<?php

/* Prototype  : int ArrayObject::uksort(callback cmp_function)
 * Description: proto int ArrayIterator::uksort(callback cmp_function)
 * Sort the entries by key using user defined function. 
 * Source code: ext/spl/spl_array.c
 * Alias to functions: 
 */
echo "*** Testing ArrayObject::uksort() : basic functionality ***\n";
// Reverse sorter
function cmp($value1, $value2)
{
    if ($value1 == $value2) {
        return 0;
    } else {
        if ($value1 < $value2) {
            return 1;
        } else {
            return -1;
        }
    }
}
$ao = new ArrayObject(array(3 => 0, 2 => 1, 5 => 2, 6 => 3, 1 => 4));
$ao->uksort('cmp');
var_dump($ao);
?>
===DONE===
 public function uksort($cmp_function)
 {
     $this->lazyLoadArray();
     parent::uksort($cmp_function);
 }
 /**
  * Implementation of ArrayObject::uksort().
  *
  * This function sorts the keys of the entries using a user-supplied
  * comparison function. The key to entry correlations will be maintained.
  *
  * No value is returned.
  *
  * @param callable $cmpFunction The callback comparison function.
  */
 public function uksort($cmpFunction)
 {
     $this->arrayObject->uksort($cmpFunction);
 }