Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoSign in
Socket

01-interfaz/php-remoteapi

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

01-interfaz/php-remoteapi - composer Package Compare versions

Comparing version
1.0.0
to
1.0.2
+23
01-interfaz-php-remoteapi-0ab31fd/.gitignore
/vendor/
node_modules/
npm-debug.log
yarn-error.log
# Laravel 4 specific
bootstrap/compiled.php
app/storage/
# Laravel 5 & Lumen specific
public/storage
public/hot
# Laravel 5 & Lumen specific with changed public path
public_html/storage
public_html/hot
storage/*.key
.env
Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
{
"name": "01-interfaz/php-remoteapi",
"description": "Remote consumer for laravel projects",
"license": "Interfaz software development",
"minimum-stability": "stable",
"type": "library",
"authors": [
{
"name": "franc",
"email": "francoe12012@gmail.com"
}
],
"require": {
"php" : ">=7.4"
},
"autoload": {
"psr-4": {
"Interfaz\\": "src/"
}
}
}
The MIT License (MIT)
Copyright (c) 2021 Interfaz <francoe12012@gmail.com>
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.
# Remote API Client for PHP
<?php
namespace Interfaz;
/**
* Para laravel agregar en .env las API que se requiren.
* APP_REMOTE_API_{NAME}="http://127.0.0.1:8000/api/v1/"
* APP_REMOTE_API_{NAME}_KEY="123456"
*/
class RemoteAPI
{
public string $apiTokenKeyName = "api_token";
private string $endpoint = "";
private string $endpointKey = "";
private $response_cookies;
private $request_cookies = [];
public function __construct($name)
{
$this->endpoint = env('APP_REMOTE_API_' . strtoupper($name));
$this->endpointKey = env('APP_REMOTE_API_' . strtoupper($name) . '_KEY');
}
public function getURL($url)
{
return $this->endpoint . $url . '?' . $this->apiTokenKeyName . '=' . $this->endpointKey;
}
public function get(string $url, ?string $query = null) : string
{
$context = $this->getContext('GET');
$url = $this->getURL($url);
if($query !== null) $url .= "&". $query;
$content = file_get_contents($url, false, $context);
$cookies = array();
foreach ($http_response_header as $hdr) {
if (preg_match('/^Set-Cookie:\s*([^;]+)/', $hdr, $matches)) {
parse_str($matches[1], $tmp);
$cookies += $tmp;
}
}
$this->response_cookies = $cookies;
return $content;
}
public function getCookies()
{
return $this->response_cookies;
}
public function setCookies($name, $value)
{
$this->request_cookies[$name] = "$name=$value";
}
private function getCookiesString(): string
{
$output = "";
foreach ($this->request_cookies as $key => $cookie) $output .= $cookie . ";";
$output = rtrim($output, ';');
return $output;
}
/**
* @return resource
*/
public function getContext(string $method)
{
$opts = array('http' => array('method' => $method, 'header' => "Cookie: " . $this->getCookiesString()));
$context = stream_context_create($opts);
return $context;
}
}
-23
/vendor/
node_modules/
npm-debug.log
yarn-error.log
# Laravel 4 specific
bootstrap/compiled.php
app/storage/
# Laravel 5 & Lumen specific
public/storage
public/hot
# Laravel 5 & Lumen specific with changed public path
public_html/storage
public_html/hot
storage/*.key
.env
Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
{
"name": "01-interfaz/php-remoteapi",
"description": "Remote consumer for laravel projects",
"license": "Interfaz software development",
"minimum-stability": "stable",
"type": "library",
"authors": [
{
"name": "franc",
"email": "francoe12012@gmail.com"
}
],
"require": {
"php" : ">=7.4"
},
"autoload": {
"psr-4": {
"Interfaz\\": "src/"
}
}
}
# Remote API Client for PHP
<?php
namespace Interfaz;
/**
* Para laravel agregar en .env las API que se requiren.
* APP_REMOTE_API_{NAME}="http://127.0.0.1:8000/api/v1/"
* APP_REMOTE_API_{NAME}_KEY="123456"
*/
class RemoteAPI
{
public string $apiTokenKeyName = "api_token";
private string $endpoint = "";
private string $endpointKey = "";
private $response_cookies;
private $request_cookies = [];
public function __construct($name)
{
$this->endpoint = env('APP_REMOTE_API_' . strtoupper($name));
$this->endpointKey = env('APP_REMOTE_API_' . strtoupper($name) . '_KEY');
}
public function getURL($url)
{
return $this->endpoint . $url . '?' . $this->apiTokenKeyName . '=' . $this->endpointKey;
}
public function get(string $url, ?string $query = null) : string
{
$context = $this->getContext('GET');
$url = $this->getURL($url);
if($query !== null) $url .= "&". $query;
$content = file_get_contents($url, false, $context);
$cookies = array();
foreach ($http_response_header as $hdr) {
if (preg_match('/^Set-Cookie:\s*([^;]+)/', $hdr, $matches)) {
parse_str($matches[1], $tmp);
$cookies += $tmp;
}
}
$this->response_cookies = $cookies;
return $content;
}
public function getCookies()
{
return $this->response_cookies;
}
public function setCookies($name, $value)
{
$this->request_cookies[$name] = "$name=$value";
}
private function getCookiesString(): string
{
$output = "";
foreach ($this->request_cookies as $key => $cookie) $output .= $cookie . ";";
$output = rtrim($output, ';');
return $output;
}
/**
* @return resource
*/
public function getContext(string $method)
{
$opts = array('http' => array('method' => $method, 'header' => "Cookie: " . $this->getCookiesString()));
$context = stream_context_create($opts);
return $context;
}
}