Initial Commit

This commit is contained in:
2018-10-15 00:37:28 -05:00
commit b0bd5569c0
7508 changed files with 849336 additions and 0 deletions

24
vendor/eveseat/eseye/.codeclimate.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
---
engines:
duplication:
enabled: true
config:
languages:
- javascript
- php
fixme:
enabled: true
phpmd:
enabled: true
checks:
Controversial/CamelCaseParameterName:
enabled: false
Controversial/CamelCasePropertyName:
enabled: false
Controversial/CamelCaseVariableName:
enabled: false
ratings:
paths:
- "**.php"
exclude_paths:
- tests/

6
vendor/eveseat/eseye/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
/vendor/
composer.lock
.idea/
/logs/
/cache/
/build/

22
vendor/eveseat/eseye/.styleci.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
preset: laravel
risky: false
enabled:
- alpha_ordered_imports
- concat_with_spaces
- no_empty_comment
disabled:
- braces
- phpdoc_no_package
- concat_without_spaces
- length_ordered_imports
- no_blank_lines_after_class_opening
- no_blank_lines_after_throw
finder:
exclude:
- "tests"
name:
- "*.php"

24
vendor/eveseat/eseye/.travis.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
language: php
php:
- 7.1
- 7.2
before_script:
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- travis_retry composer self-update
- travis_retry composer install
notifications:
on_success: never
on_failure: always
addons:
code_climate:
repo_token: $CODE_CLIMATE_TOKEN
script:
- vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml
after_success:
- vendor/bin/test-reporter

339
vendor/eveseat/eseye/LICENSE vendored Normal file
View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

38
vendor/eveseat/eseye/README.md vendored Normal file
View File

