Skip to content

Commit 9deddc3

Browse files
committed
Resolve tilde to home directory
1 parent e11fdd0 commit 9deddc3

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Prerequisites
77
=============
88

99
You'll need an OAuth consumer key & secret pair. You can find a regulary refreshed pair for testing purposes in the
10-
[UiTiD manual][uitid_docs]. These credentials are valid for the base URL http://test.uitid.be/culturefeed/rest.
10+
[UiTiD manual][uitid_docs]. These credentials are valid for the base URL http://acc.uitid.be/uitid/rest.
1111

1212
You will need to register for an UiTiD account as well. Append /auth/register' to the base URL (for example
13-
http://test.uitid.be/culturefeed/rest/auth/register), visit the resulting URL with your web browser and fill out the
13+
http://acc.uitid.be/uitid/rest/auth/register), visit the resulting URL with your web browser and fill out the
1414
registration form.
1515

1616
Installation
@@ -78,7 +78,7 @@ An example of how the contents of the file could look like:
7878
```ini
7979
consumer-key=76163fc774cb42246d9de37cadeece8a
8080
consumer-secret=fff975c5a8c7ba19ce92969c1879b211
81-
base-url[auth]=http://test.uitid.be/culturefeed/rest
81+
base-url[auth]=http://acc.uitid.be/uitid/rest
8282
```
8383

8484
The authenticate command

lib/CultuurNet/Auth/Command/Command.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CultuurNet\Auth\Command;
44

5+
use CultuurNet\Auth\FileUtility;
56
use \Symfony\Component\Console\Command\Command as BaseCommand;
67
use \Symfony\Component\Console\Input\InputArgument;
78
use \Symfony\Component\Console\Input\InputInterface;
@@ -29,6 +30,11 @@ abstract class Command extends BaseCommand
2930
*/
3031
private $defaults;
3132

33+
/**
34+
* @var FileUtility
35+
*/
36+
private $fileUtility;
37+
3238
/**
3339
* @return array
3440
*/
@@ -85,11 +91,21 @@ public function __construct($name = null)
8591
);
8692
}
8793

94+
protected function getFileUtility() {
95+
if (!isset($this->fileUtility)) {
96+
$this->fileUtility = new FileUtility();
97+
}
98+
99+
return $this->fileUtility;
100+
}
101+
88102
protected function execute(InputInterface $in, OutputInterface $out)
89103
{
90104
$sessionFile = $in->getOption('session');
91105
if (NULL !== $sessionFile) {
92106
// @todo Catch JsonValidationException and show errors.
107+
$fileUtility = $this->getFileUtility();
108+
$sessionFile = $fileUtility->expandPath($sessionFile);
93109
$this->session = JsonSessionFile::read($sessionFile);
94110
}
95111
else {
@@ -125,7 +141,7 @@ protected function execute(InputInterface $in, OutputInterface $out)
125141
/**
126142
*
127143
*/
128-
protected function resolveBaseUrl($api, InputInterface $in = NULL, $default = 'http://test.uitid.be/culturefeed/rest')
144+
protected function resolveBaseUrl($api, InputInterface $in = NULL, $default = 'http://acc.uitid.be/uitid/rest')
129145
{
130146
if (NULL === $this->session) {
131147
// @todo throw exception as session isn't initialized yet
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* @file
4+
*/
5+
6+
namespace CultuurNet\Auth;
7+
8+
class FileUtility
9+
{
10+
protected $expand;
11+
12+
/**
13+
* @var boolean
14+
*/
15+
protected $expandTilde;
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $userHomeDir;
21+
22+
public function __construct()
23+
{
24+
if (function_exists('posix_getuid')) {
25+
$this->expandTilde = TRUE;
26+
27+
$info = posix_getpwuid(posix_getuid());
28+
$this->userHomeDir = $info['dir'];
29+
}
30+
}
31+
32+
public function expandPath($path)
33+
{
34+
if ($this->expandTilde && 0 === strpos($path, '~')) {
35+
$path = substr_replace($path, $this->userHomeDir, 0, 1);
36+
}
37+
38+
return $path;
39+
}
40+
}

0 commit comments

Comments
 (0)