Esempio n. 1
0
 public function downloadAction()
 {
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     $destination = $request->getParam('destination', '');
     $languages = explode(',', $request->getParam('language', 'pt_BR'));
     $formats = explode(',', $request->getParam('format', 'php'));
     if (!file_exists($destination)) {
         throw new \InvalidArgumentException('Destination directory does not exists.');
     }
     if (!is_writable($destination)) {
         throw new \InvalidArgumentException('Destination directory is not writeable.');
     }
     $baseUrl = 'https://raw.githubusercontent.com/Lansoweb/losi18n-data/master/data/';
     echo "Downloading files ...\n";
     $adapter = new Console();
     $progressBar = new ProgressBar($adapter, 0, count($languages) * count($formats));
     $counter = 0;
     foreach ($languages as $language) {
         if (!file_exists("{$destination}/{$language}")) {
             mkdir("{$destination}/{$language}");
         }
         foreach ($formats as $format) {
             $this->downloadFile("{$baseUrl}/{$language}/languages.{$format}", "{$destination}/{$language}/languages.{$format}");
             $progressBar->update($counter++, 0);
             $this->downloadFile("{$baseUrl}/{$language}/countries.{$format}", "{$destination}/{$language}/countries.{$format}");
             $progressBar->update($counter++, 0);
         }
     }
     $progressBar->finish();
 }
Esempio n. 2
0
 /**
  * @param ProgressAdapter|null $progressAdapter
  */
 public function updateAddressFormats(ProgressAdapter $progressAdapter = null)
 {
     $localeDataUri = $this->options->getLocaleDataUri();
     $dataPath = $this->options->getDataPath();
     $locales = json_decode($this->httpClient->setUri($localeDataUri)->send()->getContent());
     foreach (scandir($dataPath) as $file) {
         if (fnmatch('*.json', $file)) {
             unlink($dataPath . '/' . $file);
         }
     }
     $countryCodes = isset($locales->countries) ? explode('~', $locales->countries) : [];
     $countryCodes[] = 'ZZ';
     if ($progressAdapter !== null) {
         $progressBar = new ProgressBar($progressAdapter, 0, count($countryCodes));
     }
     foreach ($countryCodes as $countryCode) {
         file_put_contents($dataPath . '/' . $countryCode . '.json', $this->httpClient->setUri($localeDataUri . '/' . $countryCode)->send()->getContent());
         if (isset($progressBar)) {
             $progressBar->next();
         }
     }
     if (isset($progressBar)) {
         $progressBar->finish();
     }
     // We clearly don't want the "ZZ" in the array!
     array_pop($countryCodes);
     $writer = new PhpArrayWriter();
     $writer->setUseBracketArraySyntax(true);
     $writer->toFile($this->options->getCountryCodesPath(), $countryCodes, false);
 }
Esempio n. 3
0
 /**
  * Will create all images.
  *
  * <code>
  *  $ php path/to/index.php image-generate --ignore
  * </code>
  * @throws \RuntimeException
  */
 public function imageGenerateAction()
 {
     if (!$this->getRequest() instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console!');
     }
     $rawFilePath = implode(DIRECTORY_SEPARATOR, [self::PATH_IMAGES, FileProperties::DIR_RAW]);
     //COUNT
     //  count how many file there are.
     $counter = 0;
     foreach (new DirectoryIterator($rawFilePath) as $fileInfo) {
         if ($this->isImage($fileInfo)) {
             continue;
         }
         $counter++;
     }
     $adapter = new Console();
     $progressBar = new ProgressBar($adapter, 0, $counter);
     $imageDirectory = new DirectoryIterator(self::PATH_IMAGES);
     //FOR EVERY
     //  for every file in directory...
     foreach (new DirectoryIterator($rawFilePath) as $fileInfo) {
         if ($this->isImage($fileInfo)) {
             continue;
         }
         if ($this->getRequest()->getParam('ignore', false)) {
             $smallFilePath = implode(DIRECTORY_SEPARATOR, [self::PATH_IMAGES, FileProperties::DIR_SMALL, $fileInfo->getFilename()]);
             if (is_file($smallFilePath)) {
                 $progressBar->next();
                 continue;
             }
         }
         try {
             (new ImageGenerator($fileInfo, $imageDirectory))->execute();
         } catch (\Exception $e) {
             echo $e->getMessage() . PHP_EOL;
         }
         $progressBar->next();
     }
     $progressBar->finish();
 }
