Create a templates of TyposClient and TyposClientInterface classes.

parent aec99760
.idea/
\ No newline at end of file
.idea/
vendor/
......@@ -8,5 +8,10 @@
"name": "George Popoff",
"email": "ambulance@etersoft.ru"
}
]
}
\ No newline at end of file
],
"version": "0.1",
"require": {
"fguillot/json-rpc": "@stable"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "f25e06bdf6a86c8328ae931b34106496",
"packages": [
{
"name": "fguillot/json-rpc",
"version": "v1.2.5",
"source": {
"type": "git",
"url": "https://github.com/fguillot/JsonRPC.git",
"reference": "fa075cc89c1ae5f0c4123d27772e5caeac045946"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/fa075cc89c1ae5f0c4123d27772e5caeac045946",
"reference": "fa075cc89c1ae5f0c4123d27772e5caeac045946",
"shasum": ""
},
"require": {
"php": ">=5.3.4"
},
"require-dev": {
"phpunit/phpunit": "4.8.*"
},
"type": "library",
"autoload": {
"psr-0": {
"JsonRPC": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Frédéric Guillot"
}
],
"description": "Simple Json-RPC client/server library that just works",
"homepage": "https://github.com/fguillot/JsonRPC",
"time": "2018-02-21T23:58:51+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"fguillot/json-rpc": 0
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
<?php
/**
* Created by PhpStorm.
* User: ambulance
* Date: 25.05.18
* Time: 19:47
*/
namespace Etersoft\Typos;
/**
* Class TyposArticle
*
* An article object with a text and id
*
* @package Etersoft\Typos
*/
class TyposArticle
{
public $id;
public $text;
/**
* TyposArticle constructor.
* @param $id integer Article id
* @param $text string Article text
*/
public function __construct(integer $id, string $text)
{
$this->id = $id;
$this->text = $text;
}
}
\ No newline at end of file
<?php
/**
* Created by ambulance@eterosf.ru
* Date: 25.05.18
* Time: 19:24
*/
namespace Etersoft\Typos;
// Enable autoloading
require __DIR__ . '../vendor/autoload.php';
use JsonRPC\Server;
/**
* Class TyposClient
*
* Allows to manage typos-fixing request from typo-fixing server.
* Part of the Etersoft Typo system.
* Uses a json-rpc 2.0 protocol.
*
* @package Etersoft\Typos
*/
class TyposClient
{
/**
* @var Server
*/
private $server;
private $interface;
/**
* TyposAbstractClient constructor.
*
* @param TyposClientInterface $interface Interface of server
*/
public function __construct(TyposClientInterface $interface)
{
$this->interface = $interface;
$this->server = new Server();
$procedureHandler = $this->server->getProcedureHandler();
$procedureHandler->withClassAndMethod("fixTypo", $this->interface);
}
/**
* Execute a json-rpc server
* @return string
*/
public function run() {
return $this->server->execute();
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: ambulance
* Date: 25.05.18
* Time: 19:39
*/
namespace Etersoft\Typos;
/**
* Class TyposClientInterface
*
* Interface for the TyposClient. Must be implemented by a user
* and passed to the TyposClient constructor during initialization process.
*
* @package Etersoft\Typos
*/
abstract class TyposClientInterface
{
/**
* Should return an article text for a provided article link.
*
* @param string $link A link to a article. User should define an article id.
*
* @return TyposArticle
*/
protected abstract function getArticleFromLink(string $link);
/**
* Should persist a provided article in database.
*
* @param TyposArticle $article Article
* @return void
*/
protected abstract function saveArticle(TyposArticle $article);
/**
* Fixes a typo in an article from a $link url. Uses a context while
* fixing to determine a typo position.
*
* @param string $typo Typo to be fixed
* @param string $corrected Correct variant
* @param string $context Context of typo
* @param string $link Link where the typo exist
*/
public function fixTypo(string $typo, string $corrected, string $context, string $link) {
$article = $this->getArticleFromLink($link);
$this->replaceTypoInArticle($typo, $corrected, $context, $article);
$this->saveArticle($article);
}
/**
* This method replaces a given typo in article, using the context to a correct
* variant.
*
* @param string $typo Typo to be replaced
* @param string $corrected Correct variant
* @param string $context Context where the typo found
* @param TyposArticle $article Article to fix the typo
*/
private function replaceTypoInArticle(string $typo, string $corrected, string $context, TyposArticle $article) {
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment