trntv / sitemaped Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
I meet a error when I composer update yii2-starter-kit,
"trntv/sitemaped 0.1.2 requires php ^7.1 -> your php version (8.0.13) does not satisfy that requirement."
please update it for php8.*
thanks.
Controller action code:
public function actionSitemap()
{
$links = new UrlsIterator();
$sitemap = new Sitemap(new Urlset($links));
Yii::$app->response->format = Response::FORMAT_RAW;
Yii::$app->response->headers->add('Content-Type', 'text/plain');
$content = $sitemap->toTxtString();
$linksCount = $sitemap->getCount();
if ($linksCount > 50000) {
Yii::warning(\sprintf('Sitemap links count is %d'), $linksCount);
}
return $content;
}
Exception:
Exception 'TypeError' with message 'Argument 1 passed to DOMXPath::__construct() must be an instance of DOMDocument, null given'
in /app/vendor/trntv/sitemaped/src/Sitemap.php:58
Stack trace:
#0 /app/vendor/trntv/sitemaped/src/Sitemap.php(58): DOMXPath->__construct(NULL)
#1 /app/landing/controllers/SiteController.php(178): Sitemaped\Sitemap->getCount()
The issue is caused by the fact that getCount() functions uses $this->document property which is not set by toTxtString() method
+ private $txtUrlCount = null;
public function getCount(): int
{
+ if ($this->document) {
$xpath = new \DOMXPath($this->document);
return $xpath->query('*/loc')->length;
+ }
+ if ($this->txtUrlCount === null) {
+ throw new \DomainException('txtUrlCount must be set');
+ }
+ return $this->txtUrlCount;
}
public function toTxtString($gzip = false): string
{
$str = '';
+ $this->txtUrlCount = 0;
foreach ($this->root->getValue() as $url) {
$str .= $url->loc . "\r\n";
+ $this->txtUrlCount++;
}
if ($gzip === true) {
$this->ensureZlib();
$str = \gzencode($str, $this->gzipLevel);
}
return $str;
}
I don't create pull request because this code could be improved but it does the job
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.