Esempio n. 4
0
 public function expireJobsAction()
 {
     $services = $this->getServiceLocator();
     $repositories = $services->get('repositories');
     /* @var \Jobs\Repository\Job $jobsRepo */
     $jobsRepo = $repositories->get('Jobs/Job');
     $filter = \Zend\Json\Json::decode($this->params('filter', '{}'));
     $query = array();
     $limit = 10;
     foreach ($filter as $key => $value) {
         switch ($key) {
             case "limit":
                 $limit = $value;
                 break;
             case "days":
                 $date = new \DateTime();
                 $date->modify('-' . (int) $value . ' day');
                 $q = array('$lt' => $date);
                 if (isset($query['datePublishStart.date'])) {
                     $query['datePublishStart.date'] = array_merge($query['datePublishStart.date'], $q);
                 } else {
                     $query['datePublishStart.date'] = $q;
                 }
                 break;
             default:
                 $query[$key] = $value;
                 break;
         }
     }
     $query['status.name'] = 'active';
     $jobs = $jobsRepo->findBy($query, null, $limit);
     $count = count($jobs);
     if (0 === $count) {
         return 'No jobs found.';
     }
     foreach ($repositories->getEventManager()->getListeners('preUpdate') as $listener) {
         $repositories->getEventManager()->removeEventListener('preUpdate', $listener);
     }
     echo "{$count} jobs found, which have to expire ...\n";
     $progress = new ProgressBar(new ConsoleAdapter(array('elements' => array(ConsoleAdapter::ELEMENT_TEXT, ConsoleAdapter::ELEMENT_BAR, ConsoleAdapter::ELEMENT_PERCENT, ConsoleAdapter::ELEMENT_ETA), 'textWidth' => 20, 'barLeftChar' => '-', 'barRightChar' => ' ', 'barIndicatorChar' => '>')), 0, count($jobs));
     $i = 0;
     /* @var \Jobs\Entity\Job $job */
     foreach ($jobs as $job) {
         $progress->update($i++, 'Job ' . $i . ' / ' . $count);
         $job->changeStatus('expired');
         if (0 == $i % 500) {
             $progress->update($i, 'Write to database...');
             $repositories->flush();
         }
     }
     $progress->update($i, 'Write to database...');
     $repositories->flush();
     $progress->update($i, 'Done');
     $progress->finish();
     return PHP_EOL;
 }
