Skip to content

Commit

Permalink
chore: init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimerson21 committed Sep 13, 2023
0 parents commit 2749151
Show file tree
Hide file tree
Showing 16 changed files with 794 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Blockshift

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Very short description of the package

[![Latest Version on Packagist](https://img.shields.io/packagist/v/blockshiftnetwork/node-red-laravel.svg?style=flat-square)](https://packagist.org/packages/blockshiftnetwork/node-red-laravel)
[![Total Downloads](https://img.shields.io/packagist/dt/blockshiftnetwork/node-red-laravel.svg?style=flat-square)](https://packagist.org/packages/blockshiftnetwork/node-red-laravel)
![GitHub Actions](https://github.com/blockshiftnetwork/node-red-laravel/actions/workflows/main.yml/badge.svg)

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

## Installation

You can install the package via composer:

```bash
composer require blockshiftnetwork/node-red-laravel
```

## Usage

```php
// Usage description here
```

### Testing

```bash
composer test
```

### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [Blockshift](https://github.com/blockshiftnetwork)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

## Laravel Package Boilerplate

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).
54 changes: 54 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "blockshiftnetwork/node-red-laravel",
"description": "Node Red Laravel",
"keywords": [
"blockshiftnetwork",
"node-red-laravel"
],
"homepage": "https://github.com/blockshiftnetwork/node-red-laravel",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Blockshift",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^7.4|^8.0",
"illuminate/support": "^8.0"
},
"require-dev": {
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"NodeRed\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"NodeRed\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"NodeRed\\NodeRedServiceProvider"
],
"aliases": {
"NodeRed": "NodeRed\\NodeRedFacade"
}
}
}
}
8 changes: 8 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/*
* You can place your custom package configuration in here.
*/
return [
//
];
70 changes: 70 additions & 0 deletions src/Contracts/Node.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace NodeRed\Contracts;

use Illuminate\Support\Str;

abstract class Node {

/**
* @var string
*/
public $id;

/**
* @var string
*/
public $z;

/**
* @var string
*/
public $type;

/**
* @var string
*/
public $name;

/**
* @var string
*/
public $x;

/**
* @var string
*/
public $y;

/**
* @var array
*/
public $wires = [];

/**
* @param array $data
*/
public function __construct(array $data)
{
$this->z = $data['z'];
$this->x = $data['x'];
$this->y = $data['y'];
$this->id = $data['id'] ?? Str::uuid()->toString();
$this->name = $data['name'] ?? $this->id.'-'.$this->type;
}

/**
* @param array $nodes
* @return void
*
*/
public function setWires(array $nodes)
{
$this->wires = array_filter($this->wires);

foreach ($nodes as $node) {

$this->wires[] = (is_array($node)) ? $node : [$node];
}
}
}
21 changes: 21 additions & 0 deletions src/Facades/NodeRedFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace NodeRed\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @see \Blockshiftnetwork\NodeRedLaravel\Skeleton\SkeletonClass
*/
class NodeRedFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return NodeRed::class;
}
}
135 changes: 135 additions & 0 deletions src/NodeRed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

namespace NodeRed;

class NodeRed
{
/**
* @var string
*/
public $id;

/**
* @var string
*/
public $type = 'tab';

/***
* @var string
*/
public $label = '';

/**
* @var bool
*/
public $disabled = false;

/**
* @var string
*/
public $info = '';

/**
* @var array
*/
public $nodes = [];

/**
* @var array
*/
public $subflows = [];

/**
* @var array
*/
public $env = [];

/**
* @var array
*/
public $config = [];


/**
* @param array $data
*/
public function __construct(array $data)
{
$this->id = $data['id'];
$this->label = $data['label'];
$this->disabled = $data['disabled'];
$this->info = $data['info'];
$this->env = $data['env'];
}

/**
* @param array $nodes
* @return void
*/
public function addNodes($nodes)
{
foreach ($nodes as $node) {
$this->nodes[] = $node;
}
}

/**
* @return array
*/
public function serializeNodes()
{
return array_map(function ($node) {
return json_decode(json_encode($node), true);
}, $this->nodes);
}

/**
* @param array $nodes
* @return void
*/
public function deserializeNodes($nodes)
{
foreach ($nodes as $node) {

if (!is_array($node)) {
continue;
}

switch($node['type'])
{
case 'function':
$instanceNode = new \NodeRed\Types\_Function\FunctionNode($node);
break;
case 'switch':
$instanceNode = new \NodeRed\Types\_Function\SwitchNode($node);
break;
case 'catch':
$instanceNode = new \NodeRed\Types\Common\CatchNode($node);
break;
case 'http in':
$instanceNode = new \NodeRed\Types\Network\HttpInNode($node);
break;
case 'http request':
$instanceNode = new \NodeRed\Types\Network\HttpRequestNode($node);
break;
case 'http response':
$instanceNode = new \NodeRed\Types\Network\HttpResponseNode($node);
break;
case 'pusher out':
$instanceNode = new \NodeRed\Types\Social\PusherNode($node);
break;
case str_contains($node['type'], 'subflow'):
$instanceNode = new \NodeRed\Types\Subflow\SubflowNode($node);
break;
default:
$instanceNode = null;
}

if (!is_null($instanceNode)) {

$instanceNode->setWires($node['wires']);
$this->addNodes([$instanceNode]);
}
}
}
}
Loading

0 comments on commit 2749151

Please sign in to comment.