コード例 #1
0
 /**
  * Get dictionary by type
  *
  * @param string $type Dictionary type
  * @param string $answerRootKey Root key of answer array
  * @param string $answerItemKey Item key of answer array
  *
  * @return array|bool Return dictionary or false in case of an error
  */
 protected function get($type, $answerRootKey, $answerItemKey)
 {
     ArgValidator::assert($type, ['string', 'notEmpty']);
     if (!$this->callMethod('get_dictionary', ['dictionary_type' => $type])) {
         return false;
     }
     return $this->returnAsArrayList($answerRootKey, $answerItemKey);
 }
コード例 #2
0
 /**
  * Get partners by city
  *
  * @param int $fromCity From city
  * @param int|null $toCity To city
  *
  * @return bool|array Return list of partners or false in case  of an error
  */
 public function getPartners($fromCity, $toCity = null)
 {
     ArgValidator::assert($fromCity, ['int', 'notEmpty']);
     ArgValidator::assert($toCity, ['int', 'null']);
     if (!$this->callMethod('get_all_couriers_partners', ['from_city_code' => $fromCity, 'to_city_code' => $toCity])) {
         return false;
     }
     return $this->returnAsArrayList('partners', 'partner');
 }
コード例 #3
0
 public function isFresh($name, $time)
 {
     ArgValidator::assert($name, 'string');
     ArgValidator::assert($time, 'int');
     $path = $this->resolve($name);
     if (!$path) {
         return false;
     }
     return filemtime($path) < $time;
 }
コード例 #4
0
 public function attach(EventManagerInterface $events, $priority = null)
 {
     ArgValidator::assert($priority, array('int', 'null'));
     if (null === $priority) {
         $this->listeners[] = $events->attach('renderer', array($this, 'selectRenderer'));
         $this->listeners[] = $events->attach('response', array($this, 'injectResponse'));
     } else {
         $this->listeners[] = $events->attach('renderer', array($this, 'selectRenderer'), $priority);
         $this->listeners[] = $events->attach('response', array($this, 'injectResponse'), $priority);
     }
 }
コード例 #5
0
 /**
  * findLanguage
  *
  * @param  string    $code iso 639 1- (?), 2- or 3- letter code
  * @return Language|null
  */
 public function findLanguage($code)
 {
     ArgValidator::assert($code, 'string');
     $dqb = $this->_em->createQueryBuilder();
     $dqb->select('l')->from('Yalesov\\Geoname\\Entity\\Language', 'l')->where($dqb->expr()->orX($dqb->expr()->eq('l.iso3', ':iso3'), $dqb->expr()->eq('l.iso2', ':iso2'), $dqb->expr()->eq('l.iso1', ':iso1')))->setParameters(array('iso3' => $code, 'iso2' => $code, 'iso1' => $code))->setMaxResults(1);
     if ($languages = $dqb->getQuery()->getResult()) {
         return current($languages);
     } else {
         return null;
     }
 }
コード例 #6
0
ファイル: Registry.php プロジェクト: heartsentwined/zf2-cron
 /**
  * register a cron job
  *
  * @see Cron::trySchedule() for allowed cron expression syntax
  *
  * @param  string   $code    the cron job code / identifier
  * @param  string   $frequency cron expression
  * @param  callable $callback  the actual cron job
  * @param  array  $args    args to the cron job
  * @return self
  */
 public static function register($code, $frequency, $callback, array $args = array())
 {
     ArgValidator::assert($code, array('string', 'min' => 1));
     ArgValidator::assert($callback, 'callable');
     /*
      * validation of $frequency (cron expression):
      * will be done together when scheduling
      * (errors thrown if invalid cron expression)
      */
     $instance = self::getInstance();
     $cronRegistry = $instance->getCronRegistry();
     $cronRegistry[$code] = array('frequency' => $frequency, 'callback' => $callback, 'args' => $args);
     $instance->setCronRegistry($cronRegistry);
     return $instance;
 }
コード例 #7
0
 /**
  * findByGeonameCode
  *
  * @param string $code [feature class].[feature code]
  *    e.g. A.ADM1
  * @return Feature|null
  */
 public function findByGeonameCode($code)
 {
     ArgValidator::assert($code, 'string');
     $codeParts = explode('.', $code);
     if (count($codeParts) !== 2) {
         throw new Exception\InvalidArgumentException(sprintf('$code should be in the format ' . '[feature class].[feature code], e.g. "A.ADM1". ' . '"%s" given', $code));
     }
     list($parentCode, $featureCode) = $codeParts;
     $dqb = $this->_em->createQueryBuilder();
     $dqb->select(array('f'))->from('Yalesov\\Geoname\\Entity\\Feature', 'f')->join('f.parent', 'p')->where($dqb->expr()->andX($dqb->expr()->eq('p.code', ':parentCode'), $dqb->expr()->eq('f.code', ':featureCode')))->setParameters(array('parentCode' => $parentCode, 'featureCode' => $featureCode));
     if ($features = $dqb->getQuery()->getResult()) {
         return current($features);
     } else {
         return null;
     }
 }