Esempio n. 5
0
 public function expireJobsAction()
 {
     $services = $this->serviceLocator;
     $repositories = $services->get('repositories');
     /* @var \Jobs\Repository\Job $jobsRepo */
     $jobsRepo = $repositories->get('Jobs/Job');
     $days = (int) $this->params('days');
     $limit = (string) $this->params('limit');
     $info = $this->params('info');
     if (!$days) {
         return 'Invalid value for --days. Must be integer.';
     }
     $date = new \DateTime('today');
     $date->sub(new \DateInterval('P' . $days . 'D'));
     $query = ['status.name' => StatusInterface::ACTIVE, 'datePublishStart.date' => ['$lt' => $date]];
     $offset = 0;
     if ($limit && false !== strpos($limit, ',')) {
         list($limit, $offset) = explode(',', $limit);
     }
     $jobs = $jobsRepo->findBy($query, null, (int) $limit, (int) $offset);
     $count = count($jobs);
     if (0 === $count) {
         return 'No jobs found.';
     }
     if ($info) {
         echo count($jobs), ' Jobs';
         if ($offset) {
             echo ' starting from ' . $offset;
         }
         echo PHP_EOL . PHP_EOL;
         $this->listExpiredJobs($jobs);
         return;
     }
     foreach ($repositories->getEventManager()->getListeners('preUpdate') as $listener) {
         $repositories->getEventManager()->removeEventListener('preUpdate', $listener);
     }
     echo "{$count} jobs found, which have to expire ...\n";
     $progress = new ProgressBar(new ConsoleAdapter(array('elements' => array(ConsoleAdapter::ELEMENT_TEXT, ConsoleAdapter::ELEMENT_BAR, ConsoleAdapter::ELEMENT_PERCENT, ConsoleAdapter::ELEMENT_ETA), 'textWidth' => 20, 'barLeftChar' => '-', 'barRightChar' => ' ', 'barIndicatorChar' => '>')), 0, count($jobs));
     $i = 0;
     /* @var \Jobs\Entity\Job $job */
     foreach ($jobs as $job) {
         $progress->update($i++, 'Job ' . $i . ' / ' . $count);
         $job->changeStatus('expired');
         if (0 == $i % 500) {
             $progress->update($i, 'Write to database...');
             $repositories->flush();
         }
     }
     $progress->update($i, 'Write to database...');
     $repositories->flush();
     $progress->update($i, 'Done');
     $progress->finish();
     return PHP_EOL;
 }
Esempio n. 6
0
 */
use Zend\Loader\StandardAutoloader;
use Zend\ProgressBar\Adapter\JsPull;
use Zend\ProgressBar\ProgressBar;
/**
 * This sample file demonstrates a simple use case of a jspull-driven progressbar
 */
