Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
Tourinsoft
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bolt Extensions
Tourinsoft
Commits
66b70ac0
Commit
66b70ac0
authored
May 09, 2018
by
Frédéric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Des trucs
parent
efb24d48
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
182 additions
and
22 deletions
+182
-22
.gitignore
config/contenttypes/.gitignore
+0
-0
FluxController.php
src/Controller/Backend/FluxController.php
+10
-3
Synchronisation.php
src/Synchronisation/Synchronisation.php
+29
-9
TourinsoftExtension.php
src/TourinsoftExtension.php
+1
-1
ContentTypeFile.php
src/Utils/ContentTypeFile.php
+78
-0
File.php
src/Utils/File.php
+0
-9
Parser.php
src/Utils/Parser.php
+64
-0
No files found.
config/contenttypes/.gitignore
deleted
100644 → 0
View file @
efb24d48
src/Controller/Backend/FluxController.php
View file @
66b70ac0
...
...
@@ -14,14 +14,20 @@ class FluxController extends BackendBase
* @var Application
*/
private
$application
;
/**
* @var array
*/
private
$config
;
/**
* FluxController constructor.
* @param array $config
* @param Application $application
*/
public
function
__construct
(
Application
$application
)
public
function
__construct
(
array
$config
=
[],
Application
$application
)
{
$this
->
application
=
$application
;
$this
->
config
=
$config
;
}
/**
...
...
@@ -62,13 +68,14 @@ dump($id);
* Synchornisation ('/sync/:id')
*/
public
function
sync
(
$id
)
{
$flux
=
new
Flux
();
$flux
->
setTitle
(
'Mon Titre'
);
$flux
->
setContentType
(
'test'
);
$flux
->
setContentType
(
'test
2
'
);
$flux
->
setEnabled
(
true
);
$flux
->
setKey
(
'2184659e-c7b0-4e8c-8f08-0813bbda30a6'
);
$sync
=
new
Synchronisation
(
$this
->
application
,
$flux
);
$sync
=
new
Synchronisation
(
$this
->
config
,
$this
->
application
,
$flux
);
$sync
->
sync
();
}
...
...
src/Synchronisation/Synchronisation.php
View file @
66b70ac0
...
...
@@ -4,31 +4,50 @@ namespace Bolt\Extension\Appolo\Tourinsoft\Synchronisation;
use
Bolt\Application
;
use
Bolt\Extension\Appolo\Tourinsoft\Storage\Entity\Flux
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\ContentTypeFile
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\Parser
;
class
Synchronisation
{
/**
* @var Application
*/
private
$application
;
/**
* @var Flux
*/
private
$flux
;
/**
* @var array
*/
private
$config
;
/**
* @var Application
*/
private
$application
;
/**
* TourinsoftParser constructor.
* @param
Application $application
* @param
array $config
* @param Flux $flux
* @throws \Exception
*/
public
function
__construct
(
Application
$application
,
Flux
$flux
)
public
function
__construct
(
array
$config
=
[],
Application
$application
,
Flux
$flux
)
{
$this
->
application
=
$application
;
if
(
empty
(
$config
[
'tourinsoft'
]))
{
throw
new
\Exception
(
'La configuration n\'est pas valide.'
);
}
$this
->
flux
=
$flux
;
$this
->
config
=
$config
;
$this
->
application
=
$application
;
}
/**
* @throws \Exception
*/
public
function
sync
()
{
dump
(
'fuck'
);
$options
=
$this
->
config
[
'tourinsoft'
];
$options
[
'key'
]
=
$this
->
flux
->
getKey
();
$parser
=
new
Parser
(
$options
);
$keys
=
$parser
->
getKeys
();
$file
=
new
ContentTypeFile
(
$this
->
application
,
$this
->
flux
->
getContentType
(),
$keys
);
$file
->
createOrUpdateFile
();
}
}
\ No newline at end of file
src/TourinsoftExtension.php
View file @
66b70ac0
...
...
@@ -41,7 +41,7 @@ class TourinsoftExtension extends SimpleExtension
protected
function
registerBackendControllers
()
{
return
[
'/tourinsoft'
=>
new
FluxController
(
$this
->
getContainer
()),
'/tourinsoft'
=>
new
FluxController
(
$this
->
getCon
fig
(),
$this
->
getCon
tainer
()),
];
}
...
...
src/Utils/ContentTypeFile.php
0 → 100644
View file @
66b70ac0
<?php
namespace
Bolt\Extension\Appolo\Tourinsoft\Utils
;
use
Bolt\Application
;
use
Bolt\Filesystem\Handler\YamlFile
;
use
Symfony\Component\Yaml\Yaml
;
class
ContentTypeFile
{
/**
* @var string
*/
private
$contentType
;
/**
* @var array
*/
private
$keys
;
/**
* @var Application
*/
private
$application
;
/**
* ContentTypeFile constructor.
* @param Application $application
* @param string $contentType
* @param array $keys
* @throws \Exception
*/
public
function
__construct
(
Application
$application
,
$contentType
=
''
,
array
$keys
=
[])
{
if
(
empty
(
$contentType
))
{
throw
new
\Exception
(
'Le content type est requis.'
);
}
$this
->
contentType
=
$contentType
;
$this
->
keys
=
$keys
;
$this
->
application
=
$application
;
}
/**
* Create or update file
*/
public
function
createOrUpdateFile
()
{
$yamlData
=
[
$this
->
contentType
=>
[
'name'
=>
ucfirst
(
$this
->
contentType
),
'singular_name'
=>
ucfirst
(
$this
->
contentType
),
'fields'
=>
$this
->
getFields
()
]
];
/** @var YamlFile $file */
$file
=
$this
->
application
[
'filesystem'
]
->
getFile
(
strtolower
(
"extensions_config://contenttypes/
$this->contentType
.yml"
));
$file
->
dump
(
$yamlData
);
}
/**
* @return array
*/
private
function
getFields
()
{
$fields
=
[];
foreach
(
$this
->
keys
as
$key
)
{
$fields
[
$key
]
=
[
'type'
=>
'text'
];
}
$fields
[
'slug'
]
=
[
'type'
=>
'slug'
,
'uses'
=>
'SyndicObjectID'
,
'group'
=>
'meta'
];
return
$fields
;
}
}
\ No newline at end of file
src/Utils/File.php
deleted
100644 → 0
View file @
efb24d48
<?php
namespace
Bolt\Extension\Appolo\Tourinsoft\Utils
;
class
File
{
}
\ No newline at end of file
src/Utils/Parser.php
View file @
66b70ac0
...
...
@@ -2,7 +2,70 @@
namespace
Bolt\Extension\Appolo\Tourinsoft\Utils
;
use
GuzzleHttp\Client
;
class
Parser
{
/**
* @var array
*/
private
$options
;
/**
* @var array
*/
private
$arrayStream
=
[];
/**
* @var string
*/
private
$url
;
/**
* Parser constructor.
* @param array $options
* @throws \Exception
*/
public
function
__construct
(
array
$options
=
[])
{
if
(
empty
(
$options
[
'url'
])
||
empty
(
$options
[
'ot_key'
])
||
empty
(
$options
[
'key'
]))
{
throw
new
\Exception
(
'La configuration n\'est pas valide.'
);
}
$this
->
options
=
$options
;
$this
->
url
=
$options
[
'url'
]
.
$options
[
'ot_key'
]
.
'/'
.
$options
[
'key'
]
.
'/Objects?$format=JSON'
;
$this
->
getStreamAsArray
();
}
/**
* @return array
*/
public
function
getKeys
()
{
$keys
=
[];
foreach
(
$this
->
arrayStream
[
'value'
]
as
$item
)
{
foreach
(
array_keys
(
$item
)
as
$key
)
{
if
(
!
in_array
(
$key
,
$keys
))
{
array_push
(
$keys
,
$key
);
}
}
}
return
$keys
;
}
/**
* @throws \Exception
*/
protected
function
getStreamAsArray
()
{
$client
=
new
Client
();
$res
=
$client
->
request
(
'GET'
,
$this
->
url
);
if
(
$res
->
getStatusCode
()
!==
200
)
{
throw
new
\Exception
(
'Le flux n\'a pu être récupéré.'
);
}
try
{
$this
->
arrayStream
=
json_decode
(
$res
->
getBody
(),
true
);
}
catch
(
\Exception
$e
)
{
throw
new
\Exception
(
'Le flux n\'a pu être décodé.'
);
}
}
}
\ 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