From 8cabbe191ed6bed40a68643f9a7657300038e06a Mon Sep 17 00:00:00 2001 From: Jens Nimmich Date: Thu, 24 Apr 2025 00:27:22 +0200 Subject: [PATCH 1/2] feat(#1): add first project structure --- .gitattributes | 23 ++++++++++++++++++++ .gitignore | 10 +++++++++ CHANGELOG.md | 19 +++++++++++++++++ LICENSE | 21 ++++++++++++++++++ README.md | 30 +++++++++++++++++++++++++- composer.json | 22 +++++++++++++++++++ src/Curl.php | 34 ++++++++++++++++++++++++++++++ src/CurlOptions.php | 28 ++++++++++++++++++++++++ src/Exception/RuntimeException.php | 7 ++++++ 9 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 composer.json create mode 100644 src/Curl.php create mode 100644 src/CurlOptions.php create mode 100644 src/Exception/RuntimeException.php diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..cf15f2e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +# https://git-scm.com/docs/gitattributes +# https://help.github.com/en/github/using-git/configuring-git-to-handle-line-endings + +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted to native line endings on checkout. + +# Configs +.editorconfig text eol=lf +.gitattributes text eol=lf + +# Documentation +*.md text eol=lf diff=markdown + +# Ignore files +*.*ignore text eol=lf + +# Do not export +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.gitkeep export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1663a23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +### JetBrains working directory +/.idea/ + +### Composer files +composer.phar +composer.lock +/vendor/ + +### keep all placeholders +!.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..29d19b1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added +- Feature [#1](https://gitlab.com/take-me/curl/-/issues/1) - First Project Structure + +### Changed + +### Deprecated + +### Fixed + +### Removed diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..593728a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Jens Nimmich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 5c48415..ae1066b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,31 @@ # TakeMe / cURL -A OOP PHP wrapper for native cURL functions. +--- + +This is an OOP wrapper for native PHP cURL functions without any business logic. +It does not contain all possible functions, but it will be extended on demand. + +## ⚙️Installation +Use composer to install this wrapper: + +` +composer require take-me/curl +` + +## ✔️Usage + +Create a Curl-instance and a CurlOption-instance and start: + +` + $curl = new TakeMe/Curl(); + $curlOption = new TakeMe/CurlOption($curl); + + $curl->exec(); +` + +## ⁉️ Support +If you have questions about this project please [email](mailto:lmo5-support@jens-nimmich.de?subject=Support%20for%20LMO5) me. + +## 📝 License +Copyright (C) 2025 [Jens Nimmich](mailto:project-curl@jens-nimmich.de).
+This project is [MIT](https://choosealicense.com/licenses/gpl-3.0/) licensed. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b263e9e --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "take-me/curl", + "description": "An OOP wrapper for native PHP cURL functions.", + "type": "library", + "require": { + "php": "^8.2", + "ext-curl": "*" + }, + "license": "MIT", + "autoload": { + "psr-4": { + "TakeMe\\": "src/" + } + }, + "authors": [ + { + "name": "Jens Nimmich", + "email": "project-curl@jens-nimmich.de" + } + ], + "minimum-stability": "stable" +} diff --git a/src/Curl.php b/src/Curl.php new file mode 100644 index 0000000..c031b01 --- /dev/null +++ b/src/Curl.php @@ -0,0 +1,34 @@ +handle = $this->init(); + } + + public function getHandle(): \CurlHandle + { + return $this->handle; + } + + public function exec(): string|bool + { + return curl_exec($this->handle); + } + + private function init(): \CurlHandle|false + { + return curl_init(); + } +} diff --git a/src/CurlOptions.php b/src/CurlOptions.php new file mode 100644 index 0000000..6f2d3a4 --- /dev/null +++ b/src/CurlOptions.php @@ -0,0 +1,28 @@ +setOpt(CURLOPT_RETURNTRANSFER, true); + } + + public function setUrl(string $url): bool + { + return $this->setOpt(CURLOPT_URL, $url); + } + + + private function setOpt(int $optionId, mixed $value): bool + { + return curl_setopt($this->handle, $optionId, $value); + } + +} diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php new file mode 100644 index 0000000..c39951c --- /dev/null +++ b/src/Exception/RuntimeException.php @@ -0,0 +1,7 @@ + Date: Thu, 24 Apr 2025 00:53:07 +0200 Subject: [PATCH 2/2] feat(#1): add first project structure --- .gitattributes | 1 + composer.json | 23 ++++++++++++++++------- src/Curl.php | 4 ++-- src/CurlOptions.php | 4 +--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.gitattributes b/.gitattributes index cf15f2e..7ce7846 100644 --- a/.gitattributes +++ b/.gitattributes @@ -21,3 +21,4 @@ .gitattributes export-ignore .gitignore export-ignore .gitkeep export-ignore +CHANGELOG.md export-ignore diff --git a/composer.json b/composer.json index b263e9e..3ab8501 100644 --- a/composer.json +++ b/composer.json @@ -1,22 +1,31 @@ { "name": "take-me/curl", "description": "An OOP wrapper for native PHP cURL functions.", + "license": "MIT", "type": "library", + "authors": [ + { + "name": "Jens Nimmich", + "email": "project-curl@jens-nimmich.de" + } + ], "require": { "php": "^8.2", "ext-curl": "*" }, - "license": "MIT", + "minimum-stability": "stable", "autoload": { "psr-4": { "TakeMe\\": "src/" } }, - "authors": [ - { - "name": "Jens Nimmich", - "email": "project-curl@jens-nimmich.de" + "config": { + "prefer-stable": true, + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-main": "1.0.x-dev" } - ], - "minimum-stability": "stable" + } } diff --git a/src/Curl.php b/src/Curl.php index c031b01..99c92c3 100644 --- a/src/Curl.php +++ b/src/Curl.php @@ -10,7 +10,7 @@ class Curl public function __construct() { - if (!extension_loaded('curl')) { + if (!\extension_loaded('curl')) { throw new RuntimeException('cURL library is mandatory.'); } @@ -22,7 +22,7 @@ class Curl return $this->handle; } - public function exec(): string|bool + public function exec(): bool|string { return curl_exec($this->handle); } diff --git a/src/CurlOptions.php b/src/CurlOptions.php index 6f2d3a4..409c641 100644 --- a/src/CurlOptions.php +++ b/src/CurlOptions.php @@ -5,7 +5,7 @@ namespace TakeMe; class CurlOptions { public function __construct( - private readonly \CurlHandle $handle + private readonly \CurlHandle $handle, ) { } @@ -19,10 +19,8 @@ class CurlOptions return $this->setOpt(CURLOPT_URL, $url); } - private function setOpt(int $optionId, mixed $value): bool { return curl_setopt($this->handle, $optionId, $value); } - } -- GitLab