Remove deprecated global helper functions (issue #99)

Squashed commit of the following:

commit 8ff29a8ab51ee5057ef786614ab95b005bf8918c
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Fri Feb 1 18:42:05 2019 +0000

    Replace deprecated global helpers with their facade equivalents
This commit is contained in:
Jonny Barnes 2019-02-01 18:49:35 +00:00
parent 7a4ba43b4d
commit fb44afd7ad
15 changed files with 104 additions and 90 deletions

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Services\Micropub;
use Illuminate\Support\Arr;
use App\Services\PlaceService;
class HCardService
@ -17,16 +18,16 @@ class HCardService
public function process(array $request): string
{
$data = [];
if (array_get($request, 'properties.name')) {
$data['name'] = array_get($request, 'properties.name');
$data['description'] = array_get($request, 'properties.description');
$data['geo'] = array_get($request, 'properties.geo');
if (Arr::get($request, 'properties.name')) {
$data['name'] = Arr::get($request, 'properties.name');
$data['description'] = Arr::get($request, 'properties.description');
$data['geo'] = Arr::get($request, 'properties.geo');
} else {
$data['name'] = array_get($request, 'name');
$data['description'] = array_get($request, 'description');
$data['geo'] = array_get($request, 'geo');
$data['latitude'] = array_get($request, 'latitude');
$data['longitude'] = array_get($request, 'longitude');
$data['name'] = Arr::get($request, 'name');
$data['description'] = Arr::get($request, 'description');
$data['geo'] = Arr::get($request, 'geo');
$data['latitude'] = Arr::get($request, 'latitude');
$data['longitude'] = Arr::get($request, 'longitude');
}
$place = resolve(PlaceService::class)->createPlace($data);

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Services\Micropub;
use Illuminate\Support\Arr;
use App\Services\{BookmarkService, LikeService, NoteService};
class HEntryService
@ -17,13 +18,13 @@ class HEntryService
*/
public function process(array $request, ?string $client = null): ?string
{
if (array_get($request, 'properties.like-of') || array_get($request, 'like-of')) {
if (Arr::get($request, 'properties.like-of') || Arr::get($request, 'like-of')) {
$like = resolve(LikeService::class)->createLike($request);
return $like->longurl;
}
if (array_get($request, 'properties.bookmark-of') || array_get($request, 'bookmark-of')) {
if (Arr::get($request, 'properties.bookmark-of') || Arr::get($request, 'bookmark-of')) {
$bookmark = resolve(BookmarkService::class)->createBookmark($request);
return $bookmark->longurl;

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Services\Micropub;
use App\Models\{Media, Note};
use Illuminate\Support\{Arr, Str};
use Illuminate\Database\Eloquent\ModelNotFoundException;
class UpdateService
@ -17,7 +18,7 @@ class UpdateService
*/
public function process(array $request)
{
$urlPath = parse_url(array_get($request, 'url'), PHP_URL_PATH);
$urlPath = parse_url(Arr::get($request, 'url'), PHP_URL_PATH);
//is it a note we are updating?
if (mb_substr($urlPath, 1, 5) !== 'notes') {
@ -37,20 +38,20 @@ class UpdateService
}
//got the note, are we dealing with a “replace” request?
if (array_get($request, 'replace')) {
foreach (array_get($request, 'replace') as $property => $value) {
if (Arr::get($request, 'replace')) {
foreach (Arr::get($request, 'replace') as $property => $value) {
if ($property == 'content') {
$note->note = $value[0];
}
if ($property == 'syndication') {
foreach ($value as $syndicationURL) {
if (starts_with($syndicationURL, 'https://www.facebook.com')) {
if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) {
$note->facebook_url = $syndicationURL;
}
if (starts_with($syndicationURL, 'https://www.swarmapp.com')) {
if (Str::startsWith($syndicationURL, 'https://www.swarmapp.com')) {
$note->swarm_url = $syndicationURL;
}
if (starts_with($syndicationURL, 'https://twitter.com')) {
if (Str::startsWith($syndicationURL, 'https://twitter.com')) {
$note->tweet_id = basename(parse_url($syndicationURL, PHP_URL_PATH));
}
}
@ -64,24 +65,24 @@ class UpdateService
}
//how about “add”
if (array_get($request, 'add')) {
foreach (array_get($request, 'add') as $property => $value) {
if (Arr::get($request, 'add')) {
foreach (Arr::get($request, 'add') as $property => $value) {
if ($property == 'syndication') {
foreach ($value as $syndicationURL) {
if (starts_with($syndicationURL, 'https://www.facebook.com')) {
if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) {
$note->facebook_url = $syndicationURL;
}
if (starts_with($syndicationURL, 'https://www.swarmapp.com')) {
if (Str::startsWith($syndicationURL, 'https://www.swarmapp.com')) {
$note->swarm_url = $syndicationURL;
}
if (starts_with($syndicationURL, 'https://twitter.com')) {
if (Str::startsWith($syndicationURL, 'https://twitter.com')) {
$note->tweet_id = basename(parse_url($syndicationURL, PHP_URL_PATH));
}
}
}
if ($property == 'photo') {
foreach ($value as $photoURL) {
if (starts_with($photoURL, 'https://')) {
if (Str::startsWith($photoURL, 'https://')) {
$media = new Media();
$media->path = $photoURL;
$media->type = 'image';