コード例 #8
0
 /**
  * quick method to POST to a page
  *
  * @param  string $url
  * @param  array  $params
  * @return string response body
  */
 public function post($url = '', array $params = array())
 {
     ArgValidator::assert($url, 'string');
     if (!empty($url)) {
         $this->setUri($url);
     }
     ArgValidator::assert($this->getUri(), 'notEmpty');
     try {
         $oriMethod = $this->getMethod();
         $this->setMethod('POST');
         $this->setParameterPost($params);
         $body = $this->send()->getBody();
         $this->setMethod($oriMethod);
         return $body;
     } catch (\Exception $e) {
         return '';
     }
 }
コード例 #9
0
ファイル: Place.php プロジェクト: heartsentwined/zf2-geoname
 /**
  * findPlace
  *
  * @param array $criteria (all optional)
  *  'countryCode'   => (e.g.) 'DE'
  *  'admin1Code'  => (e.g.) '03'
  *  'admin2Code'  => (e.g.) '00'
  *  'admin3Code'  => (same)
  *  'admin4Code'  => (same)
  *  'featureClass'  => (e.g.) 'A'
  *  'featureCode'   => (e.g.) 'ADM1'
  *  @param int|null $limit = null
  * @return array of Place
  */
 public function findPlace(array $criteria = array(), $limit = null)
 {
     ArgValidator::arrayAssert($criteria, array('countryCode' => array('string', 'notSet'), 'admin1Code' => array('string', 'notSet'), 'admin2Code' => array('string', 'notSet'), 'admin3Code' => array('string', 'notSet'), 'admin4Code' => array('string', 'notSet'), 'featureClass' => array('string', 'notSet'), 'featureCode' => array('string', 'notSet')));
     ArgValidator::assert($limit, array('int', 'null'));
     if (empty($criteria)) {
         return $this->findAll();
     }
     $dqb = $this->_em->createQueryBuilder();
     $dqb->select(array('p'))->from('Yalesov\\Geoname\\Entity\\Place', 'p');
     if (isset($criteria['featureCode']) || isset($criteria['featureClass'])) {
         $dqb->join('p.feature', 'f');
         if (isset($criteria['featureClass'])) {
             $dqb->join('f.parent', 'fp');
         }
     }
     $dqb->where($dqb->expr()->andX(isset($criteria['countryCode']) ? $dqb->expr()->orX($dqb->expr()->eq('p.countryCode', ':countryCode'), empty($criteria['countryCode']) ? $dqb->expr()->isNull('p.countryCode') : null) : null, isset($criteria['admin1Code']) ? $dqb->expr()->orX($dqb->expr()->eq('p.admin1Code', ':admin1Code'), empty($criteria['admin1Code']) ? $dqb->expr()->isNull('p.admin1Code') : null) : null, isset($criteria['admin2Code']) ? $dqb->expr()->orX($dqb->expr()->eq('p.admin2Code', ':admin2Code'), empty($criteria['admin2Code']) ? $dqb->expr()->isNull('p.admin2Code') : null) : null, isset($criteria['admin3Code']) ? $dqb->expr()->orX($dqb->expr()->eq('p.admin3Code', ':admin3Code'), empty($criteria['admin3Code']) ? $dqb->expr()->isNull('p.admin3Code') : null) : null, isset($criteria['admin4Code']) ? $dqb->expr()->orX($dqb->expr()->eq('p.admin4Code', ':admin4Code'), empty($criteria['admin4Code']) ? $dqb->expr()->isNull('p.admin4Code') : null) : null, isset($criteria['featureCode']) ? $dqb->expr()->orX($dqb->expr()->eq('f.code', ':featureCode'), empty($criteria['featureCode']) ? $dqb->expr()->isNull('f.code') : null) : null, isset($criteria['featureClass']) ? $dqb->expr()->orX($dqb->expr()->eq('fp.code', ':featureClass'), empty($criteria['featureClass']) ? $dqb->expr()->isNull('fp.code') : null) : null))->setMaxResults($limit);
     foreach ($criteria as $key => $value) {
         $dqb->setParameter($key, $value);
     }
     return $dqb->getQuery()->getResult();
 }
