1. Go to this page and download the library: Download shlinkio/shlink-common library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shlinkio / shlink-common example snippets
declare(strict_types=1);
return [
'debug' => false,
'cache' => [
'namespace' => 'my_namespace',
'default_lifetime' => 86400, // Optional. Defaults to "never expire"
'redis' => [
'servers' => [
// These should be valid URIs. Make sure credentials are URL-encoded
'tcp://1.1.1.1:6379',
'tcp://2.2.2.2:6379',
'tcp://3.3.3.3:6379/3', // Define a database index to use (https://redis.io/docs/commands/select/)
'tcp://user:pass%[email protected]:6379', // Redis ACL (https://redis.io/docs/management/security/acl/)
'tcp://:[email protected]:6379', // Redis security (https://redis.io/docs/management/security/)
'tls://server_with_encryption:6379',
],
'sentinel_service' => 'the_service', // Optional.
],
],
];
declare(strict_types=1);
use Shlinkio\Shlink\Common\Cache\RedisPublishingHelper;
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
$helper = $container->get(RedisPublishingHelper::class);
$helper->publishUpdate(Update::forTopicAndPayload('some_queue', ['foo' => 'bar']));
declare(strict_types=1);
namespace Shlinkio\Shlink\Common;
use Doctrine\ORM\Events;
return [
'entity_manager' => [
'orm' => [
'proxies_dir' => 'data/proxies', // Directory in which proxies will be persisted
'default_repository_classname' => '', // A FQCN for the class used as repository by default
'entities_mappings' => [ // List of directories from which entities mappings should be read
__DIR__ . '/../foo/entities-mappings',
__DIR__ . '/../bar/entities-mappings',
],
'types' => [ // List of custom database types to map
Doctrine\Type\ChronosDateTimeType::CHRONOS_DATETIME => Doctrine\Type\ChronosDateTimeType::class,
],
'load_mappings_using_functional_style' => true, // Makes loader assume mappings return a function which should be invoked. Defaults to false
'listeners' => [ // Map telling which service listeners to invoke for every ORM event
Events::postFlush => ['some_service'],
Events::preUpdate => ['foo', 'bar'],
]
],
'connection' => [ // Database connection params
'driver' => 'pdo_mysql',
'host' => 'shlink_db',
'user' => 'DB_USER',
'password' => 'DB_PASSWORD',
'dbname' => 'DB_NAME',
'charset' => 'utf8',
],
],
];
declare(strict_types=1);
return [
'mercure' => [
// A URL publicly available in which the mercure hub can be reached.
'public_hub_url' => null,
// Optional. An internal URL in which the mercure hub can be reached. Will fall back to public_hub_url if not provided.
'internal_hub_url' => null,
// The JWT secret you provided to the mercure hub as JWT_KEY, so that valid JWTs can be generated.
'jwt_secret' => null,
// Optional. The issuer for generated JWTs. Will fall back to "Shlink".
'jwt_issuer' => 'Shlink',
],
];
declare(strict_types=1);
use Symfony\Component\Mercure\Publisher;
use Symfony\Component\Mercure\Update;
$publisher = $container->get(Publisher::class);
$publisher(new Update('some_topic', json_encode([
'foo' => 'bar',
])));
declare(strict_types=1);
return [
'rabbitmq' => [
// The RabbitMQ server name
'host' => 'my-rabbitmq-server.com',
// The RabbitMQ server port
'port' => '5672',
// The username credential
'user' => 'username',
// The password credential
'password' => 'password',
// The vHost
'vhost' => '/',
// Tells if connection should be encrypted. Defaults to false if not provided
'use_ssl' => true,
],
];
declare(strict_types=1);
use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelper;
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
$helper = $container->get(RabbitMqPublishingHelper::class);
$helper->publishUpdate(Update::forTopicAndPayload('some_queue', ['foo' => 'bar']));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.