Skip to content

Commit

Permalink
feat: Initial Commit
Browse files Browse the repository at this point in the history
Initial Commit
  • Loading branch information
erkenes committed Apr 7, 2023
0 parents commit 5b6011e
Show file tree
Hide file tree
Showing 17 changed files with 1,226 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @nextbox-dev/neos-developer
21 changes: 21 additions & 0 deletions .github/workflows/new-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Create new version
on:
push:
branches:
- main
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@586e1a624db6a5a4ac2c53daeeded60c5e3d50fe
with:
app_id: ${{ secrets.TOKEN_APP_ID }}
private_key: ${{ secrets.TOKEN_APP_PRIVATE_KEY }}

- name: Create Release
uses: google-github-actions/release-please-action@v3
with:
command: manifest
token: ${{ steps.generate_token.outputs.token }}
26 changes: 26 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Format (PHP)

on:
pull_request:

jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
with:
app_id: ${{ secrets.TOKEN_APP_ID }}
private_key: ${{ secrets.TOKEN_APP_PRIVATE_KEY }}

- uses: actions/checkout@v2
with:
token: ${{ steps.generate_token.outputs.token }}

- name: Run PHP CS Fixer
uses: oskarstark/php-cs-fixer-ga@1b312141100e6b0800d5df42f73016e680c60669

- uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a
with:
commit_message: 'fix: Apply php-cs-fixer changes'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
.php-cs-fixer.cache
26 changes: 26 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in('.')
->name('*.php');

$config = new PhpCsFixer\Config();
return $config
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'@PHP81Migration' => true,
'no_empty_statement' => true,
'no_unused_imports' => true,
'no_trailing_comma_in_singleline_array' => true,
'modernize_strpos' => true,
'fully_qualified_strict_types' => true,
'heredoc_indentation' => [
'indentation' => 'same_as_start'
],
])
->setRiskyAllowed(true)
->setFinder($finder);
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.1"
}
68 changes: 68 additions & 0 deletions Classes/Command/QrCodeCommandController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
namespace NextBox\Neos\QrCode\Command;

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use NextBox\Neos\QrCode\Services\QrCodeService;

class QrCodeCommandController extends CommandController
{
/**
* @Flow\Inject
* @var QrCodeService
*/
protected $qrCodeService;

/**
* @Flow\Inject()
* @var PersistenceManagerInterface
*/
protected $persistenceManager;

/**
* Generate a new qr code if it is missing
* Force remove the existing qr code if the argument `force` is set
*
* @param string $shortIdentifier the value of the short identifier
* @param string $shortType the definition in the settings
* @param bool $force overwrite an existing image
* @return void
*/
public function generateCommand(string $shortIdentifier, string $shortType = 'default', bool $force = false): void
{
$resource = $this->qrCodeService->getFile($shortIdentifier, $shortType);

if ($resource && !$force) {
$this->output->outputLine('<comment>There is an image already existing. Use --force to overwrite this image and create a new one.</comment>');
} else {
if ($force) {
$this->qrCodeService->deleteFile($shortIdentifier, $shortType);
$this->output->outputLine('<comment>The qr-code was force removed</comment>');
$this->persistenceManager->persistAll();
}

// ToDo: Uri has `/./` after the TLD
$this->qrCodeService->generateAndSendToUri($shortIdentifier, $shortType);
$this->output->outputLine('<success>The qr-code with the `url-short-identifier` ' . $shortIdentifier . ' was created successfully.</success>');
}
}

/**
* Delete a qr-code resource
*
* @param string $shortIdentifier the value of the short identifier
* @param string $shortType
* @return void
*/
public function removeCommand(string $shortIdentifier, string $shortType = 'default'): void
{
$state = $this->qrCodeService->deleteFile($shortIdentifier, $shortType);

if ($state) {
$this->output->outputLine('<success>The qr-code with the `short-identifier` ' . $shortIdentifier . ' was removed successfully.</success>');
} else {
$this->output->outputLine('<error>Can not find a qr-code with the `short-identifier` ' . $shortIdentifier . '</error>');
}
}
}
58 changes: 58 additions & 0 deletions Classes/Controller/QrCodeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace NextBox\Neos\QrCode\Controller;

use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Exception\PageNotFoundException;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Neos\Service\LinkingService;
use NextBox\Neos\QrCode\Services\QrCodeService;
use Neos\Flow\Annotations as Flow;
use NextBox\Neos\UrlShortener\Services\RedirectService;

class QrCodeController extends ActionController
{
/**
* @Flow\Inject
* @var QrCodeService
*/
protected $qrCodeService;

/**
* @Flow\Inject
* @var RedirectService
*/
protected $redirectService;

/**
* @Flow\Inject
* @var LinkingService
*/
protected $linkingService;

/**
* @param string $shortIdentifier
* @return void
* @throws PageNotFoundException
* @throws StopActionException
*/
public function generateQrCodeAction(string $shortIdentifier, string $shortType = 'default'): void
{
$documentNode = $this->redirectService->getNodeByShortIdentifierAndType($shortIdentifier, $shortType);

if (!$documentNode instanceof NodeInterface) {
throw new PageNotFoundException();
}

$resource = $this->qrCodeService->getQrCodeResource($this->redirectService->createShortUri($shortIdentifier, $shortType), $shortIdentifier, $shortType);

$this->response->setContentType('image/png');
$this->response->setHttpHeader('Content-disposition', 'inline; filename="qrcode_' . $shortIdentifier . '_' . ($documentNode->getProperty('title') ?: '') . '.png"');
$this->response->setHttpHeader('Content-Control', 'public, must-revalidate, max-age=0');
$this->response->setHttpHeader('Pragma', 'public');
$this->response->setHttpHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
$this->response->setContent($resource->getStream());
-
throw new StopActionException();
}
}
Loading

0 comments on commit 5b6011e

Please sign in to comment.