This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pr #74 from branch 'samsonasik/contributor-page'
* contributor-page: #74 : add note to CHANGELOG.md add assertion added test for consolecontroller patch on dispatch for layout choose inject the controller with Http Client fixes cs update .phpcs fixes travis build make $contributors pass to ContributorsController fix forgotten 2columns layout fix page update fixes cs patch cs remove left bar for contribution page using "skipWelcome" layout variable using Zend navigation to build nav menu added navigation added test for contributors page fixes cs contributor page
- Loading branch information
Showing
31 changed files
with
548 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
return [ | ||
'navigation' => [ | ||
'default' => [ | ||
[ | ||
'label' => 'Home', | ||
'route' => 'home', | ||
], | ||
[ | ||
'label' => 'Contributors', | ||
'route' => 'contributors', | ||
], | ||
], | ||
], | ||
]; |
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 @@ | ||
a:3:{i:0;a:19:{s:5:"login";s:10:"samsonasik";s:2:"id";i:459648;s:10:"avatar_url";s:50:"https://avatars.githubusercontent.com/u/459648?v=3";s:11:"gravatar_id";s:0:"";s:3:"url";s:39:"https://api.github.com/users/samsonasik";s:8:"html_url";s:29:"https://github.com/samsonasik";s:13:"followers_url";s:49:"https://api.github.com/users/samsonasik/followers";s:13:"following_url";s:62:"https://api.github.com/users/samsonasik/following{/other_user}";s:9:"gists_url";s:55:"https://api.github.com/users/samsonasik/gists{/gist_id}";s:11:"starred_url";s:62:"https://api.github.com/users/samsonasik/starred{/owner}{/repo}";s:17:"subscriptions_url";s:53:"https://api.github.com/users/samsonasik/subscriptions";s:17:"organizations_url";s:44:"https://api.github.com/users/samsonasik/orgs";s:9:"repos_url";s:45:"https://api.github.com/users/samsonasik/repos";s:10:"events_url";s:56:"https://api.github.com/users/samsonasik/events{/privacy}";s:19:"received_events_url";s:55:"https://api.github.com/users/samsonasik/received_events";s:4:"type";s:4:"User";s:10:"site_admin";b:0;s:13:"contributions";i:168;s:9:"user_info";a:30:{s:5:"login";s:10:"samsonasik";s:2:"id";i:459648;s:10:"avatar_url";s:50:"https://avatars.githubusercontent.com/u/459648?v=3";s:11:"gravatar_id";s:0:"";s:3:"url";s:39:"https://api.github.com/users/samsonasik";s:8:"html_url";s:29:"https://github.com/samsonasik";s:13:"followers_url";s:49:"https://api.github.com/users/samsonasik/followers";s:13:"following_url";s:62:"https://api.github.com/users/samsonasik/following{/other_user}";s:9:"gists_url";s:55:"https://api.github.com/users/samsonasik/gists{/gist_id}";s:11:"starred_url";s:62:"https://api.github.com/users/samsonasik/starred{/owner}{/repo}";s:17:"subscriptions_url";s:53:"https://api.github.com/users/samsonasik/subscriptions";s:17:"organizations_url";s:44:"https://api.github.com/users/samsonasik/orgs";s:9:"repos_url";s:45:"https://api.github.com/users/samsonasik/repos";s:10:"events_url";s:56:"https://api.github.com/users/samsonasik/events{/privacy}";s:19:"received_events_url";s:55:"https://api.github.com/users/samsonasik/received_events";s:4:"type";s:4:"User";s:10:"site_admin";b:0;s:4:"name";s:18:"Abdul Malik Ikhsan";s:7:"company";s:19:"Sitrun Technologies";s:4:"blog";s:31:"http://samsonasik.wordpress.com";s:8:"location";s:7:"Bandung";s:5:"email";s:20:"samsonasik@gmail.com";s:8:"hireable";b:1;s:3:"bio";N;s:12:"public_repos";i:117;s:12:"public_gists";i:42;s:9:"followers";i:143;s:9:"following";i:55;s:10:"created_at";s:20:"2010-10-29T15:22:08Z";s:10:"updated_at";s:20:"2014-12-14T16:30:46Z";}}i:1;a:19:{s:5:"login";s:7:"acelaya";s:2:"id";i:2719332;s:10:"avatar_url";s:51:"https://avatars.githubusercontent.com/u/2719332?v=3";s:11:"gravatar_id";s:0:"";s:3:"url";s:36:"https://api.github.com/users/acelaya";s:8:"html_url";s:26:"https://github.com/acelaya";s:13:"followers_url";s:46:"https://api.github.com/users/acelaya/followers";s:13:"following_url";s:59:"https://api.github.com/users/acelaya/following{/other_user}";s:9:"gists_url";s:52:"https://api.github.com/users/acelaya/gists{/gist_id}";s:11:"starred_url";s:59:"https://api.github.com/users/acelaya/starred{/owner}{/repo}";s:17:"subscriptions_url";s:50:"https://api.github.com/users/acelaya/subscriptions";s:17:"organizations_url";s:41:"https://api.github.com/users/acelaya/orgs";s:9:"repos_url";s:42:"https://api.github.com/users/acelaya/repos";s:10:"events_url";s:53:"https://api.github.com/users/acelaya/events{/privacy}";s:19:"received_events_url";s:52:"https://api.github.com/users/acelaya/received_events";s:4:"type";s:4:"User";s:10:"site_admin";b:0;s:13:"contributions";i:35;s:9:"user_info";a:30:{s:5:"login";s:7:"acelaya";s:2:"id";i:2719332;s:10:"avatar_url";s:51:"https://avatars.githubusercontent.com/u/2719332?v=3";s:11:"gravatar_id";s:0:"";s:3:"url";s:36:"https://api.github.com/users/acelaya";s:8:"html_url";s:26:"https://github.com/acelaya";s:13:"followers_url";s:46:"https://api.github.com/users/acelaya/followers";s:13:"following_url";s:59:"https://api.github.com/users/acelaya/following{/other_user}";s:9:"gists_url";s:52:"https://api.github.com/users/acelaya/gists{/gist_id}";s:11:"starred_url";s:59:"https://api.github.com/users/acelaya/starred{/owner}{/repo}";s:17:"subscriptions_url";s:50:"https://api.github.com/users/acelaya/subscriptions";s:17:"organizations_url";s:41:"https://api.github.com/users/acelaya/orgs";s:9:"repos_url";s:42:"https://api.github.com/users/acelaya/repos";s:10:"events_url";s:53:"https://api.github.com/users/acelaya/events{/privacy}";s:19:"received_events_url";s:52:"https://api.github.com/users/acelaya/received_events";s:4:"type";s:4:"User";s:10:"site_admin";b:0;s:4:"name";s:16:"Alejandro Celaya";s:7:"company";s:20:"Wonnova gamification";s:4:"blog";s:30:"http://www.alejandrocelaya.com";s:8:"location";s:8:"Zaragoza";s:5:"email";s:0:"";s:8:"hireable";b:1;s:3:"bio";N;s:12:"public_repos";i:19;s:12:"public_gists";i:1;s:9:"followers";i:21;s:9:"following";i:36;s:10:"created_at";s:20:"2012-11-04T09:37:53Z";s:10:"updated_at";s:20:"2014-12-14T14:29:53Z";}}i:2;a:19:{s:5:"login";s:12:"mockiemockiz";s:2:"id";i:1708946;s:10:"avatar_url";s:51:"https://avatars.githubusercontent.com/u/1708946?v=3";s:11:"gravatar_id";s:0:"";s:3:"url";s:41:"https://api.github.com/users/mockiemockiz";s:8:"html_url";s:31:"https://github.com/mockiemockiz";s:13:"followers_url";s:51:"https://api.github.com/users/mockiemockiz/followers";s:13:"following_url";s:64:"https://api.github.com/users/mockiemockiz/following{/other_user}";s:9:"gists_url";s:57:"https://api.github.com/users/mockiemockiz/gists{/gist_id}";s:11:"starred_url";s:64:"https://api.github.com/users/mockiemockiz/starred{/owner}{/repo}";s:17:"subscriptions_url";s:55:"https://api.github.com/users/mockiemockiz/subscriptions";s:17:"organizations_url";s:46:"https://api.github.com/users/mockiemockiz/orgs";s:9:"repos_url";s:47:"https://api.github.com/users/mockiemockiz/repos";s:10:"events_url";s:58:"https://api.github.com/users/mockiemockiz/events{/privacy}";s:19:"received_events_url";s:57:"https://api.github.com/users/mockiemockiz/received_events";s:4:"type";s:4:"User";s:10:"site_admin";b:0;s:13:"contributions";i:33;s:9:"user_info";a:30:{s:5:"login";s:12:"mockiemockiz";s:2:"id";i:1708946;s:10:"avatar_url";s:51:"https://avatars.githubusercontent.com/u/1708946?v=3";s:11:"gravatar_id";s:0:"";s:3:"url";s:41:"https://api.github.com/users/mockiemockiz";s:8:"html_url";s:31:"https://github.com/mockiemockiz";s:13:"followers_url";s:51:"https://api.github.com/users/mockiemockiz/followers";s:13:"following_url";s:64:"https://api.github.com/users/mockiemockiz/following{/other_user}";s:9:"gists_url";s:57:"https://api.github.com/users/mockiemockiz/gists{/gist_id}";s:11:"starred_url";s:64:"https://api.github.com/users/mockiemockiz/starred{/owner}{/repo}";s:17:"subscriptions_url";s:55:"https://api.github.com/users/mockiemockiz/subscriptions";s:17:"organizations_url";s:46:"https://api.github.com/users/mockiemockiz/orgs";s:9:"repos_url";s:47:"https://api.github.com/users/mockiemockiz/repos";s:10:"events_url";s:58:"https://api.github.com/users/mockiemockiz/events{/privacy}";s:19:"received_events_url";s:57:"https://api.github.com/users/mockiemockiz/received_events";s:4:"type";s:4:"User";s:10:"site_admin";b:0;s:4:"name";s:13:"muhamad rifki";s:7:"company";s:0:"";s:4:"blog";s:10:"mockie.net";s:8:"location";s:9:"Indonesia";s:5:"email";s:25:"rifkimuhammad89@gmail.com";s:8:"hireable";b:1;s:3:"bio";N;s:12:"public_repos";i:6;s:12:"public_gists";i:19;s:9:"followers";i:3;s:9:"following";i:3;s:10:"created_at";s:20:"2012-05-05T16:33:57Z";s:10:"updated_at";s:20:"2014-12-08T16:18:53Z";}}} |
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
111 changes: 111 additions & 0 deletions
111
module/Application/src/Application/Controller/ConsoleController.php
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,111 @@ | ||
<?php | ||
|
||
namespace Application\Controller; | ||
|
||
use Zend\Mvc\Controller\AbstractConsoleController; | ||
use Zend\Console\Adapter\AdapterInterface as Console; | ||
use Zend\Console\ColorInterface as Color; | ||
use Zend\Http\Client as HttpClient; | ||
|
||
/** | ||
* Console controller to get contributor list | ||
* inspired and almost all code copied from https://github.com/zendframework/zf-web/blob/master/module/Application/src/Application/Controller/ConsoleController.php | ||
*/ | ||
class ConsoleController extends AbstractConsoleController | ||
{ | ||
/** | ||
* @var Console | ||
*/ | ||
protected $console; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* @var HttpClient | ||
*/ | ||
protected $httpClient; | ||
|
||
/** | ||
* Construct console and config property | ||
*/ | ||
public function __construct(Console $console, array $config, HttpClient $httpClient) | ||
{ | ||
$this->console = $console; | ||
$this->config = $config; | ||
|
||
$this->httpClient = $httpClient; | ||
} | ||
|
||
protected function reportError($width, $length, $message, $e = null) | ||
{ | ||
if (($length + 9) > $width) { | ||
$this->console->writeLine(''); | ||
$length = 0; | ||
} | ||
$spaces = $width - $length - 9; | ||
$this->console->writeLine(str_repeat('.', $spaces).'[ ERROR ]', Color::RED); | ||
$this->console->writeLine($message); | ||
if ($e) { | ||
$this->console->writeLine($e->getTraceAsString()); | ||
} | ||
} | ||
|
||
protected function reportSuccess($width, $length) | ||
{ | ||
if (($length + 8) > $width) { | ||
$this->console->writeLine(''); | ||
$length = 0; | ||
} | ||
$spaces = $width - $length - 8; | ||
$this->console->writeLine(str_repeat('.', $spaces).'[ DONE ]', Color::GREEN); | ||
} | ||
|
||
/** | ||
* route : get contributors | ||
*/ | ||
public function getcontributorsAction() | ||
{ | ||
$width = $this->console->getWidth(); | ||
$this->console->writeLine('Fetching GitHub Contributors', Color::GREEN); | ||
|
||
$response = $this->httpClient->send(); | ||
if (!$response->isSuccess()) { | ||
// report failure | ||
$message = $response->getStatusCode().': '.$response->getReasonPhrase(); | ||
$this->reportError($width, 0, $message); | ||
|
||
return; | ||
} | ||
|
||
$body = $response->getBody(); | ||
$contributors = json_decode($body, true); | ||
$total = count($contributors); | ||
|
||
foreach ($contributors as $i => $contributor) { | ||
$message = sprintf(' Processing %d/%d', $i, $total); | ||
$this->console->write($message); | ||
$this->httpClient->setUri("https://api.github.com/users/{$contributor['login']}"); | ||
$response = $this->httpClient->send(); | ||
if (!$response->isSuccess()) { | ||
// report failure | ||
$error = $response->getStatusCode().': '.$response->getReasonPhrase(); | ||
$this->reportError($width, strlen($message), $error); | ||
} | ||
$body = $response->getBody(); | ||
$userInfo = json_decode($body, 1); | ||
$contributors[$i]['user_info'] = $userInfo; | ||
$this->reportSuccess($width, strlen($message)); | ||
} | ||
|
||
$this->console->writeLine(str_repeat('-', $width)); | ||
$message = 'Writing file'; | ||
$this->console->write($message, Color::BLUE); | ||
$path = $this->config['console']['contributors']['output']; | ||
file_put_contents($path, serialize($contributors)); | ||
$this->reportSuccess($width, strlen($message)); | ||
$this->console->writeLine(sprintf('File written to %s', $path)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
module/Application/src/Application/Controller/ContributorsController.php
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,32 @@ | ||
<?php | ||
|
||
namespace Application\Controller; | ||
|
||
use Zend\Mvc\Controller\AbstractActionController; | ||
use Zend\View\Model\ViewModel; | ||
|
||
class ContributorsController extends AbstractActionController | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $contributors; | ||
|
||
/** | ||
* Construct contributors property | ||
*/ | ||
public function __construct(array $contributors) | ||
{ | ||
$this->contributors = $contributors; | ||
} | ||
|
||
public function indexAction() | ||
{ | ||
$this->layout('layout/1columns.phtml'); | ||
$this->layout()->setVariable('skipWelcome', true); | ||
|
||
return new ViewModel([ | ||
'contributors' => $this->contributors, | ||
]); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
module/Application/src/Application/Factory/Controller/ConsoleControllerFactory.php
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,28 @@ | ||
<?php | ||
|
||
namespace Application\Factory\Controller; | ||
|
||
use Application\Controller\ConsoleController; | ||
use Zend\Http\Client as HttpClient; | ||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ConsoleControllerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
$services = $serviceLocator->getServiceLocator(); | ||
$client = new HttpClient(); | ||
$client->setAdapter('Zend\Http\Client\Adapter\Curl'); | ||
$client->setUri('https://api.github.com/repos/sitrunlab/LearnZF2/contributors'); | ||
|
||
return new ConsoleController( | ||
$services->get('Console'), | ||
$services->get('Config'), | ||
$client | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
module/Application/src/Application/Factory/Controller/ContributorsControllerFactory.php
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,18 @@ | ||
<?php | ||
|
||
namespace Application\Factory\Controller; | ||
|
||
use Application\Controller\ContributorsController; | ||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ContributorsControllerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
return new ContributorsController(unserialize(file_get_contents('./data/contributors/contributors.pson'))); | ||
} | ||
} |
Oops, something went wrong.