コード例 #10
0
 public function setup($name)
 {
     ArgValidator::assert($name, 'string');
     $this->prepare();
     $lazyAm = $this->getLazyAssetManager();
     $lazyAm->setLoader('twig', new TwigFormulaLoader($this->getEnvironment()));
     $lazyAm->addResource(new TwigResource($this->getEnvironment()->getLoader(), $name), 'twig');
     $this->getAssetWriter()->writeManagerAssets($lazyAm);
     return $this;
 }
コード例 #11
0
ファイル: Exporter.php プロジェクト: heartsentwined/zf2-vcard
 /**
  * normalize vcard source string after parsing
  *
  * @param  string $vcardStr vcard source string
  * @return string
  */
 public function normalizeSource($vcardStr)
 {
     ArgValidator::assert($vcardStr, 'string');
     /* convert chars outside ASCII range to <U+xxxx> expression */
     if (preg_match_all('/[^\\x{0000}-\\x{007F}]/u', $vcardStr, $matches)) {
         $conversion = array();
         foreach (array_unique($matches[0]) as $char) {
             $conversion[$char] = '<U+' . strtoupper(dechex(Utf8::uord($char))) . '>';
         }
         $vcardStr = strtr($vcardStr, $conversion);
     }
     /* workaround to enable comma-separated values */
     $vcardStr = strtr($vcardStr, array(self::JOINCHAR => ','));
     return $vcardStr;
 }
コード例 #12
0
 public function __construct($name, $options = array())
 {
     ArgValidator::assert($name, 'string');
     parent::__construct($options);
     $this->name = $name;
 }
コード例 #13
0
 protected function setTmpDir($tmpDir)
 {
     ArgValidator::assert($tmpDir, array('string', 'min' => 1));
     $this->tmpDir = $tmpDir;
     return $this;
 }
コード例 #14
0
 /**
  * get a new browser instance
  * useful if you want to clear previous state before browsing
  *
  * @return Browser
  */
 public function newInstance()
 {
     ArgValidator::assert($this->getCookieDir(), array('string', 'min' => 1));
     $browser = new Browser();
     if ($options = $this->getOptions() && count($options)) {
         $browser->setOptions($options);
     }
     if ($headers = $this->getHeaders() && count($headers)) {
         $browser->setHeaders($headers);
     }
     //sets adapter here to force-load it, in order to set CURL opts
     $browser->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $adapter = $browser->getAdapter();
     if ($connectTimeout = $this->getConnectTimeout()) {
         $adapter->setCurlOption(CURLOPT_CONNECTTIMEOUT, $connectTimeout);
     }
     $cookieDir = $this->getCookieDir();
     if (!is_dir($cookieDir)) {
         mkdir($cookieDir, 0755, true);
     }
     //random cookie file
     $cookieFile = $cookieDir . '/' . md5(rand() . microtime(true));
     $fh = fopen($cookieFile, 'x+');
     fclose($fh);
     $adapter->setCurlOption(CURLOPT_COOKIEJAR, $cookieFile);
     $adapter->setCurlOption(CURLOPT_COOKIEFILE, $cookieFile);
     return $browser;
 }
コード例 #15
0
 public function render($nameOrModel, $vars = null)
 {
     ArgValidator::assert($nameOrModel, array('string', '\\Zend\\View\\Model\\ModelInterface'));
     ArgValidator::assert($vars, array('\\Traversable', 'null'));
     if ($nameOrModel instanceof ModelInterface) {
         $model = $nameOrModel;
         $nameOrModel = $model->getTemplate();
         if (empty($nameOrModel)) {
             throw new Exception\DomainException(sprintf('%s: received View Model argument, but template is empty', __METHOD__));
         }
         $options = $model->getOptions();
         foreach ($options as $setting => $value) {
             $method = 'set' . $setting;
             if (method_exists($this, $method)) {
                 $this->{$method}($value);
             }
             unset($method, $setting, $value);
         }
         unset($options);
         // Give view model awareness via ViewModel helper
         $helper = $this->plugin('view_model');
         $helper->setCurrent($model);
         $vars = $model->getVariables();
         if ($vars instanceof \ArrayObject) {
             $vars = $vars->getArrayCopy();
         }
         unset($model);
     }
     if ($vars === null) {
         $vars = array();
     }
     if (empty($nameOrModel)) {
         throw new Exception\InvalidArgumentException('Invalid template name provided.');
     }
     $this->getAssetic()->setup($nameOrModel);
     $output = $this->getEnvironment()->render($nameOrModel, $vars);
     return $this->getFilterChain()->filter($output);
 }
