Skip to content

Commit

Permalink
Merge pull request #2 from iota-community/develop
Browse files Browse the repository at this point in the history
Update 0.1.0
  • Loading branch information
StefanSeehaus authored Jun 28, 2021
2 parents 57585a2 + b55b90e commit f7c0b24
Show file tree
Hide file tree
Showing 217 changed files with 6,479 additions and 4,625 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
on: push
name: PHPUnit
jobs:
phpunit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v1
- name: PHPUnit for PHP 8
uses: chindit/actions-phpunit@1.0.0
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
![IOTA.php](./help/images/IOTA_PHP_Banner_Interact.png)

<p style="text-align:center;">
<a href="https://discord.iota.org/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Discord-9cf.svg?style=social&logo=discord" alt="Discord"></a>
<a href="https://twitter.com/IOTAphp/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Twitter-9cf.svg?style=social&logo=twitter" alt="Twitter"></a>
<br>
<a href="https://github.com/iota-community/iota.php/LICENSE" style="text-decoration:none;"><img src="https://img.shields.io/badge/license-Apache--2.0-green?style=flat-square" alt="Apache-2.0 license"></a>
<a href="https://www.iota.org/" style="text-decoration:none;"><img src="https://img.shields.io/badge/IOTA-lightgrey?style=flat&logo=iota" alt="IOTA"></a>
<a href="https://www.php.net/" style="text-decoration:none;"><img src="https://img.shields.io/badge/PHP->= 8.x-blue?style=flat-square" alt=">PHP 8"></a>
<img src="https://github.com/iota-community/iota.php/actions/workflows/phpunit.yml/badge.svg" alt="WorkflowUnitTest">
</p>

# Changelog

## 0.1.0 - 2021-06-28

### Added

- Builder
- iota.phar
- phpunit tests
- autoloader.php
- composer.json

### Changed

