Skip to content

Commit 954983c

Browse files
committed
Add other config files
1 parent 4dc761f commit 954983c

8 files changed

+197
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto
2+
3+
/.github export-ignore
4+
5+
/tests export-ignore
6+
phpunit.xml export-ignore
7+
8+
.editorconfig export-ignore
9+
.gitattributes export-ignore
10+
.gitignore export-ignore
11+

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea/
2+
vendor/
3+
4+
composer.lock
5+
.phpunit.result.cache

.php-cs-fixer.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$files = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . '/src')
5+
;
6+
7+
$rules = [
8+
'@PER' => true,
9+
'@PER:risky' => true,
10+
'strict_param' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
];
13+
14+
return (new PhpCsFixer\Config())
15+
->setRules($rules)
16+
->setCacheFile(__DIR__ . '/vendor/.php-cs-fixer.cache')
17+
->setFinder($files)
18+
;

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright © Kirill Nesmeyanov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Work Directory
2+
3+
<p align="center">
4+
<a href="https://packagist.org/packages/ffi/work-directory"><img src="https://poser.pugx.org/ffi/work-directory/require/php?style=for-the-badge" alt="PHP 8.1+"></a>
5+
<a href="https://packagist.org/packages/ffi/work-directory"><img src="https://poser.pugx.org/ffi/work-directory/version?style=for-the-badge" alt="Latest Stable Version"></a>
6+
<a href="https://packagist.org/packages/ffi/work-directory"><img src="https://poser.pugx.org/ffi/work-directory/v/unstable?style=for-the-badge" alt="Latest Unstable Version"></a>
7+
<a href="https://packagist.org/packages/ffi/work-directory"><img src="https://poser.pugx.org/ffi/work-directory/downloads?style=for-the-badge" alt="Total Downloads"></a>
8+
<a href="https://raw.githubusercontent.com/php-ffi/work-directory/master/LICENSE.md"><img src="https://poser.pugx.org/ffi/work-directory/license?style=for-the-badge" alt="License MIT"></a>
9+
</p>
10+
<p align="center">
11+
<a href="https://github.com/php-ffi/work-directory/actions"><img src="https://github.com/php-ffi/work-directory/workflows/build/badge.svg"></a>
12+
</p>
13+
14+
In the case that during the loading of a binary (like `*.so`, `*.dylib` or `*.dll`)
15+
through FFI it depends on some other binary module, then errors may occur if the
16+
first one and dependent libraries are in different directories, like:
17+
18+
```php
19+
// - bin/
20+
// - main.dll
21+
// - other/
22+
// - dependency.dll
23+
24+
$ffi = \FFI::cdef('...', __DIR__ . '/bin/main.dll');
25+
// Error like "can not load ..."
26+
// - In this case, an error occurs because the specified
27+
// dependency ("dependency.dll") could not be found in "bin"
28+
// or working directory.
29+
```
30+
31+
This library allows you to load similar dependencies:
32+
33+
```php
34+
// Use "bin/other" directory for dependencies.
35+
\FFI\WorkDirectory\WorkDirectory::set(__DIR__ . '/bin/other');
36+
37+
//
38+
$ffi = \FFI::cdef('...', __DIR__ . '/bin/main.dll');
39+
```
40+
41+
You can also use the built-in [chdir function](https://www.php.net/manual/en/function.chdir.php)
42+
for such operations, however it will only work in case of a Non-Thread Safe PHP
43+
build ([see remark](https://www.php.net/manual/en/function.chdir.php#refsect1-function.chdir-notes)).
44+
45+
## Requirements
46+
47+
- PHP >= 7.4
48+
49+
## Installation
50+
51+
Library is available as composer repository and can be installed using the
52+
following command in a root of your project.
53+
54+
```sh
55+
$ composer require ffi/work-directory
56+
```
57+
58+
## Usage
59+
60+
### Get Current Work Directory
61+
62+
```php
63+
$directory = \FFI\WorkDirectory\WorkDirectory::get();
64+
65+
if ($directory !== null) {
66+
echo 'CWD is: ' . $directory;
67+
}
68+
```
69+
70+
### Update Current Work Directory
71+
72+
Getting the full path to the library.
73+
74+
```php
75+
$directory = __DIR__ . '/path/to/directory';
76+
77+
if (\FFI\WorkDirectory\WorkDirectory::set($directory)) {
78+
echo 'CWD has been updated to: ' . $directory;
79+
}
80+
```

phpunit.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
colors="true"
5+
backupGlobals="true"
6+
stopOnFailure="false"
7+
processIsolation="false"
8+
backupStaticAttributes="false"
9+
bootstrap="vendor/autoload.php"
10+
convertErrorsToExceptions="true"
11+
convertNoticesToExceptions="true"
12+
convertWarningsToExceptions="true"
13+
>
14+
<coverage>
15+
<include>
16+
<directory suffix=".php">src</directory>
17+
</include>
18+
</coverage>
19+
<testsuites>
20+
<testsuite name="Test Suite">
21+
<directory suffix="TestCase.php">tests</directory>
22+
</testsuite>
23+
</testsuites>
24+
<php>
25+
<ini name="error_reporting" value="-1"/>
26+
<ini name="memory_limit" value="-1"/>
27+
</php>
28+
</phpunit>

psalm.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
resolveFromConfigFile="true"
5+
findUnusedCode="false"
6+
findUnusedBaselineEntry="true"
7+
findUnusedPsalmSuppress="true"
8+
cacheDirectory="vendor/.psalm.cache"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xmlns="https://getpsalm.org/schema/config"
11+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
12+
>
13+
<projectFiles>
14+
<directory name="src" />
15+
<ignoreFiles>
16+
<directory name="vendor" />
17+
</ignoreFiles>
18+
</projectFiles>
19+
</psalm>

0 commit comments

Comments
 (0)