Skip to content

Commit 4f3f7a5

Browse files
committed
Add Docker setup, PHP parser implementation, and API routing
- Created Dockerfile for PHP 8.2 with necessary extensions and Composer setup. - Added docker-compose.yml for service configuration and volume management. - Implemented index.php as the entry point for the PHP parser server. - Developed CodeParser and CodeVisitor classes for parsing PHP code and extracting structured data. - Added Router class to handle API requests and responses. - Included integration test scripts for validating the API functionality. - Created sample PHP and JSON files for testing purposes.
0 parents  commit 4f3f7a5

File tree

10 files changed

+998
-0
lines changed

10 files changed

+998
-0
lines changed

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM php:8.2-alpine
2+
3+
# Install required extensions and tools
4+
RUN apk add --no-cache $PHPIZE_DEPS git zip unzip linux-headers \
5+
&& docker-php-ext-install opcache \
6+
&& pecl install xdebug \
7+
&& docker-php-ext-enable xdebug
8+
9+
# Set working directory
10+
WORKDIR /app
11+
12+
# Install composer
13+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
14+
15+
# Copy composer files and install dependencies
16+
COPY composer.json composer.lock* ./
17+
RUN composer install --no-scripts --no-autoloader
18+
19+
# Copy the rest of the application
20+
COPY . .
21+
22+
# Generate optimized autoloader
23+
RUN composer dump-autoload --optimize
24+
25+
# Configure PHP for development
26+
RUN echo "xdebug.mode=develop,debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
27+
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
28+
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
29+
30+
# Expose port
31+
EXPOSE 3010
32+
33+
# Use php development server to run the application
34+
CMD ["php", "-S", "0.0.0.0:3010", "index.php"]

composer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "singularityx/php-parser",
3+
"description": "PHP Parser for parsing code structure",
4+
"type": "project",
5+
"require": {
6+
"php": ">=7.4",
7+
"nikic/php-parser": "^4.15"
8+
},
9+
"autoload": {
10+
"psr-4": {
11+
"PhpParser\\": "src/"
12+
}
13+
}
14+
}

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3'
2+
3+
services:
4+
php-parser:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
working_dir: /app
9+
volumes:
10+
- .:/app
11+
- /app/vendor
12+
ports:
13+
- "5684:3010"
14+
environment:
15+
- PORT=3010
16+
- PHP_ENV=development
17+
# Using PHP development server that auto-reloads when files change
18+
command: sh -c "php -S 0.0.0.0:3010 index.php"
19+
networks:
20+
- snorkell_network
21+
22+
networks:
23+
snorkell_network:
24+
external: true

index.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* PHP Parser Server
4+
*
5+
* Entry point for the PHP parser server that provides API endpoints
6+
* for parsing PHP code and returning structured data.
7+
*/
8+
9+
// Enable error reporting for development
10+
ini_set('display_errors', 1);
11+
ini_set('display_startup_errors', 1);
12+
error_reporting(E_ALL);
13+
14+
// Load autoloader
15+
require_once __DIR__ . '/vendor/autoload.php';
16+
17+
use PhpParser\Router;
18+
19+
// Initialize router and handle requests
20+
$router = new Router();
21+
$router->handleRequest();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"error": "Invalid request data"
3+
}

0 commit comments

Comments
 (0)