if (isset($_GET['uploadId'])) {
    require_once dirname(dirname(dirname(__DIR__))) . '/library/Zend/Loader/StandardAutoloader.php';
    $loader = new StandardAutoloader(array('autoregister_zf' => true));
    $loader->register();
    $data = uploadprogress_get_info($_GET['uploadId']);
    $bytesTotal = $data === null ? 0 : $data['bytes_total'];
    $bytesUploaded = $data === null ? 0 : $data['bytes_uploaded'];
    $adapter = new JsPull();
    $progressBar = new ProgressBar($adapter, 0, $bytesTotal, 'uploadProgress');
    if ($bytesTotal === $bytesUploaded) {
        $progressBar->finish();
    } else {
        $progressBar->update($bytesUploaded);
    }
}
?>
<html>
<head>
    <title>Zend_ProgressBar Upload Demo</title>
    <style type="text/css">
        iframe {
            position: absolute;
            left: -100px;
            top: -100px;
 /**
  * Uninstalls the specified package.
  * $package may either be the packageID or the package identifier.
  * 
  * @param	mixed	$package
  */
 private function uninstall($package)
 {
     if (Package::isValidPackageName($package)) {
         $packageID = PackageCache::getInstance()->getPackageID($package);
     } else {
         $packageID = $package;
     }
     // UninstallPackageAction::prepare()
     $package = new Package($packageID);
     if (!$package->packageID || !$package->canUninstall()) {
         $this->error('invalidUninstallation');
     }
     // get new process no
     $processNo = PackageInstallationQueue::getNewProcessNo();
     // create queue
     $queue = PackageInstallationQueueEditor::create(array('processNo' => $processNo, 'userID' => CLIWCF::getUser()->userID, 'packageName' => $package->getName(), 'packageID' => $package->packageID, 'action' => 'uninstall'));
     // initialize uninstallation
     $installation = new PackageUninstallationDispatcher($queue);
     $installation->nodeBuilder->purgeNodes();
     $installation->nodeBuilder->buildNodes();
     CLIWCF::getTPL()->assign(array('queue' => $queue));
     $queueID = $installation->nodeBuilder->getQueueByNode($queue->processNo, $installation->nodeBuilder->getNextNode());
     $step = 'uninstall';
     $node = $installation->nodeBuilder->getNextNode();
     $currentAction = CLIWCF::getLanguage()->get('wcf.package.installation.step.uninstalling');
     $progress = 0;
     // initialize progressbar
     $progressbar = new ProgressBar(new ConsoleProgressBar(array('width' => CLIWCF::getTerminal()->getWidth(), 'elements' => array(ConsoleProgressBar::ELEMENT_PERCENT, ConsoleProgressBar::ELEMENT_BAR, ConsoleProgressBar::ELEMENT_TEXT), 'textWidth' => min(floor(CLIWCF::getTerminal()->getWidth() / 2), 50))));
     // InstallPackageAction::readParameters()
     $finished = false;
     while (!$finished) {
         $queue = new PackageInstallationQueue($queueID);
         $installation = new PackageUninstallationDispatcher($queue);
         switch ($step) {
             case 'uninstall':
                 $_node = $installation->uninstall($node);
                 if ($_node == '') {
                     // remove node data
                     $installation->nodeBuilder->purgeNodes();
                     // UninstallPackageAction::finalize()
                     CacheHandler::getInstance()->flushAll();
                     // /UninstallPackageAction::finalize()
                     // show success
                     $currentAction = CLIWCF::getLanguage()->get('wcf.acp.package.uninstallation.step.success');
                     $progress = 100;
                     $step = 'success';
                     $finished = true;
                     continue;
                 }
                 // continue with next node
                 $queueID = $installation->nodeBuilder->getQueueByNode($installation->queue->processNo, $installation->nodeBuilder->getNextNode($node));
                 $step = 'uninstall';
                 $progress = $installation->nodeBuilder->calculateProgress($node);
                 $node = $_node;
         }
         $progressbar->update($progress, $currentAction);
     }
     $progressbar->getAdapter()->finish();
 }
Esempio n. 8
0
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 * @package   Zend_ProgressBar
 */
use Zend\Loader\StandardAutoloader;
use Zend\ProgressBar\Adapter\JsPush;
use Zend\ProgressBar\ProgressBar;
/**
 * This sample file demonstrates a simple use case of a jspush-driven progressbar
 */
if (isset($_GET['progress'])) {
    require_once dirname(dirname(dirname(__DIR__))) . '/library/Zend/Loader/StandardAutoloader.php';
    $loader = new StandardAutoloader(array('autoregister_zf' => true));
    $loader->register();
    $adapter = new JsPush(array('updateMethodName' => 'Zend_ProgressBar_Update', 'finishMethodName' => 'Zend_ProgressBar_Finish'));
    $progressBar = new ProgressBar($adapter, 0, 100);
    for ($i = 1; $i <= 100; $i++) {
        if ($i < 20) {
            $text = 'Just beginning';
        } elseif ($i < 50) {
            $text = 'A bit done';
        } elseif ($i < 80) {
            $text = 'Getting closer';
        } else {
            $text = 'Nearly done';
        }
        $progressBar->update($i, $text);
        usleep(100000);
    }
    $progressBar->finish();
    die;
 /**
  *  Handles Event FormatEvents::onRowEnd
  *
  *  @param GenerateEvent $event
  */
 public function onRowEnd(GenerateEvent $event)
 {
     $this->bar->next(1, 'Table ' . $event->getNode()->getId());
 }
Esempio n. 10
0
 public function finish()
 {
     $this->update($this->max, 'Done');
     return parent::finish();
 }
Esempio n. 11
0
 public function build()
 {
     if (empty($this->source)) {
         throw new \RuntimeException('Source directory not defined.');
     }
     if (empty($this->destination)) {
         throw new \RuntimeException('Destination directory not defined.');
     }
     if (!empty($this->language)) {
         $this->buildForLang($this->language);
         return;
     }
     $fileList = glob("{$this->source}/*.xml");
     $adapter = new Console();
     $progressBar = new ProgressBar($adapter, 0, count($fileList) + 1);
     $counter = 0;
     foreach ($fileList as $fileName) {
         $posDot = strrpos($fileName, '.');
         $posSlash = strrpos($fileName, '/');
         $language = substr($fileName, $posSlash + 1, $posDot - $posSlash - 1);
         // Only 'pt' or 'pt_BR' like (not "dead" languages like arc=Aramaic)
         if (strlen($language) == 2 || strlen($language) == 5) {
             $this->buildForLang($language);
         }
         $progressBar->update($counter++, 0);
     }
     if (count($this->natives) > 0) {
         $this->saveNativeLanguages($this->natives);
     }
     $progressBar->finish();
 }
<?php

if ($argc != 2 || in_array($argv[1], ['--help', '-help', '-h', '-?'])) {
    ?>

  Generates orders and stores them in mongoDB.

  Usage: <?php 
    echo $argv[0];
    ?>
 total

    total    number of orders to generate

<?php 
    exit(1);
}
require_once 'bootstrap.php';
use Zend\ProgressBar\ProgressBar;
use Zend\ProgressBar\Adapter\Console;
$orderGenerator = ServiceLocator::getInstance()->get('order_generator');
$orderRepository = ServiceLocator::getInstance()->get('order_repository');
$total = (int) $argv[1];
$progressBar = new ProgressBar(new Console(), 0, $total);
while ($total) {
    $orderRepository->add($orderGenerator->generate());
    $total--;
    $progressBar->next();
}
Esempio n. 13
0
 /**
  * Rebuild search index.
  *
  * <code>
  * $ php index.php search index
  * </code>
  *
  * @throws \RuntimeException
  * @deprecated
  */
 public function searchIndexAction()
 {
     $request = $this->getRequest();
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     $sm = $this->getServiceLocator();
     $index = $sm->get('Search\\Index\\Search');
     //Event
     //  index event entries.
     //
     $counter = 0;
     $eventService = $sm->get('Stjornvisi\\Service\\Event');
     $events = $eventService->fetchAll();
     $adapter = new Console();
     echo "\nIndexing Event entries\n";
     $progressBar = new ProgressBar($adapter, $counter, count($events));
     $i = new \Stjornvisi\Search\Index\Event();
     foreach ($events as $item) {
         $i->index($item, $index);
         $progressBar->update(++$counter);
     }
     $index->commit();
     $progressBar->finish();
     //NEWS
     //  index news entries.
     //
     $counter = 0;
     $newsService = $sm->get('Stjornvisi\\Service\\News');
     $news = $newsService->fetchAll();
     $adapter = new Console();
     echo "\nIndexing News entries\n";
     $progressBar = new ProgressBar($adapter, $counter, count($news));
     $i = new \Stjornvisi\Search\Index\News();
     foreach ($news as $item) {
         $i->index($item, $index);
         $progressBar->update(++$counter);
     }
     $index->commit();
     $progressBar->finish();
     //Articles
     //  index article entries.
     //
     $counter = 0;
     $articleService = $sm->get('Stjornvisi\\Service\\Article');
     $articles = $articleService->fetchAll();
     $adapter = new Console();
     echo "\nIndexing News entries\n";
     $progressBar = new ProgressBar($adapter, $counter, count($articles));
     $i = new \Stjornvisi\Search\Index\Article();
     foreach ($articles as $item) {
         $i->index($item, $index);
         $progressBar->update(++$counter);
     }
     $index->commit();
     $progressBar->finish();
     //Group
     //  index group entries.
     //
     $counter = 0;
     $groupService = $sm->get('Stjornvisi\\Service\\Group');
     $groups = $groupService->fetchAll();
     $adapter = new Console();
     echo "\nIndexing Group entries\n";
     $progressBar = new ProgressBar($adapter, $counter, count($groups));
     $i = new \Stjornvisi\Search\Index\Group();
     foreach ($groups as $item) {
         $i->index($item, $index);
         $progressBar->update(++$counter);
     }
     $index->commit();
     $progressBar->finish();
 }
Esempio n. 14
0
 public function generateKeywordsAction()
 {
     $services = $this->getServiceLocator();
     $repositories = $services->get('repositories');
     $jobsRepo = $repositories->get('Jobs/Job');
     $filter = \Zend\Json\Json::decode($this->params('filter', '{}'));
     $query = array();
     $limit = 0;
     foreach ($filter as $key => $value) {
         switch ($key) {
             case "limit":
                 $limit = $value;
                 break;
             case "before":
                 $date = new \DateTime($value);
                 $q = array('$lt' => $date);
                 if (isset($query['datePublishStart.date'])) {
                     $query['datePublishStart.date'] = array_merge($query['datePublishStart.date'], $q);
                 } else {
                     $query['datePublishStart.date'] = $q;
                 }
                 break;
             case "after":
                 $date = new \DateTime($value);
                 $q = array('$gt' => $date);
                 if (isset($query['datePublishStart.date'])) {
                     $query['datePublishStart.date'] = array_merge($query['datePublishStart.date'], $q);
                 } else {
                     $query['datePublishStart.date'] = $q;
                 }
                 break;
             case "title":
                 $query['title'] = '/' == $value[0] ? new \MongoRegex($value) : $value;
                 break;
             default:
                 $query[$key] = $value;
                 break;
         }
     }
     $jobs = $jobsRepo->findBy($query);
     $jobs->limit($limit);
     $count = $jobs->count(true);
     if (0 === $count) {
         return 'No jobs found.';
     }
     foreach ($repositories->getEventManager()->getListeners('preUpdate') as $listener) {
         $repositories->getEventManager()->removeEventListener('preUpdate', $listener);
     }
     echo "Generate keywords for {$count} jobs...\n";
     $progress = new ProgressBar(new ConsoleAdapter(array('elements' => array(ConsoleAdapter::ELEMENT_TEXT, ConsoleAdapter::ELEMENT_BAR, ConsoleAdapter::ELEMENT_PERCENT, ConsoleAdapter::ELEMENT_ETA), 'textWidth' => 20, 'barLeftChar' => '-', 'barRightChar' => ' ', 'barIndicatorChar' => '>')), 0, count($jobs));
     $filter = $services->get('filtermanager')->get('Core/Repository/PropertyToKeywords');
     $i = 0;
     foreach ($jobs as $job) {
         $progress->update($i++, 'Job ' . $i . ' / ' . $count);
         $keywords = $filter->filter($job);
         $job->setKeywords($keywords);
         if (0 == $i % 500) {
             $progress->update($i, 'Write to database...');
             $repositories->flush();
         }
     }
     $progress->update($i, 'Write to database...');
     $repositories->flush();
     $progress->update($i, 'Done');
     $progress->finish();
     return PHP_EOL;
 }
Esempio n. 15
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     $this->argv->setArguments($parameters);
     $this->argv->parse();
     if ($this->argv->list) {
         CLIWCF::getReader()->println(CLIUtil::generateTable($this->generateList()));
         return;
     }
     $args = $this->argv->getRemainingArgs();
     // validate parameters
     if (count($args) != 1) {
         throw new ArgvException('', $this->getUsage());
     }
     $class = $args[0];
     // assume wcf\system\worker when no FQN is given
     if (strpos($class, '\\') === false) {
         $class = 'wcf\\system\\worker\\' . $class;
     }
     $invalid = false;
     if (!class_exists($class)) {
         $invalid = true;
     } else {
         $reflection = new \ReflectionClass($class);
         if (!$reflection->isInstantiable()) {
             $invalid = true;
         } else {
             if (!ClassUtil::isInstanceOf($class, 'wcf\\system\\worker\\IWorker')) {
                 $invalid = true;
             }
         }
     }
     if ($invalid) {
         throw new ArgvException("Invalid worker '" . $class . "' given", $this->getUsage());
     }
     // parse parameters
     $options = $this->argv->getOptions();
     $parameters = array();
     foreach ($options as $option) {
         $value = $this->argv->getOption($option);
         if ($option === 'setParameter') {
             if (!is_array($value)) {
                 $value = array($value);
             }
             foreach ($value as $parameter) {
                 list($parameterKey, $parameterValue) = explode('=', $parameter);
                 $parameters[$parameterKey] = $parameterValue;
             }
         } else {
             $parameters[$option] = $value;
         }
     }
     $worker = new $class($parameters);
     $worker->validate();
     $worker->getProgress();
     // make sure objects are counted
     // initialize progressbar
     $progressbar = new ProgressBar(new ConsoleProgressBar(array('width' => CLIWCF::getTerminal()->getWidth())));
     $progress = 0;
     for ($i = 0; $progress < 100; $i++) {
         $worker->setLoopCount($i);
         $worker->validate();
         // execute worker
         $worker->execute();
         // update progress
         $progress = $worker->getProgress();
         $progressbar->update($progress);
     }
     $progressbar->update($progress);
     $progressbar->getAdapter()->finish();
 }
Esempio n. 16
0
 /**
  * Returns the actual progress of file up-/downloads
  *
  * @param  string $id The upload to get the progress for
  * @return array|null
  */
 public static function getProgress($id = null)
 {
     if (!function_exists('apc_fetch') and !function_exists('uploadprogress_get_info')) {
         throw new Exception\PhpEnvironmentException('Neither APC nor uploadprogress extension installed');
     }
     $session = 'Zend\\File\\Transfer\\Adapter\\Http\\ProgressBar';
     $status = array('total' => 0, 'current' => 0, 'rate' => 0, 'message' => '', 'done' => false);
     if (is_array($id)) {
         if (isset($id['progress'])) {
             $adapter = $id['progress'];
         }
         if (isset($id['session'])) {
             $session = $id['session'];
         }
         if (isset($id['id'])) {
             $id = $id['id'];
         } else {
             unset($id);
         }
     }
     if (!empty($id) && ($id instanceof Adapter\Adapter || $id instanceof ProgressBar\ProgressBar)) {
         $adapter = $id;
         unset($id);
     }
     if (empty($id)) {
         if (!isset($_GET['progress_key'])) {
             $status['message'] = 'No upload in progress';
             $status['done'] = true;
         } else {
             $id = $_GET['progress_key'];
         }
     }
     if (!empty($id)) {
         if (self::isApcAvailable()) {
             $call = call_user_func(self::$_callbackApc, ini_get('apc.rfc1867_prefix') . $id);
             if (is_array($call)) {
                 $status = $call + $status;
             }
         } else {
             if (self::isUploadProgressAvailable()) {
                 $call = call_user_func(self::$_callbackUploadProgress, $id);
                 if (is_array($call)) {
                     $status = $call + $status;
                     $status['total'] = $status['bytes_total'];
                     $status['current'] = $status['bytes_uploaded'];
                     $status['rate'] = $status['speed_average'];
                     if ($status['total'] == $status['current']) {
                         $status['done'] = true;
                     }
                 }
             }
         }
         if (!is_array($call)) {
             $status['done'] = true;
             $status['message'] = 'Failure while retrieving the upload progress';
         } else {
             if (!empty($status['cancel_upload'])) {
                 $status['done'] = true;
                 $status['message'] = 'The upload has been canceled';
             } else {
                 $status['message'] = self::_toByteString($status['current']) . " - " . self::_toByteString($status['total']);
             }
         }
         $status['id'] = $id;
     }
     if (isset($adapter) && isset($status['id'])) {
         if ($adapter instanceof Adapter\Adapter) {
             $adapter = new ProgressBar\ProgressBar($adapter, 0, $status['total'], $session);
         }
         if (!$adapter instanceof ProgressBar\ProgressBar) {
             throw new Exception\RuntimeException('Unknown Adapter given');
         }
         if ($status['done']) {
             $adapter->finish();
         } else {
             $adapter->update($status['current'], $status['message']);
         }
         $status['progress'] = $adapter;
     }
     return $status;
 }
Esempio n. 17
0
 /**
  *
  * @param int $count
  * @return ProgressBar
  */
 protected function getProgressBar($count)
 {
     $progressBar = new ProgressBar($this->getProgressBarAdapter(), 0, $count);
     $progressBar->update(0);
     return $progressBar;
 }