Skip to content

Commit 95f0009

Browse files
committed
first demo build
1 parent 510d2ef commit 95f0009

8 files changed

+133
-51
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea
33
.php_cs.cache
44
vendor/
5+
kimai.phar

README.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,37 @@
22

33
A PHP application to access your Kimai 2 installation via its API (http).
44

5+
**Requirements**
6+
7+
- PHP 7.2.5
8+
- cURL extension
9+
- json extension
10+
- iconv extension
11+
12+
## Installation and updates
13+
14+
```bash
15+
wget curl -LJO https://github.com/kevinpapst/kimai2-console/releases/latest/download/kimai.phar
16+
chmod +x kimai.phar
17+
mv kimai.phar /usr/local/bin/kimai
18+
```
19+
20+
Now you need to create a configuration file, which is required to connect to Kimai:
21+
22+
```bash
23+
kimai dump-configuration
24+
```
25+
26+
Afterwards edit the file and change the URL, username and API token to your needs.
27+
28+
By default the configuration file targets the demo installation and will work, but this is likely not want you intent to use ;-)
29+
30+
That's it, you can use Kimai now with e.g. `kimai customer:list`.
31+
532
## Environment variables
633

734
The following environment variables are supported:
835

936
- `KIMAI_MEMORY_LIMIT` - configures the allowed memory limit (eg `128MB`, or `-1` for unlimited) (see [here](https://www.php.net/manual/en/ini.core.php#ini.memory-limit))
10-
- `KIMAI_CONFIG` - path to your configuration file (default: $HOME/.kimai2-console.json)
11-
12-
## Roadmap
13-
14-
- [add auto completion support](https://github.com/stecman/symfony-console-completion)
37+
- `KIMAI_CONFIG` - path to your configuration file (defaults to: $HOME/.kimai2-console.json)
1538

bin/kimai

+43-8
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,56 @@
22
<?php
33

44
if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
5-
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
5+
fwrite(STDERR, 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL);
6+
exit(1);
7+
}
8+
9+
foreach (['json', 'iconv'] as $extension) {
10+
if (!extension_loaded($extension)) {
11+
fwrite(STDERR, sprintf("PHP extension ext-%s is missing from your system. Install or enable it.\n", $extension));
12+
exit(1);
13+
}
614
}
15+
unset($extension);
716

817
setlocale(LC_ALL, 'C');
918

10-
if (!file_exists(__DIR__.'/../vendor/autoload.php')) {
11-
echo 'You must set up the project dependencies using `composer install`'.PHP_EOL.
12-
'See https://getcomposer.org/download/ for instructions on installing Composer'.PHP_EOL;
13-
exit(1);
19+
// -------------------------- AUTOLOAD --------------------------
20+
$require = true;
21+
if (class_exists('Phar')) {
22+
// Maybe this file is used as phar-stub? Let's try!
23+
try {
24+
Phar::mapPhar('kimai.phar');
25+
require_once 'phar://kimai.phar/vendor/autoload.php';
26+
$require = false;
27+
} catch (PharException $e) {
28+
}
29+
}
30+
if ($require) {
31+
// OK, it's not, let give Composer autoloader a try!
32+
$possibleFiles = [__DIR__.'/../../../autoload.php', __DIR__.'/../../autoload.php', __DIR__.'/../vendor/autoload.php'];
33+
$file = null;
34+
foreach ($possibleFiles as $possibleFile) {
35+
if (file_exists($possibleFile)) {
36+
$file = $possibleFile;
37+
break;
38+
}
39+
}
40+
41+
if (null === $file) {
42+
fwrite(STDERR, "Unable to locate autoload.php file, you must set up the project dependencies using `composer install`.\n");
43+
exit(1);
44+
}
45+
46+
require_once $file;
47+
unset($possibleFiles, $possibleFile, $file);
1448
}
49+
unset($require);
50+
// -------------------------- AUTOLOAD --------------------------
1551

1652
set_time_limit(0);
1753

18-
require dirname(__DIR__).'/vendor/autoload.php';
19-
2054
use KimaiConsole\Application;
21-
use KimaiConsole\Constants;
2255

2356
if (function_exists('ini_set')) {
2457
@ini_set('display_errors', 1);
@@ -52,3 +85,5 @@ putenv('KIMAI_BINARY='.realpath($_SERVER['argv'][0]));
5285

5386
$application = new Application();
5487
$application->run();
88+
89+
__HALT_COMPILER();

box.json.dist

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"check-requirements": false,
3+
"dump-autoload": false,
4+
"stub": "bin/kimai",
5+
"main": false,
6+
"output": "kimai.phar",
7+
"compactors": [
8+
"KevinGH\\Box\\Compactor\\Json",
9+
"KevinGH\\Box\\Compactor\\Php"
10+
],
11+
"files": [
12+
"LICENSE"
13+
],
14+
"finder": [
15+
{
16+
"name": [
17+
"*.php"
18+
],
19+
"exclude": [
20+
"Test",
21+
"test",
22+
"Tests",
23+
"tests"
24+
],
25+
"in": [
26+
"src",
27+
"vendor"
28+
]
29+
}
30+
],
31+
"compression": "GZ",
32+
"git-commit": "git-commit",
33+
"git-commit-short": "git-commit-short",
34+
"datetime": "release-date"
35+
}

composer.json

+2-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "kevinpapst/kimai2-console",
33
"license": "MIT",
44
"type": "project",
5-
"description": "Kimai 2 - console application to manage your timesheets remotely",
5+
"description": "Kimai 2 - console application to manage your time-tracking data remotely",
66
"authors": [
77
{
88
"name": "Kevin Papst",
@@ -11,14 +11,11 @@
1111
],
1212
"require": {
1313
"php": "^7.2.5",
14-
"ext-ctype": "*",
1514
"ext-iconv": "*",
1615
"ext-json": "*",
1716
"guzzlehttp/guzzle": "^6.5",
1817
"symfony/console": "5.0.*"
1918
},
20-
"require-dev": {
21-
},
2219
"config": {
2320
"preferred-install": {
2421
"*": "dist"
@@ -30,30 +27,9 @@
3027
"KimaiConsole\\": "src/"
3128
}
3229
},
33-
"autoload-dev": {
34-
"psr-4": {
35-
"App\\Tests\\": "tests/"
36-
}
37-
},
3830
"replace": {
39-
"paragonie/random_compat": "2.*",
40-
"symfony/polyfill-ctype": "*",
4131
"symfony/polyfill-iconv": "*",
42-
"symfony/polyfill-php72": "*",
43-
"symfony/polyfill-php71": "*",
44-
"symfony/polyfill-php70": "*",
45-
"symfony/polyfill-php56": "*"
46-
},
47-
"scripts": {
48-
"auto-scripts": {
49-
50-
},
51-
"post-install-cmd": [
52-
"@auto-scripts"
53-
],
54-
"post-update-cmd": [
55-
"@auto-scripts"
56-
]
32+
"symfony/polyfill-php72": "*"
5733
},
5834
"conflict": {
5935
"symfony/symfony": "*"

composer.lock

+11-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Application.php

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public function __construct()
3333
parent::__construct(Constants::SOFTWARE, Constants::VERSION);
3434
}
3535

36+
public function getLongVersion()
37+
{
38+
return sprintf('<info>%s</info> version <comment>%s</comment> %s (#%s)', $this->getName(), $this->getVersion(), Constants::DATE, Constants::GIT);
39+
}
40+
3641
/**
3742
* {@inheritdoc}
3843
*/

src/Constants.php

+8
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ class Constants
1919
* The software name
2020
*/
2121
public const SOFTWARE = 'Kimai 2 - Remote Console';
22+
/**
23+
* The actual git commit
24+
*/
25+
public const GIT = '@git-commit-short@';
26+
/**
27+
* The actual date when this phar was created
28+
*/
29+
public const DATE = '@release-date@';
2230
}

0 commit comments

Comments
 (0)