From 0c48352677de0a347cb47bcaf514bf72b02258ac Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 20:03:24 +0200
Subject: [PATCH 01/10] Create .gitignore
---
.gitignore | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e69de29
From a34a951b971e80559ba68c92be1ea8d9a99513dc Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 20:04:02 +0200
Subject: [PATCH 02/10] Refactor
---
.gitignore | 2 +
CHANGELOG.md | 3 +
vendor/composer/LICENSE => LICENSE.md | 12 +-
composer.json | 69 ++-
readme.md | 66 ++-
src/Cision.php | 105 +++++
src/CisionServiceProvider.php | 21 +
src/LaravelCisionFeed.php | 145 ------
src/LaravelCisionFeedProvider.php | 19 -
vendor/autoload.php | 7 -
vendor/composer/ClassLoader.php | 572 ------------------------
vendor/composer/autoload_classmap.php | 10 -
vendor/composer/autoload_namespaces.php | 9 -
vendor/composer/autoload_psr4.php | 10 -
vendor/composer/autoload_real.php | 55 ---
vendor/composer/autoload_static.php | 36 --
16 files changed, 249 insertions(+), 892 deletions(-)
create mode 100644 CHANGELOG.md
rename vendor/composer/LICENSE => LICENSE.md (82%)
create mode 100755 src/Cision.php
create mode 100644 src/CisionServiceProvider.php
delete mode 100644 src/LaravelCisionFeed.php
delete mode 100644 src/LaravelCisionFeedProvider.php
delete mode 100644 vendor/autoload.php
delete mode 100644 vendor/composer/ClassLoader.php
delete mode 100644 vendor/composer/autoload_classmap.php
delete mode 100644 vendor/composer/autoload_namespaces.php
delete mode 100644 vendor/composer/autoload_psr4.php
delete mode 100644 vendor/composer/autoload_real.php
delete mode 100644 vendor/composer/autoload_static.php
diff --git a/.gitignore b/.gitignore
index e69de29..1f1025f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.idea
+.DS_Store
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..7585030
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,3 @@
+# Changelog
+
+All notable changes to `laravel-cision-feed` will be documented in this file.
diff --git a/vendor/composer/LICENSE b/LICENSE.md
similarity index 82%
rename from vendor/composer/LICENSE
rename to LICENSE.md
index f27399a..e90c3f2 100644
--- a/vendor/composer/LICENSE
+++ b/LICENSE.md
@@ -1,15 +1,16 @@
+The MIT License (MIT)
-Copyright (c) Nils Adermann, Jordi Boggiano
+Copyright (c) Mattitja AB
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is furnished
-to do so, subject to the following conditions:
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@@ -18,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-
diff --git a/composer.json b/composer.json
index bea6a2b..c506d37 100644
--- a/composer.json
+++ b/composer.json
@@ -1,24 +1,75 @@
{
- "name": "mathiaspalmqvist/laravel-cision-feed",
- "description": "Fetches press releases and financial reports from any public company on cision.",
+ "name": "mattitjaab/laravel-cision-feed",
+ "description": "This is my package laravel-cision-feed",
+ "keywords": [
+ "Mattitja AB",
+ "laravel",
+ "laravel-cision-feed",
+ "cision"
+ ],
+ "homepage": "https://github.com/mattitjaab/laravel-cision-feed",
"license": "MIT",
"authors": [
{
- "name": "Mathias Palmqvist",
- "email": "mathias@mattitja.se"
+ "name": "Mattitja AB",
+ "email": "hej@mattitja.se",
+ "role": "Developer"
}
],
- "require": {},
+ "require": {
+ "php": "^8.4",
+ "spatie/laravel-package-tools": "^1.16",
+ "illuminate/contracts": "^10.0||^11.0||^12.0"
+ },
+ "require-dev": {
+ "laravel/pint": "^1.14",
+ "nunomaduro/collision": "^8.1.1||^7.10.0",
+ "larastan/larastan": "^2.9||^3.0",
+ "orchestra/testbench": "^10.0.0||^9.0.0||^8.22.0",
+ "pestphp/pest": "^3.0",
+ "pestphp/pest-plugin-arch": "^3.0",
+ "pestphp/pest-plugin-laravel": "^3.0",
+ "phpstan/extension-installer": "^1.3||^2.0",
+ "phpstan/phpstan-deprecation-rules": "^1.1||^2.0",
+ "phpstan/phpstan-phpunit": "^1.3||^2.0",
+ "spatie/laravel-ray": "^1.35"
+ },
"autoload": {
"psr-4": {
- "Mathiaspalmqvist\\LaravelCisionFeed\\": "src/"
+ "Mattitja\\Cision\\": "src/",
+ }
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "Mattitja\\Cision\\Tests\\": "tests/",
+ "Workbench\\App\\": "workbench/app/"
+ }
+ },
+ "scripts": {
+ "post-autoload-dump": "@composer run prepare",
+ "prepare": "@php vendor/bin/testbench package:discover --ansi",
+ "analyse": "vendor/bin/phpstan analyse",
+ "test": "vendor/bin/pest",
+ "test-coverage": "vendor/bin/pest --coverage",
+ "format": "vendor/bin/pint"
+ },
+ "config": {
+ "sort-packages": true,
+ "allow-plugins": {
+ "pestphp/pest-plugin": true,
+ "phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"providers": [
- "Mathiaspalmqvist\\LaravelCisionFeed\\LaravelCisionFeedProvider"
- ]
+ "Mattitja\\Cision\\CisionServiceProvider"
+ ],
+ "aliases": {
+ "Cision": "Mattitja\\Cision\\Facades\\Cision"
+ }
}
- }
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true
}
diff --git a/readme.md b/readme.md
index 2af683b..21f99cd 100644
--- a/readme.md
+++ b/readme.md
@@ -1,20 +1,58 @@
-## How to install
-1. Install the package `composer require mathiaspalmqvist/laravel-cision-feed`
-2. add the cision company slug to `LARAVEL_CISION_FEED_SLUG` at your env
+# This is my package laravel-cision-feed
-## Functions
+[](https://packagist.org/packages/mattitjaab/laravel-cision-feed)
+[](https://github.com/mattitjaab/laravel-cision-feed/actions?query=workflow%3Arun-tests+branch%3Amain)
+[](https://github.com/mattitjaab/laravel-cision-feed/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
+[](https://packagist.org/packages/mattitjaab/laravel-cision-feed)
-`LaravelCisionFeed::all();`
-Returns everyting from the feed.
+This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
-`LaravelCisionFeed::press();`
-Returns all press releases from the feed.
+## Support us
-`LaravelCisionFeed::financial();`
-Returns all financial reports from the feed.
+[
](https://spatie.be/github-ad-click/laravel-cision-feed)
-`LaravelCisionFeed::news();`
-Returns all news from the feed.
+We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
-`LaravelCisionFeed::media();`
-Returns all media from the feed.
+We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
+
+## Installation
+
+You can install the package via composer:
+
+```bash
+composer require mattitjaab/laravel-cision-feed
+```
+
+## Usage
+
+```php
+$cision = new Mattitja\Cision();
+echo $cision->echoPhrase('Hello, Mattitja!');
+```
+
+## Testing
+
+```bash
+composer test
+```
+
+## Changelog
+
+Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
+
+## Contributing
+
+Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
+
+## Security Vulnerabilities
+
+Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
+
+## Credits
+
+- [Mattitja AB](https://github.com/MattitjaAB)
+- [All Contributors](../../contributors)
+
+## License
+
+The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
diff --git a/src/Cision.php b/src/Cision.php
new file mode 100755
index 0000000..3369cd6
--- /dev/null
+++ b/src/Cision.php
@@ -0,0 +1,105 @@
+slug = $slug ?? env('LARAVEL_CISION_FEED_SLUG', '');
+ }
+
+ public function all(int $page = 1): array|false
+ {
+ return $this->fetch($page);
+ }
+
+ public function press(int $page = 1): array|false
+ {
+ return $this->fetch($page, 'Press');
+ }
+
+ public function financial(int $page = 1): array|false
+ {
+ return $this->fetch($page, 'Financial');
+ }
+
+ public function news(int $page = 1): array|false
+ {
+ return $this->fetch($page, 'News');
+ }
+
+ public function media(int $page = 1): array|false
+ {
+ return $this->fetch($page, 'Media');
+ }
+
+ protected function fetch(int $page = 1, ?string $type = null): array|false
+ {
+ $response = $this->makeRequest($page, $type);
+
+ if ($response === false || $response->failed()) {
+ return false;
+ }
+
+ return $this->parseResponse($response->body(), $page);
+ }
+
+ protected function makeRequest(int $page, ?string $type = null): Response|false
+ {
+ if (empty($this->slug)) {
+ return false;
+ }
+
+ $query = [
+ 'n' => $this->slug,
+ 'pageIx' => $page,
+ 'format' => 'rss',
+ ];
+
+ if ($type) {
+ $query['m'] = $type;
+ }
+
+ return Http::get('https://news.cision.com/se/ListItems?' . http_build_query($query));
+ }
+
+ protected function parseResponse(string $data, int $page): array|false
+ {
+ if (empty($data)) {
+ return false;
+ }
+
+ $xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
+ if ($xml === false) {
+ return false;
+ }
+
+ $json = json_encode($xml);
+ $rows = json_decode($json, true);
+
+ if (!isset($rows['channel']['item'])) {
+ return false;
+ }
+
+ $items = array_map(fn ($item) => [
+ 'guid' => $item['guid'],
+ 'title' => $item['title'],
+ 'description' => $item['description'],
+ 'link' => $item['link'],
+ 'created_at' => Carbon::parse($item['pubDate'])->addHours(2)->format('Y-m-d H:i:s'),
+ ], $rows['channel']['item']);
+
+ return [
+ 'items' => $items,
+ 'previous_page' => $page > 1 ? $page - 1 : false,
+ 'next_page' => count($items) === 24 ? $page + 1 : false,
+ ];
+ }
+}
\ No newline at end of file
diff --git a/src/CisionServiceProvider.php b/src/CisionServiceProvider.php
new file mode 100644
index 0000000..80caf79
--- /dev/null
+++ b/src/CisionServiceProvider.php
@@ -0,0 +1,21 @@
+name('laravel-cision-feed');
+ }
+}
diff --git a/src/LaravelCisionFeed.php b/src/LaravelCisionFeed.php
deleted file mode 100644
index 6547474..0000000
--- a/src/LaravelCisionFeed.php
+++ /dev/null
@@ -1,145 +0,0 @@
-failed()) {
- return false;
- }
-
- return self::parse($request->body(), $page);
- }
-
- /**
- * @param int $page
- * @return array|false
- */
- public static function press(int $page = 1): bool|array
- {
- $request = self::request($page, 'Press');
-
- if ($request->failed()) {
- return false;
- }
-
- return self::parse($request->body());
- }
-
- /**
- * @param int $page
- * @return array|false
- */
- public static function financial(int $page = 1): bool|array
- {
- $request = self::request($page, 'Financial');
-
- if ($request->failed()) {
- return false;
- }
-
- return self::parse($request->body());
- }
-
- /**
- * @param int $page
- * @return array|false
- */
- public static function news(int $page = 1): bool|array
- {
- $request = self::request($page, 'News');
-
- if ($request->failed()) {
- return false;
- }
-
- return self::parse($request->body());
- }
-
- /**
- * @param int $page
- * @return array|false
- */
- public static function media(int $page = 1): bool|array
- {
- $request = self::request($page, 'Media');
-
- if ($request->failed()) {
- return false;
- }
-
- return self::parse($request->body());
- }
-
- /**
- * @param int $page
- * @param string|null $m
- * @return false|\Illuminate\Http\Client\Response
- */
- private static function request(int $page = 1, string $m = null): bool|\Illuminate\Http\Client\Response
- {
- if (env('LARAVEL_CISION_FEED_SLUG') === null) {
- return false;
- }
-
- $query = [
- 'n' => env('LARAVEL_CISION_FEED_SLUG'),
- 'pageIx' => $page,
- 'format' => 'rss',
- ];
-
- if ($m) {
- $query['m'] = $m;
- }
-
- return Http::get('https://news.cision.com/se/ListItems?'.http_build_query($query));
- }
-
- /**
- * @param string|null $data
- * @param int $page
- * @return bool|array
- */
- private static function parse(string $data = null, int $page = 1): bool|array
- {
- if ($data === null) {
- return false;
- }
-
- $xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
- $json = json_encode($xml);
- $rows = json_decode($json, true);
-
- if (! isset($rows['channel']['item'])) {
- return false;
- }
-
- $return = [];
-
- foreach ($rows['channel']['item'] as $row) {
- $return['items'][] = [
- 'guid' => $row['guid'],
- 'title' => $row['title'],
- 'description' => $row['description'],
- 'link' => $row['link'],
- 'created_at' => Carbon::parse($row['pubDate'])->addHours(2)->format('Y-m-d H:i:s'),
- ];
- }
-
- $return['previous_page'] = $page > 1 ? $page-- : false;
- $return['next_page'] = count( $rows['channel']['item'] ) === 24 ? ++$page : false;
-
- return $return;
- }
-}
diff --git a/src/LaravelCisionFeedProvider.php b/src/LaravelCisionFeedProvider.php
deleted file mode 100644
index cbad269..0000000
--- a/src/LaravelCisionFeedProvider.php
+++ /dev/null
@@ -1,19 +0,0 @@
-
- * Jordi Boggiano
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Composer\Autoload;
-
-/**
- * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
- *
- * $loader = new \Composer\Autoload\ClassLoader();
- *
- * // register classes with namespaces
- * $loader->add('Symfony\Component', __DIR__.'/component');
- * $loader->add('Symfony', __DIR__.'/framework');
- *
- * // activate the autoloader
- * $loader->register();
- *
- * // to enable searching the include path (eg. for PEAR packages)
- * $loader->setUseIncludePath(true);
- *
- * In this example, if you try to use a class in the Symfony\Component
- * namespace or one of its children (Symfony\Component\Console for instance),
- * the autoloader will first look for the class under the component/
- * directory, and it will then fallback to the framework/ directory if not
- * found before giving up.
- *
- * This class is loosely based on the Symfony UniversalClassLoader.
- *
- * @author Fabien Potencier
- * @author Jordi Boggiano
- * @see https://www.php-fig.org/psr/psr-0/
- * @see https://www.php-fig.org/psr/psr-4/
- */
-class ClassLoader
-{
- /** @var ?string */
- private $vendorDir;
-
- // PSR-4
- /**
- * @var array[]
- * @psalm-var array>
- */
- private $prefixLengthsPsr4 = array();
- /**
- * @var array[]
- * @psalm-var array>
- */
- private $prefixDirsPsr4 = array();
- /**
- * @var array[]
- * @psalm-var array
- */
- private $fallbackDirsPsr4 = array();
-
- // PSR-0
- /**
- * @var array[]
- * @psalm-var array>
- */
- private $prefixesPsr0 = array();
- /**
- * @var array[]
- * @psalm-var array
- */
- private $fallbackDirsPsr0 = array();
-
- /** @var bool */
- private $useIncludePath = false;
-
- /**
- * @var string[]
- * @psalm-var array
- */
- private $classMap = array();
-
- /** @var bool */
- private $classMapAuthoritative = false;
-
- /**
- * @var bool[]
- * @psalm-var array
- */
- private $missingClasses = array();
-
- /** @var ?string */
- private $apcuPrefix;
-
- /**
- * @var self[]
- */
- private static $registeredLoaders = array();
-
- /**
- * @param ?string $vendorDir
- */
- public function __construct($vendorDir = null)
- {
- $this->vendorDir = $vendorDir;
- }
-
- /**
- * @return string[]
- */
- public function getPrefixes()
- {
- if (!empty($this->prefixesPsr0)) {
- return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
- }
-
- return array();
- }
-
- /**
- * @return array[]
- * @psalm-return array>
- */
- public function getPrefixesPsr4()
- {
- return $this->prefixDirsPsr4;
- }
-
- /**
- * @return array[]
- * @psalm-return array
- */
- public function getFallbackDirs()
- {
- return $this->fallbackDirsPsr0;
- }
-
- /**
- * @return array[]
- * @psalm-return array
- */
- public function getFallbackDirsPsr4()
- {
- return $this->fallbackDirsPsr4;
- }
-
- /**
- * @return string[] Array of classname => path
- * @psalm-return array
- */
- public function getClassMap()
- {
- return $this->classMap;
- }
-
- /**
- * @param string[] $classMap Class to filename map
- * @psalm-param array $classMap
- *
- * @return void
- */
- public function addClassMap(array $classMap)
- {
- if ($this->classMap) {
- $this->classMap = array_merge($this->classMap, $classMap);
- } else {
- $this->classMap = $classMap;
- }
- }
-
- /**
- * Registers a set of PSR-0 directories for a given prefix, either
- * appending or prepending to the ones previously set for this prefix.
- *
- * @param string $prefix The prefix
- * @param string[]|string $paths The PSR-0 root directories
- * @param bool $prepend Whether to prepend the directories
- *
- * @return void
- */
- public function add($prefix, $paths, $prepend = false)
- {
- if (!$prefix) {
- if ($prepend) {
- $this->fallbackDirsPsr0 = array_merge(
- (array) $paths,
- $this->fallbackDirsPsr0
- );
- } else {
- $this->fallbackDirsPsr0 = array_merge(
- $this->fallbackDirsPsr0,
- (array) $paths
- );
- }
-
- return;
- }
-
- $first = $prefix[0];
- if (!isset($this->prefixesPsr0[$first][$prefix])) {
- $this->prefixesPsr0[$first][$prefix] = (array) $paths;
-
- return;
- }
- if ($prepend) {
- $this->prefixesPsr0[$first][$prefix] = array_merge(
- (array) $paths,
- $this->prefixesPsr0[$first][$prefix]
- );
- } else {
- $this->prefixesPsr0[$first][$prefix] = array_merge(
- $this->prefixesPsr0[$first][$prefix],
- (array) $paths
- );
- }
- }
-
- /**
- * Registers a set of PSR-4 directories for a given namespace, either
- * appending or prepending to the ones previously set for this namespace.
- *
- * @param string $prefix The prefix/namespace, with trailing '\\'
- * @param string[]|string $paths The PSR-4 base directories
- * @param bool $prepend Whether to prepend the directories
- *
- * @throws \InvalidArgumentException
- *
- * @return void
- */
- public function addPsr4($prefix, $paths, $prepend = false)
- {
- if (!$prefix) {
- // Register directories for the root namespace.
- if ($prepend) {
- $this->fallbackDirsPsr4 = array_merge(
- (array) $paths,
- $this->fallbackDirsPsr4
- );
- } else {
- $this->fallbackDirsPsr4 = array_merge(
- $this->fallbackDirsPsr4,
- (array) $paths
- );
- }
- } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
- // Register directories for a new namespace.
- $length = strlen($prefix);
- if ('\\' !== $prefix[$length - 1]) {
- throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
- }
- $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
- $this->prefixDirsPsr4[$prefix] = (array) $paths;
- } elseif ($prepend) {
- // Prepend directories for an already registered namespace.
- $this->prefixDirsPsr4[$prefix] = array_merge(
- (array) $paths,
- $this->prefixDirsPsr4[$prefix]
- );
- } else {
- // Append directories for an already registered namespace.
- $this->prefixDirsPsr4[$prefix] = array_merge(
- $this->prefixDirsPsr4[$prefix],
- (array) $paths
- );
- }
- }
-
- /**
- * Registers a set of PSR-0 directories for a given prefix,
- * replacing any others previously set for this prefix.
- *
- * @param string $prefix The prefix
- * @param string[]|string $paths The PSR-0 base directories
- *
- * @return void
- */
- public function set($prefix, $paths)
- {
- if (!$prefix) {
- $this->fallbackDirsPsr0 = (array) $paths;
- } else {
- $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
- }
- }
-
- /**
- * Registers a set of PSR-4 directories for a given namespace,
- * replacing any others previously set for this namespace.
- *
- * @param string $prefix The prefix/namespace, with trailing '\\'
- * @param string[]|string $paths The PSR-4 base directories
- *
- * @throws \InvalidArgumentException
- *
- * @return void
- */
- public function setPsr4($prefix, $paths)
- {
- if (!$prefix) {
- $this->fallbackDirsPsr4 = (array) $paths;
- } else {
- $length = strlen($prefix);
- if ('\\' !== $prefix[$length - 1]) {
- throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
- }
- $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
- $this->prefixDirsPsr4[$prefix] = (array) $paths;
- }
- }
-
- /**
- * Turns on searching the include path for class files.
- *
- * @param bool $useIncludePath
- *
- * @return void
- */
- public function setUseIncludePath($useIncludePath)
- {
- $this->useIncludePath = $useIncludePath;
- }
-
- /**
- * Can be used to check if the autoloader uses the include path to check
- * for classes.
- *
- * @return bool
- */
- public function getUseIncludePath()
- {
- return $this->useIncludePath;
- }
-
- /**
- * Turns off searching the prefix and fallback directories for classes
- * that have not been registered with the class map.
- *
- * @param bool $classMapAuthoritative
- *
- * @return void
- */
- public function setClassMapAuthoritative($classMapAuthoritative)
- {
- $this->classMapAuthoritative = $classMapAuthoritative;
- }
-
- /**
- * Should class lookup fail if not found in the current class map?
- *
- * @return bool
- */
- public function isClassMapAuthoritative()
- {
- return $this->classMapAuthoritative;
- }
-
- /**
- * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
- *
- * @param string|null $apcuPrefix
- *
- * @return void
- */
- public function setApcuPrefix($apcuPrefix)
- {
- $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
- }
-
- /**
- * The APCu prefix in use, or null if APCu caching is not enabled.
- *
- * @return string|null
- */
- public function getApcuPrefix()
- {
- return $this->apcuPrefix;
- }
-
- /**
- * Registers this instance as an autoloader.
- *
- * @param bool $prepend Whether to prepend the autoloader or not
- *
- * @return void
- */
- public function register($prepend = false)
- {
- spl_autoload_register(array($this, 'loadClass'), true, $prepend);
-
- if (null === $this->vendorDir) {
- return;
- }
-
- if ($prepend) {
- self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
- } else {
- unset(self::$registeredLoaders[$this->vendorDir]);
- self::$registeredLoaders[$this->vendorDir] = $this;
- }
- }
-
- /**
- * Unregisters this instance as an autoloader.
- *
- * @return void
- */
- public function unregister()
- {
- spl_autoload_unregister(array($this, 'loadClass'));
-
- if (null !== $this->vendorDir) {
- unset(self::$registeredLoaders[$this->vendorDir]);
- }
- }
-
- /**
- * Loads the given class or interface.
- *
- * @param string $class The name of the class
- * @return true|null True if loaded, null otherwise
- */
- public function loadClass($class)
- {
- if ($file = $this->findFile($class)) {
- includeFile($file);
-
- return true;
- }
-
- return null;
- }
-
- /**
- * Finds the path to the file where the class is defined.
- *
- * @param string $class The name of the class
- *
- * @return string|false The path if found, false otherwise
- */
- public function findFile($class)
- {
- // class map lookup
- if (isset($this->classMap[$class])) {
- return $this->classMap[$class];
- }
- if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
- return false;
- }
- if (null !== $this->apcuPrefix) {
- $file = apcu_fetch($this->apcuPrefix.$class, $hit);
- if ($hit) {
- return $file;
- }
- }
-
- $file = $this->findFileWithExtension($class, '.php');
-
- // Search for Hack files if we are running on HHVM
- if (false === $file && defined('HHVM_VERSION')) {
- $file = $this->findFileWithExtension($class, '.hh');
- }
-
- if (null !== $this->apcuPrefix) {
- apcu_add($this->apcuPrefix.$class, $file);
- }
-
- if (false === $file) {
- // Remember that this class does not exist.
- $this->missingClasses[$class] = true;
- }
-
- return $file;
- }
-
- /**
- * Returns the currently registered loaders indexed by their corresponding vendor directories.
- *
- * @return self[]
- */
- public static function getRegisteredLoaders()
- {
- return self::$registeredLoaders;
- }
-
- /**
- * @param string $class
- * @param string $ext
- * @return string|false
- */
- private function findFileWithExtension($class, $ext)
- {
- // PSR-4 lookup
- $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
-
- $first = $class[0];
- if (isset($this->prefixLengthsPsr4[$first])) {
- $subPath = $class;
- while (false !== $lastPos = strrpos($subPath, '\\')) {
- $subPath = substr($subPath, 0, $lastPos);
- $search = $subPath . '\\';
- if (isset($this->prefixDirsPsr4[$search])) {
- $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
- foreach ($this->prefixDirsPsr4[$search] as $dir) {
- if (file_exists($file = $dir . $pathEnd)) {
- return $file;
- }
- }
- }
- }
- }
-
- // PSR-4 fallback dirs
- foreach ($this->fallbackDirsPsr4 as $dir) {
- if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
- return $file;
- }
- }
-
- // PSR-0 lookup
- if (false !== $pos = strrpos($class, '\\')) {
- // namespaced class name
- $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
- . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
- } else {
- // PEAR-like class name
- $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
- }
-
- if (isset($this->prefixesPsr0[$first])) {
- foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
- if (0 === strpos($class, $prefix)) {
- foreach ($dirs as $dir) {
- if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
- return $file;
- }
- }
- }
- }
- }
-
- // PSR-0 fallback dirs
- foreach ($this->fallbackDirsPsr0 as $dir) {
- if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
- return $file;
- }
- }
-
- // PSR-0 include paths.
- if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
- return $file;
- }
-
- return false;
- }
-}
-
-/**
- * Scope isolated include.
- *
- * Prevents access to $this/self from included files.
- *
- * @param string $file
- * @return void
- * @private
- */
-function includeFile($file)
-{
- include $file;
-}
diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php
deleted file mode 100644
index b26f1b1..0000000
--- a/vendor/composer/autoload_classmap.php
+++ /dev/null
@@ -1,10 +0,0 @@
- $vendorDir . '/composer/InstalledVersions.php',
-);
diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php
deleted file mode 100644
index b7fc012..0000000
--- a/vendor/composer/autoload_namespaces.php
+++ /dev/null
@@ -1,9 +0,0 @@
- array($baseDir . '/src'),
-);
diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php
deleted file mode 100644
index 818f1f1..0000000
--- a/vendor/composer/autoload_real.php
+++ /dev/null
@@ -1,55 +0,0 @@
-= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
- if ($useStaticLoader) {
- require __DIR__ . '/autoload_static.php';
-
- call_user_func(\Composer\Autoload\ComposerStaticInita551a78ff0c5533943a66fc25192491f::getInitializer($loader));
- } else {
- $map = require __DIR__ . '/autoload_namespaces.php';
- foreach ($map as $namespace => $path) {
- $loader->set($namespace, $path);
- }
-
- $map = require __DIR__ . '/autoload_psr4.php';
- foreach ($map as $namespace => $path) {
- $loader->setPsr4($namespace, $path);
- }
-
- $classMap = require __DIR__ . '/autoload_classmap.php';
- if ($classMap) {
- $loader->addClassMap($classMap);
- }
- }
-
- $loader->register(true);
-
- return $loader;
- }
-}
diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php
deleted file mode 100644
index 5d56271..0000000
--- a/vendor/composer/autoload_static.php
+++ /dev/null
@@ -1,36 +0,0 @@
-
- array (
- 'Mathiaspalmqvist\\LaravelCisionFeed\\' => 35,
- ),
- );
-
- public static $prefixDirsPsr4 = array (
- 'Mathiaspalmqvist\\LaravelCisionFeed\\' =>
- array (
- 0 => __DIR__ . '/../..' . '/src',
- ),
- );
-
- public static $classMap = array (
- 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
- );
-
- public static function getInitializer(ClassLoader $loader)
- {
- return \Closure::bind(function () use ($loader) {
- $loader->prefixLengthsPsr4 = ComposerStaticInita551a78ff0c5533943a66fc25192491f::$prefixLengthsPsr4;
- $loader->prefixDirsPsr4 = ComposerStaticInita551a78ff0c5533943a66fc25192491f::$prefixDirsPsr4;
- $loader->classMap = ComposerStaticInita551a78ff0c5533943a66fc25192491f::$classMap;
-
- }, null, ClassLoader::class);
- }
-}
From 8721901494d36e54fa03b5f83f04162bd4dba9cd Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 20:05:00 +0200
Subject: [PATCH 03/10] Added git
---
.github/FUNDING.yml | 1 +
.github/ISSUE_TEMPLATE/bug.yml | 66 ++++++++++++++++
.github/ISSUE_TEMPLATE/config.yml | 11 +++
.github/dependabot.yml | 19 +++++
.github/workflows/dependabot-auto-merge.yml | 33 ++++++++
.../workflows/fix-php-code-style-issues.yml | 28 +++++++
.github/workflows/phpstan.yml | 28 +++++++
.github/workflows/run-tests.yml | 77 +++++++++++++++++++
.github/workflows/update-changelog.yml | 32 ++++++++
9 files changed, 295 insertions(+)
create mode 100644 .github/FUNDING.yml
create mode 100644 .github/ISSUE_TEMPLATE/bug.yml
create mode 100644 .github/ISSUE_TEMPLATE/config.yml
create mode 100644 .github/dependabot.yml
create mode 100644 .github/workflows/dependabot-auto-merge.yml
create mode 100644 .github/workflows/fix-php-code-style-issues.yml
create mode 100644 .github/workflows/phpstan.yml
create mode 100644 .github/workflows/run-tests.yml
create mode 100644 .github/workflows/update-changelog.yml
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..9e5cabb
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+github: Mattitja AB
diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml
new file mode 100644
index 0000000..8136330
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug.yml
@@ -0,0 +1,66 @@
+name: Bug Report
+description: Report an Issue or Bug with the Package
+title: "[Bug]: "
+labels: ["bug"]
+body:
+ - type: markdown
+ attributes:
+ value: |
+ We're sorry to hear you have a problem. Can you help us solve it by providing the following details.
+ - type: textarea
+ id: what-happened
+ attributes:
+ label: What happened?
+ description: What did you expect to happen?
+ placeholder: I cannot currently do X thing because when I do, it breaks X thing.
+ validations:
+ required: true
+ - type: textarea
+ id: how-to-reproduce
+ attributes:
+ label: How to reproduce the bug
+ description: How did this occur, please add any config values used and provide a set of reliable steps if possible.
+ placeholder: When I do X I see Y.
+ validations:
+ required: true
+ - type: input
+ id: package-version
+ attributes:
+ label: Package Version
+ description: What version of our Package are you running? Please be as specific as possible
+ placeholder: 2.0.0
+ validations:
+ required: true
+ - type: input
+ id: php-version
+ attributes:
+ label: PHP Version
+ description: What version of PHP are you running? Please be as specific as possible
+ placeholder: 8.2.0
+ validations:
+ required: true
+ - type: input
+ id: laravel-version
+ attributes:
+ label: Laravel Version
+ description: What version of Laravel are you running? Please be as specific as possible
+ placeholder: 9.0.0
+ validations:
+ required: true
+ - type: dropdown
+ id: operating-systems
+ attributes:
+ label: Which operating systems does this happen with?
+ description: You may select more than one.
+ multiple: true
+ options:
+ - macOS
+ - Windows
+ - Linux
+ - type: textarea
+ id: notes
+ attributes:
+ label: Notes
+ description: Use this field to provide any other notes that you feel might be relevant to the issue.
+ validations:
+ required: false
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..f9fdcd6
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,11 @@
+blank_issues_enabled: false
+contact_links:
+ - name: Ask a question
+ url: https://github.com/mattitjaab/laravel-cision-feed/discussions/new?category=q-a
+ about: Ask the community for help
+ - name: Request a feature
+ url: https://github.com/mattitjaab/laravel-cision-feed/discussions/new?category=ideas
+ about: Share ideas for new features
+ - name: Report a security issue
+ url: https://github.com/mattitjaab/laravel-cision-feed/security/policy
+ about: Learn how to notify us for sensitive bugs
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..39b1580
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,19 @@
+# Please see the documentation for all configuration options:
+# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+
+version: 2
+updates:
+
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ labels:
+ - "dependencies"
+
+ - package-ecosystem: "composer"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ labels:
+ - "dependencies"
diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml
new file mode 100644
index 0000000..cc8c94c
--- /dev/null
+++ b/.github/workflows/dependabot-auto-merge.yml
@@ -0,0 +1,33 @@
+name: dependabot-auto-merge
+on: pull_request_target
+
+permissions:
+ pull-requests: write
+ contents: write
+
+jobs:
+ dependabot:
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ if: ${{ github.actor == 'dependabot[bot]' }}
+ steps:
+
+ - name: Dependabot metadata
+ id: metadata
+ uses: dependabot/fetch-metadata@v2.4.0
+ with:
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
+
+ - name: Auto-merge Dependabot PRs for semver-minor updates
+ if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
+ run: gh pr merge --auto --merge "$PR_URL"
+ env:
+ PR_URL: ${{github.event.pull_request.html_url}}
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
+
+ - name: Auto-merge Dependabot PRs for semver-patch updates
+ if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
+ run: gh pr merge --auto --merge "$PR_URL"
+ env:
+ PR_URL: ${{github.event.pull_request.html_url}}
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml
new file mode 100644
index 0000000..1ec8dbf
--- /dev/null
+++ b/.github/workflows/fix-php-code-style-issues.yml
@@ -0,0 +1,28 @@
+name: Fix PHP code style issues
+
+on:
+ push:
+ paths:
+ - '**.php'
+
+permissions:
+ contents: write
+
+jobs:
+ php-code-styling:
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+ with:
+ ref: ${{ github.head_ref }}
+
+ - name: Fix PHP code style issues
+ uses: aglipanci/laravel-pint-action@2.5
+
+ - name: Commit changes
+ uses: stefanzweifel/git-auto-commit-action@v5
+ with:
+ commit_message: Fix styling
diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml
new file mode 100644
index 0000000..43a82b4
--- /dev/null
+++ b/.github/workflows/phpstan.yml
@@ -0,0 +1,28 @@
+name: PHPStan
+
+on:
+ push:
+ paths:
+ - '**.php'
+ - 'phpstan.neon.dist'
+ - '.github/workflows/phpstan.yml'
+
+jobs:
+ phpstan:
+ name: phpstan
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: '8.4'
+ coverage: none
+
+ - name: Install composer dependencies
+ uses: ramsey/composer-install@v3
+
+ - name: Run PHPStan
+ run: ./vendor/bin/phpstan --error-format=github
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
new file mode 100644
index 0000000..2b393b7
--- /dev/null
+++ b/.github/workflows/run-tests.yml
@@ -0,0 +1,77 @@
+name: run-tests
+
+on:
+ push:
+ paths:
+ - '**.php'
+ - '.github/workflows/run-tests.yml'
+ - 'phpunit.xml.dist'
+ - 'composer.json'
+ - 'composer.lock'
+
+jobs:
+ test:
+ runs-on: ${{ matrix.os }}
+ timeout-minutes: 5
+ strategy:
+ fail-fast: true
+ matrix:
+ os: [ubuntu-latest]
+ php: [8.3, 8.4]
+ laravel: [11.*, 12.*]
+ stability: [prefer-lowest, prefer-stable]
+ include:
+ - laravel: 11.*
+ php: 8.3
+ testbench: 9.*
+ carbon: ^2.63
+ - laravel: 11.*
+ php: 8.4
+ testbench: 9.*
+ carbon: ^2.63
+ - laravel: 12.*
+ php: 8.3
+ testbench: 10.*
+ carbon: ^3.8.4
+ - laravel: 12.*
+ php: 8.4
+ testbench: 10.*
+ carbon: ^3.8.4
+
+ name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
+ coverage: none
+
+ - name: Setup problem matchers
+ run: |
+ echo "::add-matcher::${{ runner.tool_cache }}/php.json"
+ echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
+
+ - name: Remove Larastan if Laravel 12
+ if: startsWith(matrix.laravel, '12.')
+ run: composer remove larastan/larastan --dev --no-update || true
+
+ - name: Install dependencies
+ run: |
+ composer require \
+ "laravel/framework:${{ matrix.laravel }}" \
+ "orchestra/testbench:${{ matrix.testbench }}" \
+ "nesbot/carbon:${{ matrix.carbon }}" \
+ --no-interaction --no-update
+
+ composer update --${{ matrix.stability }} --prefer-dist --no-interaction
+
+ - name: List Installed Dependencies
+ run: composer show -D
+
+ - name: Execute tests
+ run: vendor/bin/pest --ci
diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml
new file mode 100644
index 0000000..39de30d
--- /dev/null
+++ b/.github/workflows/update-changelog.yml
@@ -0,0 +1,32 @@
+name: "Update Changelog"
+
+on:
+ release:
+ types: [released]
+
+permissions:
+ contents: write
+
+jobs:
+ update:
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+ with:
+ ref: main
+
+ - name: Update Changelog
+ uses: stefanzweifel/changelog-updater-action@v1
+ with:
+ latest-version: ${{ github.event.release.name }}
+ release-notes: ${{ github.event.release.body }}
+
+ - name: Commit updated CHANGELOG
+ uses: stefanzweifel/git-auto-commit-action@v5
+ with:
+ branch: main
+ commit_message: Update CHANGELOG
+ file_pattern: CHANGELOG.md
From 236bdc258d60148e119e092d9bb258f37cb9eb98 Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 20:12:12 +0200
Subject: [PATCH 04/10] Update .gitignore
---
.gitignore | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 1f1025f..32b7e32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
.idea
-.DS_Store
\ No newline at end of file
+.DS_Store
+vendor
+composer.lock
From 6d3092c736a75d579dc4875c3067b1cc1f9b8cdc Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 20:12:17 +0200
Subject: [PATCH 05/10] Update composer.json
---
composer.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/composer.json b/composer.json
index c506d37..9bec4e5 100644
--- a/composer.json
+++ b/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^8.4",
+ "php": "^8.3",
"spatie/laravel-package-tools": "^1.16",
"illuminate/contracts": "^10.0||^11.0||^12.0"
},
@@ -36,7 +36,7 @@
},
"autoload": {
"psr-4": {
- "Mattitja\\Cision\\": "src/",
+ "Mattitja\\Cision\\": "src/"
}
},
"autoload-dev": {
From b325fff158cdbd1af65e693b0e0d917024636541 Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 21:04:05 +0200
Subject: [PATCH 06/10] Refactor
---
composer.json | 6 +-
src/Cision.php | 40 +++++++++++++-
src/Support/HtmlCleaner.php | 107 ++++++++++++++++++++++++++++++++++++
3 files changed, 150 insertions(+), 3 deletions(-)
create mode 100644 src/Support/HtmlCleaner.php
diff --git a/composer.json b/composer.json
index 9bec4e5..fd5e3a7 100644
--- a/composer.json
+++ b/composer.json
@@ -18,8 +18,10 @@
],
"require": {
"php": "^8.3",
+ "illuminate/contracts": "^10.0||^11.0||^12.0",
"spatie/laravel-package-tools": "^1.16",
- "illuminate/contracts": "^10.0||^11.0||^12.0"
+ "symfony/css-selector": "7.4.x-dev",
+ "symfony/dom-crawler": "7.4.x-dev"
},
"require-dev": {
"laravel/pint": "^1.14",
@@ -71,5 +73,5 @@
}
},
"minimum-stability": "dev",
- "prefer-stable": true
+ "prefer-stable": false
}
diff --git a/src/Cision.php b/src/Cision.php
index 3369cd6..430c1bc 100755
--- a/src/Cision.php
+++ b/src/Cision.php
@@ -5,11 +5,16 @@ namespace Mattitja\Cision;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\Response;
+use Symfony\Component\DomCrawler\Crawler;
+use Mattitja\Cision\Support\HtmlCleaner;
class Cision
{
protected string $slug;
+ /**
+ * Constructor that accepts a slug identifier for the feed.
+ */
public function __construct(string $slug = null)
{
$this->slug = $slug ?? env('LARAVEL_CISION_FEED_SLUG', '');
@@ -51,6 +56,39 @@ class Cision
return $this->parseResponse($response->body(), $page);
}
+ /**
+ * Fetch and parse the HTML content of a Cision article URL.
+ */
+ public function fetchContent(string $url): array
+ {
+ $html = Http::get($url)->body();
+ $crawler = new Crawler($html);
+
+ $article = $crawler->filter('article')->first();
+
+ $header = trim($article->filter('h1')->text());
+ $publishedAt = $article->filter('time')->attr('datetime');
+
+ $allowedTags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li'];
+ $allowedInline = ['strong', 'b', 'em', 'i', 'br'];
+
+ $content = [];
+
+ foreach ($article as $node) {
+ foreach ($node->childNodes as $child) {
+ $content[] = HtmlCleaner::renderNode($child, $allowedTags, $allowedInline);
+ }
+ }
+
+ $cleaned = HtmlCleaner::clean(implode("\n", array_filter($content)));
+
+ return [
+ 'header' => $header,
+ 'published_at' => $publishedAt,
+ 'content' => $cleaned,
+ ];
+ }
+
protected function makeRequest(int $page, ?string $type = null): Response|false
{
if (empty($this->slug)) {
@@ -102,4 +140,4 @@ class Cision
'next_page' => count($items) === 24 ? $page + 1 : false,
];
}
-}
\ No newline at end of file
+}
diff --git a/src/Support/HtmlCleaner.php b/src/Support/HtmlCleaner.php
new file mode 100644
index 0000000..6dd7383
--- /dev/null
+++ b/src/Support/HtmlCleaner.php
@@ -0,0 +1,107 @@
+wholeText;
+ }
+
+ if (!($node instanceof DOMElement)) {
+ return null;
+ }
+
+ $tag = $node->nodeName;
+
+ // Special case: handle
within
+ if ($tag === 'br') {
+ if ($parentTag === 'p') {
+ $prev = $node->previousSibling;
+ $next = $node->nextSibling;
+
+ $hasTextBefore = $prev instanceof DOMText && trim($prev->textContent) !== '';
+ $hasTextAfter = $next instanceof DOMText && trim($next->textContent) !== '';
+
+ if ($hasTextBefore && $hasTextAfter) {
+ return '
';
+ }
+ }
+
+ // Skip all other
+ return null;
+ }
+
+ // Recursively render children
+ $inner = '';
+ foreach ($node->childNodes as $child) {
+ $rendered = self::renderNode($child, $allowedTags, $allowedInline, $tag);
+ if ($rendered !== null) {
+ $inner .= $rendered;
+ }
+ }
+
+ // Handle block tags
+ if (in_array($tag, $allowedTags)) {
+ if ($tag === 'p') {
+ $html = $node->C14N();
+ $isItalic = str_starts_with(trim($html), '" . trim($inner) . "
";
+ }
+
+ return "<{$tag}>" . trim($inner) . "{$tag}>";
+ }
+
+ // Handle inline tags
+ if (in_array($tag, $allowedInline)) {
+ return "<{$tag}>{$inner}{$tag}>";
+ }
+
+ // Unknown tags are ignored but their content is preserved
+ return $inner;
+ }
+
+ /**
+ * Clean a raw HTML string: remove unwanted tags, empty elements, garbage phrases, and excessive whitespace.
+ */
+ public static function clean(string $html): string
+ {
+ // Remove first
+ $html = preg_replace('/]*>.*?<\/h1>/i', '', $html, 1);
+
+ // Remove empty tags like ,
+ $html = preg_replace('/<(\w+)[^>]*>\s*<\/\1>/', '', $html);
+
+ // Remove specific garbage strings
+ $unwantedStrings = [
+ 'Report this content',
+ '
Taggar:
',
+ ];
+
+ foreach ($unwantedStrings as $str) {
+ $html = str_replace($str, '', $html);
+ }
+
+ // Remove localized date lines like: fre, jul 04, 2025 09:55 CET
+ $html = preg_replace('/\b[a-z]{3},\s[a-z]{3}\s\d{2},\s\d{4}\s\d{2}:\d{2}\sCET\b/i', '', $html);
+
+ // Normalize whitespace
+ $html = str_replace(["\u{A0}", "\t", "\r"], ' ', $html); // Remove non-breaking spaces and tabs
+ $html = preg_replace('/[ ]{2,}/', ' ', $html); // Collapse double spaces
+ $html = preg_replace("/(\n\s*){2,}/", "\n", $html); // Collapse multiple newlines
+ $html = str_replace([' ', ' \n'], '', $html); // Additional spacing clean
+ $html = trim($html);
+
+ return $html;
+ }
+}
\ No newline at end of file
From 0c54185f1f98a9c7d1a8630f2ece6b0d9f78bbb1 Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 21:10:51 +0200
Subject: [PATCH 07/10] Update HtmlCleaner.php
---
src/Support/HtmlCleaner.php | 33 +++++++++------------------------
1 file changed, 9 insertions(+), 24 deletions(-)
diff --git a/src/Support/HtmlCleaner.php b/src/Support/HtmlCleaner.php
index 6dd7383..dfac263 100644
--- a/src/Support/HtmlCleaner.php
+++ b/src/Support/HtmlCleaner.php
@@ -9,7 +9,7 @@ use DOMElement;
class HtmlCleaner
{
/**
- * Render a DOM node into safe HTML, preserving allowed block and inline tags.
+ * Renders a DOM node into safe HTML, preserving only allowed tags.
*/
public static function renderNode(DOMNode $node, array $allowedTags, array $allowedInline, string $parentTag = ''): ?string
{
@@ -23,7 +23,6 @@ class HtmlCleaner
$tag = $node->nodeName;
- // Special case: handle
within
if ($tag === 'br') {
if ($parentTag === 'p') {
$prev = $node->previousSibling;
@@ -36,13 +35,11 @@ class HtmlCleaner
return '
';
}
}
-
- // Skip all other
return null;
}
- // Recursively render children
$inner = '';
+
foreach ($node->childNodes as $child) {
$rendered = self::renderNode($child, $allowedTags, $allowedInline, $tag);
if ($rendered !== null) {
@@ -50,7 +47,6 @@ class HtmlCleaner
}
}
- // Handle block tags
if (in_array($tag, $allowedTags)) {
if ($tag === 'p') {
$html = $node->C14N();
@@ -58,31 +54,24 @@ class HtmlCleaner
$class = $isItalic ? ' class="italic"' : '';
return "
" . trim($inner) . "
";
}
-
return "<{$tag}>" . trim($inner) . "{$tag}>";
}
- // Handle inline tags
if (in_array($tag, $allowedInline)) {
return "<{$tag}>{$inner}{$tag}>";
}
- // Unknown tags are ignored but their content is preserved
return $inner;
}
/**
- * Clean a raw HTML string: remove unwanted tags, empty elements, garbage phrases, and excessive whitespace.
+ * Cleans a raw HTML string: removes unwanted content, empty tags, and excess whitespace.
*/
public static function clean(string $html): string
{
- // Remove first
$html = preg_replace('/]*>.*?<\/h1>/i', '', $html, 1);
-
- // Remove empty tags like ,
$html = preg_replace('/<(\w+)[^>]*>\s*<\/\1>/', '', $html);
- // Remove specific garbage strings
$unwantedStrings = [
'Report this content',
'
Taggar:
',
@@ -92,16 +81,12 @@ class HtmlCleaner
$html = str_replace($str, '', $html);
}
- // Remove localized date lines like: fre, jul 04, 2025 09:55 CET
$html = preg_replace('/\b[a-z]{3},\s[a-z]{3}\s\d{2},\s\d{4}\s\d{2}:\d{2}\sCET\b/i', '', $html);
+ $html = str_replace(["\u{A0}", "\t", "\r"], ' ', $html);
+ $html = preg_replace('/[ ]{2,}/', ' ', $html);
+ $html = preg_replace("/(\n\s*){2,}/", "\n", $html);
+ $html = str_replace([' ', ' \n'], '', $html);
- // Normalize whitespace
- $html = str_replace(["\u{A0}", "\t", "\r"], ' ', $html); // Remove non-breaking spaces and tabs
- $html = preg_replace('/[ ]{2,}/', ' ', $html); // Collapse double spaces
- $html = preg_replace("/(\n\s*){2,}/", "\n", $html); // Collapse multiple newlines
- $html = str_replace([' ', ' \n'], '', $html); // Additional spacing clean
- $html = trim($html);
-
- return $html;
+ return trim($html);
}
-}
\ No newline at end of file
+}
From 6efcb252e1bb6e3a74ceb8e46e8b6696944b0033 Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 21:21:27 +0200
Subject: [PATCH 08/10] Added tests
---
Tests/ArchTest.php | 5 +++++
Tests/CisionTest.php | 34 +++++++++++++++++++++++++++++++++
Tests/Fixtures/article.html | 12 ++++++++++++
Tests/Fixtures/rss-press.xml | 13 +++++++++++++
Tests/Pest.php | 5 +++++
Tests/TestCase.php | 37 ++++++++++++++++++++++++++++++++++++
src/Cision.php | 19 ++++++++++++++----
7 files changed, 121 insertions(+), 4 deletions(-)
create mode 100644 Tests/ArchTest.php
create mode 100644 Tests/CisionTest.php
create mode 100644 Tests/Fixtures/article.html
create mode 100644 Tests/Fixtures/rss-press.xml
create mode 100644 Tests/Pest.php
create mode 100644 Tests/TestCase.php
diff --git a/Tests/ArchTest.php b/Tests/ArchTest.php
new file mode 100644
index 0000000..e5be658
--- /dev/null
+++ b/Tests/ArchTest.php
@@ -0,0 +1,5 @@
+expect(['dd', 'dump', 'ray'])
+ ->each->not->toBeUsed();
\ No newline at end of file
diff --git a/Tests/CisionTest.php b/Tests/CisionTest.php
new file mode 100644
index 0000000..8cdb18b
--- /dev/null
+++ b/Tests/CisionTest.php
@@ -0,0 +1,34 @@
+ Http::response(file_get_contents(__DIR__.'/Fixtures/rss-press.xml')),
+ ]);
+
+ $cision = new Cision('test-company');
+ $data = $cision->press();
+
+ expect($data)->toBeArray();
+ expect($data)->toHaveKey('items');
+ expect($data['items'])->not->toBeEmpty();
+
+ $item = $data['items'][0];
+ expect($item)->toHaveKeys(['guid', 'title', 'description', 'link', 'created_at']);
+});
+
+it('can fetch and parse full article content', function () {
+ Http::fake([
+ 'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')),
+ ]);
+
+ $cision = new Cision();
+ $content = $cision->fetchContent('https://news.cision.com/se/example/r/test,c123456');
+
+ expect($content)->toHaveKeys(['header', 'published_at', 'content']);
+ expect($content['header'])->not->toBeEmpty();
+ expect($content['content'])->toContain('
+
+
Test Article Header
+
+
Lead: This is a test article paragraph.
+
Italic sentence.
+
+
+
diff --git a/Tests/Fixtures/rss-press.xml b/Tests/Fixtures/rss-press.xml
new file mode 100644
index 0000000..857c9be
--- /dev/null
+++ b/Tests/Fixtures/rss-press.xml
@@ -0,0 +1,13 @@
+
+
+
+ Test Press Releases
+ -
+ test-guid
+ Test Press Title
+ This is a test press release description.
+ https://news.cision.com/se/example/r/test,c123456
+ Fri, 04 Jul 2025 07:55:00 GMT
+
+
+
diff --git a/Tests/Pest.php b/Tests/Pest.php
new file mode 100644
index 0000000..45c3e5c
--- /dev/null
+++ b/Tests/Pest.php
@@ -0,0 +1,5 @@
+in(__DIR__);
\ No newline at end of file
diff --git a/Tests/TestCase.php b/Tests/TestCase.php
new file mode 100644
index 0000000..7d25c9e
--- /dev/null
+++ b/Tests/TestCase.php
@@ -0,0 +1,37 @@
+ 'Mattitja\\Cision\\Database\\Factories\\'.class_basename($modelName).'Factory'
+ );
+ }
+
+ protected function getPackageProviders($app)
+ {
+ return [
+ CisionServiceProvider::class,
+ ];
+ }
+
+ public function getEnvironmentSetUp($app)
+ {
+ config()->set('database.default', 'testing');
+
+ /*
+ foreach (\Illuminate\Support\Facades\File::allFiles(__DIR__ . '/database/migrations') as $migration) {
+ (include $migration->getRealPath())->up();
+ }
+ */
+ }
+}
\ No newline at end of file
diff --git a/src/Cision.php b/src/Cision.php
index 430c1bc..1bff21f 100755
--- a/src/Cision.php
+++ b/src/Cision.php
@@ -114,30 +114,41 @@ class Cision
return false;
}
+ // Suppress XML parsing warnings
+ libxml_use_internal_errors(true);
$xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
+ libxml_clear_errors();
+
if ($xml === false) {
return false;
}
+ // Convert XML to JSON then to array
$json = json_encode($xml);
$rows = json_decode($json, true);
+ // Validate structure
if (!isset($rows['channel']['item'])) {
return false;
}
- $items = array_map(fn ($item) => [
+ // Ensure 'item' is always an array
+ $items = $rows['channel']['item'];
+ $items = isset($items[0]) ? $items : [$items];
+
+ // Format the result
+ $formatted = array_map(fn ($item) => [
'guid' => $item['guid'],
'title' => $item['title'],
'description' => $item['description'],
'link' => $item['link'],
'created_at' => Carbon::parse($item['pubDate'])->addHours(2)->format('Y-m-d H:i:s'),
- ], $rows['channel']['item']);
+ ], $items);
return [
- 'items' => $items,
+ 'items' => $formatted,
'previous_page' => $page > 1 ? $page - 1 : false,
- 'next_page' => count($items) === 24 ? $page + 1 : false,
+ 'next_page' => count($formatted) === 24 ? $page + 1 : false,
];
}
}
From db87a5d45f6dcf01df21ac631ccf1e1a2f013cb6 Mon Sep 17 00:00:00 2001
From: Mathias Palmqvist
Date: Fri, 4 Jul 2025 21:21:30 +0200
Subject: [PATCH 09/10] Update readme.md
---
readme.md | 64 +++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 48 insertions(+), 16 deletions(-)
diff --git a/readme.md b/readme.md
index 21f99cd..4026f90 100644
--- a/readme.md
+++ b/readme.md
@@ -1,58 +1,90 @@
-# This is my package laravel-cision-feed
+# Laravel Cision Feed
[](https://packagist.org/packages/mattitjaab/laravel-cision-feed)
[](https://github.com/mattitjaab/laravel-cision-feed/actions?query=workflow%3Arun-tests+branch%3Amain)
-[](https://github.com/mattitjaab/laravel-cision-feed/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
+[](https://github.com/mattitjaab/laravel-cision-feed/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)
[](https://packagist.org/packages/mattitjaab/laravel-cision-feed)
-This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
+A Laravel package for retrieving and parsing data from [Cision News](https://news.cision.com/se). Fetch press releases, financial reports, media posts, and structured article content using a simple and expressive API.
-## Support us
+---
-[
](https://spatie.be/github-ad-click/laravel-cision-feed)
+## Features
-We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
+- Retrieve Cision RSS feeds by type (Press, News, Financial, Media)
+- Parse article pages and extract clean structured HTML
+- Automatically handles encoding, formatting, and clean-up of content
+- Fully testable and extensible
-We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
+---
## Installation
-You can install the package via composer:
-
```bash
composer require mattitjaab/laravel-cision-feed
```
+You may optionally set your Cision slug in your `.env`:
+
+```
+LARAVEL_CISION_FEED_SLUG=your-cision-slug
+```
+
+---
+
## Usage
```php
-$cision = new Mattitja\Cision();
-echo $cision->echoPhrase('Hello, Mattitja!');
+use Mattitja\Cision\Cision;
+
+$cision = new Cision();
+
+// Fetch RSS entries
+$items = $cision->press(); // or ->news(), ->financial(), ->media()
+
+// Fetch full content for a specific article
+$article = $cision->fetchContent('https://news.cision.com/se/example-company/r/your-article-slug,c1234567');
+
+echo $article['header']; // Article headline
+echo $article['published_at']; // ISO timestamp
+echo $article['content']; // Clean HTML
```
+---
+
## Testing
```bash
composer test
```
+---
+
## Changelog
-Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
+See [CHANGELOG](CHANGELOG.md) for recent changes.
+
+---
## Contributing
-Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
+Contributions are welcome! Please see [CONTRIBUTING](CONTRIBUTING.md) for guidelines.
-## Security Vulnerabilities
+---
-Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
+## Security
+
+If you discover any security-related issues, please refer to our [security policy](../../security/policy).
+
+---
## Credits
- [Mattitja AB](https://github.com/MattitjaAB)
- [All Contributors](../../contributors)
+---
+
## License
-The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
+The MIT License (MIT). See [LICENSE](LICENSE.md) for details.
From aee28b34500562311ff7eac6359cc771a4d11fd1 Mon Sep 17 00:00:00 2001
From: mathiaspalmqvist <51116221+mathiaspalmqvist@users.noreply.github.com>
Date: Fri, 4 Jul 2025 19:21:52 +0000
Subject: [PATCH 10/10] Fix styling
---
Tests/ArchTest.php | 2 +-
Tests/CisionTest.php | 5 ++---
Tests/Pest.php | 2 +-
Tests/TestCase.php | 2 +-
src/Cision.php | 12 ++++++------
src/CisionServiceProvider.php | 1 -
src/Support/HtmlCleaner.php | 11 +++++++----
7 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/Tests/ArchTest.php b/Tests/ArchTest.php
index e5be658..87fb64c 100644
--- a/Tests/ArchTest.php
+++ b/Tests/ArchTest.php
@@ -2,4 +2,4 @@
arch('it will not use debugging functions')
->expect(['dd', 'dump', 'ray'])
- ->each->not->toBeUsed();
\ No newline at end of file
+ ->each->not->toBeUsed();
diff --git a/Tests/CisionTest.php b/Tests/CisionTest.php
index 8cdb18b..da78677 100644
--- a/Tests/CisionTest.php
+++ b/Tests/CisionTest.php
@@ -1,8 +1,7 @@
Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')),
]);
- $cision = new Cision();
+ $cision = new Cision;
$content = $cision->fetchContent('https://news.cision.com/se/example/r/test,c123456');
expect($content)->toHaveKeys(['header', 'published_at', 'content']);
diff --git a/Tests/Pest.php b/Tests/Pest.php
index 45c3e5c..2423448 100644
--- a/Tests/Pest.php
+++ b/Tests/Pest.php
@@ -2,4 +2,4 @@
use Mattitja\Cision\Tests\TestCase;
-uses(TestCase::class)->in(__DIR__);
\ No newline at end of file
+uses(TestCase::class)->in(__DIR__);
diff --git a/Tests/TestCase.php b/Tests/TestCase.php
index 7d25c9e..141d203 100644
--- a/Tests/TestCase.php
+++ b/Tests/TestCase.php
@@ -34,4 +34,4 @@ class TestCase extends Orchestra
}
*/
}
-}
\ No newline at end of file
+}
diff --git a/src/Cision.php b/src/Cision.php
index 1bff21f..d829d00 100755
--- a/src/Cision.php
+++ b/src/Cision.php
@@ -3,10 +3,10 @@
namespace Mattitja\Cision;
use Carbon\Carbon;
-use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\Response;
-use Symfony\Component\DomCrawler\Crawler;
+use Illuminate\Support\Facades\Http;
use Mattitja\Cision\Support\HtmlCleaner;
+use Symfony\Component\DomCrawler\Crawler;
class Cision
{
@@ -15,7 +15,7 @@ class Cision
/**
* Constructor that accepts a slug identifier for the feed.
*/
- public function __construct(string $slug = null)
+ public function __construct(?string $slug = null)
{
$this->slug = $slug ?? env('LARAVEL_CISION_FEED_SLUG', '');
}
@@ -105,7 +105,7 @@ class Cision
$query['m'] = $type;
}
- return Http::get('https://news.cision.com/se/ListItems?' . http_build_query($query));
+ return Http::get('https://news.cision.com/se/ListItems?'.http_build_query($query));
}
protected function parseResponse(string $data, int $page): array|false
@@ -116,7 +116,7 @@ class Cision
// Suppress XML parsing warnings
libxml_use_internal_errors(true);
- $xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
+ $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
libxml_clear_errors();
if ($xml === false) {
@@ -128,7 +128,7 @@ class Cision
$rows = json_decode($json, true);
// Validate structure
- if (!isset($rows['channel']['item'])) {
+ if (! isset($rows['channel']['item'])) {
return false;
}
diff --git a/src/CisionServiceProvider.php b/src/CisionServiceProvider.php
index 80caf79..54cf451 100644
--- a/src/CisionServiceProvider.php
+++ b/src/CisionServiceProvider.php
@@ -4,7 +4,6 @@ namespace Mattitja\Cision;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
-use Mattitja\Cision\Commands\CisionCommand;
class CisionServiceProvider extends PackageServiceProvider
{
diff --git a/src/Support/HtmlCleaner.php b/src/Support/HtmlCleaner.php
index dfac263..fafa1d8 100644
--- a/src/Support/HtmlCleaner.php
+++ b/src/Support/HtmlCleaner.php
@@ -2,9 +2,9 @@
namespace Mattitja\Cision\Support;
+use DOMElement;
use DOMNode;
use DOMText;
-use DOMElement;
class HtmlCleaner
{
@@ -17,7 +17,7 @@ class HtmlCleaner
return $node->wholeText;
}
- if (!($node instanceof DOMElement)) {
+ if (! ($node instanceof DOMElement)) {
return null;
}
@@ -35,6 +35,7 @@ class HtmlCleaner
return '
';
}
}
+
return null;
}
@@ -52,9 +53,11 @@ class HtmlCleaner
$html = $node->C14N();
$isItalic = str_starts_with(trim($html), '" . trim($inner) . "
";
+
+ return "".trim($inner).'
';
}
- return "<{$tag}>" . trim($inner) . "{$tag}>";
+
+ return "<{$tag}>".trim($inner)."{$tag}>";
}
if (in_array($tag, $allowedInline)) {