PhpPackage: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
 
(9 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 5: Zeile 5:
* [[PHP]]
* [[PHP]]
* [[PhpPackage]]
* [[PhpPackage]]
* https://dev.to/timoschinkel/good-practices-when-working-with-composer-5a1c


= Zielsetzung =
= Zielsetzung =
Zeile 45: Zeile 46:


= Kochbuch =
= Kochbuch =
== Aktualisieren ==
<syntaxhighlight lang="bash">
composer update
</syntaxhighlight>
== Entwicklung-Produktion ==
* https://stackoverflow.com/questions/21721495/how-to-deploy-correctly-when-using-composers-develop-production-switch
* <code>composer install {--dev | --no-dev}</code>, default ist <code>--dev</code>
* <code>composer update {--dev | --no-dev}</code>, default ist <code>--dev</code>
== Autoloaderdaten generieren ==
== Autoloaderdaten generieren ==
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Zeile 59: Zeile 70:
</syntaxhighlight>
</syntaxhighlight>


== Einbinden eines lokalen Packages ==
== Einbinden eines lokalen Pakets ==
* composer.json
* composer.json
<syntaxhighlight lang="bash">
composer config repositories.laraknife '{"type": "path", "url": "../laraknife", "options": {"symlink": true}}'
</syntaxhighlight>
* Das ergibt:
<pre>
<pre>
"repositories": [
"repositories": [
Zeile 71: Zeile 86:
     }
     }
],
],
...
"minimum-stability": "dev",
</pre>
== Einbinden eines Github-Repository ==
* composer.json
* Der Branch wird in "require" hinter "dev-" angegeben, z.B. "dev-master"
<syntaxhighlight lang="bash">
composer config repositories.laraknife vcs https://github.com/hamatoma/laraknife
# Branch main:
composer require hamatoma/laraknife:dev-main
</syntaxhighlight>
* Das ergibt dann:
<pre>
    "repositories": [
        "laraknife": {
            "type": "vcs",
            "url": "https://github.com/hamatoma/laraknife"
        }
    ],
    "require": {
        "hamatoma/laraknife": "dev-main"
    }
}
...
...
"minimum-stability": "dev",
"minimum-stability": "dev",
</pre>
</pre>

Aktuelle Version vom 30. Dezember 2023, 09:26 Uhr


Links[Bearbeiten]

Zielsetzung[Bearbeiten]

Leitfaden, wie ein PHP-Package erzeugt wird, wie es eingebunden wird.

Installation[Bearbeiten]

apt install composer

Erzeugen eines Php-Packages[Bearbeiten]

Das Erzeugen erfolgt interaktiv:

composer init

Wichtig für Benennen des Packages:

  • Paketname: hamatoma/my_super_package Namespace: Hamatoma/MySuperPackage
  • Paketname: hamatoma-only/my-super-package Namespace: HamatomaOnly\MySuperPackage
Package name (<vendor>/<name>) [hamatoma/my_super_package]: # Kleinbuchstaben. Namespace:
Description: My super Package
Author: Hamatoma <author@hamatoma.de>
Minimum Stability: dev # oder  alpha, beta, RC, stable
Package Type (e.g. library, project, metapackage, composer-plugin): library
License []: CC0 1.0 Universal
Would you like to define your dependencies (require) interactively: yes
Search for a package: the_ultimate_package
 Found 3 packages matching the_ultimate_package
   [0] fjerbi/ultimateblog 
   [1] assegaiphp/validation 
   [2] ingress-it-solutions/laravel-google-my-business 
Enter the version constraint to require (or leave blank to use the latest version):
...
Would you like to define your dev dependencies (require-dev) interactively: no

Add PSR-4 autoload mapping? Maps namespace "Hamatoma\MySuperPackage" to the path [src/ n to skip]: /src
Do you confirm generation [yes]
Would you like to install dependencies now [yes]?

Kochbuch[Bearbeiten]

Aktualisieren[Bearbeiten]

composer update

Entwicklung-Produktion[Bearbeiten]

Autoloaderdaten generieren[Bearbeiten]

composer dump-autoload

Einbinden in Startseite index.php[Bearbeiten]

require_once 'Hamatoma/MySuperPackage';
$class = new \Hamatoma\MySuperPackage\MyClass();

Einbinden in Projekt MyPhpProject[Bearbeiten]

composer require hamatoma/my_super_package

Einbinden eines lokalen Pakets[Bearbeiten]

  • composer.json
composer config repositories.laraknife '{"type": "path", "url": "../laraknife", "options": {"symlink": true}}'
  • Das ergibt:
"repositories": [
    {
        "type": "path",
        "url": "../my-package",
        "options": {
            "symlink": true
        }
    }
],
...
"minimum-stability": "dev",

Einbinden eines Github-Repository[Bearbeiten]

  • composer.json
  • Der Branch wird in "require" hinter "dev-" angegeben, z.B. "dev-master"
composer config repositories.laraknife vcs https://github.com/hamatoma/laraknife
# Branch main:
composer require hamatoma/laraknife:dev-main
  • Das ergibt dann:
    "repositories": [
        "laraknife": {
            "type": "vcs",
            "url": "https://github.com/hamatoma/laraknife"
        }
    ],
    "require": {
        "hamatoma/laraknife": "dev-main"
    }
}
...
"minimum-stability": "dev",