Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
generator-commons.php
Go to the documentation of this file.
1 <?php
21 require_once __DIR__ . '/../vendor/autoload.php';
22 
32 function makeClassName($input)
33 {
34  $return = '';
35  foreach (explode('_', $input) as $part) {
36  $return .= ucfirst($part);
37  }
38  return $return;
39 }
40 
47 function getSchema()
48 {
49  return json_decode(file_get_contents(__DIR__ . "/../resources/ethjs-schema.json"), true);
50 }
51 
52 
62 function printMe($title, $content = null)
63 {
64  echo "$title \n";
65  if ($content) {
66  if (is_array($content)) {
67  print_r($content) . "\n";
68  } else {
69  echo($content) . "\n";
70  }
71  }
72 }
73 
74 
75 function addUseStatement ($type, &$useStatements) {
76 
77  if (is_array($type)) {
78  foreach ($type as $subtype) {
79  if (!in_array($subtype, $useStatements)) {
80  $useStatements[] = $subtype;
81  }
82  }
83  }
84  else {
85  // Add type to $useStatements so we can generate e.g. 'use Ethereum\EthS;' later.
86  if (!in_array($type, $useStatements)) {
87 
88  // Special case for eth_syncing which returns Object or false.
89  if (strpos($type, '|')) {
90  // @todo This is actually very weired in the Schema: We have an "or" in Return values.
91  // For now we just include both types, but this requires deeper investigation how to handle that.
92  foreach (explode('|', $type) as $t) {
93  if (!in_array($t, $useStatements)) {
94  $useStatements[] = $t;
95  }
96  }
97  }
98  else {
99  $useStatements[] = $type;
100  }
101  }
102  }
103 }
printMe($title, $content=null)
addUseStatement($type, &$useStatements)
getSchema()
makeClassName($input)