添加网站文件

This commit is contained in:
2025-12-22 13:59:40 +08:00
commit 117aaf83d1
19468 changed files with 2111999 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php
/*
* (c) Jeroen van den Enden <info@endroid.nl>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Endroid\QrCode\Bundle\QrCodeBundle\Controller;
use Endroid\QrCode\Factory\QrCodeFactory;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
/**
* QR code controller.
*/
class QrCodeController extends Controller
{
/**
* @param Request $request
* @param string $text
* @param string $extension
*
* @return Response
*/
public function generateAction(Request $request, $text, $extension)
{
$options = $request->query->all();
$qrCode = $this->getQrCodeFactory()->create($text, $options);
$qrCode->setWriterByExtension($extension);
return new Response($qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()]);
}
/**
* @return Response
*/
public function twigFunctionsAction()
{
if (!$this->has('twig')) {
throw new \LogicException('You can not use the "@Template" annotation if the Twig Bundle is not available.');
}
$param = [
'message' => 'QR Code',
];
$renderedView = $this->get('twig')->render('@EndroidQrCode/QrCode/twigFunctions.html.twig', $param);
return new Response($renderedView, Response::HTTP_OK);
}
/**
* @return QrCodeFactory
*/
protected function getQrCodeFactory()
{
return $this->get('endroid.qrcode.factory');
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* (c) Jeroen van den Enden <info@endroid.nl>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Endroid\QrCode\Bundle\QrCodeBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class WriterRegistryCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('endroid.qrcode.writer_registry')) {
return;
}
$writerRegistryDefinition = $container->findDefinition('endroid.qrcode.writer_registry');
$taggedServices = $container->findTaggedServiceIds('endroid.qrcode.writer');
foreach ($taggedServices as $id => $tags) {
foreach ($tags as $attributes) {
$writerRegistryDefinition->addMethodCall('addWriter', [new Reference($id), isset($attributes['set_as_default']) && $attributes['set_as_default']]);
}
}
}
}

View File

@@ -0,0 +1,77 @@
<?php
/*
* (c) Jeroen van den Enden <info@endroid.nl>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Endroid\QrCode\Bundle\QrCodeBundle\DependencyInjection;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Predis\Response\Error;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$treeBuilder
->root('endroid_qr_code')
->children()
->scalarNode('writer')->end()
->integerNode('size')->min(0)->end()
->integerNode('margin')->min(0)->end()
->scalarNode('encoding')->defaultValue('UTF-8')->end()
->scalarNode('error_correction_level')
->validate()
->ifNotInArray(ErrorCorrectionLevel::toArray())
->thenInvalid('Invalid error correction level %s')
->end()
->end()
->arrayNode('foreground_color')
->children()
->scalarNode('r')->isRequired()->end()
->scalarNode('g')->isRequired()->end()
->scalarNode('b')->isRequired()->end()
->end()
->end()
->arrayNode('background_color')
->children()
->scalarNode('r')->isRequired()->end()
->scalarNode('g')->isRequired()->end()
->scalarNode('b')->isRequired()->end()
->end()
->end()
->scalarNode('logo_path')->end()
->integerNode('logo_width')->end()
->scalarNode('label')->end()
->integerNode('label_font_size')->end()
->scalarNode('label_font_path')->end()
->scalarNode('label_alignment')
->validate()
->ifNotInArray(LabelAlignment::toArray())
->thenInvalid('Invalid label alignment %s')
->end()
->end()
->arrayNode('label_margin')
->children()
->scalarNode('t')->end()
->scalarNode('r')->end()
->scalarNode('b')->end()
->scalarNode('l')->end()
->end()
->end()
->booleanNode('validate_result')->end()
->end()
->end()
;
return $treeBuilder;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* (c) Jeroen van den Enden <info@endroid.nl>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Endroid\QrCode\Bundle\QrCodeBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
class EndroidQrCodeExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), $configs);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$factoryDefinition = $container->getDefinition('endroid.qrcode.factory');
$factoryDefinition->replaceArgument(0, $config);
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* (c) Jeroen van den Enden <info@endroid.nl>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Endroid\QrCode\Bundle\QrCodeBundle;
use Endroid\QrCode\Bundle\QrCodeBundle\DependencyInjection\Compiler\WriterRegistryCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class EndroidQrCodeBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new WriterRegistryCompilerPass());
}
}

View File

@@ -0,0 +1,11 @@
endroid_qrcode_generate:
path: /{text}.{extension}
requirements:
text: "[\\w\\W]+"
defaults:
_controller: EndroidQrCodeBundle:QrCode:generate
endroid_qrcode_twig_functions:
path: /twig
defaults:
_controller: EndroidQrCodeBundle:QrCode:twigFunctions

View File

@@ -0,0 +1,31 @@
services:
endroid.qrcode.factory:
class: Endroid\QrCode\Factory\QrCodeFactory
arguments: [ null, '@endroid.qrcode.writer_registry' ]
endroid.qrcode.twig.extension:
class: Endroid\QrCode\Twig\Extension\QrCodeExtension
arguments: [ '@endroid.qrcode.factory', '@router']
tags:
- { name: twig.extension }
endroid.qrcode.writer_registry:
class: Endroid\QrCode\WriterRegistry
endroid.qrcode.writer.binary_writer:
class: Endroid\QrCode\Writer\BinaryWriter
tags:
- { name: endroid.qrcode.writer }
endroid.qrcode.writer.debug_writer:
class: Endroid\QrCode\Writer\DebugWriter
tags:
- { name: endroid.qrcode.writer }
endroid.qrcode.writer.eps_writer:
class: Endroid\QrCode\Writer\EpsWriter
tags:
- { name: endroid.qrcode.writer }
endroid.qrcode.writer.png_writer:
class: Endroid\QrCode\Writer\PngWriter
tags:
- { name: endroid.qrcode.writer, set_as_default: true }
endroid.qrcode.writer.svg_writer:
class: Endroid\QrCode\Writer\SvgWriter
tags:
- { name: endroid.qrcode.writer }

View File

@@ -0,0 +1,3 @@
<img src="{{ qrcode_path(message) }}" />
<img src="{{ qrcode_url(message, { writer: 'svg' }) }}" />
<img src="{{ qrcode_data_uri(message, { writer: 'svg', size: 150 }) }}" />