コード例 #16
0
 /**
  * Update pickup place
  *
  * @param string $code Pickup place code
  * @param array $placeData Place data
  * @param string $errorMessage Error message
  *
  * @return bool|string Return place code or false in case of an error
  */
 public function updatePlace($code, array $placeData, &$errorMessage = '')
 {
     ArgValidator::assert($code, ['string', 'int', 'notEmpty']);
     ArgValidator::arrayAssert($placeData, $this->requiredFieldsForAddPlace);
     return $this->_updatePlace(array_merge($placeData, ['code' => $code]), $errorMessage);
 }
コード例 #17
0
 protected function setBootstrap($bootstrap)
 {
     ArgValidator::assert($bootstrap, array('string', 'min' => 1));
     $this->bootstrap = $bootstrap;
     return $this;
 }
コード例 #18
0
 /**
  * Call method and get answer
  *
  * @param string $method Method name
  * @param array $args Method arguments
  *
  * @return Answer
  * @throws AnswerException
  */
 public function callMethod($method, array $args = [])
 {
     ArgValidator::assert($method, ['string', 'notEmpty']);
     $xml = $this->prepareXmlForRequest($method, $args);
     $result = $this->curl->post($this->apiUrl, ['xml' => base64_encode($xml)]);
     return $this->parseAnswer($result);
 }
コード例 #19
0
ファイル: Cli.php プロジェクト: heartsentwined/zf2-cli
 /**
  * output text with template
  *
  * @param  string    $text
  * @param  string    $code the template code
  * @param  bool    $echo = true, if false, will return print string instead
  * @return void|string
  */
 public function write($text, $code, $echo = true)
 {
     ArgValidator::assert($text, 'string');
     ArgValidator::assert($code, 'string');
     $templates = $this->getTemplates();
     if (!isset($templates[$code])) {
         throw new Exception\InvalidArgumentException(sprintf('the template "%s" is not defined', $code));
     }
     $template = $templates[$code];
     if (!$echo) {
         ob_start();
     }
     if (!$this->getConsole()) {
         $this->initConsole();
     }
     $console = $this->getConsole();
     if ($console && isset($template['color']) && defined("Zend\\Console\\ColorInterface::{$template['color']}")) {
         $console->setColor(constant("Zend\\Console\\ColorInterface::{$template['color']}"));
     }
     if (isset($template['template'])) {
         printf("\n{$template['template']}\n", $text);
     } else {
         echo "\n{$text}\n";
     }
     if ($console) {
         $console->resetColor();
     }
     if (!$echo) {
         return ob_get_clean();
     }
 }
コード例 #20
0
 public function __construct($dir)
 {
     ArgValidator::assert($dir, 'string');
     $this->dir = $dir;
     parent::__construct($dir);
 }
コード例 #21
0
ファイル: Importer.php プロジェクト: heartsentwined/zf2-vcard
 /**
  * parse vcard source into intermediate object
  *
  * @param  string  $vcardStr vcard source string
  * @return Node|null
  */
 public function parseSource($vcardStr)
 {
     ArgValidator::assert($vcardStr, 'string');
     try {
         $card = $this->getReader()->read($vcardStr);
     } catch (ParseException $e) {
         return null;
     }
     return $card;
 }
コード例 #22
0
 /**
  * remove .lock and .done markers
  *
  * @param  string $dir target dir, will scan it and its children for files
  * @return self
  */
 public function resetFiles($dir)
 {
     ArgValidator::assert($dir, 'string');
     foreach (FileSystemManager::fileIterator($dir) as $file) {
         if (strpos($file, '.done') || strpos($file, '.lock')) {
             rename($file, substr($file, 0, strlen($file) - 5));
         }
     }
     return $this;
 }
コード例 #23
0
 public function render($name, array $vars = array())
 {
     ArgValidator::assert($name, 'string');
     $this->prepareRender();
     return parent::render($name, $vars);
 }
コード例 #24
0
 /**
  * Get list of delivery statuses data
  *
  * @param array $deliveryCodes List of delivery codes
  *
  * @return bool|array Return list of delivery statuses data or false in case of an error
  */
 public function getStatuses(array $deliveryCodes)
 {
     ArgValidator::assert($deliveryCodes, ['arrayOf', 'string']);
     if (!$this->callMethod('get_order_status_array', ['deliveries' => ['code' => $deliveryCodes]])) {
         return false;
     }
     return $this->returnAsArrayList('deliveries', 'delivery');
 }