- New [Iota.php](https://github.com/iota-community/iota.php) lib structure
- New [example](./examples) structure
- [Iota.php Help](./help/000_index.md)

### Removed

- Old lib structure
- Old example structure
- client/Api
File renamed without changes.
55 changes: 37 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
![IOTA.php](./help/images/header.jpg)
![IOTA.php](./help/images/IOTA_PHP_Banner_Interact.png)


<p align="center">
<p style="text-align:center;">
<a href="https://discord.iota.org/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Discord-9cf.svg?style=social&logo=discord" alt="Discord"></a>
<a href="https://twitter.com/IOTAphp/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Twitter-9cf.svg?style=social&logo=twitter" alt="Twitter"></a>
<br>

<img src="https://img.shields.io/badge/license-Apache--2.0-green?style=flat-square" alt="Apache-2.0 license">
<img src="https://img.shields.io/badge/IOTA-lightgrey?style=flat&logo=iota" alt="IOTA">
<img src="https://img.shields.io/badge/PHP->= 8.x-blue?style=flat-square" alt=">PHP 8">
<a href="https://github.com/iota-community/iota.php/LICENSE" style="text-decoration:none;"><img src="https://img.shields.io/badge/license-Apache--2.0-green?style=flat-square" alt="Apache-2.0 license"></a>
<a href="https://www.iota.org/" style="text-decoration:none;"><img src="https://img.shields.io/badge/IOTA-lightgrey?style=flat&logo=iota" alt="IOTA"></a>
<a href="https://www.php.net/" style="text-decoration:none;"><img src="https://img.shields.io/badge/PHP->= 8.x-blue?style=flat-square" alt=">PHP 8"></a>
<img src="https://github.com/iota-community/iota.php/actions/workflows/phpunit.yml/badge.svg" alt="WorkflowUnitTest">
</p>

# About
Expand All @@ -19,26 +18,29 @@ PHP library to use IOTA REST API to help node management and tangle queries.
This library allows you to do the following:

- [x] Create messages with indexation and transaction payloads
- [x] Get messages and outputs
- [x] Generate addresses
- [x] Interact with an IOTA node
- [x] Create messages with indexation and transaction payloads
- [x] Get messages and outputs
- [x] Generate addresses
- [x] Interact with the IOTA Faucet Api
- [x] Get funds on testnet

# Requirements

+ PHP 8+
+ PHP Extensions:
+ [ext-curl](http://php.net/manual/en/book.curl.php)
+ [ext-mbstring](http://php.net/manual/en/book.mbstring.php)
+ [ext-sodium](http://php.net/manual/en/book.sodium.php) (api client don't need this)

# Example

```php
<?php
// include iota lib
require_once("../iota.php");
require_once("autoload.php");
// create client
$client = new iota('https://api.lb-0.testnet.chrysalis2.com');
$client = new IOTA\Client\SingleNodeClient();
// print result of node information
echo $client->info();
```
Expand All @@ -49,20 +51,29 @@ This library allows you to do the following:

Additional Examples: Please find other examples in the [./examples](examples) folder.

<hr>
---

### What's next,done
Check [ToDo](TODO.md)

---

### Joining the discussion

<a href="https://discord.iota.org/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Discord-9cf.svg?style=social&logo=discord" alt="Discord"></a>
<a href="https://twitter.com/IOTAphp/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Twitter-9cf.svg?style=social&logo=twitter" alt="Twitter"></a>

If you want to get involved in the community, need help with getting set up, have any issues or just want to discuss IOTA, feel free to join
our [Discord](https://discord.iota.org/).
If you want to get involved in the community, need help with getting set up, have any issues or just want to discuss IOTA, feel free to join our
IOTA [Discord](https://discord.iota.org/) and post in the #php channel.

![IOTA.php](./help/images/discord_help_phpchannel.png)


___

> Follow me on Twitter [@IOTAphp](https://twitter.com/IOTAphp)
<hr>
---

### Donation

Expand All @@ -71,8 +82,16 @@ It took me a lot of time to develop **iota.php** and need to pay for the server
[<img src="https://img.shields.io/badge/iota1qppu7wdws394euyvflvevsnpdawvsl820c3c3jy92wky6wfj656wqqxtf9m-lightgrey?style=social&logo=iota" alt="IOTA">](./help/100_Donation.md)


<hr>
---

### Special thanks to

- Andi [@modell_84](https://twitter.com/modell_84) [Graphic designer]
- Antonio [@antonionardella](https://twitter.com/antonionardella) [Support]
- Vrom [@Vrom14286662](https://twitter.com/Vrom14286662) [Support]

---

# License

The Apache 2.0 license can be found [here](LICENCE.md).
The Apache 2.0 license can be found [here](LICENSE).
65 changes: 65 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
![IOTA.php](./help/images/IOTA_PHP_Banner_Interact.png)

<p style="text-align:center;">
<a href="https://discord.iota.org/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Discord-9cf.svg?style=social&logo=discord" alt="Discord"></a>
<a href="https://twitter.com/IOTAphp/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Twitter-9cf.svg?style=social&logo=twitter" alt="Twitter"></a>
<br>
<a href="https://github.com/iota-community/iota.php/LICENSE" style="text-decoration:none;"><img src="https://img.shields.io/badge/license-Apache--2.0-green?style=flat-square" alt="Apache-2.0 license"></a>
<a href="https://www.iota.org/" style="text-decoration:none;"><img src="https://img.shields.io/badge/IOTA-lightgrey?style=flat&logo=iota" alt="IOTA"></a>
<a href="https://www.php.net/" style="text-decoration:none;"><img src="https://img.shields.io/badge/PHP->= 8.x-blue?style=flat-square" alt=">PHP 8"></a>
<img src="https://github.com/iota-community/iota.php/actions/workflows/phpunit.yml/badge.svg" alt="WorkflowUnitTest">
</p>

### In Progress

- [ ] Wallet lib
- [ ] expand PHPUnit tests
- [ ] expand new Actions
- [ ] expand Builder class

---

### Todo

- [ ] Wallet lib
- [ ] Address Searcher
- [ ] Safe Saving Seeds, according to Iota Stronghold Standard


- [ ] expand new Actions
- [ ] expand Builder class
- [ ] expand PHPUnit tests


- [ ] Amount class
- [ ] QR Code class


- [ ] IOTA Native Digital Assets
- [ ] Interact with IOTA Streams
- [ ] Interact with IOTA Identity

---

### Done ✓

- [x] Builder class
- [x] Create ToDo
- [x] Create phar
- [x] Change lib structure
- [x] PHPUnit tests
- [x] New Design (logo, header,...)


- [x] Interact with the IOTA Faucet Api
- [x] Get funds on testnet


- [x] Create help


- [x] Interact with an IOTA node
- [x] Create messages transaction payloads
- [x] Create messages with indexation
- [x] Get messages and outputs
- [x] Generate addresses
160 changes: 160 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php
$autoload = null;
$autoloadFiles = [
__DIR__ . '/../vendor/autoload.php',
];
foreach($autoloadFiles as $autoloadFile) {
if(file_exists($autoloadFile)) {
$autoload = $autoloadFile;
break;
}
}
if(!$autoload) {
if(0 > version_compare(PHP_VERSION, '8.0.0')) {
die('PHP >= 8.0.0 needed (' . PHP_VERSION . " is installed)");
}
if(!extension_loaded('curl')) {
die("'curl' extension not loaded!");
}
$autoload = new autoload();
$autoload->addNamespace('IOTA\\', __DIR__ . '/src');
$autoload->register();
}
else {
echo $autoload . PHP_EOL;
require $autoload;
}
/**
* Class autoload
*/
class autoload {
/**
* An associative array where the key is a namespace prefix and the value
* is an array of base directories for classes in that namespace.
*
* @var array
*/
protected array $prefixes = [];

/**
* Register loader with SPL autoloader stack.
*
* @return void
*/
public function register() {
spl_autoload_register([
$this,
'loadClass',
]);
}

/**
* Adds a base directory for a namespace prefix.
*
* @param string $prefix The namespace prefix.
* @param string $base_dir A base directory for class files in the
* namespace.
* @param bool $prepend If true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last.
*
* @return void
*/
public function addNamespace(string $prefix, string $base_dir, bool $prepend = false) {
// normalize namespace prefix
$prefix = trim($prefix, '\\') . '\\';
// normalize the base directory with a trailing separator
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/';
// initialize the namespace prefix array
if(isset($this->prefixes[$prefix]) === false) {
$this->prefixes[$prefix] = [];
}
// retain the base directory for the namespace prefix
if($prepend) {
array_unshift($this->prefixes[$prefix], $base_dir);
}
else {
array_push($this->prefixes[$prefix], $base_dir);
}
}

/**
* Loads the class file for a given class name.
*
* @param string $class The fully-qualified class name.
*
* @return string|bool The mapped file name on success, or boolean false on
* failure.
*/
public function loadClass(string $class): string|bool {
// the current namespace prefix
$prefix = $class;
// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while(false !== $pos = strrpos($prefix, '\\')) {

// retain the trailing namespace separator in the prefix
$prefix = substr($class, 0, $pos + 1);
// the rest is the relative class name
$relative_class = substr($class, $pos + 1);
// try to load a mapped file for the prefix and relative class
$mapped_file = $this->loadMappedFile($prefix, $relative_class);
if($mapped_file) {
return $mapped_file;
}
// remove the trailing namespace separator for the next iteration
// of strrpos()
$prefix = rtrim($prefix, '\\');
}
// never found a mapped file
return false;
}

/**
* Load the mapped file for a namespace prefix and relative class.
*
* @param string $prefix The namespace prefix.
* @param string $relative_class The relative class name.
*
* @return false|string Boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded.
*/
protected function loadMappedFile(string $prefix, string $relative_class): bool|string {
// are there any base directories for this namespace prefix?
if(isset($this->prefixes[$prefix]) === false) {
return false;
}
// look through base directories for this namespace prefix
foreach($this->prefixes[$prefix] as $base_dir) {

// replace the namespace prefix with the base directory,
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
// if the mapped file exists, require it
if($this->requireFile($file)) {
// yes, we're done
return $file;
}
}
// never found it
return false;
}

/**
* If a file exists, require it from the file system.
*
* @param string $file The file to require.
*
* @return bool True if the file exists, false if not.
*/
protected function requireFile(string $file): bool {
if(file_exists($file)) {
require $file;

return true;
}

return false;
}
}
Loading

0 comments on commit f7c0b24

Please sign in to comment.