Skip to content

Commit

Permalink
first demo build
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Dec 21, 2019
1 parent 510d2ef commit 95f0009
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea
.php_cs.cache
vendor/
kimai.phar
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,37 @@

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

**Requirements**

- PHP 7.2.5
- cURL extension
- json extension
- iconv extension

## Installation and updates

```bash
wget curl -LJO https://github.com/kevinpapst/kimai2-console/releases/latest/download/kimai.phar
chmod +x kimai.phar
mv kimai.phar /usr/local/bin/kimai
```

Now you need to create a configuration file, which is required to connect to Kimai:

```bash
kimai dump-configuration
```

Afterwards edit the file and change the URL, username and API token to your needs.

By default the configuration file targets the demo installation and will work, but this is likely not want you intent to use ;-)

That's it, you can use Kimai now with e.g. `kimai customer:list`.

## Environment variables

The following environment variables are supported:

- `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))
- `KIMAI_CONFIG` - path to your configuration file (default: $HOME/.kimai2-console.json)

## Roadmap

- [add auto completion support](https://github.com/stecman/symfony-console-completion)
- `KIMAI_CONFIG` - path to your configuration file (defaults to: $HOME/.kimai2-console.json)

51 changes: 43 additions & 8 deletions bin/kimai
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,56 @@
<?php

if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
fwrite(STDERR, 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL);
exit(1);
}

foreach (['json', 'iconv'] as $extension) {
if (!extension_loaded($extension)) {
fwrite(STDERR, sprintf("PHP extension ext-%s is missing from your system. Install or enable it.\n", $extension));
exit(1);
}
}
unset($extension);

setlocale(LC_ALL, 'C');

if (!file_exists(__DIR__.'/../vendor/autoload.php')) {
echo 'You must set up the project dependencies using `composer install`'.PHP_EOL.
'See https://getcomposer.org/download/ for instructions on installing Composer'.PHP_EOL;
exit(1);
// -------------------------- AUTOLOAD --------------------------
$require = true;
if (class_exists('Phar')) {
// Maybe this file is used as phar-stub? Let's try!
try {
Phar::mapPhar('kimai.phar');
require_once 'phar://kimai.phar/vendor/autoload.php';
$require = false;
} catch (PharException $e) {
}
}
if ($require) {
// OK, it's not, let give Composer autoloader a try!
$possibleFiles = [__DIR__.'/../../../autoload.php', __DIR__.'/../../autoload.php', __DIR__.'/../vendor/autoload.php'];
$file = null;
foreach ($possibleFiles as $possibleFile) {
if (file_exists($possibleFile)) {
$file = $possibleFile;
break;
}
}

if (null === $file) {
fwrite(STDERR, "Unable to locate autoload.php file, you must set up the project dependencies using `composer install`.\n");
exit(1);
}

require_once $file;
unset($possibleFiles, $possibleFile, $file);
}
unset($require);
// -------------------------- AUTOLOAD --------------------------

set_time_limit(0);

require dirname(__DIR__).'/vendor/autoload.php';

use KimaiConsole\Application;
use KimaiConsole\Constants;

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

$application = new Application();
$application->run();

__HALT_COMPILER();
35 changes: 35 additions & 0 deletions box.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"check-requirements": false,
"dump-autoload": false,
"stub": "bin/kimai",
"main": false,
"output": "kimai.phar",
"compactors": [
"KevinGH\\Box\\Compactor\\Json",
"KevinGH\\Box\\Compactor\\Php"
],
"files": [
"LICENSE"
],
"finder": [
{
"name": [
"*.php"
],
"exclude": [
"Test",
"test",
"Tests",
"tests"
],
"in": [
"src",
"vendor"
]
}
],
"compression": "GZ",
"git-commit": "git-commit",
"git-commit-short": "git-commit-short",
"datetime": "release-date"
}
28 changes: 2 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "kevinpapst/kimai2-console",
"license": "MIT",
"type": "project",
"description": "Kimai 2 - console application to manage your timesheets remotely",
"description": "Kimai 2 - console application to manage your time-tracking data remotely",
"authors": [
{
"name": "Kevin Papst",
Expand All @@ -11,14 +11,11 @@
],
"require": {
"php": "^7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.5",
"symfony/console": "5.0.*"
},
"require-dev": {
},
"config": {
"preferred-install": {
"*": "dist"
Expand All @@ -30,30 +27,9 @@
"KimaiConsole\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {

},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
"symfony/polyfill-php72": "*"
},
"conflict": {
"symfony/symfony": "*"
Expand Down
23 changes: 11 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public function __construct()
parent::__construct(Constants::SOFTWARE, Constants::VERSION);
}

public function getLongVersion()
{
return sprintf('<info>%s</info> version <comment>%s</comment> %s (#%s)', $this->getName(), $this->getVersion(), Constants::DATE, Constants::GIT);
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ class Constants
* The software name
*/
public const SOFTWARE = 'Kimai 2 - Remote Console';
/**
* The actual git commit
*/
public const GIT = '@git-commit-short@';
/**
* The actual date when this phar was created
*/
public const DATE = '@release-date@';
}

0 comments on commit 95f0009

Please sign in to comment.