Helper package used for the validation of social links.
This project requires PHP 8.2 or higher with the mbstring
extension installed.
Install via [composer], simply run:
composer require dealroom/socials-helpers
The Factory
class provides a simple wrapper for the validation functionality, for example, to get normalized URL:
use Dealroom\SocialsHelpers\Factory;
use Dealroom\SocialsHelpers\Normalizers\TwitterNormalizer;
$data = Factory::parseUrl('http://twitter.com/Dealroom', [TwitterNormalizer::getPlatform()])->getNormalizedUrl();
echo $data;
// "https://twitter.com/dealroom"
Or if you want to extract social network ID (handle):
use Dealroom\SocialsHelpers\Factory;
use Dealroom\SocialsHelpers\Normalizers\TwitterNormalizer;
$data = Factory::parseUrl('https://twitter.com/dealroom', [TwitterNormalizer::getPlatform()])->getId();
echo $data;
// "dealroom"
The following platforms are supported by default:
- Apple Music
- YouTube
- TikTok
- SoundCloud
- X
- Spotify
To register a new normalizer, you need to create a new class that implements
the NormalizerInterface
interface (for example, by extending the AbstractNormalizer
class).
After that, you need to register the new normalizer in the Factory
class.
use Dealroom\SocialsHelpers\Normalizers\AbstractNormalizer;
use Dealroom\SocialsHelpers\Normalizers\Factory;
use Dealroom\SocialsHelpers\Factory;
class CustomNormalizer extends AbstractNormalizer
{
// Implement the interface methods
}
Factory::addNormalizer(CustomNormalizer::class);
$data = Factory::parseUrl('https://custom.com/Dealroom', [CustomNormalizer::getPlatform()])->getNormalizedUrl();
PHPUnit is used for testing, run:
./vendor/bin/phpunit
The release is done automatically using GitHub Actions on every push to the main
branch.
After the release is done, a new tag is created and pushed to GitHub,
which triggers a new release in packagist.