Home Development Tools composer How to write your own zhazha composer package

How to write your own zhazha composer package

Apr 28, 2021 pm 04:48 PM
composer php

下面由composer教程栏目给大家介绍怎么写一个自己的渣渣composer包,希望对需要的朋友有所帮助!

How to write your own zhazha composer package

如何写一个自己的渣渣composer包

很多教程都在教大家如何写一个自己的composer包,但总不放代码。

你不放代码,就会导致看你帖子的人呐,不能得到很好很直观的理解。用产品的角度来思考呢,就是用户体验差。我就贴代码。简单的 Hello World 我也贴出来。你看,这样不仅能够凑字数,还能让用户觉得体验好,真是美滋滋呀。

大家纷纷可以上 https://packagist.org/ 上搜一些包,放到自己的项目中,这样很方便。假如你有一些功能类,没地方保存,比如你的功能类很大,硬盘不够...不过这倒不太可能。那假如你丢三落四,好不容易有一天,写(chao)了(xi)一个很牛x的类,curl类,兴致勃勃保存到 curl.txt 第二天丢了。很尴尬...

那你可以放到 github 呀。如果方便使用呢,你就放到 packagist.org 呀。

比如我写了一个 XorEncryption(异或加密) 的方法。

关于 composer 的一些知识,需要自行了解呢。

有人说贴图比较好,我就爱文字叙述/(ㄒoㄒ)/:首先你去 github 上新建一个项目。比如我的 opqnext/XorEncryptiono

然后你在你在本地创建一个目录。把项目 clone 下来。之后你可以用 composer init 一步一步按提示添加项目名称,描述,作者,依赖包等等信息最后生成一个 composer.json 的文件。或者也可以新建一个文件,然后直接把我下面这个内容拷贝到你的 composer.json 里。然后对应的配置改一改,第一步完成了。

{
    "name": "opqnext/xor-encryption",
    "description": "php xor-encryption",
    "type": "library",
    "keywords": [
        "php",
        "xor"
    ],
    "license": "MIT",
    "authors": [
        {
            "name": "opqnext",
            "email": "309622694@qq.com"
        }
    ],
    "require": {
        "php": ">=5.3.0"
    },
    "autoload": {
        "psr-0": {
            "XorEncryption\\": "src/"
        }
    }
}
Copy after login

还是直接拷贝来的容易的,一定要写上 autoload

然后你就开发你的代码 创建一个src目录。如果看我的代码,就到我的 github 去看。我这里说一下,假如我们要写一个 Hello World 的包。创建一个 src 目录。 创建一个 HelloWorld 的目录,写一个 HelloWorld 的类 :

<?php
/**
 * Hello World
 * @author: 郭贰小姐
 */

namespace HelloWorld;

class HelloWorld {

    public function say_hello()
    {
        return "hello world";
    }
}
Copy after login

push 到 github 上面,你可以打一些 tag 标明版本号的呀。

到这里,代码应该就开发完成了。然后你代码提交到 submit packages 把你的 git 地址写上。

把 readme.md 完善一下。就这么多了。

我提交了 v1.0.1 版本之后,不知道为什么,国内的镜像总是不能同步过来。真是伤心...

The above is the detailed content of How to write your own zhazha composer package. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

See all articles