Add automagic-images plugin v1.1.1
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# PHPHtmlParser Contribution Guide
|
||||
|
||||
This page contains guidelines for contributing to the PHPHtmlParser package. Please review these guidelines before submitting any puLl requests to the package.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
The pull request process differs for new features and bugs. Before sending a pull request for a new feature, you should first create an issue with `[Proposal]` in the title. The proposal should describe the new feature, as well as implementation ideas. The proposal will then be reviewed and either approved or denied. Once a proposal is approved, a pull request may be created implementing the new feature. Pull requests which do not follow this guideline will be closed immediately.
|
||||
|
||||
Pull requests for bugs may be sent without creating any proposal issue. If you believe that you know of a solution for a bug that has been filed on Github, please leave a comment detailing your proposed fix.
|
||||
|
||||
### Feature Requests
|
||||
|
||||
If you have an idea for a new feature you would like to see added to the package, you may create an issue on Github with `[Request]` in the title. The feature request will then be reviewed.
|
||||
|
||||
## Coding Guidelines
|
||||
|
||||
We follow the [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) autoloading standard and take heavily from the [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) coding standards. In addition to these standards, below is a list of other coding standards that should be followed:
|
||||
|
||||
- Class opening `{` should be on the same line as the class name.
|
||||
- Function and control structure opening `{` should be on a separate line.
|
||||
- Interface names are suffixed with `Interface` (`FooInterface`)
|
||||
@@ -0,0 +1,28 @@
|
||||
String Encode
|
||||
==========================
|
||||
|
||||
Version 1.0.1
|
||||
|
||||
String Encode is a simple PHP wrapper package to facilitate the encoding of strings in different charsets.
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
This package can be found on [packagist](https://packagist.org/packages/paquettg/stringencode) and is best loaded using [composer](http://getcomposer.org/). It does require php 7.1 or higher, so keep that in consideration.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
This is a really simple package so there is not much to say about it. The following is just about the only usage for this package at the moment.
|
||||
|
||||
```php
|
||||
use stringEncode\Encode;
|
||||
|
||||
$str = "Calendrier de l'avent façon Necta!"
|
||||
$encode = new Encode;
|
||||
$encode->detect($str);
|
||||
$newstr = $encode->convert($str);
|
||||
echo $newstr; // "Calendrier de l'avent façon Necta!" in UTF-8 encoding (default)
|
||||
```
|
||||
|
||||
As you can see, it is a very simple encoding converter.
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "paquettg/string-encode",
|
||||
"type": "library",
|
||||
"description": "Facilitating the process of altering string encoding in PHP.",
|
||||
"version": "1.0.1",
|
||||
"keywords": ["encoding", "charset", "string"],
|
||||
"homepage": "https://github.com/paquettg/string-encoder",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gilles Paquette",
|
||||
"email": "paquettg@gmail.com",
|
||||
"homepage": "http://gillespaquette.ca"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"stringEncode": "src/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register The Composer Auto Loader
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Composer provides a convenient, automatically generated class loader
|
||||
| for our application. We just need to utilize it! We'll require it
|
||||
| into the script here so that we do not have to worry about the
|
||||
| loading of any our classes "manually". Feels great to relax.
|
||||
|
|
||||
*/
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Set The Default Timezone
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here we will set the default timezone for PHP. PHP is notoriously mean
|
||||
| if the timezone is not explicitly set. This will be used by each of
|
||||
| the PHP date and date-time functions throughout the application.
|
||||
|
|
||||
*/
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="phpunit.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Repository Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="false">
|
||||
<directory suffix=".php">src</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
namespace stringEncode;
|
||||
|
||||
class Encode {
|
||||
|
||||
/**
|
||||
* The encoding that the string is currently in.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $from;
|
||||
|
||||
/**
|
||||
* The encoding that we would like the string to be in.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $to;
|
||||
|
||||
/**
|
||||
* Sets the default charsets for thie package.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// default from encoding
|
||||
$this->from = 'CP1252';
|
||||
|
||||
// default to encoding
|
||||
$this->to = 'UTF-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the charset that we will be converting to.
|
||||
*
|
||||
* @param string $charset
|
||||
* @chainable
|
||||
*/
|
||||
public function to($charset)
|
||||
{
|
||||
$this->to = strtoupper($charset);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the charset that we will be converting from.
|
||||
*
|
||||
* @param string $charset
|
||||
* @chainable
|
||||
*/
|
||||
public function from($charset)
|
||||
{
|
||||
$this->from = strtoupper($charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the to and from charset that we will be using.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function charset()
|
||||
{
|
||||
return [
|
||||
'from' => $this->from,
|
||||
'to' => $this->to,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to detect the encoding of the given string from the encodingList.
|
||||
*
|
||||
* @param string $str
|
||||
* @param array $encodingList
|
||||
* @return bool
|
||||
*/
|
||||
public function detect($str, $encodingList = ['UTF-8', 'CP1252'])
|
||||
{
|
||||
$charset = mb_detect_encoding($str, $encodingList);
|
||||
if ($charset === false)
|
||||
{
|
||||
// could not detect charset
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->from = $charset;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to convert the string to the proper charset.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert($str)
|
||||
{
|
||||
if ($this->from != $this->to)
|
||||
{
|
||||
$str = iconv($this->from, $this->to, $str);
|
||||
}
|
||||
|
||||
if ($str === false)
|
||||
{
|
||||
// the convertion was a failure
|
||||
throw new Exception('The convertion from "'.$this->from.'" to "'.$this->to.'" was a failure.');
|
||||
}
|
||||
|
||||
// deal with BOM issue for utf-8 text
|
||||
if ($this->to == 'UTF-8')
|
||||
{
|
||||
if (substr($str, 0, 3) == "\xef\xbb\xbf")
|
||||
{
|
||||
$str = substr($str, 3);
|
||||
}
|
||||
if (substr($str, -3, 3) == "\xef\xbb\xbf")
|
||||
{
|
||||
$str = substr($str, 0, -3);
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
namespace stringEncode;
|
||||
|
||||
class Exception extends \Exception {}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stringEncode\Encode;
|
||||
|
||||
class ContentTest extends TestCase {
|
||||
|
||||
public function testTo()
|
||||
{
|
||||
$encode = new Encode;
|
||||
$encode->to('ISO-8859-1');
|
||||
$this->assertEquals('ISO-8859-1', $encode->charset()['to']);
|
||||
}
|
||||
|
||||
public function testFrom()
|
||||
{
|
||||
$encode = new Encode;
|
||||
$encode->from('ISO-8859-1');
|
||||
$this->assertEquals('ISO-8859-1', $encode->charset()['from']);
|
||||
}
|
||||
|
||||
public function testDetect()
|
||||
{
|
||||
$encode = new Encode;
|
||||
$encode->detect('Calendrier de l\'avent façon Necta!');
|
||||
$this->assertEquals('UTF-8', $encode->charset()['from']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user