Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maillotf committed Sep 30, 2020
0 parents commit a4199fc
Show file tree
Hide file tree
Showing 15 changed files with 1,001 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Papercut-bridge-bundle

Symfony bundle for Papercut XML-RPC client which is base on token authentication

## Required configuration

### Modify framework.yaml
```yaml
papercut:
authentication:
protocol: "http"
host: "127.0.0.1"
port: "80"
path: "/rpc/api/xmlrpc"
token: "TOKEN"
```
```yaml
papercut:
authentication:
path: "http://URL/rpc/api/xmlrpc"
token: "TOKEN"
```
### Modify services.yaml
```yaml
services:
MaillotF\Papercut\PapercutBridgeBundle\Service\PapercutService: '@papercut.service'
```
##Package instalation with composer
```console
$ composer require maillotf/papercut-bridge-bundle
```

## Use in controller:

```php
<?php
//...
use MaillotF\Papercut\PapercutBridgeBundle\Service\PapercutService;

class exampleController extends AbstractController
{
/**
* Example
*
* @Route("example", name="example", methods={"GET"})
*
*/
public function test(PapercutService $ps)
{
$user = $ps->user->getUser('4665');

return ($this->json($user->getEmail()));
}

}
```
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

{
"name": "maillotf/papercut-bridge-bundle",
"type": "symfony-bundle",
"description": "A Papercut bundle for Symfony",
"keywords": ["papercut", "print", "bridge", "symfony"],
"homepage": "https://github.com/maillotf/papercut-bridge-bundle",
"authors": [{
"name": "Flavien Maillot",
"email": "contact@webcomputing.fr"
}],
"require": {
"php": "^7.1",
"symfony/http-kernel": "^3.2|^4.0|^4.1|^5.1",
"symfony/config": "^3.2|^4.0|^4.1|^5.1",
"symfony/dependency-injection": "^3.2|^4.0|^4.1|^5.1",
"phpxmlrpc/phpxmlrpc": "^4.3"
},
"require-dev": {
"phpunit/phpunit": "^6.5"
},
"autoload": {
"psr-4": {
"MaillotF\\Papercut\\PapercutBridgeBundle\\": "src/"
}
}
}
56 changes: 56 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace MaillotF\Papercut\PapercutBridgeBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* Description of Configuration
*
* @package MaillotF\Papercut\PapercutBridgeBundle\DependencyInjection
* @author Flavien Maillot "contact@webcomputing.fr"
*/
class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
$builder = new TreeBuilder('papercut');

$builder->getRootNode()->addDefaultsIfNotSet()
->children()
->arrayNode('authentication')
->isRequired()
->children()
->scalarNode('protocol')
// ->isRequired()
// ->cannotBeEmpty()
->defaultValue(null)
->end()
->scalarNode('host')
// ->isRequired()
// ->cannotBeEmpty()
->defaultValue(null)
->end()
->integerNode('port')
// ->isRequired()
->defaultValue(null)
->end()
->scalarNode('path')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('token')
->isRequired()
->cannotBeEmpty()
->end()
->end()
->end()
->end()
;
return ($builder);
}
}
37 changes: 37 additions & 0 deletions src/DependencyInjection/PapercutExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace MaillotF\Papercut\PapercutBridgeBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

/**
* Class PapercutExtension
*
* @package MaillotF\Papercut\PapercutBridgeBundle\DependencyInjection
* @author Flavien Maillot "contact@webcomputing.fr"
*/
class PapercutExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

// Authentication
$container->setParameter('papercut.authentication.protocol', $config['authentication']['protocol']);
$container->setParameter('papercut.authentication.host', $config['authentication']['host']);
$container->setParameter('papercut.authentication.port', $config['authentication']['port']);
$container->setParameter('papercut.authentication.path', $config['authentication']['path']);
$container->setParameter('papercut.authentication.token', $config['authentication']['token']);

// load services for bundle
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
$loader->load('services.yml');
}
}
12 changes: 12 additions & 0 deletions src/Exception/PapercutException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace MaillotF\Papercut\PapercutBridgeBundle\Exception;

/**
* Description of PapercutException
*
* @author Flavien Maillot "contact@webcomputing.fr"
*/
class PapercutException extends \Exception
{
}
19 changes: 19 additions & 0 deletions src/Objects/AbstractPapercutObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace MaillotF\Papercut\PapercutBridgeBundle\Objects;

/**
* Description of AbstractPapercutObject
*
* @author Flavien Maillot "contact@webcomputing.fr"
*/
class AbstractPapercutObject
{

}
122 changes: 122 additions & 0 deletions src/Objects/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

namespace MaillotF\Papercut\PapercutBridgeBundle\Objects;

/**
* Description of User
*
* @author Flavien Maillot "contact@webcomputing.fr"
*/
class User
{
private $username;

private $password;

private $fullName;

private $email;

private $balance;

private $primaryCardNumber;

private $secondaryCardNumber;

private $restricted;

public function getProperties(): array
{
$properties = array_keys(get_object_vars($this));
unset($properties[0]);
unset($properties[1]);
return \MaillotF\Papercut\PapercutBridgeBundle\Utils\Normalizer::normalizeArray($properties);
}

public function setUsername(string $username)
{
$this->username = $username;
return $this;
}

public function getUsername(): string
{
return $this->username;
}

public function setPassword(string $password)
{
$this->password = $password;
return $this;
}

public function getPassword(): string
{
return $this->password;
}

public function setFullname(string $fullName)
{
$this->fullName = $fullName;
return $this;
}

public function getFullname(): string
{
return $this->fullName;
}

public function setEmail(string $email)
{
$this->email = $email;
return $this;
}

public function getEmail(): string
{
return $this->email;
}

public function setBalance(string $balance)
{
$this->balance = $balance;
return $this;
}

public function getBalance(): string
{
return $this->balance;
}

public function setPrimaryCardNumber(string $primaryCardNumber)
{
$this->primaryCardNumber = $primaryCardNumber;
return $this;
}
public function getPrimaryCardNumber(): string
{
return $this->primaryCardNumber;
}

public function setSecondaryCardNumber(string $secondaryCardNumber)
{
$this->secondaryCardNumber = $secondaryCardNumber;
return $this;
}
public function getSecondaryCardNumber(): string
{
return $this->secondaryCardNumber;
}

public function setRestricted(string $restricted)
{
$this->restricted = $restricted;
return $this;
}

public function getRestricted(): string
{
return $this->restricted;
}

}
21 changes: 21 additions & 0 deletions src/PapercutBridgeBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace MaillotF\Papercut\PapercutBridgeBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

use MaillotF\Papercut\PapercutBridgeBundle\DependencyInjection\PapercutExtension;

/**
* Class PapercutBridgeBundle
*
* @package MaillotF\Papercut\PapercutBridgeBundle
* @author Flavien Maillot "contact@webcomputing.fr"
*/
class PapercutBridgeBundle extends Bundle
{
public function getContainerExtension()
{
return new PapercutExtension();
}
}
9 changes: 9 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
papercut.service:
class: MaillotF\Papercut\PapercutBridgeBundle\Service\PapercutService
arguments:
- "%papercut.authentication.path%"
- "%papercut.authentication.token%"
- "%papercut.authentication.protocol%"
- "%papercut.authentication.host%"
- "%papercut.authentication.port%"
Loading

0 comments on commit a4199fc

Please sign in to comment.