Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docker/8.1-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM php:8.1-alpine

# Install os-level dependencies
RUN apk update \
&& apk --no-cache --virtual add git pcre-dev ${PHPIZE_DEPS}

# Install scalar extension
RUN git clone https://github.com/nikic/scalar_objects.git \
&& cd scalar_objects \
&& phpize \
&& ./configure --enable-scalar_objects \
&& make \
&& make install \
&& php run-tests.php -p `which php` --show-diff -d extension=`pwd`/modules/scalar_objects.so -q \
&& docker-php-ext-enable scalar_objects

# Remove os-level dependencies and src code
RUN apk del git pcre-dev ${PHPIZE_DEPS} \
&& rm -rf scalar_objects \
&& apk del git pcre-dev ${PHPIZE_DEPS} \
&& rm -rf /tmp/* /var/tmp/*

ENTRYPOINT ["docker-php-entrypoint"]
CMD ["php", "-a"]
23 changes: 23 additions & 0 deletions docker/8.1-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM php:8.1-cli

# Install os-level dependencies
RUN apt-get update && apt-get install -y git

# Install scalar extension
RUN git clone https://github.com/nikic/scalar_objects.git \
&& cd scalar_objects \
&& phpize \
&& ./configure --enable-scalar_objects \
&& make \
&& make install \
&& php run-tests.php -p `which php` --show-diff -d extension=`pwd`/modules/scalar_objects.so -q \
&& docker-php-ext-enable scalar_objects

# Delete src code and os-level dependencies
RUN rm -rf scalar_objects \
&& apt-get purge -y git \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENTRYPOINT ["docker-php-entrypoint"]
CMD ["php", "-a"]
58 changes: 58 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Docker images

Use `nikic/scalar_objects` with docker

# Steps

1. Build your image
```shell
$ docker build -t php-scalar-objects ./8.1-alpine
```

2. Create a docker file for your projects

Example `Dockerfile`
```dockerfile
FROM php-scalar-objects
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
CMD [ "php", "./index.php" ]
```

Example `index.php`
```php
<?php

class StringHandler
{
public static function length($self)
{
return strlen($self);
}

public static function startsWith($self, $other)
{
return strpos($self, $other) === 0;
}
}

register_primitive_type_handler('string', 'StringHandler');

$string = "abc";
var_dump($string->length()); // int(3)
var_dump($string->startsWith("a")); // bool(true)
```

3. Build your project

```shell
$ docker build -t my-php-app .
```

> Execute this in the same directory where your app is

4. Run your app

```shell
$ docker run -it --rm --name my-php-running-app my-php-app:latest
```