Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site.... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Creare un nuovo repository per Composer

Per il corretto funzionamento di progetti php è necessario, normalmente, adoperare librerie esterne.

Per farlo si utilizza sovente composer.

Questo è un gestore di dipendenze di librerie che consente di indicare quali librerie utilizzare e il programma composer le scaricherà in automatico dal proprio repository.

Le librerie vengono indicate in un file chiamato composer.json.

Un esempio di questo file è il seguente, utilizzato in un progetto con yii2:

{
    "name": "yiisoft/yii2-app-advanced",
    "description": "Yii 2 Advanced Project Template",
    "keywords": ["yii2", "framework", "advanced", "project template"],
    "homepage": "https://www.yiiframework.com/",
    "type": "project",
    "license": "BSD-3-Clause",
    "support": {
        "issues": "https://github.com/yiisoft/yii2/issues?state=open",
        "forum": "https://www.yiiframework.com/forum/",
        "wiki": "https://www.yiiframework.com/wiki/",
        "irc": "irc://irc.freenode.net/yii",
        "source": "https://github.com/yiisoft/yii2"
    },
    "minimum-stability": "stable",
    "require": {
        "php": ">=7.4.0",
        "yiisoft/yii2": "~2.0.45",
        "yiisoft/yii2-bootstrap5": "~2.0.2",
        "yiisoft/yii2-symfonymailer": "~2.0.3",
        "yiisoft/yii2-jui": "~2.0.0",
        "pzavoli71/yii2-widget-datetimepicker": "*",
        "yiisoft/yii2-bootstrap5": "@dev"
    },
    "require-dev": {
        "yiisoft/yii2-debug": "~2.1.0",
        "yiisoft/yii2-gii": "~2.2.0",
        "yiisoft/yii2-faker": "~2.0.0",
        "phpunit/phpunit": "~9.5.0",
        "codeception/codeception": "^5.0.0 || ^4.0",
        "codeception/lib-innerbrowser": "^3.0 || ^1.1",
        "codeception/module-asserts": "^3.0 || ^1.1",
        "codeception/module-yii2": "^1.1",
        "codeception/module-filesystem": "^2.0 || ^1.1",
        "codeception/verify": "^2.2",
        "symfony/browser-kit": "^6.0 || >=2.7 <=4.2.4",
        "yiisoft/yii2-jui": "~2.0.0",
        "pzavoli71/yii2-widget-datetimepicker": "dev-master",   
        "kartik-v/yii2-datecontrol": "dev-master",
        "kartik-v/yii2-widgets": "@dev",
        "kartik-v/yii2-widget-datepicker": "dev-master",
        "twbs/bootstrap-icons":"*" ,        
        "yiisoft/yii2-bootstrap5": "@dev"
    },
    "autoload-dev": {
        "psr-4": {
            "common\\tests\\": ["common/tests/", "common/tests/_support"],
            "backend\\tests\\": ["backend/tests/", "backend/tests/_support"],
            "frontend\\tests\\": ["frontend/tests/", "frontend/tests/_support"]
        }
    },
    "config": {
        "allow-plugins": {
            "yiisoft/yii2-composer" : true
        },
        "process-timeout": 1800,
        "fxp-asset": {
            "enabled": false
        }
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ]
}

La parte più importante è quella indicata con “require” che contiene l’elenco delle librerie con le relative versioni.

Può capitare di dover utilizzare una libreria non fornita, oppure di doverne utilizzare una modificata da una libreria esistente.

Composer preleva le librerie da progetti github, pertanto se si deve modificare una libreria già esistente è necessario effettuarne un fork.

Nel repository github corrispondente è necessario inserire un file denominato composer.json, così fatto:

{
    "name": "pzavoli71/yii2-widget-datetimepicker",
    "description": "An updated version of kartik-v datetimepicker to enable dd/mm/yyyy hh:ii format datetime",
    "keywords": [
        "yii2",
        "extension",
        "widget",
        "select2",
        "form",
        "datetime",
        "picker",
        "jquery",
        "plugin"
    ],
    "homepage": "https://github.com/pzavoli71/yii2-widget-datetimepicker",
    "type": "yii2-extension",
    "license": "BSD-3-Clause",
    "authors": [
        {
            "name": "Paride Zavoli",
            "email": "paride.zavoli71@gmail.com",
            "homepage": "https://fattodate.org"
        }
    ],
    "require": {
        "kartik-v/yii2-krajee-base": ">=3.0.4"
    },
    "autoload": {
        "psr-4": {
            "kartik\\datetime\\": "src"
        }
    },
    "extra": {
        "branch-alias": {
            "dev-master": "1.5.x-dev"
        }
    }
}

Successivamente si deve caricare il progetto nuovo nel repository di composer che si trova nel sito Packagist.org.

Qui è necessario registrarsi e successivamente premere su https://packagist.org/packages/submit indicando nel campo di testo il path del progetto github che contiene la libreria e il file composer.json.

A quel punto il progetto è pronto per essere utilizzato come libreria.

Lascia un commento