@@ -0,0 +1,38 @@
![SeAT](http://i.imgur.com/aPPOxSK.png)
[![Build Status](https://travis-ci.org/eveseat/eseye.svg?branch=master)](https://travis-ci.org/eveseat/eseye)
[![Code Climate](https://codeclimate.com/github/eveseat/eseye/badges/gpa.svg)](https://codeclimate.com/github/eveseat/eseye)
[![Test Coverage](https://codeclimate.com/github/eveseat/eseye/badges/coverage.svg)](https://codeclimate.com/github/eveseat/eseye/coverage)
[![Latest Stable Version](https://poser.pugx.org/eveseat/eseye/v/stable)](https://packagist.org/packages/eveseat/eseye)
[![Total Downloads](https://poser.pugx.org/eveseat/eseye/downloads)](https://packagist.org/packages/eveseat/eseye)
[![Latest Unstable Version](https://poser.pugx.org/eveseat/eseye/v/unstable)](https://packagist.org/packages/eveseat/eseye)
[![License](https://poser.pugx.org/eveseat/eseye/license)](https://packagist.org/packages/eseye/eveapi)
[![StyleCI](https://styleci.io/repos/78866259/shield?branch=master)](https://styleci.io/repos/78866259)
# eseye
👾 A Standalone, Dynamic ESI (EVE Swagger Interface) Client Library written in PHP
## example usage
Its supposed to be simple!
```php
// initialization stuff
$esi = new Eseye();
// Optionally, set the ESI endpoint version to use.
// If you dont set this, Eseye will use /latest
$esi->setVersion('v4');
// make a call
$character_info = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => 1477919642,
]);
// get data!
echo $character_info->name;
```
For a more complete usage example, please refer to [example.php](example.php)
## documentation
For up to date documentation, more examples and other goodies, please check out the [project wiki](https://github.com/eveseat/eseye/wiki)!

401
vendor/eveseat/eseye/bin/index.php vendored Normal file
View File

@@ -0,0 +1,401 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// If you are reading this, prepare the eye bleach! This is absolutely
// some of the shittest PHP you will _ever_ read. It is mostly because
// we want to have everyting in a single file, making it easy to run
// using the tokenegenerator command. Still, its terrible, and I know.
session_start();
// Helpers
/**
* Redirect a request to the start of this script.
*/
function redirect_to_new()
{
header('Location: ' . $_SERVER['PHP_SELF'] . '?action=new');
die();
}
/**
* @return string
*/
function get_sso_callback_url()
{
if (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
$protocol = 'https://';
else
$protocol = 'http://';
return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?action=eveonlinecallback';
}
// UI Parts
/**
* @return string
*/
function get_header()
{
return <<<'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>New ESI Refresh Token</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Custom styles for this template -->
<style type='text/css'>.header,body{padding-bottom:20px}.header,.jumbotron{border-bottom:1px solid #e5e5e5}body{padding-top:20px}.footer,.header,.marketing{padding-right:15px;padding-left:15px}.header h3{margin-top:0;margin-bottom:0;line-height:40px}.footer{padding-top:19px;color:#777;border-top:1px solid #e5e5e5}@media (min-width:768px){.container{max-width:730px}}.container-narrow>hr{margin:30px 0}.jumbotron{text-align:center}.jumbotron .btn{padding:14px 24px;font-size:21px}.marketing{margin:40px 0}.marketing p+h4{margin-top:28px}@media screen and (min-width:768px){.footer,.header,.marketing{padding-right:0;padding-left:0}.header{margin-bottom:30px}.jumbotron{border-bottom:0}}</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="header clearfix">
<h3 class="text-muted">ESI Refresh Token Generator</h3>
</div>
EOF;
}
/**
* @return string
*/
function get_footer()
{
return <<<'EOF'
</div> <!-- /container -->
</body>
</html>
EOF;
}
// Page contents
/**
* Fresh, new login page.
*/
function new_login()
{
$action = $_SERVER['PHP_SELF'] . '?action=submitsecrets';
$callback = get_sso_callback_url();
echo get_header();
echo <<<EOF
<div class="jumbotron">
<p>
Create a new Application on the
<a href="https://developers.eveonline.com/applications/create" target="_blank">EVE Online Developers Site</a>.
Use the resultant <b>Client ID</b> and <b>Secret Key</b> in the form below.
</p>
<p>
The callback url to use in the application form is: <pre>$callback</pre>
</p>
</div>
<div class="row marketing">
<form action="$action" method="post" class="form-horizontal">
<fieldset>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="clientid">Client ID</label>
<div class="col-md-4">
<input id="clientid" name="clientid" type="text" placeholder="Client ID" class="form-control input-md">
<span class="help-block">ClientID From the EVE Online Developers Site</span>
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="secret">Secret</label>
<div class="col-md-4">
<input id="secret" name="secret" type="password" placeholder="Secret" class="form-control input-md">
<span class="help-block">Secret From the EVE Online Developers Site</span>
</div>
</div>
<!-- Select Multiple -->
<div class="form-group">
<label class="col-md-4 control-label" for="scopes">Scopes</label>
<div class="col-md-4">
<select id="scopes" name="scopes[]" class="form-control" multiple="multiple">
<!-- in the tools directory, run: -->
<!-- php get_endpoints_and_scopes.php | grep "|" | cut -d"|" -f 3 | sort | uniq | grep -v public | awk '{ print "<option value=\"" $1 "\">" $1 "</option>"}' -->
<!-- done :D -->
<option value="esi-alliances.read_contacts.v1">esi-alliances.read_contacts.v1</option>
<option value="esi-assets.read_assets.v1">esi-assets.read_assets.v1</option>
<option value="esi-assets.read_corporation_assets.v1">esi-assets.read_corporation_assets.v1</option>
<option value="esi-bookmarks.read_character_bookmarks.v1">esi-bookmarks.read_character_bookmarks.v1</option>
<option value="esi-bookmarks.read_corporation_bookmarks.v1">esi-bookmarks.read_corporation_bookmarks.v1</option>
<option value="esi-calendar.read_calendar_events.v1">esi-calendar.read_calendar_events.v1</option>
<option value="esi-calendar.respond_calendar_events.v1">esi-calendar.respond_calendar_events.v1</option>
<option value="esi-characters.read_agents_research.v1">esi-characters.read_agents_research.v1</option>
<option value="esi-characters.read_blueprints.v1">esi-characters.read_blueprints.v1</option>
<option value="esi-characters.read_chat_channels.v1">esi-characters.read_chat_channels.v1</option>
<option value="esi-characters.read_contacts.v1">esi-characters.read_contacts.v1</option>
<option value="esi-characters.read_corporation_roles.v1">esi-characters.read_corporation_roles.v1</option>
<option value="esi-characters.read_fatigue.v1">esi-characters.read_fatigue.v1</option>
<option value="esi-characters.read_fw_stats.v1">esi-characters.read_fw_stats.v1</option>
<option value="esi-characters.read_loyalty.v1">esi-characters.read_loyalty.v1</option>
<option value="esi-characters.read_medals.v1">esi-characters.read_medals.v1</option>
<option value="esi-characters.read_notifications.v1">esi-characters.read_notifications.v1</option>
<option value="esi-characters.read_opportunities.v1">esi-characters.read_opportunities.v1</option>
<option value="esi-characters.read_standings.v1">esi-characters.read_standings.v1</option>
<option value="esi-characters.read_titles.v1">esi-characters.read_titles.v1</option>
<option value="esi-characters.write_contacts.v1">esi-characters.write_contacts.v1</option>
<option value="esi-characterstats.read.v1">esi-characterstats.read.v1</option>
<option value="esi-clones.read_clones.v1">esi-clones.read_clones.v1</option>
<option value="esi-clones.read_implants.v1">esi-clones.read_implants.v1</option>
<option value="esi-contracts.read_character_contracts.v1">esi-contracts.read_character_contracts.v1</option>
<option value="esi-contracts.read_corporation_contracts.v1">esi-contracts.read_corporation_contracts.v1</option>
<option value="esi-corporations.read_blueprints.v1">esi-corporations.read_blueprints.v1</option>
<option value="esi-corporations.read_contacts.v1">esi-corporations.read_contacts.v1</option>
<option value="esi-corporations.read_container_logs.v1">esi-corporations.read_container_logs.v1</option>
<option value="esi-corporations.read_corporation_membership.v1">esi-corporations.read_corporation_membership.v1</option>
<option value="esi-corporations.read_divisions.v1">esi-corporations.read_divisions.v1</option>
<option value="esi-corporations.read_facilities.v1">esi-corporations.read_facilities.v1</option>
<option value="esi-corporations.read_fw_stats.v1">esi-corporations.read_fw_stats.v1</option>
<option value="esi-corporations.read_medals.v1">esi-corporations.read_medals.v1</option>
<option value="esi-corporations.read_standings.v1">esi-corporations.read_standings.v1</option>
<option value="esi-corporations.read_starbases.v1">esi-corporations.read_starbases.v1</option>
<option value="esi-corporations.read_structures.v1">esi-corporations.read_structures.v1</option>
<option value="esi-corporations.read_titles.v1">esi-corporations.read_titles.v1</option>
<option value="esi-corporations.track_members.v1">esi-corporations.track_members.v1</option>
<option value="esi-corporations.write_structures.v1">esi-corporations.write_structures.v1</option>
<option value="esi-fittings.read_fittings.v1">esi-fittings.read_fittings.v1</option>
<option value="esi-fittings.write_fittings.v1">esi-fittings.write_fittings.v1</option>
<option value="esi-fleets.read_fleet.v1">esi-fleets.read_fleet.v1</option>
<option value="esi-fleets.write_fleet.v1">esi-fleets.write_fleet.v1</option>
<option value="esi-industry.read_character_jobs.v1">esi-industry.read_character_jobs.v1</option>
<option value="esi-industry.read_character_mining.v1">esi-industry.read_character_mining.v1</option>
<option value="esi-industry.read_corporation_jobs.v1">esi-industry.read_corporation_jobs.v1</option>
<option value="esi-industry.read_corporation_mining.v1">esi-industry.read_corporation_mining.v1</option>
<option value="esi-killmails.read_corporation_killmails.v1">esi-killmails.read_corporation_killmails.v1</option>
<option value="esi-killmails.read_killmails.v1">esi-killmails.read_killmails.v1</option>
<option value="esi-location.read_location.v1">esi-location.read_location.v1</option>
<option value="esi-location.read_online.v1">esi-location.read_online.v1</option>
<option value="esi-location.read_ship_type.v1">esi-location.read_ship_type.v1</option>
<option value="esi-mail.organize_mail.v1">esi-mail.organize_mail.v1</option>
<option value="esi-mail.read_mail.v1">esi-mail.read_mail.v1</option>
<option value="esi-mail.send_mail.v1">esi-mail.send_mail.v1</option>
<option value="esi-markets.read_character_orders.v1">esi-markets.read_character_orders.v1</option>
<option value="esi-markets.read_corporation_orders.v1">esi-markets.read_corporation_orders.v1</option>
<option value="esi-markets.structure_markets.v1">esi-markets.structure_markets.v1</option>
<option value="esi-planets.manage_planets.v1">esi-planets.manage_planets.v1</option>
<option value="esi-planets.read_customs_offices.v1">esi-planets.read_customs_offices.v1</option>
<option value="esi-search.search_structures.v1">esi-search.search_structures.v1</option>
<option value="esi-skills.read_skillqueue.v1">esi-skills.read_skillqueue.v1</option>
<option value="esi-skills.read_skills.v1">esi-skills.read_skills.v1</option>
<option value="esi-ui.open_window.v1">esi-ui.open_window.v1</option>
<option value="esi-ui.write_waypoint.v1">esi-ui.write_waypoint.v1</option>
<option value="esi-universe.read_structures.v1">esi-universe.read_structures.v1</option>
<option value="esi-wallet.read_character_wallet.v1">esi-wallet.read_character_wallet.v1</option>
<option value="esi-wallet.read_corporation_wallets.v1">esi-wallet.read_corporation_wallets.v1</option>
</select>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="login"></label>
<div class="col-md-4">
<button id="login" name="login" class="btn btn-primary">Generate Login</button>
</div>
</div>
</fieldset>
</form>
</div>
EOF;
echo get_footer();
}
/**
* @param $url
*/
function print_sso_url($url)
{
echo get_header();
echo <<<EOF
<div class="jumbotron">
<p>
Click the button below to login with your EVE Online account.<br>
<a href="$url">
<img src="https://images.contentful.com/idjq7aai9ylm/18BxKSXCymyqY4QKo8KwKe/c2bdded6118472dd587c8107f24104d7/EVE_SSO_Login_Buttons_Small_White.png?w=195&h=30" />
</a>
</p>
<p>
The generated URL is:
<pre>$url</pre>
</p>
</div>
EOF;
echo get_footer();
}
/**
* @param $access_token
* @param $refresh_token
*/
function print_tokens($access_token, $refresh_token)
{
$start_again_url = $_SERVER['PHP_SELF'] . '?action=new';
echo get_header();
echo <<<EOF
<div class="jumbotron">
<p>
Your current access token is: <pre>$access_token</pre><br>
Valid for ~20 minutes.
</p>
<p>
Your refresh token is: <pre>$refresh_token</pre><br>
Valid until you delete the app from your account
<a href="https://community.eveonline.com/support/third-party-applications/">here</a>.
</p>
<a class="btn btn-lg btn-success" href="$start_again_url" role="button">Start Again</a>
</div>
EOF;
echo get_footer();
}
// Ensure we have an action!
if (! isset($_GET['action']))
redirect_to_new();
// Worlds most caveman router!
// Decide where to go based on the value of 'action'
switch ($_GET['action']) {
// Display the form to create a new login.
case 'new':
$_SESSION['test'] = 'bob';
new_login();
break;
case 'submitsecrets':
// Ensure we got some values
if (! isset($_REQUEST['clientid']) ||
! isset($_REQUEST['secret']) ||
! isset($_REQUEST['scopes'])
) {
echo 'All fields are mandatory!<br>' . PHP_EOL;
echo '<a href="' . $_SERVER['PHP_SELF'] . '?action=new">Start again</a>';
die();
}
$_SESSION['clientid'] = $_REQUEST['clientid'];
$_SESSION['secret'] = $_REQUEST['secret'];
$_SESSION['state'] = uniqid();
// Generate the url with the requested scopes
$url = 'https://login.eveonline.com/oauth/authorize/?response_type=code&redirect_uri=' .
urlencode(get_sso_callback_url()) . '&client_id=' .
$_SESSION['clientid'] . '&scope=' . implode(' ', $_REQUEST['scopes']) . ' &state=' . $_SESSION['state'];
// Print the HTML with the login button.
print_sso_url($url);
break;
case 'eveonlinecallback':
// Verify the state.
if ($_REQUEST['state'] != $_SESSION['state']) {
echo 'Invalid State! You will have to start again!<br>';
echo '<a href="' . $_SERVER['PHP_SELF'] . '?action=new">Start again</a>';
die();
}
// Clear the state value.
$_SESSION['state'] = null;
// Prep the authentication header.
$headers = [
'Authorization: Basic ' . base64_encode($_SESSION['clientid'] . ':' . $_SESSION['secret']),
'Content-Type: application/json',
];
// Seems like CCP does not mind JSON in the body. Yay.
$fields = json_encode([
'grant_type' => 'authorization_code',
'code' => $_REQUEST['code'],
]);
// Start a cURL session
$ch = curl_init('https://login.eveonline.com/oauth/token');
curl_setopt_array($ch, [
CURLOPT_URL => 'https://login.eveonline.com/oauth/token',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $fields,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'eseye/tokengenerator',
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_CIPHER_LIST => 'TLSv1',
]
);
$result = curl_exec($ch);
$data = json_decode($result);
print_tokens($data->access_token, $data->refresh_token);
break;
// If we dont know what 'action' to perform, then redirect.
default:
redirect_to_new();
break;
}

18
vendor/eveseat/eseye/bin/tokengenerator vendored Normal file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
# 2017 - Leon Jacobs
# Server the token generator app using PHP's builtin web server.
# Thanks: http://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within?answertab=votes#tab-top
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
php -S 127.0.0.1:9009 -t $DIR

35
vendor/eveseat/eseye/composer.json vendored Normal file
View File

@@ -0,0 +1,35 @@
{
"name": "eveseat/eseye",
"description": "A Standalone PHP ESI (EVE Swagger Interface) Client Library",
"type": "library",
"require": {
"php": ">= 7.1",
"guzzlehttp/guzzle": "^6.2",
"nesbot/carbon": "^1.21",
"monolog/monolog": "^1.22",
"predis/predis": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"mikey179/vfsStream": "~1",
"codeclimate/php-test-reporter": "dev-master"
},
"license": "GPL-2.0",
"authors": [
{
"name": "Leon Jacobs",
"email": "leonja511@gmail.com"
}
],
"autoload": {
"psr-4": {
"Seat\\Eseye\\": "src/"
},
"files": [
"src/Helpers/helpers.php"
]
},
"bin": [
"bin/tokengenerator"
]
}

74
vendor/eveseat/eseye/example.php vendored Normal file
View File

@@ -0,0 +1,74 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
include 'vendor/autoload.php';
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
// Disable all caching by setting the NullCache as the
// preferred cache handler. By default, Eseye will use the
// FileCache.
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
// Prepare an authentication container for ESI
$authentication = new EsiAuthentication([
'client_id' => 'SSO_CLIENT_ID',
'secret' => 'SSO_SECRET',
'refresh_token' => 'CHARACTER_REFRESH_TOKEN',
]);
// Instantiate a new ESI instance.
$esi = new Eseye($authentication);
// Get character information. This is a public call to the EVE
// Swagger Interface
$character_info = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => 1477919642,
]);
// Get the location information for a character. This is an authenticated
// call to the EVE Swagger Interface.
$location = $esi->invoke('get', '/characters/{character_id}/location/', [
'character_id' => 1477919642,
]);
$clones = $esi->invoke('get', '/characters/{character_id}/clones/', [
'character_id' => 1477919642,
]);
// Print some information from the calls we have made.
echo 'Character Name is: ' . $character_info->name . PHP_EOL;
echo 'Character was born: ' . carbon($character_info->birthday)
->diffForHumans() . PHP_EOL; // The 'carbon' helper is included in the package.
echo 'Home Solar System ID is: ' . $location->solar_system_id . PHP_EOL;
echo 'Home Station ID is: ' . $location->station_id . PHP_EOL;
echo 'You have the following clones: ' . PHP_EOL;
foreach ($clones->jump_clones as $jump_clone) {
echo 'Clone at a ' . $jump_clone->location_type .
' with ' . count($jump_clone->implants) . ' implants' . PHP_EOL;
}

17
vendor/eveseat/eseye/phpunit.xml vendored Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
bootstrap="./vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -0,0 +1,39 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Access;
/**
* Interface AccessInterface.
* @package Seat\Eseye\Access
*/
interface AccessInterface
{
/**
* @param string $method
* @param string $uri
* @param array $scopes
*
* @return bool|mixed
*/
public function can(string $method, string $uri, array $scopes): bool;
}

View File

@@ -0,0 +1,286 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Access;
use Seat\Eseye\Configuration;
/**
* Class CheckAccess.
* @package Seat\Eseye\Access
*/
class CheckAccess implements AccessInterface
{
/**
* @var array
*/
protected $scope_map = [
'get' => [
// 'meta' URI's. see: https://esi.evetech.net/ui/?version=meta
'/ping' => 'public',
// Generated using tools: php get_endpoints_and_scopes.php
'/alliances/{alliance_id}/' => 'public',
'/alliances/{alliance_id}/corporations/' => 'public',
'/alliances/names/' => 'public',
'/alliances/{alliance_id}/icons/' => 'public',
'/alliances/' => 'public',
'/characters/{character_id}/assets/' => 'esi-assets.read_assets.v1',
'/corporations/{corporation_id}/assets/' => 'esi-assets.read_corporation_assets.v1',
'/characters/{character_id}/bookmarks/' => 'esi-bookmarks.read_character_bookmarks.v1',
'/characters/{character_id}/bookmarks/folders/' => 'esi-bookmarks.read_character_bookmarks.v1',
'/corporations/{corporation_id}/bookmarks/' => 'esi-bookmarks.read_corporation_bookmarks.v1',
'/corporations/{corporation_id}/bookmarks/folders/' => 'esi-bookmarks.read_corporation_bookmarks.v1',
'/characters/{character_id}/calendar/' => 'esi-calendar.read_calendar_events.v1',
'/characters/{character_id}/calendar/{event_id}/' => 'esi-calendar.read_calendar_events.v1',
'/characters/{character_id}/calendar/{event_id}/attendees/' => 'esi-calendar.read_calendar_events.v1',
'/characters/{character_id}/stats/' => 'esi-characterstats.read.v1',
'/characters/{character_id}/' => 'public',
'/characters/names/' => 'public',
'/characters/{character_id}/portrait/' => 'public',
'/characters/{character_id}/corporationhistory/' => 'public',
'/characters/{character_id}/chat_channels/' => 'esi-characters.read_chat_channels.v1',
'/characters/{character_id}/medals/' => 'esi-characters.read_medals.v1',
'/characters/{character_id}/standings/' => 'esi-characters.read_standings.v1',
'/characters/{character_id}/agents_research/' => 'esi-characters.read_agents_research.v1',
'/characters/{character_id}/blueprints/' => 'esi-characters.read_blueprints.v1',
'/characters/{character_id}/fatigue/' => 'esi-characters.read_fatigue.v1',
'/characters/{character_id}/notifications/contacts/' => 'esi-characters.read_notifications.v1',
'/characters/{character_id}/notifications/' => 'esi-characters.read_notifications.v1',
'/characters/{character_id}/roles/' => 'esi-characters.read_corporation_roles.v1',
'/characters/{character_id}/titles/' => 'esi-characters.read_titles.v1',
'/characters/{character_id}/clones/' => 'esi-clones.read_clones.v1',
'/characters/{character_id}/implants/' => 'esi-clones.read_implants.v1',
'/characters/{character_id}/contacts/' => 'esi-characters.read_contacts.v1',
'/corporations/{corporation_id}/contacts/' => 'esi-corporations.read_contacts.v1',
'/alliances/{alliance_id}/contacts/' => 'esi-alliances.read_contacts.v1',
'/characters/{character_id}/contacts/labels/' => 'esi-characters.read_contacts.v1',
'/characters/{character_id}/contracts/' => 'esi-contracts.read_character_contracts.v1',
'/characters/{character_id}/contracts/{contract_id}/items/' => 'esi-contracts.read_character_contracts.v1',
'/characters/{character_id}/contracts/{contract_id}/bids/' => 'esi-contracts.read_character_contracts.v1',
'/corporations/{corporation_id}/contracts/' => 'esi-contracts.read_corporation_contracts.v1',
'/corporations/{corporation_id}/contracts/{contract_id}/items/' => 'esi-contracts.read_corporation_contracts.v1',
'/corporations/{corporation_id}/contracts/{contract_id}/bids/' => 'esi-contracts.read_corporation_contracts.v1',
'/corporations/{corporation_id}/shareholders/' => 'esi-wallet.read_corporation_wallets.v1',
'/corporations/{corporation_id}/' => 'public',
'/corporations/{corporation_id}/alliancehistory/' => 'public',
'/corporations/names/' => 'public',
'/corporations/{corporation_id}/members/' => 'esi-corporations.read_corporation_membership.v1',
'/corporations/{corporation_id}/roles/' => 'esi-corporations.read_corporation_membership.v1',
'/corporations/{corporation_id}/roles/history/' => 'esi-corporations.read_corporation_membership.v1',
'/corporations/{corporation_id}/icons/' => 'public',
'/corporations/npccorps/' => 'public',
'/corporations/{corporation_id}/structures/' => 'esi-corporations.read_structures.v1',
'/corporations/{corporation_id}/membertracking/' => 'esi-corporations.track_members.v1',
'/corporations/{corporation_id}/divisions/' => 'esi-corporations.read_divisions.v1',
'/corporations/{corporation_id}/members/limit/' => 'esi-corporations.track_members.v1',
'/corporations/{corporation_id}/titles/' => 'esi-corporations.read_titles.v1',
'/corporations/{corporation_id}/members/titles/' => 'esi-corporations.read_titles.v1',
'/corporations/{corporation_id}/blueprints/' => 'esi-corporations.read_blueprints.v1',
'/corporations/{corporation_id}/standings/' => 'esi-corporations.read_standings.v1',
'/corporations/{corporation_id}/starbases/' => 'esi-corporations.read_starbases.v1',
'/corporations/{corporation_id}/starbases/{starbase_id}/' => 'esi-corporations.read_starbases.v1',
'/corporations/{corporation_id}/containers/logs/' => 'esi-corporations.read_container_logs.v1',
'/corporations/{corporation_id}/facilities/' => 'esi-corporations.read_facilities.v1',
'/corporations/{corporation_id}/medals/' => 'esi-corporations.read_medals.v1',
'/corporations/{corporation_id}/medals/issued/' => 'esi-corporations.read_medals.v1',
'/dogma/attributes/' => 'public',
'/dogma/attributes/{attribute_id}/' => 'public',
'/dogma/effects/' => 'public',
'/dogma/effects/{effect_id}/' => 'public',
'/fw/wars/' => 'public',
'/fw/stats/' => 'public',
'/fw/systems/' => 'public',
'/fw/leaderboards/' => 'public',
'/fw/leaderboards/characters/' => 'public',
'/fw/leaderboards/corporations/' => 'public',
'/corporations/{corporation_id}/fw/stats/' => 'esi-corporations.read_fw_stats.v1',
'/characters/{character_id}/fw/stats/' => 'esi-characters.read_fw_stats.v1',
'/characters/{character_id}/fittings/' => 'esi-fittings.read_fittings.v1',
'/fleets/{fleet_id}/' => 'esi-fleets.read_fleet.v1',
'/characters/{character_id}/fleet/' => 'esi-fleets.read_fleet.v1',
'/fleets/{fleet_id}/members/' => 'esi-fleets.read_fleet.v1',
'/fleets/{fleet_id}/wings/' => 'esi-fleets.read_fleet.v1',
'/incursions/' => 'public',
'/industry/facilities/' => 'public',
'/industry/systems/' => 'public',
'/characters/{character_id}/industry/jobs/' => 'esi-industry.read_character_jobs.v1',
'/characters/{character_id}/mining/' => 'esi-industry.read_character_mining.v1',
'/corporation/{corporation_id}/mining/observers/' => 'esi-industry.read_corporation_mining.v1',
'/corporation/{corporation_id}/mining/observers/{observer_id}/' => 'esi-industry.read_corporation_mining.v1',
'/corporations/{corporation_id}/industry/jobs/' => 'esi-industry.read_corporation_jobs.v1',
'/corporation/{corporation_id}/mining/extractions/' => 'esi-industry.read_corporation_mining.v1',
'/insurance/prices/' => 'public',
'/killmails/{killmail_id}/{killmail_hash}/' => 'public',
'/characters/{character_id}/killmails/recent/' => 'esi-killmails.read_killmails.v1',
'/corporations/{corporation_id}/killmails/recent/' => 'esi-killmails.read_corporation_killmails.v1',
'/characters/{character_id}/location/' => 'esi-location.read_location.v1',
'/characters/{character_id}/ship/' => 'esi-location.read_ship_type.v1',
'/characters/{character_id}/online/' => 'esi-location.read_online.v1',
'/loyalty/stores/{corporation_id}/offers/' => 'public',
'/characters/{character_id}/loyalty/points/' => 'esi-characters.read_loyalty.v1',
'/characters/{character_id}/mail/' => 'esi-mail.read_mail.v1',
'/characters/{character_id}/mail/labels/' => 'esi-mail.read_mail.v1',
'/characters/{character_id}/mail/lists/' => 'esi-mail.read_mail.v1',
'/characters/{character_id}/mail/{mail_id}/' => 'esi-mail.read_mail.v1',
'/markets/prices/' => 'public',
'/markets/{region_id}/orders/' => 'public',
'/markets/{region_id}/history/' => 'public',
'/markets/structures/{structure_id}/' => 'esi-markets.structure_markets.v1',
'/markets/groups/' => 'public',
'/markets/groups/{market_group_id}/' => 'public',
'/characters/{character_id}/orders/' => 'esi-markets.read_character_orders.v1',
'/markets/{region_id}/types/' => 'public',
'/corporations/{corporation_id}/orders/' => 'esi-markets.read_corporation_orders.v1',
'/opportunities/groups/' => 'public',
'/opportunities/groups/{group_id}/' => 'public',
'/opportunities/tasks/' => 'public',
'/opportunities/tasks/{task_id}/' => 'public',
'/characters/{character_id}/opportunities/' => 'esi-characters.read_opportunities.v1',
'/characters/{character_id}/planets/' => 'esi-planets.manage_planets.v1',
'/characters/{character_id}/planets/{planet_id}/' => 'esi-planets.manage_planets.v1',
'/universe/schematics/{schematic_id}/' => 'public',
'/corporations/{corporation_id}/customs_offices/' => 'esi-planets.read_customs_offices.v1',
'/route/{origin}/{destination}/' => 'public',
'/characters/{character_id}/search/' => 'esi-search.search_structures.v1',
'/search/' => 'public',
'/characters/{character_id}/skillqueue/' => 'esi-skills.read_skillqueue.v1',
'/characters/{character_id}/skills/' => 'esi-skills.read_skills.v1',
'/characters/{character_id}/attributes/' => 'esi-skills.read_skills.v1',
'/sovereignty/structures/' => 'public',
'/sovereignty/campaigns/' => 'public',
'/sovereignty/map/' => 'public',
'/status/' => 'public',
'/universe/planets/{planet_id}/' => 'public',
'/universe/stations/{station_id}/' => 'public',
'/universe/structures/{structure_id}/' => 'esi-universe.read_structures.v1',
'/universe/systems/{system_id}/' => 'public',
'/universe/systems/' => 'public',
'/universe/types/{type_id}/' => 'public',
'/universe/types/' => 'public',
'/universe/groups/' => 'public',
'/universe/groups/{group_id}/' => 'public',
'/universe/categories/' => 'public',
'/universe/categories/{category_id}/' => 'public',
'/universe/structures/' => 'public',
'/universe/races/' => 'public',
'/universe/factions/' => 'public',
'/universe/bloodlines/' => 'public',
'/universe/regions/' => 'public',
'/universe/regions/{region_id}/' => 'public',
'/universe/constellations/' => 'public',
'/universe/constellations/{constellation_id}/' => 'public',
'/universe/moons/{moon_id}/' => 'public',
'/universe/stargates/{stargate_id}/' => 'public',
'/universe/graphics/' => 'public',
'/universe/graphics/{graphic_id}/' => 'public',
'/universe/system_jumps/' => 'public',
'/universe/system_kills/' => 'public',
'/universe/stars/{star_id}/' => 'public',
'/characters/{character_id}/wallet/' => 'esi-wallet.read_character_wallet.v1',
'/characters/{character_id}/wallet/journal/' => 'esi-wallet.read_character_wallet.v1',
'/characters/{character_id}/wallet/transactions/' => 'esi-wallet.read_character_wallet.v1',
'/corporations/{corporation_id}/wallets/' => 'esi-wallet.read_corporation_wallets.v1',
'/corporations/{corporation_id}/wallets/{division}/journal/' => 'esi-wallet.read_corporation_wallets.v1',
'/corporations/{corporation_id}/wallets/{division}/transactions/' => 'esi-wallet.read_corporation_wallets.v1',
'/wars/' => 'public',
'/wars/{war_id}/' => 'public',
'/wars/{war_id}/killmails/' => 'public',
],
'post' => [
'/characters/{character_id}/assets/names/' => 'esi-assets.read_assets.v1',
'/characters/{character_id}/assets/locations/' => 'esi-assets.read_assets.v1',
'/corporations/{corporation_id}/assets/names/' => 'esi-assets.read_corporation_assets.v1',
'/corporations/{corporation_id}/assets/locations/' => 'esi-assets.read_corporation_assets.v1',
'/characters/affiliation/' => 'public',
'/characters/{character_id}/cspa/' => 'esi-characters.read_contacts.v1',
'/characters/{character_id}/contacts/' => 'esi-characters.write_contacts.v1',
'/characters/{character_id}/fittings/' => 'esi-fittings.write_fittings.v1',
'/fleets/{fleet_id}/members/' => 'esi-fleets.write_fleet.v1',
'/fleets/{fleet_id}/wings/' => 'esi-fleets.write_fleet.v1',
'/fleets/{fleet_id}/wings/{wing_id}/squads/' => 'esi-fleets.write_fleet.v1',
'/characters/{character_id}/mail/' => 'esi-mail.send_mail.v1',
'/characters/{character_id}/mail/labels/' => 'esi-mail.organize_mail.v1',
'/universe/names/' => 'public',
'/universe/ids/' => 'public',
'/ui/openwindow/marketdetails/' => 'esi-ui.open_window.v1',
'/ui/openwindow/contract/' => 'esi-ui.open_window.v1',
'/ui/openwindow/information/' => 'esi-ui.open_window.v1',
'/ui/autopilot/waypoint/' => 'esi-ui.write_waypoint.v1',
'/ui/openwindow/newmail/' => 'esi-ui.open_window.v1',
],
'put' => [
'/characters/{character_id}/calendar/{event_id}/' => 'esi-calendar.respond_calendar_events.v1',
'/characters/{character_id}/contacts/' => 'esi-characters.write_contacts.v1',
'/corporations/{corporation_id}/structures/{structure_id}/' => 'esi-corporations.write_structures.v1',
'/fleets/{fleet_id}/' => 'esi-fleets.write_fleet.v1',
'/fleets/{fleet_id}/members/{member_id}/' => 'esi-fleets.write_fleet.v1',
'/fleets/{fleet_id}/wings/{wing_id}/' => 'esi-fleets.write_fleet.v1',
'/fleets/{fleet_id}/squads/{squad_id}/' => 'esi-fleets.write_fleet.v1',
'/characters/{character_id}/mail/{mail_id}/' => 'esi-mail.organize_mail.v1',
],
'delete' => [
'/characters/{character_id}/contacts/' => 'esi-characters.write_contacts.v1',
'/characters/{character_id}/fittings/{fitting_id}/' => 'esi-fittings.write_fittings.v1',
'/fleets/{fleet_id}/members/{member_id}/' => 'esi-fleets.write_fleet.v1',
'/fleets/{fleet_id}/wings/{wing_id}/' => 'esi-fleets.write_fleet.v1',
'/fleets/{fleet_id}/squads/{squad_id}/' => 'esi-fleets.write_fleet.v1',
'/characters/{character_id}/mail/labels/{label_id}/' => 'esi-mail.organize_mail.v1',
'/characters/{character_id}/mail/{mail_id}/' => 'esi-mail.organize_mail.v1',
],
'patch' => [
],
];
/**
* @param string $method
* @param string $uri
* @param array $scopes
*
* @return bool|mixed
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function can(string $method, string $uri, array $scopes): bool
{
if (! array_key_exists($uri, $this->scope_map[$method])) {
Configuration::getInstance()->getLogger()
->warning('An unknown URI was called. Allowing ' . $uri);
return true;
}
$required_scope = $this->scope_map[$method][$uri];
// Public scopes require no authentication!
if ($required_scope == 'public')
return true;
if (! in_array($required_scope, $scopes))
return false;
return true;
}
}

View File

@@ -0,0 +1,65 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Cache;
use Seat\Eseye\Containers\EsiResponse;
/**
* Interface CacheInterface.
* @package Seat\Eseye\Cache
*/
interface CacheInterface
{
/**
* @param string $uri
* @param string $query
* @param \Seat\Eseye\Containers\EsiResponse $data
*
* @return mixed
*/
public function set(string $uri, string $query, EsiResponse $data);
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function get(string $uri, string $query = '');
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function forget(string $uri, string $query = '');
/**
* @param string $uri
* @param string $query
*
* @return bool|mixed
*/
public function has(string $uri, string $query = ''): bool;
}

View File

@@ -0,0 +1,207 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Cache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiResponse;
use Seat\Eseye\Exceptions\CachePathException;
/**
* Class FileCache.
* @package Seat\Eseye\Cache
*/
class FileCache implements CacheInterface
{
use HashesStrings;
/**
* @var string
*/
protected $cache_path;
/**
* @var string
*/
protected $results_filename = 'results.cache';
/**
* FileCache constructor.
* @throws \Seat\Eseye\Exceptions\CachePathException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function __construct()
{
$this->cache_path = Configuration::getInstance()
->file_cache_location;
// Ensure the cache directory is OK
$this->checkCacheDirectory();
}
/**
* @return bool
* @throws \Seat\Eseye\Exceptions\CachePathException
*/
public function checkCacheDirectory()
{
// Ensure the cache path exists
if (! is_dir($this->cache_path) &&
! @mkdir($this->cache_path, 0775, true)
) {
throw new CachePathException(
'Unable to create cache directory ' . $this->cache_path);
}
// Ensure the cache directory is readable/writable
if (! is_readable($this->cache_path) ||
! is_writable($this->cache_path)
) {
if (! chmod($this->getCachePath(), 0775))
throw new CachePathException(
$this->cache_path . ' must be readable and writable');
}
return true;
}
/**
* @return string
*/
public function getCachePath(): string
{
return $this->cache_path;
}
/**
* @param string $uri
* @param string $query
* @param \Seat\Eseye\Containers\EsiResponse $data
*
* @return mixed|void
*/
public function set(string $uri, string $query, EsiResponse $data)
{
$path = $this->buildRelativePath($this->safePath($uri), $query);
// Create the subpath if that does not already exist
if (! file_exists($path))
@mkdir($path, 0775, true);
// Dump the contents to file
file_put_contents($path . $this->results_filename, serialize($data));
}
/**
* @param string $path
* @param string $query
*
* @return string
*/
public function buildRelativePath(string $path, string $query = ''): string
{
// If the query string has data, hash it.
if ($query != '')
$query = $this->hashString($query);
return rtrim(rtrim($this->cache_path, '/') . rtrim($path), '/') .
'/' . $query . '/';
}
/**
* @param string $uri
*
* @return string
*/
public function safePath(string $uri): string
{
return preg_replace('/[^A-Za-z0-9\/]/', '', $uri);
}
/**
* @param string $uri
* @param string $query
*
* @return bool|mixed
*/
public function has(string $uri, string $query = ''): bool
{
if ($status = $this->get($uri, $query))
return true;
return false;
}
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function get(string $uri, string $query = '')
{
$path = $this->buildRelativePath($this->safePath($uri), $query);
$cache_file_path = $path . $this->results_filename;
// If we cant read from the cache, then just return false.
if (! is_readable($cache_file_path))
return false;
// Get the data from the file and unserialize it
$file = unserialize(file_get_contents($cache_file_path));
// If the cached entry is expired, remove it.
if ($file->expired()) {
$this->forget($uri, $query);
return false;
}
return $file;
}
/**
* @param string $uri
* @param string $query
*
* @return void
*/
public function forget(string $uri, string $query = '')
{
$path = $this->buildRelativePath($uri, $query);
$cache_file_path = $path . $this->results_filename;
@unlink($cache_file_path);
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Cache;
/**
* Class HashesStrings.
* @package Seat\Eseye\Cache
*/
trait HashesStrings
{
/**
* @param string $string
*
* @return string
*/
public function hashString(string $string)
{
return sha1($string);
}
}

View File

@@ -0,0 +1,168 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Cache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiResponse;
/**
* Class MemcachedCache.
* @package Seat\Eseye\Cache
*/
class MemcachedCache implements CacheInterface
{
use HashesStrings;
/**
* @var mixed
*/
protected $prefix;
/**
* @var bool
*/
protected $is_memcached;
/**
* @var \Memcache
*/
protected $memcached;
/**
* @var int
*/
protected $flags;
/**
* MemcachedCache constructor.
*
* @param null $instance
*
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function __construct($instance = null)
{
if ($instance != null)
$this->memcached = $instance;
$this->is_memcached = class_exists('Memcached', false);
$configuration = Configuration::getInstance();
$this->prefix = $configuration->memcached_cache_prefix;
if (is_null($this->memcached)) {
if ($this->is_memcached)
$this->memcached = new \Memcached();
else
$this->memcached = new \Memcache();
$this->memcached->addServer($configuration->memcached_cache_host, $configuration->memcached_cache_port, 0);
if ($this->is_memcached)
$this->memcached->setOption(\Memcached::OPT_COMPRESSION, ($configuration->memcached_cache_compressed));
else
$this->flags = ($configuration->memcached_cache_compressed) ? MEMCACHE_COMPRESSED : 0;
}
}
/**
* @param string $uri
* @param string $query
* @param \Seat\Eseye\Containers\EsiResponse $data
*
* @return void
*/
public function set(string $uri, string $query, EsiResponse $data)
{
if ($this->is_memcached)
$this->memcached->set($this->buildCacheKey($uri, $query), serialize($data), 0);
else
$this->memcached->set($this->buildCacheKey($uri, $query), serialize($data), $this->flags, 0);
}
/**
* @param string $uri
* @param string $query
*
* @return string
*/
public function buildCacheKey(string $uri, string $query = ''): string
{
if ($query != '')
$query = $this->hashString($query);
return $this->prefix . $this->hashString($uri . $query);
}
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function get(string $uri, string $query = '')
{
$value = $this->memcached->get($this->buildCacheKey($uri, $query));
if ($value === false)
return false;
$data = unserialize($value);
if ($data->expired()) {
$this->forget($uri, $query);
return false;
}
return $data;
}
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function forget(string $uri, string $query = '')
{
return $this->memcached->delete($this->buildCacheKey($uri, $query));
}
/**
* @param string $uri
* @param string $query
*
* @return bool|mixed
*/
public function has(string $uri, string $query = ''): bool
{
return $this->memcached->get($this->buildCacheKey($uri, $query)) !== false;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Cache;
use Seat\Eseye\Containers\EsiResponse;
/**
* Class NullCache.
* @package Seat\Eseye\Cache
*/
class NullCache implements CacheInterface
{
/**
* @param string $uri
* @param string $query
* @param \Seat\Eseye\Containers\EsiResponse $data
*
* @return mixed
*/
public function set(string $uri, string $query, EsiResponse $data)
{
}
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function get(string $uri, string $query = '')
{
return false;
}
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function forget(string $uri, string $query = '')
{
}
/**
* @param string $uri
* @param string $query
*
* @return bool|mixed
*/
public function has(string $uri, string $query = ''): bool
{
return false;
}
}

View File

@@ -0,0 +1,145 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Cache;
use Predis\Client;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiResponse;
/**
* Class RedisCache.
* @package Seat\Eseye\Cache
*/
class RedisCache implements CacheInterface
{
use HashesStrings;
/**
* @var \Predis\Client
*/
protected $redis;
/**
* RedisCache constructor.
*
* @param \Predis\Client $redis
*
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function __construct(Client $redis = null)
{
// If we didn't get a Redis instance in the constructor,
// build a new one.
if (is_null($redis)) {
$configuration = Configuration::getInstance();
$this->redis = new Client($configuration->redis_cache_location, [
'prefix' => $configuration->redis_cache_prefix,
]);
return;
}
$this->redis = $redis;
}
/**
* @param string $uri
* @param string $query
* @param \Seat\Eseye\Containers\EsiResponse $data
*
* @return void
*/
public function set(string $uri, string $query, EsiResponse $data)
{
$this->redis->set($this->buildCacheKey($uri, $query), serialize($data));
}
/**
* @param string $uri
* @param string $query
*
* @return string
*/
public function buildCacheKey(string $uri, string $query = ''): string
{
if ($query != '')
$query = $this->hashString($query);
return $this->hashString($uri . $query);
}
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function get(string $uri, string $query = '')
{
if (! $this->has($uri, $query))
return false;
$data = unserialize($this->redis
->get($this->buildCacheKey($uri, $query)));
if ($data->expired()) {
$this->forget($uri, $query);
return false;
}
return $data;
}
/**
* @param string $uri
* @param string $query
*
* @return bool|mixed
*/
public function has(string $uri, string $query = ''): bool
{
return $this->redis->exists($this->buildCacheKey($uri, $query));
}
/**
* @param string $uri
* @param string $query
*
* @return mixed
*/
public function forget(string $uri, string $query = '')
{
return $this->redis->del([$this->buildCacheKey($uri, $query)]);
}
}

View File

@@ -0,0 +1,153 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye;
use Seat\Eseye\Cache\CacheInterface;
use Seat\Eseye\Containers\EsiConfiguration;
use Seat\Eseye\Exceptions\InvalidConfigurationException;
use Seat\Eseye\Log\LogInterface;
/**
* Class Configuration.
* @package Seat\Eseye
*/
class Configuration
{
/**
* @var Configuration
*/
private static $instance;
/**
* @var LogInterface
*/
protected $logger;
/**
* @var CacheInterface
*/
protected $cache;
/**
* @var EsiConfiguration
*/
protected $configuration;
/**
* Configuration constructor.
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function __construct()
{
$this->configuration = new EsiConfiguration;
}
/**
* @return \Seat\Eseye\Configuration
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public static function getInstance(): self
{
if (is_null(self::$instance))
self::$instance = new self();
return self::$instance;
}
/**
* @return \Seat\Eseye\Containers\EsiConfiguration
*/
public function getConfiguration()
{
return $this->configuration;
}
/**
* @param \Seat\Eseye\Containers\EsiConfiguration $configuration
*
* @throws \Seat\Eseye\Exceptions\InvalidConfigurationException
*/
public function setConfiguration(EsiConfiguration $configuration)
{
if (! $configuration->valid())
throw new InvalidConfigurationException(
'The configuration is empty/invalid values');
$this->configuration = $configuration;
}
/**
* @return \Seat\Eseye\Log\LogInterface
*/
public function getLogger(): LogInterface
{
if (! $this->logger)
$this->logger = new $this->configuration->logger;
return $this->logger;
}
/**
* @return \Seat\Eseye\Cache\CacheInterface
*/
public function getCache(): CacheInterface
{
if (! $this->cache)
$this->cache = new $this->configuration->cache;
return $this->cache;
}
/**
* Magic method to get the configuration from the configuration
* property.
*
* @param $name
*
* @return mixed
*/
public function __get(string $name)
{
return $this->configuration->$name;
}
/**
* @param string $name
* @param string $value
*
* @return string
*/
public function __set(string $name, string $value)
{
return $this->configuration->$name = $value;
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Containers;
/**
* Class AbstractArrayAccess.
* @package Seat\Eseye\Containers
*/
abstract class AbstractArrayAccess implements \ArrayAccess
{
/**
* @var
*/
protected $data;
/**
* @param mixed $offset
*
* @return bool
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->data);
}
/**
* @param mixed $offset
*
* @return mixed
*/
public function offsetGet($offset)
{
return $this->data[$offset];
}
/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
$this->data[$offset] = $value;
}
/**
* @param mixed $offset
*/
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
/**
* @param $key
*
* @return mixed
*/
public function __get($key)
{
return $this[$key];
}
/**
* @param $key
* @param $val
*/
public function __set($key, $val)
{
$this[$key] = $val;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Containers;
use Seat\Eseye\Traits\ConstructsContainers;
use Seat\Eseye\Traits\ValidatesContainers;
/**
* Class EsiAuthentication.
* @package Seat\Eseye\Containers
*/
class EsiAuthentication extends AbstractArrayAccess
{
use ConstructsContainers, ValidatesContainers;
/**
* @var array
*/
protected $data = [
'client_id' => null,
'secret' => null,
'access_token' => '_',
'refresh_token' => null,
'token_expires' => '1970-01-01 00:00:00',
'scopes' => [],
];
public function setRefreshToken(String $refreshToken): self
{
$this->data['refresh_token'] = $refreshToken;
return $this;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Containers;
use Monolog\Logger;
use Seat\Eseye\Cache\FileCache;
use Seat\Eseye\Fetchers\GuzzleFetcher;
use Seat\Eseye\Log\RotatingFileLogger;
use Seat\Eseye\Traits\ConstructsContainers;
use Seat\Eseye\Traits\ValidatesContainers;
/**
* Class EsiConfiguration.
* @package Seat\Eseye\Containers
*/
class EsiConfiguration extends AbstractArrayAccess
{
use ConstructsContainers, ValidatesContainers;
/**
* @var array
*/
protected $data = [
'http_user_agent' => 'Eseye Default Library',
'datasource' => 'tranquility',
// Fetcher
'fetcher' => GuzzleFetcher::class,
// Logging
'logger' => RotatingFileLogger::class,
'logger_level' => Logger::INFO,
'logfile_location' => 'logs/',
// Rotating Logger Details
'log_max_files' => 10,
// Cache
'cache' => FileCache::class,
// File Cache
'file_cache_location' => 'cache/',
// Redis Cache
'redis_cache_location' => 'tcp://127.0.0.1',
'redis_cache_prefix' => 'eseye:',
// Memcached Cache
'memcached_cache_host' => '127.0.0.1',
'memcached_cache_port' => '11211',
'memcached_cache_prefix' => 'eseye:',
'memcached_cache_compressed' => false,
];
}

View File

@@ -0,0 +1,245 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Containers;
use ArrayObject;
use Carbon\Carbon;
/**
* Class EsiResponse.
* @package Seat\Eseye\Containers
*/
class EsiResponse extends ArrayObject
{
/**
* @var string
*/
public $raw;
/**
* @var array
*/
public $headers;
/**
* @var array
*/
public $raw_headers;
/**
* @var int
*/
public $error_limit;
/**
* @var int
*/
public $pages;
/**
* @var array
*/
protected $expires_at;
/**
* @var string
*/
protected $response_code;
/**
* @var mixed
*/
protected $error_message;
/**
* @var mixed
*/
protected $optional_return;
/**
* @var bool
*/
protected $cached_load = false;
/**
* EsiResponse constructor.
*
* @param string $data
* @param array $headers
* @param string $expires
* @param int $response_code
*/
public function __construct(
string $data, array $headers, string $expires, int $response_code)
{
// set the raw data to the raw property
$this->raw = $data;
// Normalize and parse the response headers
$this->parseHeaders($headers);
// decode and create an object from the data
$data = (object) json_decode($data);
// Ensure that the value for 'expires' is longer than
// 2 characters. The shortest expected value is 'now'. If it
// is not longer than 2 characters it might be empty.
$this->expires_at = strlen($expires) > 2 ? $expires : 'now';
$this->response_code = $response_code;
// If there is an error, set that
if (property_exists($data, 'error'))
$this->error_message = $data->error;
// If there is an error description, set that.
if (property_exists($data, 'error_description'))
$this->error_message .= ': ' . $data->error_description;
// Run the parent constructor
parent::__construct($data, ArrayObject::ARRAY_AS_PROPS);
}
/**
* Parse an array of header key value pairs.
*
* Interesting header values such as X-Esi-Error-Limit-Remain
* and X-Pages are automatically mapped to properties in this
* object.
*
* @param array $headers
*/
private function parseHeaders(array $headers)
{
// Set the raw headers as we got from the constructor.
$this->raw_headers = $headers;
// flatten the headers array so that values are not arrays themselves
// but rather simple key value pairs.
$headers = array_map(function ($value) {
if (! is_array($value))
return $value;
return implode(';', $value);
}, $headers);
// Set the parsed headers.
$this->headers = $headers;
// Check for some header values that might be interesting
// such as the current error limit and number of pages
// available.
array_key_exists('X-Esi-Error-Limit-Remain', $headers) ?
$this->error_limit = (int) $headers['X-Esi-Error-Limit-Remain'] : null;
array_key_exists('X-Pages', $headers) ? $this->pages = (int) $headers['X-Pages'] : null;
}
/**
* A helper method when a key might not exist within the
* response object.
*
* @param string $index
*
* @return mixed
*/
public function optional(string $index)
{
if (! $this->offsetExists($index))
return null;
return $this->$index;
}
/**
* Determine if this containers data should be considered
* expired.
*
* Expiry is calculated by taking the expiry time and comparing
* that to the local time. Before comparison though, the local
* time is converted to the timezone in which the expiry time
* is recorded. The resultant local time is then checked to
* ensure that the expiry is not less than local time.
*
* @return bool
*/
public function expired(): bool
{
if ($this->expires()->lte(
carbon()->now($this->expires()->timezoneName))
)
return true;
return false;
}
/**
* @return \Carbon\Carbon
*/
public function expires(): Carbon
{
return carbon($this->expires_at);
}
/**
* @return null|string
*/
public function error()
{
return $this->error_message;
}
/**
* @return int
*/
public function getErrorCode(): int
{
return $this->response_code;
}
/**
* @return bool
*/
public function setIsCachedload(): bool
{
return $this->cached_load = true;
}
/**
* @return bool
*/
public function isCachedLoad(): bool
{
return $this->cached_load;
}
}

508
vendor/eveseat/eseye/src/Eseye.php vendored Normal file
View File

@@ -0,0 +1,508 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye;
use GuzzleHttp\Psr7\Uri;
use Seat\Eseye\Access\AccessInterface;
use Seat\Eseye\Access\CheckAccess;
use Seat\Eseye\Cache\CacheInterface;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Containers\EsiResponse;
use Seat\Eseye\Exceptions\EsiScopeAccessDeniedException;
use Seat\Eseye\Exceptions\InvalidAuthenticationException;
use Seat\Eseye\Exceptions\InvalidContainerDataException;
use Seat\Eseye\Exceptions\UriDataMissingException;
use Seat\Eseye\Fetchers\FetcherInterface;
use Seat\Eseye\Log\LogInterface;
/**
* Class Eseye.
* @package Seat\Eseye
*/
class Eseye
{
/**
* The Eseye Version.
*/
const VERSION = '1.1.6';
/**
* @var \Seat\Eseye\Containers\EsiAuthentication
*/
protected $authentication;
/**
* @var
*/
protected $fetcher;
/**
* @var
*/
protected $cache;
/**
* @var \Seat\Eseye\Log\LogInterface
*/
protected $logger;
/**
* @var
*/
protected $access_checker;
/**
* @var array
*/
protected $query_string = [];
/**
* @var array
*/
protected $request_body = [];
/**
* @var string
*/
protected $esi = [
'scheme' => 'https',
'host' => 'esi.evetech.net',
];
/**
* @var string
*/
protected $version = '/latest';
/**
* HTTP verbs that could have their responses cached.
*
* @var array
*/
protected $cachable_verb = ['get'];
/**
* Eseye constructor.
*
* @param \Seat\Eseye\Containers\EsiAuthentication $authentication
*
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function __construct(
EsiAuthentication $authentication = null)
{
if (! is_null($authentication))
$this->authentication = $authentication;
// Setup the logger
$this->logger = $this->getLogger();
return $this;
}
/**
* @return \Seat\Eseye\Log\LogInterface
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function getLogger(): LogInterface
{
return $this->getConfiguration()->getLogger();
}
/**
* @return \Seat\Eseye\Configuration
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function getConfiguration(): Configuration
{
return Configuration::getInstance();
}
/**
* @return \Seat\Eseye\Containers\EsiAuthentication
* @throws \Seat\Eseye\Exceptions\InvalidAuthenticationException
*/
public function getAuthentication(): EsiAuthentication
{
if (is_null($this->authentication))
throw new InvalidAuthenticationException('Authentication data not set.');
return $this->authentication;
}
/**
* @param \Seat\Eseye\Containers\EsiAuthentication $authentication
*
* @return \Seat\Eseye\Eseye
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function setAuthentication(EsiAuthentication $authentication): self
{
if (! $authentication->valid())
throw new InvalidContainerDataException('Authentication data invalid/empty');
$this->authentication = $authentication;
return $this;
}
/**
* @param string $refreshToken
*
* @return \Seat\Eseye\Eseye
*/
public function setRefreshToken(String $refreshToken): self
{
$this->authentication = $this->authentication->setRefreshToken($refreshToken);
return $this;
}
/**
* @param \Seat\Eseye\Fetchers\FetcherInterface $fetcher
*/
public function setFetcher(FetcherInterface $fetcher)
{
$this->fetcher = $fetcher;
}
/**
* @param array $body
*
* @return \Seat\Eseye\Eseye
*/
public function setBody(array $body): self
{
$this->request_body = $body;
return $this;
}
/**
* @param string $method
* @param string $uri
* @param array $uri_data
*
* @return \Seat\Eseye\Containers\EsiResponse
* @throws \Seat\Eseye\Exceptions\EsiScopeAccessDeniedException
* @throws \Seat\Eseye\Exceptions\UriDataMissingException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function invoke(string $method, string $uri, array $uri_data = []): EsiResponse
{
// Check the Access Requirement
if (! $this->getAccessChecker()->can(
$method, $uri, $this->getFetcher()->getAuthenticationScopes())
) {
// Build the uri so that there is context around what is denied.
$uri = $this->buildDataUri($uri, $uri_data);
// Log the deny.
$this->logger->warning('Access denied to ' . $uri . ' due to ' .
'missing scopes.');
throw new EsiScopeAccessDeniedException('Access denied to ' . $uri);
}
// Build the URI from the parts we have.
$uri = $this->buildDataUri($uri, $uri_data);
// Check if there is a cached response we can return
if (in_array(strtolower($method), $this->cachable_verb) &&
$cached = $this->getCache()->get($uri->getPath(), $uri->getQuery())
) {
// Mark the response as one that was loaded from the cache
$cached->setIsCachedload();
// Perform some debug logging
$this->getLogger()->debug('Loaded cached response for ' . $method . ' -> ' . $uri);
return $cached;
}
// Call ESI itself and get the EsiResponse
$result = $this->rawFetch($method, $uri, $this->getBody());
// Cache the response if it was a get and is not already expired
if (in_array(strtolower($method), $this->cachable_verb) && ! $result->expired())
$this->getCache()->set($uri->getPath(), $uri->getQuery(), $result);
// In preparation for the next request, perform some
// self cleanups of this objects request data such as
// query string parameters and post bodies.
$this->cleanupRequestData();
return $result;
}
/**
* @return \Seat\Eseye\Access\CheckAccess
*/
public function getAccessChecker()
{
if (! $this->access_checker)
$this->access_checker = new CheckAccess;
return $this->access_checker;
}
/**
* @param \Seat\Eseye\Access\AccessInterface $checker
*
* @return \Seat\Eseye\Eseye
*/
public function setAccessChecker(AccessInterface $checker): self
{
$this->access_checker = $checker;
return $this;
}
/**
* @return \Seat\Eseye\Fetchers\FetcherInterface
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
private function getFetcher(): FetcherInterface
{
if (! $this->fetcher) {
$fetcher_class = $this->getConfiguration()->fetcher;
$this->fetcher = new $fetcher_class(...[$this->authentication]);
}
return $this->fetcher;
}
/**
* @param string $uri
* @param array $data
*
* @return \GuzzleHttp\Psr7\Uri
* @throws \Seat\Eseye\Exceptions\UriDataMissingException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function buildDataUri(string $uri, array $data): Uri
{
// Create a query string for the URI. We automatically
// include the datasource value from the configuration.
$query_params = array_merge([
'datasource' => $this->getConfiguration()->datasource,
], $this->getQueryString());
return Uri::fromParts([
'scheme' => $this->esi['scheme'],
'host' => $this->esi['host'],
'path' => rtrim($this->getVersion(), '/') .
$this->mapDataToUri($uri, $data),
'query' => http_build_query($query_params),
]);
}
/**
* @return array
*/
public function getQueryString(): array
{
return $this->query_string;
}
/**
* @param array $query
*
* @return \Seat\Eseye\Eseye
*/
public function setQueryString(array $query): self
{
foreach ($query as $key => $value) {
if (is_array($value)) {
$query[$key] = implode(',', $value);
}
}
$this->query_string = array_merge($this->query_string, $query);
return $this;
}
/**
* Get the versioned baseURI to use.
*
* @return string
*/
public function getVersion(): string
{
return $this->version;
}
/**
* Set the version of the API endpoints base URI.
*
* @param string $version
*
* @return \Seat\Eseye\Eseye
*/
public function setVersion(string $version)
{
if (substr($version, 0, 1) !== '/')
$version = '/' . $version;
$this->version = $version;
return $this;
}
/**
* @param string $uri
* @param array $data
*
* @return string
* @throws \Seat\Eseye\Exceptions\UriDataMissingException
*/
private function mapDataToUri(string $uri, array $data): string
{
// Extract fields in curly braces. If there are fields,
// replace the data with those in the URI
if (preg_match_all('/{+(.*?)}/', $uri, $matches)) {
if (empty($data))
throw new UriDataMissingException(
'The data array for the uri ' . $uri . ' is empty. Please provide data to use.');
foreach ($matches[1] as $match) {
if (! array_key_exists($match, $data))
throw new UriDataMissingException(
'Data for ' . $match . ' is missing. Please provide this by setting a value ' .
'for ' . $match . '.');
$uri = str_replace('{' . $match . '}', $data[$match], $uri);
}
}
return $uri;
}
/**
* @return \Seat\Eseye\Cache\CacheInterface
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
private function getCache(): CacheInterface
{
return $this->getConfiguration()->getCache();
}
/**
* @param string $method
* @param string $uri
* @param array $body
*
* @return mixed
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function rawFetch(string $method, string $uri, array $body)
{
return $this->getFetcher()->call($method, $uri, $body);
}
/**
* @return array
*/
public function getBody(): array
{
return $this->request_body;
}
/**
* @return \Seat\Eseye\Eseye
*/
public function cleanupRequestData(): self
{
$this->unsetBody();
$this->unsetQueryString();
return $this;
}
/**
* @return \Seat\Eseye\Eseye
*/
public function unsetBody(): self
{
$this->request_body = [];
return $this;
}
/**
* @return \Seat\Eseye\Eseye
*/
public function unsetQueryString(): self
{
$this->query_string = [];
return $this;
}
/**
* A helper method to specify the page to retrieve.
*
* @param int $page
*
* @return \Seat\Eseye\Eseye
*/
public function page(int $page): self
{
$this->setQueryString(['page' => $page]);
return $this;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Exceptions;
use Exception;
/**
* Class CachePathException.
* @package Seat\Eseye\Exceptions
*/
class CachePathException extends Exception
{
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Exceptions;
use Exception;
/**
* Class EsiScopeAccessDeniedException.
* @package Seat\Eseye\Exceptions
*/
class EsiScopeAccessDeniedException extends Exception
{
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Exceptions;
use Exception;
/**
* Class InvalidAuthenticationException.
* @package Seat\Eseye\Exceptions
*/
class InvalidAuthenticationException extends Exception
{
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Exceptions;
use Exception;
/**
* Class InvalidConfigurationException.
* @package Seat\Eseye\Exceptions
*/
class InvalidConfigurationException extends Exception
{
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Exceptions;
use Exception;
/**
* Class InvalidContainerDataException.
* @package Seat\Eseye\Exceptions
*/
class InvalidContainerDataException extends Exception
{
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Exceptions;
use Exception;
/**
* Class InvalidEsiSpecException.
* @package Seat\Eseye\Exceptions
*/
class InvalidEsiSpecException extends Exception
{
}

View File

@@ -0,0 +1,91 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Exceptions;
use Exception;
use Seat\Eseye\Containers\EsiResponse;
/**
* Class RequestFailedException.
* @package Seat\Eseye\Exceptions
*/
class RequestFailedException extends Exception
{
/**
* @var \Seat\Eseye\Containers\EsiResponse
*/
private $esi_response;
/**
* @var \Exception
*/
private $original_exception;
/**
* RequestFailedException constructor.
*
* @param \Exception $exception
* @param \Seat\Eseye\Containers\EsiResponse $esi_response
*/
public function __construct(Exception $exception, EsiResponse $esi_response)
{
$this->esi_response = $esi_response;
$this->original_exception = $exception;
// Finish constructing the exception
parent::__construct(
$this->getError(),
$this->getEsiResponse()->getErrorCode(),
$exception->getPrevious()
);
}
/**
* @return null|string
*/
public function getError()
{
return $this->getEsiResponse()->error();
}
/**
* @return \Seat\Eseye\Containers\EsiResponse
*/
public function getEsiResponse(): EsiResponse
{
return $this->esi_response;
}
/**
* @return \Exception
*/
public function getOriginalException(): Exception
{
return $this->original_exception;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Exceptions;
use Exception;
/**
* Class UriDataMissingException.
* @package Seat\Eseye\Exceptions
*/
class UriDataMissingException extends Exception
{
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Fetchers;
use Seat\Eseye\Containers\EsiResponse;
/**
* Interface FetcherInterface.
* @package Seat\Eseye\Fetchers
*/
interface FetcherInterface
{
/**
* @param string $method
* @param string $uri
* @param array $body
* @param array $headers
*
* @return \Seat\Eseye\Containers\EsiResponse
*/
public function call(string $method, string $uri, array $body, array $headers = []): EsiResponse;
/**
* @return array
*/
public function getAuthenticationScopes(): array;
}

View File

@@ -0,0 +1,377 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Fetchers;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Containers\EsiResponse;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\InvalidAuthenticationException;
use Seat\Eseye\Exceptions\RequestFailedException;
/**
* Class GuzzleFetcher.
* @package Seat\Eseye\Fetchers
*/
class GuzzleFetcher implements FetcherInterface
{
/**
* @var string
*/
protected $authentication;
/**
* @var \GuzzleHttp\Client
*/
protected $client;
/**
* @var \Seat\Eseye\Log\LogInterface
*/
protected $logger;
/**
* @var string
*/
protected $sso_base = 'https://login.eveonline.com/oauth';
/**
* EseyeFetcher constructor.
*
* @param \Seat\Eseye\Containers\EsiAuthentication $authentication
*
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function __construct(EsiAuthentication $authentication = null)
{
$this->authentication = $authentication;
// Setup the logger
$this->logger = Configuration::getInstance()->getLogger();
}
/**
* @param string $method
* @param string $uri
* @param array $body
* @param array $headers
*
* @return mixed|\Seat\Eseye\Containers\EsiResponse
* @throws \Seat\Eseye\Exceptions\InvalidAuthenticationException
* @throws \Seat\Eseye\Exceptions\RequestFailedException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function call(
string $method, string $uri, array $body, array $headers = []): EsiResponse
{
// If we have authentication data, add the
// Authorization header.
if ($this->getAuthentication())
$headers = array_merge($headers, [
'Authorization' => 'Bearer ' . $this->getToken(),
]);
return $this->httpRequest($method, $uri, $headers, $body);
}
/**
* @return \Seat\Eseye\Containers\EsiAuthentication|null
*/
public function getAuthentication()
{
return $this->authentication;
}
/**
* @param \Seat\Eseye\Containers\EsiAuthentication $authentication
*
* @throws \Seat\Eseye\Exceptions\InvalidAuthenticationException
*/
public function setAuthentication(EsiAuthentication $authentication)
{
if (! $authentication->valid())
throw new InvalidAuthenticationException('Authentication data invalid/empty');
$this->authentication = $authentication;
}
/**
* @return string
* @throws \Seat\Eseye\Exceptions\InvalidAuthenticationException
* @throws \Seat\Eseye\Exceptions\RequestFailedException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
private function getToken(): string
{
// Ensure that we have authentication data before we try
// and get a token.
if (! $this->getAuthentication())
throw new InvalidAuthenticationException(
'Trying to get a token without authentication data.');
// Check the expiry date.
$expires = carbon($this->getAuthentication()->token_expires);
// If the token expires in the next minute, refresh it.
if ($expires->lte(carbon('now')->addMinute(1)))
$this->refreshToken();
return $this->getAuthentication()->access_token;
}
/**
* Refresh the Access token that we have in the EsiAccess container.
*
* @throws \Seat\Eseye\Exceptions\RequestFailedException
* @throws \Seat\Eseye\Exceptions\InvalidAuthenticationException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
private function refreshToken()
{
// Make the post request for a new access_token
$response = $this->httpRequest('post',
$this->sso_base . '/token/?grant_type=refresh_token&refresh_token=' .
$this->authentication->refresh_token, [
'Authorization' => 'Basic ' . base64_encode(
$this->authentication->client_id . ':' . $this->authentication->secret),
]
);
// Get the current EsiAuth container
$authentication = $this->getAuthentication();
// Set the new authentication values from the request
$authentication->access_token = $response->access_token;
$authentication->refresh_token = $response->refresh_token;
$authentication->token_expires = carbon('now')
->addSeconds($response->expires_in);
// ... and update the container
$this->setAuthentication($authentication);
}
/**
* @param string $method
* @param string $uri
* @param array $headers
* @param array $body
*
* @return mixed|\Seat\Eseye\Containers\EsiResponse
* @throws \Seat\Eseye\Exceptions\RequestFailedException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function httpRequest(
string $method, string $uri, array $headers = [], array $body = []): EsiResponse
{
// Include some basic headers to those already passed in. Everything
// is considered to be Json.
$headers = array_merge($headers, [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'User-Agent' => 'Eseye/' . Eseye::VERSION . '/' .
Configuration::getInstance()->http_user_agent,
]);
// Add some debug logging and start measuring how long the request took.
$this->logger->debug('Making ' . $method . ' request to ' . $uri);
$start = microtime(true);
// Json encode the body if it has data, else just null it
if (count($body) > 0)
$body = json_encode($body);
else
$body = null;
try {
// Make the _actual_ request to ESI
$response = $this->getClient()->send(
new Request($method, $uri, $headers, $body));
} catch (ClientException | ServerException $e) {
// Log the event as failed
$this->logger->error('[http ' . $e->getResponse()->getStatusCode() . ', ' .
strtolower($e->getResponse()->getReasonPhrase()) . '] ' .
$method . ' -> ' . $this->stripRefreshTokenValue($uri) . ' [t/e: ' .
number_format(microtime(true) - $start, 2) . 's/' .
implode(' ', $e->getResponse()->getHeader('X-Esi-Error-Limit-Remain')) . ']'
);
// Grab the body from the StreamInterface intance.
$responseBody = $e->getResponse()->getBody()->getContents();
// For debugging purposes, log the response body
$this->logger->debug('Request for ' . $method . ' -> ' . $uri . ' failed. Response body was: ' .
$responseBody);
// Raise the exception that should be handled by the caller
throw new RequestFailedException($e, $this->makeEsiResponse(
$responseBody,
$e->getResponse()->getHeaders(),
'now',
$e->getResponse()->getStatusCode())
);
}
// Log the successful request.
$this->logger->log('[http ' . $response->getStatusCode() . ', ' .
strtolower($response->getReasonPhrase()) . '] ' .
$method . ' -> ' . $this->stripRefreshTokenValue($uri) . ' [t/e: ' .
number_format(microtime(true) - $start, 2) . 's/' .
implode(' ', $response->getHeader('X-Esi-Error-Limit-Remain')) . ']'
);
// Return a container response that can be parsed.
return $this->makeEsiResponse(
$response->getBody()->getContents(),
$response->getHeaders(),
$response->hasHeader('Expires') ? $response->getHeader('Expires')[0] : 'now',
$response->getStatusCode()
);
}
/**
* @return \GuzzleHttp\Client
*/
public function getClient(): Client
{
if (! $this->client)
$this->client = new Client([
'timeout' => 30,
]);
return $this->client;
}
/**
* @param \GuzzleHttp\Client $client
*/
public function setClient(Client $client)
{
$this->client = $client;
}
/**
* @param string $uri
*
* @return string
*/
public function stripRefreshTokenValue(string $uri): string
{
// If we have 'refresh_token' in the URI, strip it.
if (strpos($uri, 'refresh_token'))
return Uri::withoutQueryValue((new Uri($uri)), 'refresh_token')
->__toString();
return $uri;
}
/**
* @param string $body
* @param array $headers
* @param string $expires
* @param int $status_code
*
* @return \Seat\Eseye\Containers\EsiResponse
*/
public function makeEsiResponse(
string $body, array $headers, string $expires, int $status_code): EsiResponse
{
return new EsiResponse($body, $headers, $expires, $status_code);
}
/**
* @return array
*
* @throws \Seat\Eseye\Exceptions\InvalidAuthenticationException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
* @throws \Seat\Eseye\Exceptions\RequestFailedException
*/
public function getAuthenticationScopes(): array
{
// If we don't have any authentication data, then
// only public calls can be made.
if (is_null($this->getAuthentication()))
return ['public'];
// If there are no scopes that we know of, update them.
// There will always be at least 1 as we add the internal
// 'public' scope.
if (count($this->getAuthentication()->scopes) <= 0)
$this->setAuthenticationScopes();
return $this->getAuthentication()->scopes;
}
/**
* Query the eveseat/resources repository for SDE
* related information.
*
* @throws \Seat\Eseye\Exceptions\InvalidAuthenticationException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
* @throws \Seat\Eseye\Exceptions\RequestFailedException
*/
public function setAuthenticationScopes()
{
$scopes = $this->verifyToken()['Scopes'];
// Add the internal 'public' scope
$scopes = $scopes . ' public';
$this->authentication->scopes = explode(' ', $scopes);
}
/**
* Verify that an access_token is still valid.
*
* @throws \Seat\Eseye\Exceptions\RequestFailedException
* @throws \Seat\Eseye\Exceptions\InvalidAuthenticationException
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
private function verifyToken()
{
return $this->httpRequest('get', $this->sso_base . '/verify/', [
'Authorization' => 'Bearer ' . $this->getToken(),
]);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
if (! function_exists('carbon')) {
/**
* A helper to get a fresh instance of Carbon.
*
* @param null $data
*
* @return \Carbon\Carbon
*/
function carbon($data = null)
{
if (! is_null($data))
return new \Carbon\Carbon($data);
return new \Carbon\Carbon;
}
}

View File

@@ -0,0 +1,106 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Log;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Seat\Eseye\Configuration;
/**
* Class FileLogger.
* @package Seat\Eseye\Log
*/
class FileLogger implements LogInterface
{
/**
* @var \Monolog\Logger
*/
protected $logger;
/**
* FileLogger constructor.
* @throws \Exception
*/
public function __construct()
{
// Get the configuration values
$configuration = Configuration::getInstance();
$formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message%\n");
$stream = new StreamHandler(
rtrim($configuration->logfile_location, '/') . '/eseye.log',
$configuration->logger_level
);
$stream->setFormatter($formatter);
$this->logger = new Logger('eseye');
$this->logger->pushHandler($stream);
}
/**
* @param string $message
*
* @return mixed|void
*/
public function log(string $message)
{
$this->logger->addInfo($message);
}
/**
* @param string $message
*
* @return mixed|void
*/
public function debug(string $message)
{
$this->logger->addDebug($message);
}
/**
* @param string $message
*
* @return mixed|void
*/
public function warning(string $message)
{
$this->logger->addWarning($message);
}
/**
* @param string $message
*
* @return mixed|void
*/
public function error(string $message)
{
$this->logger->addError($message);
}
}

View File

@@ -0,0 +1,58 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Log;
/**
* Interface LogInterface.
* @package Seat\Eseye\Log
*/
interface LogInterface
{
/**
* @param string $message
*
* @return mixed
*/
public function log(string $message);
/**
* @param string $message
*
* @return mixed
*/
public function debug(string $message);
/**
* @param string $message
*
* @return mixed
*/
public function warning(string $message);
/**
* @param string $message
*
* @return mixed
*/
public function error(string $message);
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Log;
/**
* Class NullLogger.
* @package Seat\Eseye\Log
*/
class NullLogger implements LogInterface
{
/**
* @param string $message
*
* @return mixed
*/
public function log(string $message)
{
}
/**
* @param string $message
*
* @return mixed
*/
public function debug(string $message)
{
}
/**
* @param string $message
*
* @return mixed
*/
public function warning(string $message)
{
}
/**
* @param string $message
*
* @return mixed
*/
public function error(string $message)
{
}
}

View File

@@ -0,0 +1,106 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Log;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Seat\Eseye\Configuration;
/**
* Class RotatingFileLogger.
* @package Seat\Eseye\Log
*/
class RotatingFileLogger implements LogInterface
{
/**
* @var \Monolog\Logger
*/
protected $logger;
/**
* FileLogger constructor.
* @throws \Exception
*/
public function __construct()
{
// Get the configuration values
$configuration = Configuration::getInstance();
$formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message%\n");
$stream = new RotatingFileHandler(
rtrim($configuration->logfile_location, '/') . '/eseye.log',
$configuration->log_max_files,
$configuration->logger_level
);
$stream->setFormatter($formatter);
$this->logger = new Logger('eseye');
$this->logger->pushHandler($stream);
}
/**
* @param string $message
*
* @return mixed|void
*/
public function log(string $message)
{
$this->logger->addInfo($message);
}
/**
* @param string $message
*
* @return mixed|void
*/
public function debug(string $message)
{
$this->logger->addDebug($message);
}
/**
* @param string $message
*
* @return mixed|void
*/
public function warning(string $message)
{
$this->logger->addWarning($message);
}
/**
* @param string $message
*
* @return mixed|void
*/
public function error(string $message)
{
$this->logger->addError($message);
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Traits;
use Seat\Eseye\Exceptions\InvalidContainerDataException;
/**
* Class ConstructsContainers.
* @package Seat\Eseye\Traits
*/
trait ConstructsContainers
{
/**
* ConstructsContainers constructor.
*
* This constructor is used in Containers to allow setting
* data when a new instance is created. It will validate
* the incoming array to ensure that only the keys in
* the data property of the container is set.
*
* @param array|null $data
*
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function __construct(array $data = null)
{
if (! is_null($data)) {
foreach ($data as $key => $value) {
if (! array_key_exists($key, $this->data))
throw new InvalidContainerDataException(
'Key ' . $key . ' is not valid for this container'
);
$this->$key = $value;
}
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye\Traits;
/**
* Class ValidatesContainers.
* @package Seat\Eseye\Traits
*/
trait ValidatesContainers
{
/**
* Determine is a Container should be considered valid by
* check if there are any null values in the data property.
*
* @return bool
*/
public function valid(): bool
{
return ! in_array(null, $this->data, true);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Access\CheckAccess;
use Seat\Eseye\Configuration;
use Seat\Eseye\Log\NullLogger;
class CheckAccessTest extends PHPUnit_Framework_TestCase
{
protected $check_access;
public function setUp()
{
$this->check_access = new CheckAccess;
}
public function testCheckAccessObjectInstantiation()
{
$this->assertInstanceOf(CheckAccess::class, $this->check_access);
}
public function testCheckAccessCanShouldGrantAccess()
{
$scopes = [
'esi-assets.read_assets.v1',
];
$result = $this->check_access->can('get', '/characters/{character_id}/assets/', $scopes);
$this->assertTrue($result);
}
public function testCheckAccessCanShouldDenyAccess()
{
$scopes = [
'esi-assets.read_assets.v1',
];
$result = $this->check_access->can('get', '/characters/{character_id}/bookmarks/', $scopes);
$this->assertFalse($result);
}
public function testCheckAccessCanShouldAllowPublicOnlyCall()
{
$result = $this->check_access->can('get', '/alliances/', []);
$this->assertTrue($result);
}
public function testCheckAccessShouldAllowAccessToUnknownUri()
{
// Disable logging.
Configuration::getInstance()->logger = NullLogger::class;
$result = $this->check_access->can('get', '/invalid/uri', []);
$this->assertTrue($result);
}
}

View File

@@ -0,0 +1,116 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use org\bovigo\vfs\vfsStream;
use Seat\Eseye\Cache\FileCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Exceptions\CachePathException;
class FileCacheTest extends PHPUnit_Framework_TestCase
{
protected $root;
protected $file_cache;
public function setUp()
{
// Set the file cache path in the config singleton
$this->root = vfsStream::setup('cache');
Configuration::getInstance()->file_cache_location = vfsStream::url('cache');
$this->file_cache = new FileCache;
}
public function testFileCacheCanInstantiate()
{
$this->assertInstanceOf(FileCache::class, new FileCache);
}
public function testFileCacheCheckCacheDirectory()
{
$this->assertTrue($this->file_cache->checkCacheDirectory());
}
public function testFileCacheBuildsRelativePathWithoutQueryString()
{
$path = $this->file_cache->buildRelativePath('/test');
$this->assertEquals('vfs://cache/test//', $path);
}
public function testFileCacheBuildsRelativePathWithQueryString()
{
$path = $this->file_cache->buildRelativePath('/test', 'foo=bar');
$this->assertEquals('vfs://cache/test/2fb8f40115dd1e695cbe23d4f97ce5b1fb697eee/', $path);
}
public function testFileCacheFailsCreatingDirectoryOnInvalidPath()
{
$this->expectException(CachePathException::class);
if (substr(PHP_OS, 0, 3) == 'WIN')
$invalid_path = '/completely:invalid?path';
else
$invalid_path = '/completely/invalid/path';
Configuration::getInstance()
->file_cache_location = $invalid_path;
new FileCache();
}
/**
* @param $input
* @param $output
*
* @dataProvider providerTestFileCacheSafePathValues
*/
public function testFileCacheSafePathValues($input, $output)
{
$result = $this->file_cache->safePath($input);
$this->assertEquals($output, $result);
}
/**
* @return array
*/
public function providerTestFileCacheSafePathValues()
{
return [
['A/B/C', 'A/B/C'],
['\'A/B/C', 'A/B/C'],
['`A/B/C`', 'A/B/C'],
['|&*A%/$B!/C', 'A/B/C'],
];
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Cache\HashesStrings;
class HashesStringsTest extends PHPUnit_Framework_TestCase
{
use HashesStrings;
public function testHashesStringsToExpectedValue()
{
$this->assertEquals('a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
$this->hashString('test'));
}
public function testHashesStringsToUnexpectedValue()
{
$this->assertNotEquals('nope', $this->hashString('test'));
}
}

View File

@@ -0,0 +1,75 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Cache\MemcachedCache;
use Seat\Eseye\Containers\EsiResponse;
class MemcachedCacheTest extends PHPUnit_Framework_TestCase
{
/*
* @var MemcachedCache
*/
protected $memcached_cache;
protected $esi_response_object;
public function setUp()
{
$is_memcached = class_exists('Memcached', false);
if ($is_memcached)
$instance = $this->createMock(\Memcached::class);
else
$instance = $this->createMock(\Memcache::class);
// Set the cache
$this->memcached_cache = new MemcachedCache($instance);
$this->esi_response_object = new EsiResponse('', [], 'now', 200);
}
public function testMemcachedCacheInstantiates()
{
$this->assertInstanceOf(MemcachedCache::class, $this->memcached_cache);
}
public function testMemcachedCacheBuildsCacheKey()
{
$key = $this->memcached_cache->buildCacheKey('/test', 'foo=bar');
$this->assertEquals('eseye:b0f071c288f528954cddef0e1aa24df41de874aa', $key);
}
public function testMemcachedCacheSetsKey()
{
$this->memcached_cache->set('/foo', 'foo=bar', $this->esi_response_object);
}
public function testMemcachedCacheForgetsKey()
{
$this->memcached_cache->forget('/foo', 'foo=bar');
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Containers\EsiResponse;
class NullCacheTest extends PHPUnit_Framework_TestCase
{
protected $null_cache;
public function setUp()
{
$this->null_cache = new NullCache;
}
public function testNullCacheInstantiates()
{
$this->assertInstanceOf(NullCache::class, $this->null_cache);
}
public function testNullCacheSetsValue()
{
$esi_response = $this->createMock(EsiResponse::class);
$return = $this->null_cache->set('/test', 'foo=bar', $esi_response);
$this->assertNull($return);
}
public function testNullCacheGetsValue()
{
$this->assertFalse($this->null_cache->get('/test', 'foo=bar'));
}
public function testNullCacheForgetsValues()
{
$this->assertNull($this->null_cache->forget('/test', 'foo=bar'));
}
public function testNullCacheHasValue()
{
$this->assertFalse($this->null_cache->has('/test', 'foo=bar'));
}
}

View File

@@ -0,0 +1,78 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Predis\Client;
use Seat\Eseye\Cache\RedisCache;
use Seat\Eseye\Containers\EsiResponse;
class RedisCacheTest extends PHPUnit_Framework_TestCase
{
/**
* @var RedisCache
*/
protected $redis_cache;
protected $esi_response_object;
public function setUp()
{
$redis = $this->createMock(Client::class);
// Set the cache
$this->redis_cache = new RedisCache($redis);
$this->esi_response_object = new EsiResponse('', [], 'now', 200);
}
public function testRedisCacheInstantiates()
{
$this->assertInstanceOf(RedisCache::class, $this->redis_cache);
}
public function testRedisCacheInstantiatesWithoutArgument()
{
$this->assertInstanceOf(RedisCache::class, new RedisCache);
}
public function testRedisCacheBuildsCacheKey()
{
$key = $this->redis_cache->buildCacheKey('/test', 'foo=bar');
$this->assertEquals('b0f071c288f528954cddef0e1aa24df41de874aa', $key);
}
public function testRedisCacheSetsKey()
{
$this->redis_cache->set('/foo', 'foo=bar', $this->esi_response_object);
}
public function testRedisCacheForgetsKey()
{
$this->redis_cache->forget('/foo', 'foo=bar');
}
}

View File

@@ -0,0 +1,102 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Cache\CacheInterface;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiConfiguration;
use Seat\Eseye\Exceptions\InvalidContainerDataException;
use Seat\Eseye\Log\LogInterface;
class ConfigurationTest extends PHPUnit_Framework_TestCase
{
public function testConfigurationInstantiation()
{
$this->assertInstanceOf(Configuration::class, Configuration::getInstance());
}
public function testConfigurationSingleton()
{
$instance1 = Configuration::getInstance();
$instance2 = Configuration::getInstance();
$instance1->setConfiguration(new EsiConfiguration([
'datasource' => 'test',
]));
// Got a feeling this assert is wrong
$this->assertNotEquals('<string:test>', $instance2->getConfiguration()->datasource);
}
public function testConfigurationGetConfigurationValuesContainer()
{
$this->assertInstanceOf(EsiConfiguration::class, Configuration::getInstance()->getConfiguration());
}
public function testConfigurationSetsNewConfigurationContainerWithValidData()
{
$configuration = new EsiConfiguration(['http_user_agent' => 'Eseye Library']);
$this->assertInstanceOf(EsiConfiguration::class, $configuration);
}
public function testConfigurationSetsNewConfigurationsContainerWithInvalidData()
{
$this->expectException(InvalidContainerDataException::class);
new EsiConfiguration(['invalid' => 'invalid']);
}
public function testConfigurationSetsNewConfigurationContainerWithNullData()
{
$this->expectException(InvalidContainerDataException::class);
new EsiConfiguration(['value' => null]);
}
public function testConfigurationGetsLogger()
{
$logger = Configuration::getInstance()->getLogger();
$this->assertInstanceOf(LogInterface::class, $logger);
}
public function testConfigurationGetsCache()
{
$cache = Configuration::getInstance()->getCache();
$this->assertInstanceOf(CacheInterface::class, $cache);
}
public function testConfigurationSetsNewValue()
{
$configuration = Configuration::getInstance();
$configuration->test = 'test';
$this->assertEquals('test', $configuration->test);
$this->assertEquals('test', $configuration->getConfiguration()->test);
}
}

View File

@@ -0,0 +1,139 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Exceptions\InvalidContainerDataException;
class EsiAuthenticationTest extends PHPUnit_Framework_TestCase
{
protected $esi_authentication;
public function setUp()
{
$this->esi_authentication = new EsiAuthentication;
}
public function testEsiAuthenticationInstantiation()
{
$this->assertInstanceOf(EsiAuthentication::class, $this->esi_authentication);
}
public function testFreshEsiAuthenticationInstanceIsNotValid()
{
$this->assertFalse($this->esi_authentication->valid());
}
public function testEsiAuthenticationCanAccessAsArrayKey()
{
$this->assertArrayHasKey('client_id', $this->esi_authentication);
}
public function testEsiAuthenticationCanAccessAsObjectProperty()
{
$client_id = $this->esi_authentication->client_id;
$this->assertNull($client_id);
}
public function testCanSetAndAccessConfigurationValueAsArrayKey()
{
$authentication = new EsiAuthentication;
$authentication['test'] = 'test';
$this->assertEquals('test', $authentication['test']);
}
public function testCanSetAndAccessConfigurationValueAsObjectProperty()
{
$authentication = new EsiAuthentication;
$authentication->test = 'test';
$this->assertEquals('test', $authentication->test);
}
public function testEsiAuthenticationContainerConstructWithValuePasses()
{
$authentication = new EsiAuthentication([
'client_id' => '123',
]);
$this->assertInstanceOf(EsiAuthentication::class, $authentication);
}
public function testEsiAuthenticationContainerConstructWithUnknownKeyFails()
{
$this->expectException(InvalidContainerDataException::class);
new EsiAuthentication([
'foo' => 'bar',
]);
}
/**
* @param $key The key to check for existence
*
* @dataProvider providerTestRequiredKeysExists
*/
public function testRequiredKeysExists($key)
{
$authentication = new EsiAuthentication;
$this->assertArrayHasKey($key, $authentication);
}
/**
* Keys that _should_ exists in a new Configuration instance
*
* @return array
*/
public function providerTestRequiredKeysExists()
{
return [
['client_id'],
['secret'],
['access_token'],
['refresh_token'],
['token_expires'],
['scopes'],
];
}
public function testEsiAuthenticationContainerSetRefreshToken()
{
$authentication = new EsiAuthentication;
$authentication->setRefreshToken('REFRESH_TOKEN');
$this->assertEquals('REFRESH_TOKEN', $authentication->refresh_token);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Containers\EsiConfiguration;
use Seat\Eseye\Exceptions\InvalidContainerDataException;
/**
* Class EsiConfigurationTest
*/
class EsiConfigurationTest extends \PHPUnit_Framework_TestCase
{
protected $esi_configuration;
public function setUp()
{
$this->esi_configuration = new EsiConfiguration;
}
public function testEsiConfigurationInstantiation()
{
$instance = new EsiConfiguration;
$this->assertInstanceOf(EsiConfiguration::class, $instance);
}
public function testFreshEsiConfigurationInstanceIsValid()
{
$this->assertTrue($this->esi_configuration->valid());
}
public function testEsiConfigurationCanAccessAsArrayKey()
{
$this->assertArrayHasKey('datasource', $this->esi_configuration);
}
public function testEsiConfigurationCanAccessAsObjectProperty()
{
$datasource = $this->esi_configuration->datasource;
$this->assertEquals('tranquility', $datasource);
}
public function testCanSetAndAccessConfigurationValueAsArrayKey()
{
$configuration = new EsiConfiguration;
$configuration['test'] = 'test';
$this->assertEquals('test', $configuration['test']);
}
public function testCanSetAndAccessConfigurationValueAsObjectProperty()
{
$configuration = new EsiConfiguration;
$configuration->test = 'test';
$this->assertEquals('test', $configuration->test);
}
public function testEsiConfigurationContainerConstructWithValuePasses()
{
$configuration = new EsiConfiguration([
'datasource' => 'tranquility',
]);
$this->assertInstanceOf(EsiConfiguration::class, $configuration);
}
public function testEsiConfigurationContainerConstructWithUnknownKeyFails()
{
$this->expectException(InvalidContainerDataException::class);
new EsiConfiguration([
'foo' => 'bar',
]);
}
/**
* @param $key The key to check for existence
*
* @dataProvider providerTestRequiredKeysExists
*/
public function testRequiredKeysExists($key)
{
$configuration = new EsiConfiguration;
$this->assertArrayHasKey($key, $configuration);
}
/**
* Keys that _should_ exists in a new Configuration instance
*
* @return array
*/
public function providerTestRequiredKeysExists()
{
return [
['http_user_agent'],
['datasource'],
['logger'],
['logger_level'],
['logfile_location'],
['cache'],
];
}
}

View File

@@ -0,0 +1,186 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Containers\EsiResponse;
class EsiResponseTest extends PHPUnit_Framework_TestCase
{
protected $esi_response;
protected $headers;
public function setUp()
{
// Sample data to work with
$data = json_encode([
'name' => 'Foo',
'details' => [
'age' => 40,
'human' => 'yes',
],
]);
// Sample response headers
$this->headers = $headers = [
"Access-Control-Allow-Credentials" => [
0 => "true",
],
"Access-Control-Allow-Headers" => [
0 => "Content-Type,Authorization,X-User-Agent",
],
"Content-Type" => [
0 => "application/json",
],
"Expires" => [
0 => "Sat, 30 Dec 2017 09:00:32 GMT",
],
"Strict-Transport-Security" => [
0 => "max-age=31536000",
],
"X-Esi-Error-Limit-Remain" => [
0 => "64",
],
"X-Esi-Error-Limit-Reset" => [
0 => "52",
],
"X-Pages" => [
0 => "4",
],
"Date" => [
0 => "Sat, 30 Dec 2017 08:23:08 GMT",
],
];
$this->esi_response = new EsiResponse($data, $headers, 'now', 200);
}
public function testEsiResponseInstantiation()
{
$this->assertInstanceOf(EsiResponse::class, $this->esi_response);
}
public function testEsiResponseTestPayloadIsExpired()
{
$this->assertTrue($this->esi_response->expired());
}
public function testEsiResponseTestPayloadIsNotExpired()
{
$data = json_encode(['foo' => 'bar']);
$esi = new EsiResponse($data, [], '3000-01-01 00:00:00', 200);
$this->assertFalse($esi->expired());
}
public function testEsiResponseDoesNotHaveError()
{
$this->assertNull($this->esi_response->error());
}
public function testEsiResponseDoesHaveError()
{
$data = json_encode(['error' => 'Test Error']);
$esi = new EsiResponse($data, [], 'now', 500);
$this->assertEquals('Test Error', $esi->error());
}
public function testEsiResponseDoesHaveErrorAndDescription()
{
$data = json_encode(['error' => 'Test Error', 'error_description' => 'Test Description']);
$esi = new EsiResponse($data, [], 'now', 500);
$this->assertEquals('Test Error: Test Description', $esi->error());
}
public function testEsiResponseCanGetErrorCode()
{
$this->assertEquals(200, $this->esi_response->getErrorCode());
}
public function testEsiResponseCanGetDataValue()
{
$this->assertEquals('Foo', $this->esi_response->name);
}
public function testEsiResponseCanGetNestedDataValue()
{
$this->assertEquals('yes', $this->esi_response->details->human);
}
public function testEsiResponseCanGetRawDataFromContainer()
{
$this->assertEquals('{"name":"Foo","details":{"age":40,"human":"yes"}}',
$this->esi_response->raw);
}
public function testEsiResponseCanGetRawResponseHeaders()
{
$this->assertEquals($this->headers, $this->esi_response->raw_headers);
}
public function testEsiResponseCanGetParseHeaderValue()
{
$this->assertEquals('Content-Type,Authorization,X-User-Agent',
$this->esi_response->headers['Access-Control-Allow-Headers']);
}
public function testEsiResponseCanGetParsedPagesFromHeaders()
{
$this->assertEquals(4, $this->esi_response->pages);
}
public function testEsiResponseCanGetParsedErrorLomitFromHeaders()
{
$this->assertEquals(64, $this->esi_response->error_limit);
}
public function testEsiResponseIsNotCachedByDefault()
{
$this->assertFalse($this->esi_response->isCachedLoad());
}
public function testEsiResponseMarksResponseAsCached()
{
$this->esi_response->setIsCachedload();
$this->assertTrue($this->esi_response->isCachedLoad());
}
}

354
vendor/eveseat/eseye/tests/EseyeTest.php vendored Normal file
View File

@@ -0,0 +1,354 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Seat\Eseye\Access\CheckAccess;
use Seat\Eseye\Cache\CacheInterface;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\EseyeFetcher;
use Seat\Eseye\Exceptions\EsiScopeAccessDeniedException;
use Seat\Eseye\Exceptions\InvalidAuthenticationException;
use Seat\Eseye\Exceptions\InvalidContainerDataException;
use Seat\Eseye\Exceptions\UriDataMissingException;
use Seat\Eseye\Fetchers\FetcherInterface;
use Seat\Eseye\Fetchers\GuzzleFetcher;
use Seat\Eseye\Log\LogInterface;
class EseyeTest extends PHPUnit_Framework_TestCase
{
/**
* @var Eseye
*/
protected $esi;
public function setUp()
{
// Remove logging
$configuration = Configuration::getInstance();
$configuration->logger = NullLogger::class;
// Remove caching
$configuration->cache = NullCache::class;
$this->esi = new Eseye;
}
public function testEseyeInstantiation()
{
$this->assertInstanceOf(Eseye::class, $this->esi);
}
public function testEseyeInstantiateWithInvalidAuthenticationData()
{
$this->expectException(InvalidContainerDataException::class);
$authentication = new EsiAuthentication([
'foo' => 'bar',
]);
new Eseye($authentication);
}
public function testEseyeInstantiateWithValidAuthenticationData()
{
$authentication = new EsiAuthentication([
'client_id' => 'SSO_CLIENT_ID',
'secret' => 'SSO_SECRET',
'refresh_token' => 'CHARACTER_REFRESH_TOKEN',
]);
new Eseye($authentication);
}
public function testEseyeSetNewInvalidAuthenticationData()
{
$this->expectException(InvalidContainerDataException::class);
$authentication = new EsiAuthentication([
'foo' => 'bar',
'baz' => null,
]);
$this->esi->setAuthentication($authentication);
}
public function testEseyeSetNewValidAuthenticationData()
{
$authentication = new EsiAuthentication([
'client_id' => 'SSO_CLIENT_ID',
'secret' => 'SSO_SECRET',
'access_token' => 'ACCESS_TOKEN',
'refresh_token' => 'CHARACTER_REFRESH_TOKEN',
'token_expires' => '1970-01-01 00:00:00',
'scopes' => ['public'],
]);
$this->esi->setAuthentication($authentication);
}
public function testEseyeGetAuthenticationBeforeSet()
{
$this->expectException(InvalidAuthenticationException::class);
$this->esi->getAuthentication();
}
public function testEseyeGetAuthenticationAfterSet()
{
$authentication = new EsiAuthentication([
'client_id' => 'SSO_CLIENT_ID',
'secret' => 'SSO_SECRET',
'access_token' => 'ACCESS_TOKEN',
'refresh_token' => 'CHARACTER_REFRESH_TOKEN',
'token_expires' => '1970-01-01 00:00:00',
'scopes' => ['public'],
]);
$this->esi->setAuthentication($authentication);
$this->assertInstanceOf(EsiAuthentication::class, $this->esi->getAuthentication());
}
public function testEseyeGetConfigurationInstance()
{
$this->assertInstanceOf(Configuration::class, $this->esi->getConfiguration());
}
public function testEseyeGetLogger()
{
$this->assertInstanceOf(LogInterface::class, $this->esi->getLogger());
}
public function testEseyeSetAccessChecker()
{
$access = $this->createMock(CheckAccess::class);
$this->assertInstanceOf(Eseye::class, $this->esi->setAccessChecker($access));
}
public function testEseyeGetAccessChecker()
{
$this->assertInstanceOf(CheckAccess::class, $this->esi->getAccessChecker());
}
public function testEseyeGetsFetcher()
{
$get_fetcher = self::getMethod('getFetcher');
$return = $get_fetcher->invokeArgs(new Eseye, []);
$this->assertInstanceOf(FetcherInterface::class, $return);
}
/**
* Helper method to set private methods public.
*
* @param $name
*
* @return \ReflectionMethod
*/
protected static function getMethod($name)
{
$class = new ReflectionClass('Seat\Eseye\Eseye');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
public function testEseyeGetsCache()
{
$get_fetcher = self::getMethod('getCache');
$return = $get_fetcher->invokeArgs(new Eseye, []);
$this->assertInstanceOf(CacheInterface::class, $return);
}
public function testEseyeGetAndSetQueryString()
{
$object = $this->esi->setQueryString([
'foo' => 'bar',
'foobar' => ['foo', 'bar'],
]);
$this->assertInstanceOf(Eseye::class, $object);
$this->assertEquals([
'foo' => 'bar',
'foobar' => 'foo,bar',
], $this->esi->getQueryString());
}
public function testEseyeGetAndSetBody()
{
$object = $this->esi->setBody(['foo']);
$this->assertInstanceOf(Eseye::class, $object);
$this->assertEquals(['foo'], $this->esi->getBody());
}
public function testEseyeGetDefaultVersionString()
{
$version = $this->esi->getVersion();
$this->assertEquals('/latest', $version);
}
public function testEseyeSetIncompleteVersionStringAndGetsCompleteVersionString()
{
$this->esi->setVersion('v1');
$this->assertEquals('/v1', $this->esi->getVersion());
}
public function testEseyeReturnsEseyeAfterSettingEsiApiVersion()
{
$esi = $this->esi->setVersion('v4');
$this->assertInstanceOf(Eseye::class, $esi);
}
public function testEseyeBuildValidDataUri()
{
$uri = $this->esi->buildDataUri('/{foo}/', ['foo' => 'bar']);
$this->assertEquals('https://esi.evetech.net/latest/bar/?datasource=test',
$uri->__toString());
}
public function testEseyeBuildDataUriFailsOnEmptyDataArray()
{
$this->expectException(UriDataMissingException::class);
$this->esi->buildDataUri('/{foo}/', []);
}
public function testEseyeBuildDataUriFailsOnIncompleteDataArray()
{
$this->expectException(UriDataMissingException::class);
$this->esi->buildDataUri('/{foo}/', ['bar' => 'baz']);
}
public function testEseyeMakesEsiApiCallWithCachedResponse()
{
$mock = new MockHandler([
new Response(200, ['Expires' => 'Sat, 28 Jan 4017 05:46:49 GMT'], json_encode(['foo' => 'bar'])),
]);
$fetcher = new GuzzleFetcher;
$fetcher->setClient(new Client([
'handler' => HandlerStack::create($mock),
]));
// Update the fetchers client
$this->esi->setFetcher($fetcher);
$response = $this->esi->invoke('get', '/foo');
$this->assertEquals('bar', $response->foo);
}
public function testEseyeMakesEsiApiCallWithoutCachedResponse()
{
$mock = new MockHandler([
new Response(200, ['Foo' => 'Bar'], json_encode(['foo' => 'bar'])),
]);
$fetcher = new GuzzleFetcher;
$fetcher->setClient(new Client([
'handler' => HandlerStack::create($mock),
]));
// Update the fetchers client
$this->esi->setFetcher($fetcher);
$response = $this->esi->invoke('post', '/foo');
$this->assertEquals('bar', $response->foo);
}
public function testEseyeMakesEsiApiCallToAuthenticatedEndpointWithoutAccess()
{
$this->expectException(EsiScopeAccessDeniedException::class);
$mock = new MockHandler([
new Response(401),
]);
// Update the fetchers client
$this->esi->setFetcher(new GuzzleFetcher(null, new Client([
'handler' => HandlerStack::create($mock),
])));
$this->esi->invoke('get', '/characters/{character_id}/assets/', [
'character_id' => 123,
]);
}
public function testEseyeSetRefreshToken()
{
$authentication = new EsiAuthentication([
'client_id' => 'SSO_CLIENT_ID',
'secret' => 'SSO_SECRET',
'access_token' => 'ACCESS_TOKEN',
'refresh_token' => 'CHARACTER_REFRESH_TOKEN',
'token_expires' => '1970-01-01 00:00:00',
'scopes' => ['public'],
]);
$this->esi->setAuthentication($authentication);
$this->esi->setRefreshToken('ALTERNATE_REFRESH_TOKEN');
$this->assertEquals('ALTERNATE_REFRESH_TOKEN', $this->esi->getAuthentication()->refresh_token);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Containers\EsiResponse;
use Seat\Eseye\Exceptions\RequestFailedException;
class RequestFailedExceptionTest extends PHPUnit_Framework_TestCase
{
/**
* @var RequestFailedException
*/
protected $exception;
public function setUp()
{
$this->exception = new RequestFailedException(new Exception('Foo'), new EsiResponse(
json_encode(['error' => 'test']),
[],
'now',
500
));
}
public function testRequestFailedGetsErrors()
{
$error = $this->exception->getError();
$this->assertEquals('test', $error);
}
public function testRequestFailedGetsEsiResponse()
{
$response = $this->exception->getEsiResponse();
$this->assertInstanceOf(EsiResponse::class, $response);
}
public function testRequestFailedGetsOriginalException()
{
$response = $this->exception->getOriginalException();
$this->assertInstanceOf(Exception::class, $response);
}
}

View File

@@ -0,0 +1,300 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Containers\EsiResponse;
use Seat\Eseye\EseyeFetcher;
use Seat\Eseye\Exceptions\InvalidAuthenticationException;
use Seat\Eseye\Exceptions\RequestFailedException;
use Seat\Eseye\Fetchers\GuzzleFetcher;
use Seat\Eseye\Log\NullLogger;
class GuzzleFetcherTest extends PHPUnit_Framework_TestCase
{
/**
* @var GuzzleFetcher
*/
protected $fetcher;
public function setUp()
{
// Remove logging
$configuration = Configuration::getInstance();
$configuration->logger = NullLogger::class;
$this->fetcher = new GuzzleFetcher;
}
public function testGuzzleFetcherInstantiation()
{
$this->assertInstanceOf(GuzzleFetcher::class, $this->fetcher);
}
public function testGuzzleGetsClientIfNoneSet()
{
$fetcher = new GuzzleFetcher;
$client = $fetcher->getClient();
$this->assertInstanceOf(Client::class, $client);
}
public function testGuzzleFetcherStripRefreshTokenFromUrl()
{
$url = 'https://esi.url/oauth?type=refresh_token&refresh_token=foo';
$stripped = $this->fetcher->stripRefreshTokenValue($url);
$this->assertEquals('https://esi.url/oauth?type=refresh_token', $stripped);
}
public function testGuzzleFetcherStripRefreshTokenFromUrlWithoutRefreshToken()
{
$url = 'https://esi.url/type=refresh_token';
$stripped = $this->fetcher->stripRefreshTokenValue($url);
$this->assertEquals('https://esi.url/type=refresh_token', $stripped);
}
public function testGuzzleFetcherStripRefreshTokenNoTokenMention()
{
$url = 'https://esi.url/foo=bar';
$stripped = $this->fetcher->stripRefreshTokenValue($url);
$this->assertEquals($url, $stripped);
}
public function testGuzzleFetcherMakeEsiResponseContainer()
{
$response = json_encode(['response' => 'ok']);
$container = $this->fetcher->makeEsiResponse($response, [], 'now', 200);
$this->assertInstanceOf(EsiResponse::class, $container);
}
public function testGuzzleFetcherGetAuthenticationWhenNoneSet()
{
$authentication = $this->fetcher->getAuthentication();
$this->assertNull($authentication);
}
public function testGuzzleFetcherGetAuthenticationWhenSettingAuthentication()
{
$fetcher = new GuzzleFetcher(new EsiAuthentication([
'client_id' => 'foo',
]));
$this->assertInstanceOf(EsiAuthentication::class, $fetcher->getAuthentication());
}
public function testGuzzleSetsAuthentication()
{
$this->fetcher->setAuthentication(new EsiAuthentication([
'client_id' => 'foo',
'secret' => 'bar',
'access_token' => '_',
'refresh_token' => 'baz',
'token_expires' => '1970-01-01 00:00:00',
'scopes' => ['public'],
]));
$this->assertInstanceOf(EsiAuthentication::class, $this->fetcher->getAuthentication());
}
public function testGuzzleFailsSettingInvalidAuthentication()
{
$this->expectException(InvalidAuthenticationException::class);
$this->fetcher->setAuthentication(new EsiAuthentication([
'client_id' => null,
]));
}
public function testGuzzleShouldFailGettingTokenWithoutAuthentication()
{
$this->expectException(InvalidAuthenticationException::class);
$get_token = self::getMethod('getToken');
$get_token->invokeArgs(new GuzzleFetcher, []);
}
/**
* Helper method to set private methods public.
*
* @param $name
*
* @return \ReflectionMethod
*/
protected static function getMethod($name)
{
$class = new ReflectionClass('Seat\Eseye\Fetchers\GuzzleFetcher');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
public function testGuzzleFetcherGetPublicScopeWithoutAuthentication()
{
$scopes = $this->fetcher->getAuthenticationScopes();
$this->assertEquals(1, count($scopes));
}
public function testGuzzleCallingWithoutAuthentication()
{
$mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar'], json_encode(['foo' => 'var'])),
]);
// Update the fetchers client
$this->fetcher->setClient(new Client([
'handler' => HandlerStack::create($mock),
]));
$response = $this->fetcher->call('get', '/foo', ['foo' => 'bar']);
$this->assertInstanceOf(EsiResponse::class, $response);
}
public function testGuzzleCallingWithAuthentication()
{
$mock = new MockHandler([
// RefreshToken response
new Response(200, ['X-Foo' => 'Bar'], json_encode([
'access_token' => 'foo', 'expires_in' => 1200, 'refresh_token' => 'bar',
])),
new Response(200, ['X-Foo' => 'Bar'], json_encode(['foo' => 'var'])),
]);
// Update the fetchers client
$this->fetcher->setClient(new Client([
'handler' => HandlerStack::create($mock),
]));
// Update the fetchers authentication
$this->fetcher->setAuthentication(new EsiAuthentication([
'client_id' => 'foo',
'secret' => 'bar',
'access_token' => '_',
'refresh_token' => 'baz',
'token_expires' => '1970-01-01 00:00:00',
'scopes' => ['public'],
]));
$response = $this->fetcher->call('get', '/foo', ['foo' => 'bar']);
$this->assertInstanceOf(EsiResponse::class, $response);
}
public function testGuzzleCallingCatchesRequestAuthenticationFailure()
{
$this->expectException(RequestFailedException::class);
$mock = new MockHandler([
new Response(401),
]);
// Update the fetchers client
$this->fetcher->setClient(new Client([
'handler' => HandlerStack::create($mock),
]));
$this->fetcher->call('get', '/foo', ['foo' => 'bar']);
}
public function testGuzzleFetcherMakesHttpRequest()
{
$mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar'], json_encode(['foo' => 'var'])),
]);
// Update the fetchers client
$this->fetcher->setClient(new Client([
'handler' => HandlerStack::create($mock),
]));
$response = $this->fetcher->httpRequest('get', '/foo');
$this->assertInstanceOf(EsiResponse::class, $response);
}
public function testGuzzleConstructsWithClientAndGetsAuthenticationScopes()
{
$mock = new MockHandler([
// RefreshToken response
new Response(200, ['X-Foo' => 'Bar'], json_encode([
'access_token' => 'foo', 'expires_in' => 1200, 'refresh_token' => 'bar',
])),
new Response(200, ['X-Foo' => 'Bar'], json_encode([
'Scopes' => 'foo bar baz',
])),
]);
// Update the fetchers client
$client = new Client([
'handler' => HandlerStack::create($mock),
]);
// Update the fetchers authentication
$authentication = new EsiAuthentication([
'client_id' => 'foo',
'secret' => 'bar',
'access_token' => '_',
'refresh_token' => 'baz',
'token_expires' => '1970-01-01 00:00:00',
]);
$fetcher = new GuzzleFetcher($authentication);
$fetcher->setClient($client);
$scopes = $fetcher->getAuthenticationScopes();
$this->assertEquals(['foo', 'bar', 'baz', 'public'], $scopes);
}
}

View File

@@ -0,0 +1,95 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Monolog\Logger;
use org\bovigo\vfs\vfsStream;
use Seat\Eseye\Configuration;
use Seat\Eseye\Log\FileLogger;
class FileLoggerTest extends PHPUnit_Framework_TestCase
{
protected $root;
protected $logger;
public function setUp()
{
// Set the file cache path in the config singleton
$this->root = vfsStream::setup('logs/');
Configuration::getInstance()->logfile_location = vfsStream::url('logs/');
$this->logger = new FileLogger;
}
public function testFileLoggerWritesLogInfo()
{
$this->logger->log('foo');
$logfile_content = $this->root->getChild('eseye.log')->getContent();
$this->assertContains('eseye.INFO: foo', $logfile_content);
}
public function testFileLoggerSkipWritesLogDebugWithoutRequiredLevel()
{
$this->logger->debug('foo');
$logfile_content = $this->root->getChild('eseye.log');
$this->assertNull($logfile_content);
}
public function testFileLoggerWritesLogDebug()
{
Configuration::getInstance()->logger_level = Logger::DEBUG;
// Init a new logger with the updated config
$logger = new FileLogger;
$logger->debug('foo');
$logfile_content = $this->root->getChild('eseye.log')->getContent();
$this->assertContains('eseye.DEBUG: foo', $logfile_content);
}
public function testFileLoggerWritesLogWarning()
{
$this->logger->warning('foo');
$logfile_content = $this->root->getChild('eseye.log')->getContent();
$this->assertContains('eseye.WARNING: foo', $logfile_content);
}
public function testFileLoggerWritesLogError()
{
$this->logger->error('foo');
$logfile_content = $this->root->getChild('eseye.log')->getContent();
$this->assertContains('eseye.ERROR: foo', $logfile_content);
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Seat\Eseye\Log\NullLogger;
class NullLoggerTest extends PHPUnit_Framework_TestCase
{
protected $logger;
public function setUp()
{
$this->logger = new NullLogger;
}
public function testNullLoggerIgnoresInfo()
{
$this->assertNull($this->logger->log('foo'));
}
public function testNullLoggerIgnoresDebug()
{
$this->assertNull($this->logger->debug('foo'));
}
public function testNullLoggerIgnoresWarning()
{
$this->assertNull($this->logger->warning('foo'));
}
public function testNullLoggerIgnoresErro()
{
$this->assertNull($this->logger->error('foo'));
}
}

View File

@@ -0,0 +1,101 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use Monolog\Logger;
use org\bovigo\vfs\vfsStream;
use Seat\Eseye\Configuration;
use Seat\Eseye\Log\RotatingFileLogger;
class RotatingFileLoggerTest extends PHPUnit_Framework_TestCase
{
protected $root;
protected $logger;
protected $logfile_name;
public function setUp()
{
// Set the file cache path in the config singleton
$this->root = vfsStream::setup('logs');
Configuration::getInstance()->logfile_location = $this->root->url();
Configuration::getInstance()->logger_level = 'info';
$this->logger = new RotatingFileLogger;
# Shitty hack to get the filename to expect. Format: eseye-2018-05-06.log
$this->logfile_name = 'eseye-' . date('Y-m-d') . '.log';
}
public function testFileLoggerWritesLogInfo()
{
$this->logger->log('foo');
$logfile_content = $this->root->getChild($this->logfile_name)->getContent();
$this->assertContains('eseye.INFO: foo', $logfile_content);
}
public function testFileLoggerSkipWritesLogDebugWithoutRequiredLevel()
{
$this->logger->debug('foo');
$logfile_content = $this->root->getChild($this->logfile_name);
$this->assertNull($logfile_content);
}
public function testFileLoggerWritesLogDebug()
{
Configuration::getInstance()->logger_level = Logger::DEBUG;
// Init a new logger with the updated config
$logger = new RotatingFileLogger;
$logger->debug('foo');
$logfile_content = $this->root->getChild($this->logfile_name)->getContent();
$this->assertContains('eseye.DEBUG: foo', $logfile_content);
}
public function testFileLoggerWritesLogWarning()
{
$this->logger->warning('foo');
$logfile_content = $this->root->getChild($this->logfile_name)->getContent();
$this->assertContains('eseye.WARNING: foo', $logfile_content);
}
public function testFileLoggerWritesLogError()
{
$this->logger->error('foo');
$logfile_content = $this->root->getChild($this->logfile_name)->getContent();
$this->assertContains('eseye.ERROR: foo', $logfile_content);
}
}

1
vendor/eveseat/eseye/tools/esi.json vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,57 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
echo 'Reading esi.json ..' . PHP_EOL;
$esi = json_decode(file_get_contents('esi.json'), true);
echo 'ESI Version: ' . $esi['info']['version'] . PHP_EOL;
$scope_map = [
'get' => [],
'post' => [],
'put' => [],
'delete' => [],
'patch' => [],
];
echo 'Mapping Scopes to endpoints and methods ..' . PHP_EOL;
foreach ($esi['paths'] as $path => $description) {
foreach ($description as $method => $data) {
if (isset($data['security']))
$scope = $data['security'][0]['evesso'][0];
else
$scope = 'public';
// Update the scope map!
$scope_map[$method][$path] = $scope;
echo $method . ' | ' . $path . ' | ' . $scope . PHP_EOL;
}
}
// Output the scopes in a way that we can
// copy/pasta in code!
echo 'Var Export of the scope map:' . PHP_EOL;
echo PHP_EOL;
var_export($scope_map);
echo PHP_EOL;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,28 @@
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015, 2016, 2017, 2018 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
include '../vendor/autoload.php';
$client = new \GuzzleHttp\Client();
$client->request('get', 'https://esi.evetech.net/latest/swagger.json?datasource=tranquility', [
'sink' => 'esi.json',
]);