This repository has been archived by the owner on Nov 26, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
Add extra docs to Github package; light refactoring; bug fixes. #295
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule Joomla
updated
6 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
/** | ||
* Part of the Joomla Framework Github Package | ||
* | ||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE | ||
*/ | ||
|
||
namespace Joomla\Github; | ||
|
||
use Joomla\Http\Response; | ||
use Joomla\Uri\Uri; | ||
use Joomla\Registry\Registry; | ||
|
||
/** | ||
* GitHub API object class for the Joomla Framework. | ||
* | ||
* @since 1.0 | ||
*/ | ||
abstract class AbstractGithubObject | ||
{ | ||
/** | ||
* @var Registry Options for the GitHub object. | ||
* @since 1.0 | ||
*/ | ||
protected $options; | ||
|
||
/** | ||
* @var Http The HTTP client object to use in sending HTTP requests. | ||
* @since 1.0 | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @var string | ||
* @since 1.0 | ||
*/ | ||
protected $package = ''; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Registry $options GitHub options object. | ||
* @param Http $client The HTTP client object. | ||
* | ||
* @since 1.0 | ||
*/ | ||
public function __construct(Registry $options = null, Http $client = null) | ||
{ | ||
$this->options = isset($options) ? $options : new Registry; | ||
$this->client = isset($client) ? $client : new Http($this->options); | ||
|
||
$this->package = get_class($this); | ||
$this->package = substr($this->package, strrpos($this->package, '\\') + 1); | ||
} | ||
|
||
/** | ||
* Method to build and return a full request URL for the request. This method will | ||
* add appropriate pagination details if necessary and also prepend the API url | ||
* to have a complete URL for the request. | ||
* | ||
* @param string $path URL to inflect | ||
* @param integer $page Page to request | ||
* @param integer $limit Number of results to return per page | ||
* | ||
* @return string The request URL. | ||
* | ||
* @since 1.0 | ||
*/ | ||
protected function fetchUrl($path, $page = 0, $limit = 0) | ||
{ | ||
// Get a new Uri object fousing the api url and given path. | ||
$uri = new Uri($this->options->get('api.url') . $path); | ||
|
||
if ($this->options->get('gh.token', false)) | ||
{ | ||
// Use oAuth authentication - @todo set in request header ? | ||
$uri->setVar('access_token', $this->options->get('gh.token')); | ||
} | ||
else | ||
{ | ||
// Use basic authentication | ||
if ($this->options->get('api.username', false)) | ||
{ | ||
$uri->setUser($this->options->get('api.username')); | ||
} | ||
|
||
if ($this->options->get('api.password', false)) | ||
{ | ||
$uri->setPass($this->options->get('api.password')); | ||
} | ||
} | ||
|
||
// If we have a defined page number add it to the JUri object. | ||
if ($page > 0) | ||
{ | ||
$uri->setVar('page', (int) $page); | ||
} | ||
|
||
// If we have a defined items per page add it to the JUri object. | ||
if ($limit > 0) | ||
{ | ||
$uri->setVar('per_page', (int) $limit); | ||
} | ||
|
||
return (string) $uri; | ||
} | ||
|
||
/** | ||
* Process the response and decode it. | ||
* | ||
* @param Response $response The response. | ||
* @param integer $expectedCode The expected "good" code. | ||
* | ||
* @return mixed | ||
* | ||
* @since 1.0 | ||
* @throws \DomainException | ||
*/ | ||
protected function processResponse(Response $response, $expectedCode = 200) | ||
{ | ||
// Validate the response code. | ||
if ($response->code != $expectedCode) | ||
{ | ||
// Decode the error response and throw an exception. | ||
$error = json_decode($response->body); | ||
$message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; | ||
throw new \DomainException($message, $response->code); | ||
} | ||
|
||
return json_decode($response->body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Part of the Joomla Framework Github Package | ||
* | ||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE | ||
*/ | ||
|
||
namespace Joomla\Github; | ||
|
||
use Joomla\Registry\Registry; | ||
|
||
/** | ||
* GitHub API package class for the Joomla Framework. | ||
* | ||
* @since 1.0 | ||
*/ | ||
abstract class AbstractPackage extends AbstractGithubObject | ||
{ | ||
/** | ||
* Constructor. | ||
* | ||
* @param Registry $options GitHub options object. | ||
* @param Http $client The HTTP client object. | ||
* | ||
* @since 1.0 | ||
*/ | ||
public function __construct(Registry $options = null, Http $client = null) | ||
{ | ||
parent::__construct($options, $client); | ||
|
||
$this->package = get_class($this); | ||
$this->package = substr($this->package, strrpos($this->package, '\\') + 1); | ||
} | ||
|
||
/** | ||
* Magic method to lazily create API objects | ||
* | ||
* @param string $name Name of property to retrieve | ||
* | ||
* @since 1.0 | ||
* @throws \InvalidArgumentException | ||
* | ||
* @return AbstractPackage GitHub API package object. | ||
*/ | ||
public function __get($name) | ||
{ | ||
$class = '\\Joomla\\Github\\Package\\' . $this->package . '\\' . ucfirst($name); | ||
|
||
if (false == class_exists($class)) | ||
{ | ||
throw new \InvalidArgumentException( | ||
sprintf( | ||
'Argument %1$s produced an invalid class name: %2$s in package %3$s', | ||
$name, $class, $this->package | ||
) | ||
); | ||
} | ||
|
||
if (false == isset($this->$name)) | ||
{ | ||
$this->$name = new $class($this->options, $this->client); | ||
} | ||
|
||
return $this->$name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use normal getters because it looks like you access a mutable (public) property.
I would rather see a normal factory to create the top level objects and getters for the sublevel ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a simple renaming of the file. The idea is that the package API is available just using magic properties, sort of like mixins. The Docblocks help the IDE work out what should be returned during chaining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be handy but the problem is that you can "navigate" inside a package like this :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But does that cause an actual problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but it shouldn't be possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm mentionning it as I see it. It is the same "issue" with
Input
.Maybe using the
Github
class as factory to create the objectsI think, ideally it should be structured this way
Each issue is a plain object with setters and getters and the manager acting as Data access object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My goal was simply to rename the file to agree with the naming standards. This isn't new work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created an issue #301
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem :)