Skip to content

Commit febc62c

Browse files
committed
Initial commit
0 parents  commit febc62c

29 files changed

+5476
-0
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; top-most EditorConfig file
2+
root = true
3+
4+
; Unix-style newlines
5+
[*]
6+
end_of_line = LF
7+
8+
[*.php]
9+
indent_style = space
10+
indent_size = 4

.formatter.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use-sort:
2+
group:
3+
- _main
4+
- Mmoreram
5+
group-type: each
6+
sort-type: alph
7+
sort-direction: asc
8+
strict: true
9+
header: |
10+
/*
11+
* This file is part of the Search PHP Library.
12+
*
13+
* For the full copyright and license information, please view the LICENSE
14+
* file that was distributed with this source code.
15+
*
16+
* Feel free to edit as you please, and have fun.
17+
*
18+
* @author Marc Morera <[email protected]>
19+
* @author PuntMig Technologies
20+
*/

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

.php_cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
$config = Symfony\CS\Config\Config::create()
4+
// use SYMFONY_LEVEL:
5+
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
6+
// and extra fixers:
7+
->fixers([
8+
'concat_with_spaces',
9+
'multiline_spaces_before_semicolon',
10+
'short_array_syntax',
11+
'-remove_lines_between_uses',
12+
'-empty_return',
13+
'-phpdoc_var_without_name',
14+
'-phpdoc_to_comment',
15+
]);
16+
17+
if (null === $input->getArgument('path')) {
18+
$config
19+
->finder(
20+
Symfony\CS\Finder\DefaultFinder::create()
21+
->in('.')
22+
->exclude('vendor')
23+
->exclude('web')
24+
->exclude('bin')
25+
->exclude('var')
26+
);
27+
}
28+
29+
return $config;

Http/GuzzleClient.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Search PHP Library.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
* @author PuntMig Technologies
13+
*/
14+
15+
declare(strict_types=1);
16+
17+
namespace Puntmig\Search\Http;
18+
19+
use GuzzleHttp\Client;
20+
use Psr\Http\Message\ResponseInterface;
21+
22+
/**
23+
* Class GuzzleClient.
24+
*/
25+
class GuzzleClient implements HttpClient
26+
{
27+
/**
28+
* @var string
29+
*
30+
* Host
31+
*/
32+
private $host;
33+
34+
/**
35+
* GuzzleClient constructor.
36+
*
37+
* @param string $host
38+
*/
39+
public function __construct(string $host)
40+
{
41+
$this->host = $host;
42+
}
43+
44+
/**
45+
* Get a response given some parameters.
46+
* Return an array with the status code and the body.
47+
*
48+
* @param string $url
49+
* @param string $method
50+
* @param array $options
51+
*
52+
* @return array
53+
*/
54+
public function get(
55+
string $url,
56+
string $method,
57+
array $options
58+
): array {
59+
$client = new Client([
60+
'defaults' => [
61+
'timeout' => 5,
62+
],
63+
]);
64+
65+
$bodyFieldName = ($method === 'get')
66+
? 'query'
67+
: 'form_params';
68+
69+
/**
70+
* @var ResponseInterface $response
71+
*/
72+
$response = $client->$method(
73+
$this->host . $url,
74+
[$bodyFieldName => $options]
75+
);
76+
77+
return [
78+
'code' => $response->getStatusCode(),
79+
'body' => json_decode($response->getBody()->getContents(), true),
80+
];
81+
}
82+
}

Http/HttpClient.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Search PHP Library.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
* @author PuntMig Technologies
13+
*/
14+
15+
declare(strict_types=1);
16+
17+
namespace Puntmig\Search\Http;
18+
19+
/**
20+
* Class HttpClient.
21+
*/
22+
interface HttpClient
23+
{
24+
/**
25+
* Get a response given some parameters.
26+
* Return an array with the status code and the body.
27+
*
28+
* @param string $url
29+
* @param string $method
30+
* @param array $options
31+
*
32+
* @return array
33+
*/
34+
public function get(
35+
string $url,
36+
string $method,
37+
array $options
38+
) : array;
39+
}

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) Marc Morera <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

Model/Brand.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Search PHP Library.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
* @author PuntMig Technologies
13+
*/
14+
15+
declare(strict_types=1);
16+
17+
namespace Puntmig\Search\Model;
18+
19+
/**
20+
* Class Brand.
21+
*/
22+
class Brand extends IdNameWrapper
23+
{
24+
/**
25+
* @var string
26+
*
27+
* Name
28+
*/
29+
const TYPE = 'brand';
30+
}

Model/Category.php

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Search PHP Library.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
* @author PuntMig Technologies
13+
*/
14+
15+
declare(strict_types=1);
16+
17+
namespace Puntmig\Search\Model;
18+
19+
/**
20+
* Class Category.
21+
*/
22+
class Category extends IdNameWrapper implements WithLevel
23+
{
24+
/**
25+
* @var string
26+
*
27+
* Name
28+
*/
29+
const TYPE = 'category';
30+
31+
/**
32+
* @var int
33+
*
34+
* Level
35+
*/
36+
private $level;
37+
38+
/**
39+
* Category constructor.
40+
*
41+
* @param string $id
42+
* @param string $name
43+
* @param int $level
44+
*/
45+
public function __construct(
46+
string $id,
47+
string $name,
48+
int $level = 1
49+
) {
50+
parent::__construct($id, $name);
51+
52+
$this->level = $level;
53+
}
54+
55+
/**
56+
* Create from array.
57+
*
58+
* @param array $array
59+
*
60+
* @return static
61+
*/
62+
public static function createFromArray(array $array)
63+
{
64+
if (
65+
!isset($array['id']) ||
66+
!isset($array['name'])
67+
) {
68+
return null;
69+
}
70+
71+
return new static(
72+
(string) $array['id'],
73+
(string) $array['name'],
74+
$array['level'] ?? 1
75+
);
76+
}
77+
78+
/**
79+
* Get level.
80+
*
81+
* @return int
82+
*/
83+
public function getLevel(): int
84+
{
85+
return $this->level;
86+
}
87+
88+
/**
89+
* To array.
90+
*
91+
* @return array
92+
*/
93+
public function toArray() : array
94+
{
95+
return [
96+
'id' => $this->getId(),
97+
'name' => $this->getName(),
98+
'level' => $this->level,
99+
];
100+
}
101+
}

Model/HttpTransportable.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Search PHP Library.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
* @author PuntMig Technologies
13+
*/
14+
15+
declare(strict_types=1);
16+
17+
namespace Puntmig\Search\Model;
18+
19+
/**
20+
* Interface HttpTransportable.
21+
*/
22+
interface HttpTransportable
23+
{
24+
/**
25+
* To array.
26+
*
27+
* @return array
28+
*/
29+
public function toArray() : array;
30+
31+
/**
32+
* Create from array.
33+
*
34+
* @param array $array
35+
*
36+
* @return self
37+
*/
38+
public static function createFromArray(array $array);
39+
}

0 commit comments

Comments
 (0)