Skip to content

Commit e4ed331

Browse files
[8.x] StringEncrypter interface for better DX (#36578)
* StringEncrypter interface for better DX * StyleCI * Update Encrypter.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 6d1da01 commit e4ed331

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Illuminate\Contracts\Encryption;
4+
5+
interface StringEncrypter
6+
{
7+
/**
8+
* Encrypt a string without serialization.
9+
*
10+
* @param string $value
11+
* @return string
12+
*
13+
* @throws \Illuminate\Contracts\Encryption\EncryptException
14+
*/
15+
public function encryptString($value);
16+
17+
/**
18+
* Decrypt the given string without unserialization.
19+
*
20+
* @param string $payload
21+
* @return string
22+
*
23+
* @throws \Illuminate\Contracts\Encryption\DecryptException
24+
*/
25+
public function decryptString($payload);
26+
}

src/Illuminate/Encryption/Encrypter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
use Illuminate\Contracts\Encryption\DecryptException;
66
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
77
use Illuminate\Contracts\Encryption\EncryptException;
8+
use Illuminate\Contracts\Encryption\StringEncrypter;
89
use RuntimeException;
910

10-
class Encrypter implements EncrypterContract
11+
class Encrypter implements EncrypterContract, StringEncrypter
1112
{
1213
/**
1314
* The encryption key.

src/Illuminate/Foundation/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,9 +1302,9 @@ public function registerCoreContainerAliases()
13021302
'cache.psr6' => [\Symfony\Component\Cache\Adapter\Psr16Adapter::class, \Symfony\Component\Cache\Adapter\AdapterInterface::class, \Psr\Cache\CacheItemPoolInterface::class],
13031303
'config' => [\Illuminate\Config\Repository::class, \Illuminate\Contracts\Config\Repository::class],
13041304
'cookie' => [\Illuminate\Cookie\CookieJar::class, \Illuminate\Contracts\Cookie\Factory::class, \Illuminate\Contracts\Cookie\QueueingFactory::class],
1305-
'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class],
13061305
'db' => [\Illuminate\Database\DatabaseManager::class, \Illuminate\Database\ConnectionResolverInterface::class],
13071306
'db.connection' => [\Illuminate\Database\Connection::class, \Illuminate\Database\ConnectionInterface::class],
1307+
'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\StringEncrypter::class],
13081308
'events' => [\Illuminate\Events\Dispatcher::class, \Illuminate\Contracts\Events\Dispatcher::class],
13091309
'files' => [\Illuminate\Filesystem\Filesystem::class],
13101310
'filesystem' => [\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class],

0 commit comments

Comments
 (0)