Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
retypos-adapter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
eterfund
retypos-adapter
Commits
635296f1
Commit
635296f1
authored
Sep 07, 2018
by
Георгий Попов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an implementation of new TyposClientInterface methods to the example
parent
35843dee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
MyClientInterface.php
example/MyClientInterface.php
+50
-0
No files found.
example/MyClientInterface.php
View file @
635296f1
...
...
@@ -9,6 +9,9 @@ use Etersoft\Typos\TyposClientInterface;
*/
class
MyClientInterface
extends
TyposClientInterface
{
private
$baseUrl
=
"https://some-site.org"
;
private
$editPath
=
"/edit?article="
;
/**
* Should return an article text for a provided article link.
*
...
...
@@ -30,4 +33,50 @@ class MyClientInterface extends TyposClientInterface {
protected
function
saveArticle
(
TyposArticle
$article
)
{
}
/**
* Should return an article id from provided article url
*
* @param string $link Article URL
* @return integer Article ID
*
* @throws \InvalidArgumentException If id cannot be extracted from link
*/
protected
function
getArticleIdFromLink
(
string
$link
)
{
// $link = https://some-site.org/?article=$link
$query
=
parse_url
(
$link
,
PHP_URL_QUERY
);
$params
=
[];
parse_str
(
$query
,
$params
);
// Provide all checks needed
if
(
count
(
$params
)
===
0
)
{
throw
new
\InvalidArgumentException
();
}
if
(
!
isset
(
$params
[
"article"
]))
{
throw
new
\InvalidArgumentException
();
}
if
(
!
is_numeric
(
$params
[
"article"
]))
{
throw
new
\InvalidArgumentException
();
}
// Return article id
return
$params
[
"article"
];
}
/**
* Should return an edit link for an article with a given id
*
* @param int $id Article ID
* @return string Article edit URL
*/
protected
function
getArticleEditLink
(
int
$id
)
{
// https://some-site.org/edit?article=$id
return
`{$this->baseUrl}{$this->editPath}$id`
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment