Exemple #1
0
 public function toArray(HydratableInterface &$obj, $map_id = null, $hints_only = false)
 {
     $this->assertHydratable($obj);
     $hints = $obj->__toArray($map_id) ?: [];
     if (!$hints_only) {
         $properties = [];
         foreach (get_class_methods($obj) as $method) {
             if ($propertyName = $this->findPropertyName($method, ['get', 'is'])) {
                 $properties[$propertyName] = $propertyName;
             }
         }
         $hints = array_merge($properties, $hints);
     }
     $array = [];
     foreach ($hints as $p_name => $p_hint) {
         try {
             $value = $this->getProperty($obj, $p_hint);
             if (is_object($value)) {
                 if (!$value instanceof HydratableInterface) {
                     $valueClass = get_class($value);
                     throw new HydratorException("Hydrated class {$valueClass} must implement Corelib\\Data\\Hydratable interface.");
                 }
                 $value = $value->toArray();
             }
             $array[$p_hint] = $value;
         } catch (HydratorException $hex) {
             Console::warn($hex->getMessage());
             continue;
         }
     }
     return $array;
 }
Exemple #2
0
 /**
  * Method uses XPUB to generate next deterministic address.
  *
  * @param string $xpub  Master public key (XPUB)
  * @param int    $index Index of the deterministic address
  *
  * @return string Generated address for specified index
  */
 public static function generateAddress($xpub, $index = 0)
 {
     if (!class_exists('BitWasp\\BitcoinLib\\BIP32')) {
         // if class BIP32 is not available, trigger an error
         trigger_error("Library BitWasp/bitcoin-lib-php is required to generate deterministic address", E_USER_ERROR);
     }
     Console::debug("Generating address for XPUB '%s' index %d", $xpub, $index);
     $address = BIP32::build_address($xpub, sprintf('0/%d', $index))[0];
     Console::debug("Generated address (index %d): '%s'", $index, $address);
     return $address;
 }
Exemple #3
0
 protected function logQueryParameters($params = null, $verbosity = Console::WARNING)
 {
     if (Console::isLevelEnabled($verbosity)) {
         if (is_array($params) && count($params)) {
             $logParams = [];
             foreach ($params as $key => $value) {
                 $logParams[] = sprintf('"%s" => "%s"', $key, $value);
             }
             Console::log(sprintf("+ parameters = [%s]", implode(';', $logParams)), $verbosity);
         }
     }
 }
Exemple #4
0
 public function dump($level = Console::INFO)
 {
     if (Console::isLevelEnabled($level)) {
         Console::log("Command-line arguments:", $level);
         foreach ($this->_args as $name => $arg) {
             $value = $arg->getValue();
             Console::log(sprintf("  %s = %s", $name, is_array($value) ? "'" . implode("', '", $value) . "'" : "'{$value}'"), $level);
         }
     }
 }