-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 76b78d2
Showing
15 changed files
with
1,305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor | ||
.idea/ | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2023 Selim Görmüş <[email protected]> | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in | ||
> all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
> THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Siberfx\BiletAll | ||
|
||
|
||
## Install | ||
|
||
1) In your terminal: | ||
|
||
``` bash | ||
$ composer require siberfx/biletall-php | ||
``` | ||
|
||
|
||
## Testing | ||
|
||
``` bash | ||
// TODO | ||
``` | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "siberfx/biletall-php", | ||
"description": "BiletAll Bus Api Implementation for laravel.", | ||
"keywords": [ | ||
"laravel", | ||
"bilet all", | ||
"biletall", | ||
"bus" | ||
], | ||
"homepage": "https://github.com/siberfx/biletall-php", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Selim Görmüş", | ||
"email": "[email protected]", | ||
"role": "Lead Developer" | ||
} | ||
], | ||
"require": { | ||
"ext-soap": "*", | ||
"ext-json": "*", | ||
"ext-dom": "*", | ||
"php": "^8.1", | ||
"laravel/framework": "^10.0", | ||
"laravel/helpers": "^1.7" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5" | ||
}, | ||
"autoload": { | ||
"files": [ | ||
"src/Helpers/helper.php" | ||
], | ||
"psr-4": { | ||
"Siberfx\\BiletAll\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Siberfx\\BiletAll\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "phpunit" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
}, | ||
"laravel": { | ||
"providers": [ | ||
"Siberfx\\BiletAll\\BiletAllServiceProvider" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Siberfx\BiletAll; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Illuminate\Routing\Router; | ||
|
||
class BiletAllServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Where the route file lives, both inside the package and in the app (if overwritten). | ||
* | ||
* @var string | ||
*/ | ||
public $routeFilePath = '/routes/siberfx/biletall.php'; | ||
|
||
/** | ||
* Perform post-registration booting of services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->setupRoutes($this->app->router); | ||
|
||
$this->mergeConfigFrom( | ||
__DIR__ . '/config/biletall.php', 'biletall' | ||
); | ||
|
||
// publish config file | ||
$this->publishes([__DIR__.'/config' => config_path()], 'config'); | ||
|
||
} | ||
|
||
|
||
/** | ||
* Register any package services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
|
||
} | ||
|
||
|
||
/** | ||
* Define the routes for the application. | ||
* | ||
* @param \Illuminate\Routing\Router $router | ||
* @return void | ||
*/ | ||
public function setupRoutes(Router $router) | ||
{ | ||
// by default, use the routes file provided in vendor | ||
$routeFilePathInUse = __DIR__.$this->routeFilePath; | ||
|
||
// but if there's a file with the same name in routes/backpack, use that one | ||
if (file_exists(base_path().$this->routeFilePath)) { | ||
$routeFilePathInUse = base_path().$this->routeFilePath; | ||
} | ||
|
||
$this->loadRoutesFrom($routeFilePathInUse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Siberfx\BiletAll\Helpers; | ||
|
||
class BooleanParser | ||
{ | ||
|
||
public static function parse(string $binaryString = '', array $valueMap = []) | ||
{ | ||
$length = strlen($binaryString); | ||
|
||
for ($i = 0; $i < $length; $i++) { | ||
$currentChar = $binaryString[$i]; | ||
$booleanValue = self::charToBoolean($currentChar); | ||
|
||
$valueMap[$i] = $booleanValue; | ||
} | ||
|
||
return collect($valueMap)->map(fn($value, $id) => [ | ||
'id' => $id, | ||
'value' => $value, | ||
]) | ||
->where('value', 1); | ||
} | ||
|
||
private static function charToBoolean($char): int | ||
{ | ||
// Assuming '1' is true and '0' is false | ||
return $char == '1'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Siberfx\BiletAll\Helpers; | ||
|
||
class BusSpecHelper | ||
{ | ||
|
||
public static function handle(string $string = '') | ||
{ | ||
$defaultSet = '11111111001000100000000000000000000000000000000000'; | ||
|
||
if (empty($string)) { | ||
return []; | ||
} | ||
|
||
if (app()->environment('local')) { | ||
$string = str_limit($defaultSet, 23); | ||
} | ||
|
||
|
||
// @todo test data for 23 characters string | ||
|
||
$ids = BooleanParser::parse(str_limit($string, 23))->pluck('id')->toArray(); | ||
|
||
if (empty($ids)) { | ||
return []; | ||
} | ||
|
||
return collect(config('biletall.set'))->whereIn('tip', $ids)->get()->map(function ($item) { | ||
return [ | ||
'id' => $item->id, | ||
'title' => $item->title, | ||
'description' => $item->description, | ||
'image' => !empty($item->image) ? asset($item->image) : '' | ||
]; | ||
}); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Siberfx\BiletAll\Helpers; | ||
|
||
use DOMDocument; | ||
|
||
class XmlToArray | ||
{ | ||
/** | ||
* Convert valid XML to an array. | ||
* | ||
* @param string $xml | ||
* @param bool $outputRoot | ||
* @return array | ||
*/ | ||
public static function convert(string $xml, bool $outputRoot = false) | ||
{ | ||
$array = self::xmlStringToArray($xml); | ||
if (!$outputRoot && array_key_exists('@root', $array)) { | ||
unset($array['@root']); | ||
} | ||
return $array; | ||
} | ||
|
||
protected static function xmlStringToArray($xmlstr) | ||
{ | ||
$doc = new DOMDocument(); | ||
$doc->loadXML($xmlstr); | ||
$root = $doc->documentElement; | ||
$output = self::domNodeToArray($root); | ||
$output['@root'] = $root->tagName; | ||
return $output; | ||
} | ||
|
||
protected static function domNodeToArray($node) | ||
{ | ||
$output = []; | ||
switch ($node->nodeType) { | ||
case XML_CDATA_SECTION_NODE: | ||
case XML_TEXT_NODE: | ||
$output = trim($node->textContent); | ||
break; | ||
case XML_ELEMENT_NODE: | ||
for ($i = 0, $m = $node->childNodes->length; $i < $m; $i++) { | ||
$child = $node->childNodes->item($i); | ||
$v = self::domNodeToArray($child); | ||
if (isset($child->tagName)) { | ||
$t = $child->tagName; | ||
if (!isset($output[$t])) { | ||
$output[$t] = []; | ||
} | ||
$output[$t][] = $v; | ||
} elseif ($v || $v === '0') { | ||
$output = (string)$v; | ||
} | ||
} | ||
if ($node->attributes->length && !is_array($output)) { // Has attributes but isn't an array | ||
$output = ['@content' => $output]; // Change output into an array. | ||
} | ||
if (is_array($output)) { | ||
if ($node->attributes->length) { | ||
$a = []; | ||
foreach ($node->attributes as $attrName => $attrNode) { | ||
$a[$attrName] = (string)$attrNode->value; | ||
} | ||
$output['@attributes'] = $a; | ||
} | ||
foreach ($output as $t => $v) { | ||
if ((count($v) === 1) && is_array($v) && $t !== '@attributes') { | ||
$output[$t] = $v[0]; | ||
} | ||
} | ||
} | ||
break; | ||
} | ||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
function xml_to_array($xml, $outputRoot = false): array|string | ||
{ | ||
return \Siberfx\BiletAll\Helpers\XmlToArray::convert($xml, $outputRoot); | ||
} |
Oops, something went wrong.