Update LIC #1
+17
@@ -1 +1,18 @@
|
||||
.idea/
|
||||
|
||||
### Node ###
|
||||
node_modules/
|
||||
*.log
|
||||
|
||||
### VitePress ###
|
||||
# scripts/sync-zh.mjs 生成的站点源文件(由 src/ 和 i18n/zh/ 组装)
|
||||
/site/
|
||||
# scripts/generate.mjs 生成的配置
|
||||
/.vitepress/generated/
|
||||
/.vitepress/dist/
|
||||
/.vitepress/cache/
|
||||
/.vitepress/.temp/
|
||||
/.vitepress/node_modules/
|
||||
|
||||
### Cloudflare Wrangler ###
|
||||
.wrangler/
|
||||
|
||||
Generated
+2
-2
@@ -8,8 +8,8 @@
|
||||
<option name="activeLocationIds" />
|
||||
<option name="locations">
|
||||
<list>
|
||||
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
|
||||
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
|
||||
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">bundled-sun-checks</ConfigurationLocation>
|
||||
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">bundled-google-checks</ConfigurationLocation>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { defineConfig, type DefaultTheme, type LocaleConfig } from 'vitepress';
|
||||
|
||||
type GeneratedLocale = {
|
||||
label: string;
|
||||
base: string;
|
||||
sidebar: DefaultTheme.SidebarMulti;
|
||||
};
|
||||
|
||||
const siteFile = path.join(path.dirname(fileURLToPath(import.meta.url)), 'generated', 'site.json');
|
||||
if (!fs.existsSync(siteFile))
|
||||
throw new Error('Run "node scripts/generate.mjs" first. The file .vitepress/generated/site.json is missing.');
|
||||
const site: { locales: Record<string, GeneratedLocale> } = JSON.parse(fs.readFileSync(siteFile, 'utf8'));
|
||||
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const englishSrcDir = path.join(rootDir, 'src');
|
||||
|
||||
const EN_PREFIX = '/en';
|
||||
const FORUM_URL = 'https://www.isharkfly.com/';
|
||||
const SOURCE_URL = 'https://src.sharkdat.com/iSharkFly-Docs/Composer-iSharkFly-Com';
|
||||
|
||||
// iSharkFly links shown as a dropdown at the end of the nav bar.
|
||||
function isharkflyNav(zh: boolean): DefaultTheme.NavItem {
|
||||
return {
|
||||
text: 'iSharkFly',
|
||||
items: [
|
||||
{ text: 'iSharkFly', link: FORUM_URL },
|
||||
{ text: zh ? '文档导航' : 'Docs Portal', link: 'https://docs.isharkfly.com/' },
|
||||
{ text: zh ? '本站源码' : 'Source Code', link: SOURCE_URL },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
// Sidebar text (groups and pages) shown on the Chinese site; English text comes from scripts/nav.json.
|
||||
const zhSidebarText: Record<string, string> = {
|
||||
'Book': '手册',
|
||||
'Introduction': '简介',
|
||||
'Basic usage': '基本用法',
|
||||
'Libraries': '库(资源包)',
|
||||
'Command-line interface / Commands': '命令行',
|
||||
'The composer.json schema': 'composer.json 架构',
|
||||
'Repositories': '资源库',
|
||||
'Config': '配置',
|
||||
'Runtime Composer utilities': '运行时工具',
|
||||
'Community': '社区',
|
||||
'Articles': '文章',
|
||||
'Aliases': '别名',
|
||||
'Authentication for privately hosted packages and repositories': '私有资源包和资源库的身份认证',
|
||||
'Autoloader optimization': '自动加载优化',
|
||||
'Caching Composer dependencies': '缓存 Composer 依赖',
|
||||
'Composer platform dependencies': 'Composer 平台依赖',
|
||||
'Setting up and using custom installers': '自定义安装程序',
|
||||
'Handling private packages': '处理私有资源包',
|
||||
'Setting up and using plugins': '插件',
|
||||
'Repository priorities': '资源库优先级',
|
||||
'Resolving merge conflicts': '解决合并冲突',
|
||||
'Scripts': '脚本',
|
||||
'Troubleshooting': '故障排除',
|
||||
'Vendor binaries and the vendor/bin directory': '二进制供应库与 vendor/bin 目录',
|
||||
'Versions and constraints': '版本与约束',
|
||||
'FAQs': '常见问题',
|
||||
'How do I install a package to a custom path for my framework?': '如何为我的框架自定义一个资源包安装目录?',
|
||||
'How do I install Composer programmatically?': '如何通过程序安装 Composer?',
|
||||
'How do I install untrusted packages safely? Is it safe to run Composer as superuser or root?': '如何安全地安装不受信任的资源包?以超级用户或 root 身份运行 Composer 安全吗?',
|
||||
'How to use Composer behind a proxy': '如何在代理后使用 Composer',
|
||||
'Should I commit the dependencies in my vendor directory?': '我应该提交 vendor 目录中的依赖包吗?',
|
||||
'Which version numbering system does Composer itself use?': 'Composer 自身使用哪种版本编号方式?',
|
||||
'Why are unbound version constraints a bad idea?': '为什么说无上限的版本约束是坏主意?',
|
||||
'Why are version constraints combining comparisons and wildcards a bad idea?': '为什么说“比较符”和“通配符”相结合的版本约束是坏主意?',
|
||||
'Why can\'t Composer load repositories recursively?': '为什么 Composer 不递归加载资源库?',
|
||||
'Internals': '内部机制',
|
||||
'Default Solver Policy': '默认依赖求解策略',
|
||||
};
|
||||
|
||||
function enLink(link: string) {
|
||||
return link.startsWith('/') ? EN_PREFIX + link : link;
|
||||
}
|
||||
|
||||
function mapSidebar(
|
||||
sidebar: DefaultTheme.SidebarMulti,
|
||||
mapLink: (link: string) => string,
|
||||
mapText: (text: string) => string,
|
||||
): DefaultTheme.SidebarMulti {
|
||||
const mapItems = (items: DefaultTheme.SidebarItem[]): DefaultTheme.SidebarItem[] => items.map(item => ({
|
||||
...item,
|
||||
text: mapText(item.text ?? ''),
|
||||
...(item.items ? { items: mapItems(item.items) } : {}),
|
||||
...(item.link ? { link: mapLink(item.link) } : {}),
|
||||
}));
|
||||
return Object.fromEntries(Object.entries(sidebar).map(([key, value]) => [
|
||||
mapLink(key),
|
||||
Array.isArray(value) ? mapItems(value) : { ...value, base: mapLink(value.base), items: mapItems(value.items) },
|
||||
]));
|
||||
}
|
||||
|
||||
const zhThemeText: DefaultTheme.Config = {
|
||||
outline: { level: [2, 3], label: '本页目录' },
|
||||
docFooter: { prev: '上一页', next: '下一页' },
|
||||
darkModeSwitchLabel: '外观',
|
||||
lightModeSwitchTitle: '切换到浅色模式',
|
||||
darkModeSwitchTitle: '切换到深色模式',
|
||||
sidebarMenuLabel: '菜单',
|
||||
returnToTopLabel: '回到顶部',
|
||||
langMenuLabel: '切换语言',
|
||||
skipToContentLabel: '跳到正文',
|
||||
notFound: {
|
||||
title: '页面未找到',
|
||||
quote: '你要找的页面不存在,或者已经被移动。',
|
||||
linkLabel: '返回首页',
|
||||
linkText: '返回首页',
|
||||
},
|
||||
footer: {
|
||||
message: '基于 MIT 许可证发布。',
|
||||
copyright: 'Copyright © Nils Adermann, Jordi Boggiano',
|
||||
},
|
||||
};
|
||||
|
||||
const zhSearchText = {
|
||||
button: { buttonText: '搜索', buttonAriaLabel: '搜索' },
|
||||
modal: {
|
||||
displayDetails: '显示详细列表',
|
||||
resetButtonTitle: '清除查询',
|
||||
backButtonTitle: '关闭搜索',
|
||||
noResultsText: '没有找到结果',
|
||||
footer: {
|
||||
selectText: '选择',
|
||||
selectKeyAriaLabel: '回车',
|
||||
navigateText: '切换',
|
||||
navigateUpKeyAriaLabel: '向上',
|
||||
navigateDownKeyAriaLabel: '向下',
|
||||
closeText: '关闭',
|
||||
closeKeyAriaLabel: 'Esc',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const zhLocales: LocaleConfig<DefaultTheme.Config> = {};
|
||||
const enLocales: LocaleConfig<DefaultTheme.Config> = {};
|
||||
|
||||
for (const [key, locale] of Object.entries(site.locales)) {
|
||||
zhLocales[key] = {
|
||||
label: `简体中文`,
|
||||
lang: 'zh-CN',
|
||||
link: locale.base,
|
||||
title: 'Composer',
|
||||
description: `Composer 中文文档`,
|
||||
themeConfig: {
|
||||
...zhThemeText,
|
||||
nav: [
|
||||
{ text: '手册', link: `${locale.base}00-intro`, activeMatch: `^${locale.base}\\d\\d-` },
|
||||
{ text: '文章', link: `${locale.base}articles/aliases`, activeMatch: `^${locale.base}articles/` },
|
||||
{ text: '常见问题', link: `${locale.base}faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework`, activeMatch: `^${locale.base}faqs/` },
|
||||
isharkflyNav(true),
|
||||
],
|
||||
sidebar: mapSidebar(locale.sidebar, link => link, text => zhSidebarText[text] ?? text),
|
||||
},
|
||||
};
|
||||
|
||||
const enBase = enLink(locale.base);
|
||||
enLocales[key === 'root' ? 'en' : `en/${key}`] = {
|
||||
label: `English`,
|
||||
lang: 'en-US',
|
||||
link: enBase,
|
||||
title: 'Composer',
|
||||
description: `Composer documentation`,
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Book', link: `${enBase}00-intro`, activeMatch: `^${enBase}\\d\\d-` },
|
||||
{ text: 'Articles', link: `${enBase}articles/aliases`, activeMatch: `^${enBase}articles/` },
|
||||
{ text: 'FAQs', link: `${enBase}faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework`, activeMatch: `^${enBase}faqs/` },
|
||||
isharkflyNav(false),
|
||||
],
|
||||
sidebar: mapSidebar(locale.sidebar, enLink, text => text),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const locales: LocaleConfig<DefaultTheme.Config> = { ...zhLocales };
|
||||
for (const key of Object.keys(enLocales).sort((a, b) => b.length - a.length))
|
||||
locales[key] = enLocales[key];
|
||||
|
||||
function listPages(dir: string, rel = ''): string[] {
|
||||
if (!fs.existsSync(dir))
|
||||
return [];
|
||||
return fs.readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
|
||||
const entryRel = rel + entry.name;
|
||||
if (entry.isDirectory()) {
|
||||
if (!rel && (['zh', 'en', 'public'].includes(entry.name) || site.locales[entry.name]))
|
||||
return [];
|
||||
return listPages(path.join(dir, entry.name), `${entryRel}/`);
|
||||
}
|
||||
return entry.name.endsWith('.md') ? [entryRel] : [];
|
||||
});
|
||||
}
|
||||
|
||||
const pagesByLanguage = Object.fromEntries(Object.keys(site.locales).map(key => [
|
||||
key,
|
||||
listPages(key === 'root' ? englishSrcDir : path.join(englishSrcDir, key)),
|
||||
]));
|
||||
|
||||
export default defineConfig({
|
||||
srcDir: 'site',
|
||||
lang: 'zh-CN',
|
||||
title: 'Composer',
|
||||
description: 'Composer 中文文档',
|
||||
cleanUrls: true,
|
||||
lastUpdated: false,
|
||||
ignoreDeadLinks: true,
|
||||
locales,
|
||||
head: [
|
||||
['link', { rel: 'icon', href: 'https://getcomposer.org/favicon.ico' }],
|
||||
// Google Tag Manager
|
||||
['script', {}, `(function (w, d, s, l, i) {
|
||||
w[l] = w[l] || [];
|
||||
w[l].push({
|
||||
'gtm.start':
|
||||
new Date().getTime(), event: 'gtm.js'
|
||||
});
|
||||
var f = d.getElementsByTagName(s)[0],
|
||||
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
|
||||
j.async = true;
|
||||
j.src =
|
||||
'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
|
||||
f.parentNode.insertBefore(j, f);
|
||||
})(window, document, 'script', 'dataLayer', 'GTM-W3NL9V');`],
|
||||
// End Google Tag Manager
|
||||
],
|
||||
markdown: {
|
||||
theme: { light: 'github-light', dark: 'github-dark' },
|
||||
config: md => {
|
||||
const defaultCodeInline = md.renderer.rules.code_inline!;
|
||||
md.renderer.rules.code_inline = (tokens, idx, options, env, self) =>
|
||||
defaultCodeInline(tokens, idx, options, env, self).replace(/^<code/, '<code v-pre');
|
||||
const defaultText = md.renderer.rules.text!;
|
||||
md.renderer.rules.text = (tokens, idx, options, env, self) =>
|
||||
defaultText(tokens, idx, options, env, self).replace(/\{\{/g, '{{').replace(/\}\}/g, '}}');
|
||||
},
|
||||
},
|
||||
themeConfig: {
|
||||
logo: 'https://getcomposer.org/img/logo-composer-transparent5.png',
|
||||
search: {
|
||||
provider: 'local',
|
||||
options: {
|
||||
locales: Object.fromEntries(Object.keys(zhLocales).map(key => [key, { translations: zhSearchText }])),
|
||||
},
|
||||
},
|
||||
outline: { level: [2, 3] },
|
||||
socialLinks: [
|
||||
{ icon: 'github', link: 'https://github.com/composer/composer' },
|
||||
],
|
||||
editLink: undefined,
|
||||
footer: {
|
||||
message: 'Released under the MIT License.',
|
||||
copyright: 'Copyright © Nils Adermann, Jordi Boggiano',
|
||||
},
|
||||
languageSwitcher: {
|
||||
enPrefix: EN_PREFIX,
|
||||
pages: pagesByLanguage,
|
||||
},
|
||||
} as DefaultTheme.Config,
|
||||
vite: {
|
||||
build: { chunkSizeWarningLimit: 4096 },
|
||||
plugins: [
|
||||
{
|
||||
// 文档工具链只安装在 .vitepress/node_modules,项目根目录没有 node_modules。
|
||||
// SSR 构建时 site/*.md 会 import "vue" 和 "vue/server-renderer",Vite 从 site/ 向上查找
|
||||
// 解析不到(Jenkins 上报 "Rollup failed to resolve import")。SSR 产物在 .vitepress/.temp/
|
||||
// 中由 Node 运行,能从 .vitepress/node_modules 加载这些包,所以 SSR 时直接标为 external。
|
||||
// 浏览器端构建不受影响:VitePress 已为 "vue" 配置了指向自身依赖的别名。
|
||||
name: 'docs-tools-ssr-externals',
|
||||
enforce: 'pre',
|
||||
resolveId(id, _importer, options) {
|
||||
if (options?.ssr && /^(vue|@vue\/[^/]+)(\/.*)?$/.test(id))
|
||||
return { id, external: true };
|
||||
},
|
||||
},
|
||||
],
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: /^.*\/VPNavBarTranslations\.vue$/,
|
||||
replacement: fileURLToPath(new URL('./theme/components/NavBarLanguageSwitcher.vue', import.meta.url)),
|
||||
},
|
||||
{
|
||||
find: /^.*\/VPNavScreenTranslations\.vue$/,
|
||||
replacement: fileURLToPath(new URL('./theme/components/NavScreenLanguageSwitcher.vue', import.meta.url)),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
<script setup lang="ts">
|
||||
import VPFlyout from 'vitepress/dist/client/theme-default/components/VPFlyout.vue';
|
||||
import { VPLink } from 'vitepress/theme';
|
||||
import { useLanguageSwitcher } from '../languageSwitcher';
|
||||
|
||||
const { readingLanguages, labels } = useLanguageSwitcher();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VPFlyout class="NavBarLanguageSwitcher" icon="vpi-languages" :label="labels.menu">
|
||||
<div class="items">
|
||||
<p class="title">{{ labels.reading }}</p>
|
||||
<VPLink
|
||||
v-for="item in readingLanguages"
|
||||
:key="item.text"
|
||||
class="link"
|
||||
:class="{ active: item.active }"
|
||||
:href="item.link"
|
||||
:lang="item.lang"
|
||||
:hreflang="item.lang"
|
||||
rel="alternate"
|
||||
>{{ item.text }}</VPLink>
|
||||
</div>
|
||||
</VPFlyout>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.NavBarLanguageSwitcher {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
.NavBarLanguageSwitcher {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.items {
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.title {
|
||||
padding: 0 12px;
|
||||
line-height: 32px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.link {
|
||||
display: block;
|
||||
border-radius: 6px;
|
||||
padding: 0 12px;
|
||||
line-height: 32px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--vp-c-text-1);
|
||||
white-space: nowrap;
|
||||
transition: background-color 0.25s, color 0.25s;
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
color: var(--vp-c-brand-1);
|
||||
background-color: var(--vp-c-default-soft);
|
||||
}
|
||||
|
||||
.link.active {
|
||||
color: var(--vp-c-brand-1);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { VPLink } from 'vitepress/theme';
|
||||
import { useLanguageSwitcher } from '../languageSwitcher';
|
||||
|
||||
const { readingLanguages, labels, currentLabel } = useLanguageSwitcher();
|
||||
const isOpen = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="NavScreenLanguageSwitcher" :class="{ open: isOpen }">
|
||||
<button class="toggle" :aria-expanded="isOpen" @click="isOpen = !isOpen">
|
||||
<span class="vpi-languages icon lang" />
|
||||
{{ currentLabel }}
|
||||
<span class="vpi-chevron-down icon chevron" />
|
||||
</button>
|
||||
|
||||
<div class="groups">
|
||||
<p class="title">{{ labels.reading }}</p>
|
||||
<ul class="list">
|
||||
<li v-for="item in readingLanguages" :key="item.text">
|
||||
<VPLink class="link" :class="{ active: item.active }" :href="item.link" :lang="item.lang">
|
||||
{{ item.text }}
|
||||
</VPLink>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.NavScreenLanguageSwitcher {
|
||||
height: 24px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.NavScreenLanguageSwitcher.open {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--vp-c-text-1);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.icon.lang {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.icon.chevron {
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.groups {
|
||||
padding: 4px 0 0 24px;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.list {
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
.link {
|
||||
line-height: 32px;
|
||||
font-size: 13px;
|
||||
color: var(--vp-c-text-1);
|
||||
}
|
||||
|
||||
.link.active {
|
||||
color: var(--vp-c-brand-1);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useData } from 'vitepress';
|
||||
|
||||
const { frontmatter, page } = useData();
|
||||
const englishLink = computed(() =>
|
||||
'/en/' + page.value.relativePath.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, ''));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="frontmatter.untranslated" class="untranslated-notice" lang="zh-CN">
|
||||
本页尚未翻译成中文,以下为英文原文。
|
||||
<a :href="englishLink">查看英文版</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.untranslated-notice {
|
||||
margin: 0 0 24px;
|
||||
border: 1px solid var(--vp-custom-block-info-border);
|
||||
border-radius: 8px;
|
||||
padding: 12px 16px;
|
||||
font-size: 14px;
|
||||
line-height: 24px;
|
||||
color: var(--vp-custom-block-info-text);
|
||||
background-color: var(--vp-custom-block-info-bg);
|
||||
}
|
||||
|
||||
.untranslated-notice a {
|
||||
font-weight: 500;
|
||||
color: var(--vp-c-brand-1);
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,17 @@
|
||||
:root {
|
||||
--vp-c-brand-1: #8c5a2b;
|
||||
--vp-c-brand-2: #a06a37;
|
||||
--vp-c-brand-3: #6f4621;
|
||||
--vp-c-brand-soft: rgba(140, 90, 43, 0.14);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-brand-1: #e0a66b;
|
||||
--vp-c-brand-2: #cf9050;
|
||||
--vp-c-brand-3: #b9793b;
|
||||
--vp-c-brand-soft: rgba(224, 166, 107, 0.16);
|
||||
}
|
||||
|
||||
.vp-doc img {
|
||||
display: inline-block;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { h } from 'vue';
|
||||
import DefaultTheme from 'vitepress/theme';
|
||||
import type { Theme } from 'vitepress';
|
||||
import UntranslatedNotice from './components/UntranslatedNotice.vue';
|
||||
import './custom.css';
|
||||
|
||||
export default {
|
||||
extends: DefaultTheme,
|
||||
Layout: () => h(DefaultTheme.Layout, null, {
|
||||
'doc-before': () => h(UntranslatedNotice),
|
||||
}),
|
||||
} satisfies Theme;
|
||||
@@ -0,0 +1,58 @@
|
||||
import { computed } from 'vue';
|
||||
import { useData } from 'vitepress';
|
||||
|
||||
type SwitcherConfig = {
|
||||
enPrefix: string;
|
||||
pages: Record<string, string[]>;
|
||||
};
|
||||
|
||||
export type SwitcherLink = { text: string; link: string; lang?: string; active: boolean };
|
||||
|
||||
const READING_LANGUAGES = [
|
||||
{ key: 'zh', text: '简体中文', lang: 'zh-CN' },
|
||||
{ key: 'en', text: 'English', lang: 'en-US' },
|
||||
] as const;
|
||||
|
||||
function pageUrl(base: string, page: string) {
|
||||
return base + page.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, '');
|
||||
}
|
||||
|
||||
export function useLanguageSwitcher() {
|
||||
const { page, theme, hash } = useData();
|
||||
const config = computed(() => theme.value.languageSwitcher as SwitcherConfig);
|
||||
|
||||
const current = computed(() => {
|
||||
let rest = page.value.relativePath;
|
||||
const enDir = config.value.enPrefix.replace(/^\//, '') + '/';
|
||||
const reading = rest.startsWith(enDir) ? 'en' : 'zh';
|
||||
if (reading === 'en')
|
||||
rest = rest.slice(enDir.length);
|
||||
return { reading, page: rest };
|
||||
});
|
||||
|
||||
function linkFor(reading: string, keepHash: boolean) {
|
||||
const base = reading === 'en' ? config.value.enPrefix + '/' : '/';
|
||||
const pages = config.value.pages['root'] ?? [];
|
||||
if (!pages.includes(current.value.page))
|
||||
return base;
|
||||
return pageUrl(base, current.value.page) + (keepHash ? hash.value : '');
|
||||
}
|
||||
|
||||
const isZh = computed(() => current.value.reading === 'zh');
|
||||
|
||||
const readingLanguages = computed<SwitcherLink[]>(() => READING_LANGUAGES.map(reading => ({
|
||||
text: reading.text,
|
||||
lang: reading.lang,
|
||||
link: linkFor(reading.key, true),
|
||||
active: reading.key === current.value.reading,
|
||||
})));
|
||||
|
||||
const labels = computed(() => isZh.value
|
||||
? { menu: '切换语言', reading: '阅读语言' }
|
||||
: { menu: 'Change language', reading: 'Language' });
|
||||
|
||||
const currentLabel = computed(() =>
|
||||
READING_LANGUAGES.find(reading => reading.key === current.value.reading)!.text);
|
||||
|
||||
return { readingLanguages, labels, currentLabel, isZh };
|
||||
}
|
||||
+9
-26
@@ -2,38 +2,21 @@
|
||||
|
||||
请使用下面的联系方式和我们联系:
|
||||
|
||||
| 联系方式名称 | 联系方式 |
|
||||
|--------|-----------------------------------------------|
|
||||
| 电子邮件 | [service@ossez.com](mailto:service@ossez.com) |
|
||||
| QQ 或微信 | 103899765 |
|
||||
| 社区论坛 | https://www.isharkfly.com/ |
|
||||
|
||||
# 公众平台
|
||||
|
||||
我们建议您通过社区论坛来和我们进行沟通,请关注我们公众平台上的账号。
|
||||
| 联系方式名称 | 联系方式 |
|
||||
|--------|---------------------------------------|
|
||||
| 电子邮件 | [yhu@ossez.com](mailto:yhu@ossez.com) |
|
||||
| QQ 或微信 | 103899765 |
|
||||
| 社区论坛 | https://www.isharkfly.com/ |
|
||||
|
||||
## 微信公众号
|
||||
|
||||

|
||||

|
||||
|
||||
## 头条号
|
||||
|
||||

|
||||

|
||||
|
||||
## 百家号
|
||||
|
||||

|
||||

|
||||
|
||||
## 知乎
|
||||
https://www.isharkfly.com/people/huyuchengus
|
||||
|
||||
https://www.zhihu.com/people/huyuchengus
|
||||
|
||||
## 快速导航
|
||||
|
||||
在下面的表格中,我们列出了有用的 iSharkFly 相关软件开发使用教程的导航,欢迎访问下面的链接获得更多的内容和参与讨论:
|
||||
|
||||
| 网站名称 | URL | NOTE |
|
||||
|--------------------|----------------------------------------------------------------|---------------------------|
|
||||
| WIKI 维基 | [track.ossez.com](https://track.ossez.com/articles) | YouTrack 部署的 WIKI 知识库 |
|
||||
| DOCS.ISHARKFLY.COM | [https://docs.isharkfly.com/#/](https://docs.isharkfly.com/#/) | 本手册的编译版本将会部署在这个链接上 |
|
||||
| CN 博客 | [http://www.cwikius.cn/](http://www.cwikius.cn/) | CWIKIUS.CN 一个有独立思考和温度的清新站 |
|
||||
|
||||
Vendored
+157
@@ -0,0 +1,157 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
options {
|
||||
ansiColor('xterm')
|
||||
disableConcurrentBuilds()
|
||||
// 文档约 70 页(中英文各 34 页),构建约 1 分钟
|
||||
timeout(time: 30, unit: 'MINUTES')
|
||||
}
|
||||
|
||||
tools {
|
||||
nodejs 'NodeJS 22.14.0'
|
||||
}
|
||||
|
||||
environment {
|
||||
PRJ_NAME = 'composer-isharkfly-com'
|
||||
// 显式指定 wrangler 配置文件
|
||||
WRANGLER_CONFIG = 'wrangler.jsonc'
|
||||
// 与 Angular-iSharkFly-Com 一致,文档工具链单独安装在 .vitepress/node_modules
|
||||
DOCS_TOOLS = '.vitepress/node_modules'
|
||||
WRANGLER = '.vitepress/node_modules/.bin/wrangler'
|
||||
// 发布到线上的分支
|
||||
RELEASE_BRANCH = 'main'
|
||||
// Cloudflare API Token(Jenkins Secret text 凭据,需要 Workers Scripts:Edit 权限)
|
||||
CLOUDFLARE_API_TOKEN = credentials('sharkdat-cloudflare-api-token')
|
||||
// Cloudflare Account ID(Secret text 凭据)。设置后 wrangler 不再调用 /memberships 查询账号,
|
||||
// 避免 token 缺少 Account 读取权限时报 "You may have incorrect permissions on your API token"
|
||||
CLOUDFLARE_ACCOUNT_ID = credentials('sharkdat-cloudflare-account-id')
|
||||
// 不让 wrangler 发送使用统计、不弹交互提示
|
||||
WRANGLER_SEND_METRICS = 'false'
|
||||
CI = 'true'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Configure') {
|
||||
steps {
|
||||
sh 'git config --global url."https://github.com/".insteadOf git://github.com/'
|
||||
sh '''
|
||||
set -eu
|
||||
node --version
|
||||
npm --version
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install') {
|
||||
steps {
|
||||
// 只安装文档工具链(VitePress、Vue、Wrangler)
|
||||
sh '''
|
||||
set -eu
|
||||
npm install --prefix .vitepress --no-save --no-package-lock --no-audit --no-fund \
|
||||
[email protected] [email protected] [email protected]
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo 'Build VitePress docs ...'
|
||||
sh '''
|
||||
set -eu
|
||||
node scripts/generate.mjs
|
||||
node scripts/sync-zh.mjs
|
||||
node ${DOCS_TOOLS}/vitepress/bin/vitepress.js build .
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy - CF') {
|
||||
steps {
|
||||
script {
|
||||
withEnv([
|
||||
'LANG=C.UTF-8',
|
||||
'LC_ALL=C.UTF-8',
|
||||
'NO_COLOR=1',
|
||||
'TERM=dumb'
|
||||
]) {
|
||||
// 部署消息:显示在 Cloudflare 控制台 → Worker → Deployments
|
||||
def shortSha = env.GIT_COMMIT ? env.GIT_COMMIT.take(7) : 'unknown'
|
||||
def deployMsg = "Jenkins ${env.JOB_NAME} #${env.BUILD_NUMBER} (${shortSha})"
|
||||
|
||||
// Tag 构建:部署到 production 环境(wrangler.jsonc 中的 env.production)
|
||||
if (env.TAG_NAME?.trim()) {
|
||||
sh """
|
||||
${env.WRANGLER} deploy --config ${env.WRANGLER_CONFIG} --env production \
|
||||
--message '${deployMsg}' \
|
||||
--tag '${env.TAG_NAME}'
|
||||
"""
|
||||
return
|
||||
}
|
||||
|
||||
// main 分支:部署默认 Worker
|
||||
if (env.BRANCH_NAME == env.RELEASE_BRANCH) {
|
||||
sh """
|
||||
${env.WRANGLER} deploy --config ${env.WRANGLER_CONFIG} --env="" \
|
||||
--message '${deployMsg}' \
|
||||
--tag '${shortSha}'
|
||||
"""
|
||||
return
|
||||
}
|
||||
|
||||
// PR 或其他分支:上传 Preview Version,不影响线上流量
|
||||
def branchArg = env.CHANGE_ID
|
||||
? "pr-${env.CHANGE_ID}"
|
||||
: env.BRANCH_NAME
|
||||
|
||||
def previewAlias = branchArg
|
||||
.toLowerCase()
|
||||
.replaceAll(/[^a-z0-9-]+/, '-')
|
||||
.replaceAll(/^-+|-+$/, '')
|
||||
|
||||
// 打印当前 token 所属账号,便于排查 "Worker does not yet exist"(通常是账号不对)
|
||||
sh "${env.WRANGLER} whoami"
|
||||
|
||||
// versions upload 要求 Worker 已存在;首次构建时先 deploy 一次创建 Worker
|
||||
def workerExists = sh(
|
||||
script: "${env.WRANGLER} deployments list --config ${env.WRANGLER_CONFIG} --env=\"\" > /dev/null 2>&1",
|
||||
returnStatus: true
|
||||
) == 0
|
||||
if (!workerExists) {
|
||||
echo "Worker ${env.PRJ_NAME} 尚不存在,先执行首次 deploy 创建 Worker ..."
|
||||
sh """
|
||||
${env.WRANGLER} deploy --config ${env.WRANGLER_CONFIG} --env="" \
|
||||
--message 'Initial deploy: ${deployMsg}'
|
||||
"""
|
||||
}
|
||||
|
||||
sh """
|
||||
${env.WRANGLER} versions upload --config ${env.WRANGLER_CONFIG} --env="" \
|
||||
--preview-alias '${previewAlias}' \
|
||||
--message 'Jenkins ${env.JOB_NAME} #${env.BUILD_NUMBER}'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
env.BUILD_STARTED_AT = new Date(currentBuild.startTimeInMillis)
|
||||
.format('yyyy-MM-dd HH:mm:ss z', TimeZone.getTimeZone('America/New_York'))
|
||||
|
||||
env.BUILD_DURATION_TEXT = currentBuild.durationString
|
||||
|
||||
emailext (
|
||||
mimeType: 'text/html; charset=UTF-8',
|
||||
subject: "Build ${currentBuild.currentResult}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
|
||||
body: '${DEFAULT_CONTENT}',
|
||||
from: '[email protected]',
|
||||
to: '[email protected], [email protected]'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 iSharkFly-Docs
|
||||
Copyright (c) 2026 iSharkFly.Com
|
||||
|
||||
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:
|
||||
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 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.
|
||||
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.
|
||||
|
||||
@@ -1,20 +1,35 @@
|
||||
# Links
|
||||
# 快速导航
|
||||
|
||||
In this page, we provide the quick reference link can help you increase ability to learning and coding.
|
||||
在下面的表格中,我们列出了一些比较有用相关软件开发使用教程的导航,在我们文档的整理中,也参考了一些这些文档。
|
||||
|
||||
## JDK
|
||||
在这里对原作者表示感谢。
|
||||
|
||||
| Webiste | Links |
|
||||
|---------|-----------------------------------------------------|
|
||||
| Oracle | https://www.oracle.com/java/technologies/downloads/ |
|
||||
| OpenJDK | https://adoptium.net/temurin/releases/ |
|
||||
| 网站名称 | URL | NOTE | GitHub |
|
||||
|--------------------|----------------------------------------------------------------|---------------------------|--------------------------------------------------------------------------------------------------------------------------|
|
||||
| DOCS.ISHARKFLY.COM | [https://docs.isharkfly.com/#/](https://docs.isharkfly.com/#/) | 本手册的编译版本将会部署在这个链接上 | [https://src.sharkdat.com/iSharkFly-Docs/docs-isharkfly-com](https://src.sharkdat.com/iSharkFly-Docs/docs-isharkfly-com) |
|
||||
| WWW.CWIKIUS.CN | [http://www.cwikius.cn/](http://www.cwikius.cn/) | CWIKIUS.CN 一个有独立思考和温度的清新站 | N/A |
|
||||
|
||||
### 语言和框架
|
||||
|
||||
## Useful Links
|
||||
| 网站名称 | URL | NOTE |
|
||||
|-----------------|----------------------------------------------------|-----------------------------|
|
||||
| iSharkFly - 飞鲨 | https://www.isharkfly.com/c/software-development/5 | 计算机相关的前端框架和讨论 |
|
||||
| TypeScript | https://typescript.ossez.com/ | TypeScript 相关技术文档和手册 |
|
||||
| Mumps | https://mumps.sharkfly.com/ | Mumps 相关技术文档和手册 |
|
||||
| Angular | https://angular.isharkfly.com/ | Angular 手册的在线翻译版本,从源代码中进行编译 |
|
||||
| Docsify | https://docsify.isharkfly.com/ | Docsify 可以快速帮你生成文档网站 |
|
||||
|
||||
| Webiste | Links |
|
||||
|----------------|-------------------------------------------------|
|
||||
| Eclipse | https://www.eclipse.org/ |
|
||||
| GitHub | https://github.com/ |
|
||||
| stackoverflow | https://stackoverflow.com/questions/tagged/java |
|
||||
| Apache Commons | https://commons.apache.org/ |
|
||||
### 后端和数据
|
||||
|
||||
| 网站名称 | URL | NOTE |
|
||||
|------------------------|-----------------------------------|----------------------|
|
||||
| Apache Druid | https://druid.isharkfly.com/ | Druid 手册的在线翻译版本 |
|
||||
| OpenSearch | https://opensearch.isharkfly.com/ | OpenSearch 手册的在线翻译版本 |
|
||||
| HAPI FHIR | https://fhir.isharkfly.com/#/ | FHIR 相关技术文档的收集和讨论 |
|
||||
|
||||
### docker
|
||||
|
||||
| 网站名称 | URL | NOTE |
|
||||
|--------------------|--------------------------------|-------------------------------------------------------------|
|
||||
| Docker 手册中译在线版 | https://docker.ossez.com/ | 基于 Docker 容器英文手册的翻译版本 |
|
||||
| Docker 手册中译 MD 在线版 | https://docker-docs.ossez.com/ | 因为 Docker 的官方手册进行了渲染,我们推荐你使用上面的链接,这个版本为 docsify 渲染版本,可能会丢格式 |
|
||||
|
||||
@@ -1,49 +1,66 @@
|
||||
composer-doc-cn
|
||||
===============
|
||||
# Composer 中文文档
|
||||
|
||||
Composer 中文文档
|
||||
composer.isharkfly.com 站点源码。站点使用 [VitePress](https://vitepress.dev/) 构建,部署到 Cloudflare Workers Static Assets,项目结构与 Angular-iSharkFly-Com 保持一致。
|
||||
|
||||
---
|
||||
- 中文(默认):`/<路径>`
|
||||
- 英文原文:`/en/<路径>`
|
||||
|
||||
- 希望更多的朋友能够参与此文档的翻译、勘误(您可以 Fork 本项目,并提交 Pull Request)。
|
||||
- 新版本文档翻译缓慢进行中,详见 [1.6分支](https://github.com/5-say/composer-doc-cn/blob/1.6/README.md)
|
||||
- 当前文档基本不影响新版 Composer 的使用,新文档在结构以及章节内容上做了比较大的调整,针对性的翻译会逐步完善。
|
||||
- [中文翻译贡献者名单](/contributors.md)
|
||||
## 目录结构
|
||||
|
||||
---
|
||||
```
|
||||
├── src/ 英文原文(来自 Composer 2.11.3 的 doc/,不要手动修改)
|
||||
├── i18n/
|
||||
│ ├── zh/ 中文译文,与 src/ 路径一一对应
|
||||
│ └── TRANSLATION-GUIDE.md 翻译规范和术语表
|
||||
├── scripts/
|
||||
│ ├── import-composer.mjs 从 Composer 仓库导入英文原文、首页和侧边栏(nav.json)
|
||||
│ ├── nav.json 侧边栏(英文),由 import-composer.mjs 生成
|
||||
│ ├── generate.mjs 生成 .vitepress/generated/site.json
|
||||
│ └── sync-zh.mjs 组装 site/:中文放在根路径,英文放在 site/en/
|
||||
├── site/ 构建时生成(git 忽略)
|
||||
├── .vitepress/
|
||||
│ ├── config.mts VitePress 配置
|
||||
│ └── theme/ 主题:语言切换、未翻译提示
|
||||
├── wrangler.jsonc Cloudflare 部署配置
|
||||
└── Jenkinsfile CI:构建并部署到 Cloudflare
|
||||
```
|
||||
|
||||
## Book
|
||||
- [简介](/cn-introduction/00-intro.md)
|
||||
- [基本用法](/cn-introduction/01-basic-usage.md)
|
||||
- [库(资源包)](/cn-introduction/02-libraries.md)
|
||||
- [命令行](/cn-introduction/03-cli.md)
|
||||
- [架构](/cn-introduction/04-schema.md)
|
||||
- [资源库](/cn-introduction/05-repositories.md)
|
||||
- [社区](/cn-introduction/06-community.md)
|
||||
## 本地开发
|
||||
|
||||
## Articles
|
||||
- [别名](/cn-introduction/articles/aliases.md)
|
||||
版本分支名称的别名。
|
||||
- [自定义安装程序](/cn-introduction/articles/custom-installers.md)
|
||||
修改某些特殊类型包的安装方式。
|
||||
- [Handling Private Packages With Satis](/cn-introduction/articles/handling-private-packages-with-satis.md)
|
||||
Host your own composer repository
|
||||
- [插件](/cn-introduction/articles/plugins.md)
|
||||
修改和扩展 Composer 的功能。
|
||||
- [脚本](/cn-introduction/articles/scripts.md)
|
||||
脚本是指一些 Composer 事件的回调,它们在安装资源包的过程中被触发执行。
|
||||
- [Troubleshooting](/cn-introduction/articles/troubleshooting.md)
|
||||
Solving problems
|
||||
- [二进制供应库](/cn-introduction/articles/vendor-binaries.md)
|
||||
从资源包中暴露命令行脚本。
|
||||
文档工具链安装在 `.vitepress/node_modules`(与 Jenkins 一致):
|
||||
|
||||
## FAQs
|
||||
```bash
|
||||
npm install --prefix .vitepress --no-save --no-package-lock [email protected] [email protected] [email protected]
|
||||
|
||||
- [如何为我的框架自定义一个资源包安装目录?](/cn-introduction/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md)
|
||||
- [我应该提交 vendor 目录中的依赖包吗?](/cn-introduction/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md)
|
||||
- [为什么说“比较符”和“通配符”相结合的版本约束是坏主意?](/cn-introduction/faqs/why-are-version-constraints-combining-comparisons-and-wildcards-a-bad-idea.md)
|
||||
- [为什么 Composer 不递归加载储存库?](/cn-introduction/faqs/why-can%27t-composer-load-repositories-recursively.md)
|
||||
node scripts/generate.mjs
|
||||
node scripts/sync-zh.mjs
|
||||
node .vitepress/node_modules/vitepress/bin/vitepress.js dev . # 本地预览
|
||||
node .vitepress/node_modules/vitepress/bin/vitepress.js build . # 构建到 .vitepress/dist
|
||||
```
|
||||
|
||||
## 相关文章推荐
|
||||
修改 `src/` 或 `i18n/zh/` 后需要重新运行 `sync-zh.mjs`。
|
||||
|
||||
- [PHP 开发者该知道的5个 Composer 小技巧](http://segmentfault.com/a/1190000000355928)
|
||||
> Windows 下请在盘符为大写的路径中运行(例如 `D:\WorkDir\...`),否则 VitePress 构建会报 `Cannot read properties of undefined (reading 'imports')`。
|
||||
|
||||
## 更新英文原文
|
||||
|
||||
```bash
|
||||
git clone --depth 1 --branch 2.11.3 https://github.com/composer/composer.git /tmp/composer
|
||||
node scripts/import-composer.mjs /tmp/composer
|
||||
```
|
||||
|
||||
导入时会给每个标题加上与 getcomposer.org 一致的锚点 `{#id}`(例如 `03-cli.md#update--u--upgrade`、`#composer_no_dev`),并把文章开头的 `tagline` 注释转为 frontmatter 的 `description`。升级版本后,需要同步更新 `.vitepress/config.mts` 中的侧边栏中文标题(`zhSidebarText`)和 `i18n/zh/index.md`。
|
||||
|
||||
## 翻译
|
||||
|
||||
见 [i18n/TRANSLATION-GUIDE.md](i18n/TRANSLATION-GUIDE.md)。部分中文译文来自早期版本的 Composer 文档,需要按新版原文重新翻译。
|
||||
|
||||
早期译文的贡献者见 [contributors.md](contributors.md)。
|
||||
|
||||
## 部署
|
||||
|
||||
Jenkins 多分支流水线(见 `Jenkinsfile`):
|
||||
|
||||
- `main` 分支:部署到 Worker `composer-isharkfly-com`
|
||||
- Tag:部署到 `production` 环境
|
||||
- 其他分支 / PR:上传 Preview 版本
|
||||
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
- HIS 医疗数据信息化
|
||||
- [Readme](README.md)
|
||||
- [Contact](CONTACT.md)
|
||||
- [FHIR In Action](fhir-in-action/index.md)
|
||||
- [Week 2](week-2/index.md)
|
||||
- [Week 3](week-3/index.md)
|
||||
- [Week 4](week-4/_index.md)
|
||||
- Week 5
|
||||
- Week 6
|
||||
- Week 7
|
||||
- [Links](LINKS.md)
|
||||
@@ -1,202 +0,0 @@
|
||||
<!--
|
||||
tagline: Host your own composer repository
|
||||
-->
|
||||
|
||||
# 用 Satis 处理私有资源包
|
||||
|
||||
Satis is a static `composer` repository generator. It is a bit like an ultra-
|
||||
lightweight, static file-based version of packagist and can be used to host the
|
||||
metadata of your company's private packages, or your own. It basically acts as
|
||||
a micro-packagist. You can get it from
|
||||
[GitHub](http://github.com/composer/satis) or install via CLI:
|
||||
`composer.phar create-project composer/satis --stability=dev`.
|
||||
|
||||
Satis 是一个静态的 `composer` 代码库生成器。
|
||||
|
||||
## Setup
|
||||
|
||||
For example let's assume you have a few packages you want to reuse across your
|
||||
company but don't really want to open-source. You would first define a Satis
|
||||
configuration: a json file with an arbitrary name that lists your curated
|
||||
[repositories](../05-repositories.md).
|
||||
|
||||
Here is an example configuration, you see that it holds a few VCS repositories,
|
||||
but those could be any types of [repositories](../05-repositories.md). Then it
|
||||
uses `"require-all": true` which selects all versions of all packages in the
|
||||
repositories you defined.
|
||||
|
||||
The default file Satis looks for is `satis.json` in the root of the repository.
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "My Repository",
|
||||
"homepage": "http://packages.example.org",
|
||||
"repositories": [
|
||||
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo" },
|
||||
{ "type": "vcs", "url": "http://svn.example.org/private/repo" },
|
||||
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" }
|
||||
],
|
||||
"require-all": true
|
||||
}
|
||||
```
|
||||
|
||||
If you want to cherry pick which packages you want, you can list all the packages
|
||||
you want to have in your satis repository inside the classic composer `require` key,
|
||||
using a `"*"` constraint to make sure all versions are selected, or another
|
||||
constraint if you want really specific versions.
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo" },
|
||||
{ "type": "vcs", "url": "http://svn.example.org/private/repo" },
|
||||
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" }
|
||||
],
|
||||
"require": {
|
||||
"company/package": "*",
|
||||
"company/package2": "*",
|
||||
"company/package3": "2.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Once you did this, you just run `php bin/satis build <configuration file> <build dir>`.
|
||||
For example `php bin/satis build config.json web/` would read the `config.json`
|
||||
file and build a static repository inside the `web/` directory.
|
||||
|
||||
When you ironed out that process, what you would typically do is run this
|
||||
command as a cron job on a server. It would then update all your package info
|
||||
much like Packagist does.
|
||||
|
||||
Note that if your private packages are hosted on GitHub, your server should have
|
||||
an ssh key that gives it access to those packages, and then you should add
|
||||
the `--no-interaction` (or `-n`) flag to the command to make sure it falls back
|
||||
to ssh key authentication instead of prompting for a password. This is also a
|
||||
good trick for continuous integration servers.
|
||||
|
||||
Set up a virtual-host that points to that `web/` directory, let's say it is
|
||||
`packages.example.org`. Alternatively, with PHP >= 5.4.0, you can use the built-in
|
||||
CLI server `php -S localhost:port -t satis-output-dir/` for a temporary solution.
|
||||
|
||||
## Usage
|
||||
|
||||
In your projects all you need to add now is your own composer repository using
|
||||
the `packages.example.org` as URL, then you can require your private packages and
|
||||
everything should work smoothly. You don't need to copy all your repositories
|
||||
in every project anymore. Only that one unique repository that will update
|
||||
itself.
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [ { "type": "composer", "url": "http://packages.example.org/" } ],
|
||||
"require": {
|
||||
"company/package": "1.2.0",
|
||||
"company/package2": "1.5.2",
|
||||
"company/package3": "dev-master"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Security
|
||||
|
||||
To secure your private repository you can host it over SSH or SSL using a client
|
||||
certificate. In your project you can use the `options` parameter to specify the
|
||||
connection options for the server.
|
||||
|
||||
Example using a custom repository using SSH (requires the SSH2 PECL extension):
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "ssh2.sftp://example.org",
|
||||
"options": {
|
||||
"ssh2": {
|
||||
"username": "composer",
|
||||
"pubkey_file": "/home/composer/.ssh/id_rsa.pub",
|
||||
"privkey_file": "/home/composer/.ssh/id_rsa"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
> **Tip:** See [ssh2 context options](http://www.php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-options) for more information.
|
||||
|
||||
Example using HTTP over SSL using a client certificate:
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "https://example.org",
|
||||
"options": {
|
||||
"ssl": {
|
||||
"local_cert": "/home/composer/.ssl/composer.pem"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
> **Tip:** See [ssl context options](http://www.php.net/manual/en/context.ssl.php) for more information.
|
||||
|
||||
### Downloads
|
||||
|
||||
When GitHub or BitBucket repositories are mirrored on your local satis, the build process will include
|
||||
the location of the downloads these platforms make available. This means that the repository and your setup depend
|
||||
on the availability of these services.
|
||||
|
||||
At the same time, this implies that all code which is hosted somewhere else (on another service or for example in
|
||||
Subversion) will not have downloads available and thus installations usually take a lot longer.
|
||||
|
||||
To enable your satis installation to create downloads for all (Git, Mercurial and Subversion) your packages, add the
|
||||
following to your `satis.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"archive": {
|
||||
"directory": "dist",
|
||||
"format": "tar",
|
||||
"prefix-url": "https://amazing.cdn.example.org",
|
||||
"skip-dev": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Options explained
|
||||
|
||||
* `directory`: the location of the dist files (inside the `output-dir`)
|
||||
* `format`: optional, `zip` (default) or `tar`
|
||||
* `prefix-url`: optional, location of the downloads, homepage (from `satis.json`) followed by `directory` by default
|
||||
* `skip-dev`: optional, `false` by default, when enabled (`true`) satis will not create downloads for branches
|
||||
|
||||
Once enabled, all downloads (include those from GitHub and BitBucket) will be replaced with a _local_ version.
|
||||
|
||||
#### prefix-url
|
||||
|
||||
Prefixing the URL with another host is especially helpful if the downloads end up in a private Amazon S3
|
||||
bucket or on a CDN host. A CDN would drastically improve download times and therefore package installation.
|
||||
|
||||
Example: A `prefix-url` of `http://my-bucket.s3.amazonaws.com` (and `directory` set to `dist`) creates download URLs
|
||||
which look like the following: `http://my-bucket.s3.amazonaws.com/dist/vendor-package-version-ref.zip`.
|
||||
|
||||
|
||||
### Resolving dependencies
|
||||
|
||||
It is possible to make satis automatically resolve and add all dependencies for your projects. This can be used
|
||||
with the Downloads functionality to have a complete local mirror of packages. Just add the following
|
||||
to your `satis.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"require-dependencies": true
|
||||
}
|
||||
```
|
||||
|
||||
When searching for packages, satis will attempt to resolve all the required packages from the listed repositories.
|
||||
Therefore, if you are requiring a package from Packagist, you will need to define it in your `satis.json`.
|
||||
@@ -1,153 +0,0 @@
|
||||
<!--
|
||||
tagline: Solving problems
|
||||
-->
|
||||
# Troubleshooting
|
||||
|
||||
This is a list of common pitfalls on using Composer, and how to avoid them.
|
||||
|
||||
## General
|
||||
|
||||
1. Before asking anyone, run [`composer diagnose`](../03-cli.md#diagnose) to check
|
||||
for common problems. If it all checks out, proceed to the next steps.
|
||||
|
||||
2. When facing any kind of problems using Composer, be sure to **work with the
|
||||
latest version**. See [self-update](../03-cli.md#self-update) for details.
|
||||
|
||||
3. Make sure you have no problems with your setup by running the installer's
|
||||
checks via `curl -sS https://getcomposer.org/installer | php -- --check`.
|
||||
|
||||
4. Ensure you're **installing vendors straight from your `composer.json`** via
|
||||
`rm -rf vendor && composer update -v` when troubleshooting, excluding any
|
||||
possible interferences with existing vendor installations or `composer.lock`
|
||||
entries.
|
||||
|
||||
## Package not found
|
||||
|
||||
1. Double-check you **don't have typos** in your `composer.json` or repository
|
||||
branches and tag names.
|
||||
|
||||
2. Be sure to **set the right
|
||||
[minimum-stability](../04-schema.md#minimum-stability)**. To get started or be
|
||||
sure this is no issue, set `minimum-stability` to "dev".
|
||||
|
||||
3. Packages **not coming from [Packagist](https://packagist.org/)** should
|
||||
always be **defined in the root package** (the package depending on all
|
||||
vendors).
|
||||
|
||||
4. Use the **same vendor and package name** throughout all branches and tags of
|
||||
your repository, especially when maintaining a third party fork and using
|
||||
`replace`.
|
||||
|
||||
## Package not found on travis-ci.org
|
||||
|
||||
1. Check the ["Package not found"](#package-not-found) item above.
|
||||
|
||||
2. If the package tested is a dependency of one of its dependencies (cyclic
|
||||
dependency), the problem might be that composer is not able to detect the version
|
||||
of the package properly. If it is a git clone it is generally alright and Composer
|
||||
will detect the version of the current branch, but travis does shallow clones so
|
||||
that process can fail when testing pull requests and feature branches in general.
|
||||
The best solution is to define the version you are on via an environment variable
|
||||
called COMPOSER_ROOT_VERSION. You set it to `dev-master` for example to define
|
||||
the root package's version as `dev-master`.
|
||||
Use: `before_script: COMPOSER_ROOT_VERSION=dev-master composer install` to export
|
||||
the variable for the call to composer.
|
||||
|
||||
## Need to override a package version
|
||||
|
||||
Let say your project depends on package A which in turn depends on a specific
|
||||
version of package B (say 0.1) and you need a different version of that
|
||||
package - version 0.11.
|
||||
|
||||
You can fix this by aliasing version 0.11 to 0.1:
|
||||
|
||||
composer.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"A": "0.2",
|
||||
"B": "0.11 as 0.1"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
See [aliases](aliases.md) for more information.
|
||||
|
||||
## Memory limit errors
|
||||
|
||||
If composer shows memory errors on some commands:
|
||||
|
||||
`PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...>`
|
||||
|
||||
The PHP `memory_limit` should be increased.
|
||||
|
||||
> **Note:** Composer internally increases the `memory_limit` to `512M`.
|
||||
> If you have memory issues when using composer, please consider [creating
|
||||
> an issue ticket](https://github.com/composer/composer/issues) so we can look into it.
|
||||
|
||||
To get the current `memory_limit` value, run:
|
||||
|
||||
```sh
|
||||
php -r "echo ini_get('memory_limit').PHP_EOL;"
|
||||
```
|
||||
|
||||
Try increasing the limit in your `php.ini` file (ex. `/etc/php5/cli/php.ini` for
|
||||
Debian-like systems):
|
||||
|
||||
```ini
|
||||
; Use -1 for unlimited or define an explicit value like 512M
|
||||
memory_limit = -1
|
||||
```
|
||||
|
||||
Or, you can increase the limit with a command-line argument:
|
||||
|
||||
```sh
|
||||
php -d memory_limit=-1 composer.phar <...>
|
||||
```
|
||||
|
||||
## "The system cannot find the path specified" (Windows)
|
||||
|
||||
1. Open regedit.
|
||||
2. Search for an ```AutoRun``` key inside ```HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor```
|
||||
or ```HKEY_CURRENT_USER\Software\Microsoft\Command Processor```.
|
||||
3. Check if it contains any path to non-existent file, if it's the case, just remove them.
|
||||
|
||||
## API rate limit and OAuth tokens
|
||||
|
||||
Because of GitHub's rate limits on their API it can happen that Composer prompts
|
||||
for authentication asking your username and password so it can go ahead with its work.
|
||||
|
||||
If you would prefer not to provide your GitHub credentials to Composer you can
|
||||
manually create a token using the following procedure:
|
||||
|
||||
1. [Create](https://github.com/settings/applications) an OAuth token on GitHub.
|
||||
[Read more](https://github.com/blog/1509-personal-api-tokens) on this.
|
||||
|
||||
2. Add it to the configuration running `composer config -g github-oauth.github.com <oauthtoken>`
|
||||
|
||||
Now Composer should install/update without asking for authentication.
|
||||
|
||||
## proc_open(): fork failed errors
|
||||
If composer shows proc_open() fork failed on some commands:
|
||||
|
||||
`PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar`
|
||||
|
||||
This could be happening because the VPS runs out of memory and has no Swap space enabled.
|
||||
|
||||
```sh
|
||||
free -m
|
||||
|
||||
total used free shared buffers cached
|
||||
Mem: 2048 357 1690 0 0 237
|
||||
-/+ buffers/cache: 119 1928
|
||||
Swap: 0 0 0
|
||||
```
|
||||
|
||||
To enable the swap you can use for example:
|
||||
|
||||
```sh
|
||||
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
|
||||
/sbin/mkswap /var/swap.1
|
||||
/sbin/swapon /var/swap.1
|
||||
```
|
||||
@@ -1,21 +0,0 @@
|
||||
# Why are unbound version constraints a bad idea?
|
||||
|
||||
A version constraint without an upper bound such as `*`, `>=3.4` or
|
||||
`dev-master` will allow updates to any future version of the dependency.
|
||||
This includes major versions breaking backward compatibility.
|
||||
|
||||
Once a release of your package is tagged, you cannot tweak its dependencies
|
||||
anymore in case a dependency breaks BC - you have to do a new release but the
|
||||
previous one stays broken.
|
||||
|
||||
The only good alternative is to define an upper bound on your constraints,
|
||||
which you can increase in a new release after testing that your package is
|
||||
compatible with the new major version of your dependency.
|
||||
|
||||
For example instead of using `>=3.4` you should use `~3.4` which allows all
|
||||
versions up to `3.999` but does not include `4.0` and above. The `~` operator
|
||||
works very well with libraries follow [semantic versioning](http://semver.org).
|
||||
|
||||
**Note:** As a package maintainer, you can make the life of your users easier
|
||||
by providing an [alias version](../articles/aliases.md) for your development
|
||||
branch to allow it to match bound constraints.
|
||||
@@ -1,171 +0,0 @@
|
||||
# Introduction
|
||||
|
||||
Composer is a tool for dependency management in PHP. It allows you to declare
|
||||
the libraries your project depends on and it will manage (install/update) them
|
||||
for you.
|
||||
|
||||
## Dependency management
|
||||
|
||||
Composer is **not** a package manager in the same sense as Yum or Apt are. Yes,
|
||||
it deals with "packages" or libraries, but it manages them on a per-project
|
||||
basis, installing them in a directory (e.g. `vendor`) inside your project. By
|
||||
default it will never install anything globally. Thus, it is a dependency
|
||||
manager.
|
||||
|
||||
This idea is not new and Composer is strongly inspired by node's
|
||||
[npm](https://npmjs.org/) and ruby's [bundler](http://bundler.io/).
|
||||
|
||||
Suppose:
|
||||
|
||||
a) You have a project that depends on a number of libraries.
|
||||
|
||||
b) Some of those libraries depend on other libraries.
|
||||
|
||||
Composer:
|
||||
|
||||
c) Enables you to declare the libraries you depend on.
|
||||
|
||||
d) Finds out which versions of which packages can and need to be installed, and
|
||||
installs them (meaning it downloads them into your project).
|
||||
|
||||
See the [Basic usage](01-basic-usage.md) chapter for more details on declaring
|
||||
dependencies.
|
||||
|
||||
## System Requirements
|
||||
|
||||
Composer requires PHP 5.3.2+ to run. A few sensitive php settings and compile
|
||||
flags are also required, but when using the installer you will be warned about
|
||||
any incompatibilities.
|
||||
|
||||
To install packages from sources instead of simple zip archives, you will need
|
||||
git, svn or hg depending on how the package is version-controlled.
|
||||
|
||||
Composer is multi-platform and we strive to make it run equally well on Windows,
|
||||
Linux and OSX.
|
||||
|
||||
## Installation - Linux / Unix / OSX
|
||||
|
||||
### Downloading the Composer Executable
|
||||
|
||||
Composer offers a convenient installer that you can execute directly from the
|
||||
commandline. Feel free to [download this file](https://getcomposer.org/installer)
|
||||
or review it on [GitHub](https://github.com/composer/getcomposer.org/blob/master/web/installer)
|
||||
if you wish to know more about the inner workings of the installer. The source
|
||||
is plain PHP.
|
||||
|
||||
There are in short, two ways to install Composer. Locally as part of your
|
||||
project, or globally as a system wide executable.
|
||||
|
||||
#### Locally
|
||||
|
||||
Installing Composer locally is a matter of just running the installer in your
|
||||
project directory:
|
||||
|
||||
```sh
|
||||
curl -sS https://getcomposer.org/installer | php
|
||||
```
|
||||
|
||||
> **Note:** If the above fails for some reason, you can download the installer
|
||||
> with `php` instead:
|
||||
|
||||
```sh
|
||||
php -r "readfile('https://getcomposer.org/installer');" | php
|
||||
```
|
||||
|
||||
The installer will just check a few PHP settings and then download
|
||||
`composer.phar` to your working directory. This file is the Composer binary. It
|
||||
is a PHAR (PHP archive), which is an archive format for PHP which can be run on
|
||||
the command line, amongst other things.
|
||||
|
||||
Now just run `php composer.phar` in order to run Composer.
|
||||
|
||||
You can install Composer to a specific directory by using the `--install-dir`
|
||||
option and additionally (re)name it as well using the `--filename` option:
|
||||
|
||||
```sh
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=bin --filename=composer
|
||||
```
|
||||
|
||||
Now just run `php bin/composer` in order to run Composer.
|
||||
|
||||
#### Globally
|
||||
|
||||
You can place the Composer PHAR anywhere you wish. If you put it in a directory
|
||||
that is part of your `PATH`, you can access it globally. On unixy systems you
|
||||
can even make it executable and invoke it without directly using the `php`
|
||||
interpreter.
|
||||
|
||||
Run these commands to globally install `composer` on your system:
|
||||
|
||||
```sh
|
||||
curl -sS https://getcomposer.org/installer | php
|
||||
mv composer.phar /usr/local/bin/composer
|
||||
```
|
||||
|
||||
> **Note:** If the above fails due to permissions, run the `mv` line again
|
||||
> with sudo.
|
||||
|
||||
A quick copy-paste version including sudo:
|
||||
|
||||
```sh
|
||||
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
|
||||
```
|
||||
|
||||
> **Note:** On some versions of OSX the `/usr` directory does not exist by
|
||||
> default. If you receive the error "/usr/local/bin/composer: No such file or
|
||||
> directory" then you must create the directory manually before proceeding:
|
||||
> `mkdir -p /usr/local/bin`.
|
||||
|
||||
> **Note:** For information on changing your PATH, please read the
|
||||
> [Wikipedia article](https://en.wikipedia.org/wiki/PATH_(variable)) and/or use Google.
|
||||
|
||||
Now just run `composer` in order to run Composer instead of `php composer.phar`.
|
||||
|
||||
## Installation - Windows
|
||||
|
||||
### Using the Installer
|
||||
|
||||
This is the easiest way to get Composer set up on your machine.
|
||||
|
||||
Download and run
|
||||
[Composer-Setup.exe](https://getcomposer.org/Composer-Setup.exe). It will
|
||||
install the latest Composer version and set up your PATH so that you can just
|
||||
call `composer` from any directory in your command line.
|
||||
|
||||
> **Note:** Close your current terminal. Test usage with a new terminal: This is
|
||||
> important since the PATH only gets loaded when the terminal starts.
|
||||
|
||||
### Manual Installation
|
||||
|
||||
Change to a directory on your `PATH` and run the install snippet to download
|
||||
`composer.phar`:
|
||||
|
||||
```sh
|
||||
C:\Users\username>cd C:\bin
|
||||
C:\bin>php -r "readfile('https://getcomposer.org/installer');" | php
|
||||
```
|
||||
|
||||
> **Note:** If the above fails due to readfile, use the `http` url or enable
|
||||
> php_openssl.dll in php.ini
|
||||
|
||||
Create a new `composer.bat` file alongside `composer.phar`:
|
||||
|
||||
```sh
|
||||
C:\bin>echo @php "%~dp0composer.phar" %*>composer.bat
|
||||
```
|
||||
|
||||
Add the directory to your PATH environment variable if it isn't already.
|
||||
|
||||
Close your current terminal. Test usage with a new terminal:
|
||||
|
||||
```sh
|
||||
C:\Users\username>composer -V
|
||||
Composer version 27d8904
|
||||
```
|
||||
|
||||
## Using Composer
|
||||
|
||||
Now that you've installed Composer, you are ready to use it! Head on over to the
|
||||
next chapter for a short and simple demonstration.
|
||||
|
||||
[Basic usage](01-basic-usage.md) →
|
||||
@@ -1,207 +0,0 @@
|
||||
# Basic usage
|
||||
|
||||
## Introduction
|
||||
|
||||
For our basic usage introduction, we will be installing `monolog/monolog`,
|
||||
a logging library. If you have not yet installed Composer, refer to the
|
||||
[Intro](00-intro.md) chapter.
|
||||
|
||||
> **Note:** for the sake of simplicity, this introduction will assume you
|
||||
> have performed a [local](00-intro.md#locally) install of Composer.
|
||||
|
||||
## `composer.json`: Project Setup
|
||||
|
||||
To start using Composer in your project, all you need is a `composer.json`
|
||||
file. This file describes the dependencies of your project and may contain
|
||||
other metadata as well.
|
||||
|
||||
### The `require` Key
|
||||
|
||||
The first (and often only) thing you specify in `composer.json` is the
|
||||
[`require`](04-schema.md#require) key. You're simply telling Composer which
|
||||
packages your project depends on.
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"monolog/monolog": "1.0.*"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
As you can see, [`require`](04-schema.md#require) takes an object that maps
|
||||
**package names** (e.g. `monolog/monolog`) to **version constraints** (e.g.
|
||||
`1.0.*`).
|
||||
|
||||
### Package Names
|
||||
|
||||
The package name consists of a vendor name and the project's name. Often these
|
||||
will be identical - the vendor name just exists to prevent naming clashes. It
|
||||
allows two different people to create a library named `json`, which would then
|
||||
just be named `igorw/json` and `seldaek/json`.
|
||||
|
||||
Here we are requiring `monolog/monolog`, so the vendor name is the same as the
|
||||
project's name. For projects with a unique name this is recommended. It also
|
||||
allows adding more related projects under the same namespace later on. If you
|
||||
are maintaining a library, this would make it really easy to split it up into
|
||||
smaller decoupled parts.
|
||||
|
||||
### Package Versions
|
||||
|
||||
In the previous example we were requiring version
|
||||
[`1.0.*`](http://semver.mwl.be/#?package=monolog%2Fmonolog&version=1.0.*) of
|
||||
Monolog. This means any version in the `1.0` development branch. It is the
|
||||
equivalent of saying versions that match `>=1.0 <1.1`.
|
||||
|
||||
Version constraints can be specified in several ways, read
|
||||
[versions](articles/versions.md) for more in-depth information on this topic.
|
||||
|
||||
### Stability
|
||||
|
||||
By default only stable releases are taken into consideration. If you would
|
||||
like to also get RC, beta, alpha or dev versions of your dependencies you can
|
||||
do so using [stability flags](04-schema.md#package-links). To change that for
|
||||
all packages instead of doing per dependency you can also use the
|
||||
[minimum-stability](04-schema.md#minimum-stability) setting.
|
||||
|
||||
## Installing Dependencies
|
||||
|
||||
To install the defined dependencies for your project, just run the
|
||||
[`install`](03-cli.md#install) command.
|
||||
|
||||
```sh
|
||||
php composer.phar install
|
||||
```
|
||||
|
||||
This will find the latest version of `monolog/monolog` that matches the
|
||||
supplied version constraint and download it into the `vendor` directory.
|
||||
It's a convention to put third party code into a directory named `vendor`.
|
||||
In case of Monolog it will put it into `vendor/monolog/monolog`.
|
||||
|
||||
> **Tip:** If you are using git for your project, you probably want to add
|
||||
> `vendor` in your `.gitignore`. You really don't want to add all of that
|
||||
> code to your repository.
|
||||
|
||||
You will notice the [`install`](03-cli.md#install) command also created a
|
||||
`composer.lock` file.
|
||||
|
||||
## `composer.lock` - The Lock File
|
||||
|
||||
After installing the dependencies, Composer writes the list of the exact
|
||||
versions it installed into a `composer.lock` file. This locks the project
|
||||
to those specific versions.
|
||||
|
||||
**Commit your application's `composer.lock` (along with `composer.json`)
|
||||
into version control.**
|
||||
|
||||
This is important because the [`install`](03-cli.md#install) command checks
|
||||
if a lock file is present, and if it is, it downloads the versions specified
|
||||
there (regardless of what `composer.json` says).
|
||||
|
||||
This means that anyone who sets up the project will download the exact same
|
||||
version of the dependencies. Your CI server, production machines, other
|
||||
developers in your team, everything and everyone runs on the same dependencies,
|
||||
which mitigates the potential for bugs affecting only some parts of the
|
||||
deployments. Even if you develop alone, in six months when reinstalling the
|
||||
project you can feel confident the dependencies installed are still working even
|
||||
if your dependencies released many new versions since then.
|
||||
|
||||
If no `composer.lock` file exists, Composer will read the dependencies and
|
||||
versions from `composer.json` and create the lock file after executing the
|
||||
[`update`](03-cli.md#update) or the [`install`](03-cli.md#install) command.
|
||||
|
||||
This means that if any of the dependencies get a new version, you won't get the
|
||||
updates automatically. To update to the new version, use the
|
||||
[`update`](03-cli.md#update) command. This will fetch the latest matching
|
||||
versions (according to your `composer.json` file) and also update the lock file
|
||||
with the new version.
|
||||
|
||||
```sh
|
||||
php composer.phar update
|
||||
```
|
||||
> **Note:** Composer will display a Warning when executing an `install` command
|
||||
> if `composer.lock` and `composer.json` are not synchronized.
|
||||
|
||||
If you only want to install or update one dependency, you can whitelist them:
|
||||
|
||||
```sh
|
||||
php composer.phar update monolog/monolog [...]
|
||||
```
|
||||
|
||||
> **Note:** For libraries it is not necessary to commit the lock
|
||||
> file, see also: [Libraries - Lock file](02-libraries.md#lock-file).
|
||||
|
||||
## Packagist
|
||||
|
||||
[Packagist](https://packagist.org/) is the main Composer repository. A Composer
|
||||
repository is basically a package source: a place where you can get packages
|
||||
from. Packagist aims to be the central repository that everybody uses. This
|
||||
means that you can automatically `require` any package that is available there.
|
||||
|
||||
If you go to the [Packagist website](https://packagist.org/) (packagist.org),
|
||||
you can browse and search for packages.
|
||||
|
||||
Any open source project using Composer is recommended to publish their packages
|
||||
on Packagist. A library doesn't need to be on Packagist to be used by Composer,
|
||||
but it enables discovery and adoption by other developers more quickly.
|
||||
|
||||
## Autoloading
|
||||
|
||||
For libraries that specify autoload information, Composer generates a
|
||||
`vendor/autoload.php` file. You can simply include this file and you will get
|
||||
autoloading for free.
|
||||
|
||||
```php
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
```
|
||||
|
||||
This makes it really easy to use third party code. For example: If your project
|
||||
depends on Monolog, you can just start using classes from it, and they will be
|
||||
autoloaded.
|
||||
|
||||
```php
|
||||
$log = new Monolog\Logger('name');
|
||||
$log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING));
|
||||
$log->addWarning('Foo');
|
||||
```
|
||||
|
||||
You can even add your own code to the autoloader by adding an
|
||||
[`autoload`](04-schema.md#autoload) field to `composer.json`.
|
||||
|
||||
```json
|
||||
{
|
||||
"autoload": {
|
||||
"psr-4": {"Acme\\": "src/"}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Composer will register a [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloader
|
||||
for the `Acme` namespace.
|
||||
|
||||
You define a mapping from namespaces to directories. The `src` directory would
|
||||
be in your project root, on the same level as `vendor` directory is. An example
|
||||
filename would be `src/Foo.php` containing an `Acme\Foo` class.
|
||||
|
||||
After adding the [`autoload`](04-schema.md#autoload) field, you have to re-run
|
||||
[`dump-autoload`](03-cli.md#dump-autoload) to re-generate the
|
||||
`vendor/autoload.php` file.
|
||||
|
||||
Including that file will also return the autoloader instance, so you can store
|
||||
the return value of the include call in a variable and add more namespaces.
|
||||
This can be useful for autoloading classes in a test suite, for example.
|
||||
|
||||
```php
|
||||
$loader = require __DIR__ . '/vendor/autoload.php';
|
||||
$loader->add('Acme\\Test\\', __DIR__);
|
||||
```
|
||||
|
||||
In addition to PSR-4 autoloading, Composer also supports PSR-0, classmap and
|
||||
files autoloading. See the [`autoload`](04-schema.md#autoload) reference for
|
||||
more information.
|
||||
|
||||
> **Note:** Composer provides its own autoloader. If you don't want to use that
|
||||
> one, you can just include `vendor/composer/autoload_*.php` files, which return
|
||||
> associative arrays allowing you to configure your own autoloader.
|
||||
|
||||
← [Intro](00-intro.md) | [Libraries](02-libraries.md) →
|
||||
@@ -1,212 +0,0 @@
|
||||
# Libraries
|
||||
|
||||
This chapter will tell you how to make your library installable through
|
||||
Composer.
|
||||
|
||||
## Every project is a package
|
||||
|
||||
As soon as you have a `composer.json` in a directory, that directory is a
|
||||
package. When you add a [`require`](04-schema.md#require) to a project, you are
|
||||
making a package that depends on other packages. The only difference between
|
||||
your project and libraries is that your project is a package without a name.
|
||||
|
||||
In order to make that package installable you need to give it a name. You do
|
||||
this by adding the [`name`](04-schema.md#name) property in `composer.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "acme/hello-world",
|
||||
"require": {
|
||||
"monolog/monolog": "1.0.*"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this case the project name is `acme/hello-world`, where `acme` is the vendor
|
||||
name. Supplying a vendor name is mandatory.
|
||||
|
||||
> **Note:** If you don't know what to use as a vendor name, your GitHub
|
||||
> username is usually a good bet. While package names are case insensitive, the
|
||||
> convention is all lowercase and dashes for word separation.
|
||||
|
||||
## Platform packages
|
||||
|
||||
Composer has platform packages, which are virtual packages for things that are
|
||||
installed on the system but are not actually installable by Composer. This
|
||||
includes PHP itself, PHP extensions and some system libraries.
|
||||
|
||||
* `php` represents the PHP version of the user, allowing you to apply
|
||||
constraints, e.g. `>=5.4.0`. To require a 64bit version of php, you can
|
||||
require the `php-64bit` package.
|
||||
|
||||
* `hhvm` represents the version of the HHVM runtime (aka HipHop Virtual
|
||||
Machine) and allows you to apply a constraint, e.g., '>=2.3.3'.
|
||||
|
||||
* `ext-<name>` allows you to require PHP extensions (includes core
|
||||
extensions). Versioning can be quite inconsistent here, so it's often
|
||||
a good idea to just set the constraint to `*`. An example of an extension
|
||||
package name is `ext-gd`.
|
||||
|
||||
* `lib-<name>` allows constraints to be made on versions of libraries used by
|
||||
PHP. The following are available: `curl`, `iconv`, `icu`, `libxml`,
|
||||
`openssl`, `pcre`, `uuid`, `xsl`.
|
||||
|
||||
You can use [`show --platform`](03-cli.md#show) to get a list of your locally
|
||||
available platform packages.
|
||||
|
||||
## Specifying the version
|
||||
|
||||
When you publish your package on Packagist, it is able to infer the version
|
||||
from the VCS (git, svn, hg) information. This means you don't have to
|
||||
explicitly declare it. Read [tags](#tags) and [branches](#branches) to see how
|
||||
version numbers are extracted from these.
|
||||
|
||||
If you are creating packages by hand and really have to specify it explicitly,
|
||||
you can just add a `version` field:
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "1.0.0"
|
||||
}
|
||||
```
|
||||
|
||||
> **Note:** You should avoid specifying the version field explicitly, because
|
||||
> for tags the value must match the tag name.
|
||||
|
||||
### Tags
|
||||
|
||||
For every tag that looks like a version, a package version of that tag will be
|
||||
created. It should match 'X.Y.Z' or 'vX.Y.Z', with an optional suffix of
|
||||
`-patch` (`-p`), `-alpha` (`-a`), `-beta` (`-b`) or `-RC`. The suffix can also
|
||||
be followed by a number.
|
||||
|
||||
Here are a few examples of valid tag names:
|
||||
|
||||
- 1.0.0
|
||||
- v1.0.0
|
||||
- 1.10.5-RC1
|
||||
- v4.4.4-beta2
|
||||
- v2.0.0-alpha
|
||||
- v2.0.4-p1
|
||||
|
||||
> **Note:** Even if your tag is prefixed with `v`, a
|
||||
> [version constraint](01-basic-usage.md#package-versions) in a `require`
|
||||
> statement has to be specified without prefix (e.g. tag `v1.0.0` will result
|
||||
> in version `1.0.0`).
|
||||
|
||||
### Branches
|
||||
|
||||
For every branch, a package development version will be created. If the branch
|
||||
name looks like a version, the version will be `{branchname}-dev`. For example,
|
||||
the branch `2.0` will get the `2.0.x-dev` version (the `.x` is added for
|
||||
technical reasons, to make sure it is recognized as a branch). The `2.0.x`
|
||||
branch would also be valid and be turned into `2.0.x-dev` as well. If the
|
||||
branch does not look like a version, it will be `dev-{branchname}`. `master`
|
||||
results in a `dev-master` version.
|
||||
|
||||
Here are some examples of version branch names:
|
||||
|
||||
- 1.x
|
||||
- 1.0 (equals 1.0.x)
|
||||
- 1.1.x
|
||||
|
||||
> **Note:** When you install a development version, it will be automatically
|
||||
> pulled from its `source`. See the [`install`](03-cli.md#install) command
|
||||
> for more details.
|
||||
|
||||
### Aliases
|
||||
|
||||
It is possible to alias branch names to versions. For example, you could alias
|
||||
`dev-master` to `1.0.x-dev`, which would allow you to require `1.0.x-dev` in
|
||||
all the packages.
|
||||
|
||||
See [Aliases](articles/aliases.md) for more information.
|
||||
|
||||
## Lock file
|
||||
|
||||
For your library you may commit the `composer.lock` file if you want to. This
|
||||
can help your team to always test against the same dependency versions.
|
||||
However, this lock file will not have any effect on other projects that depend
|
||||
on it. It only has an effect on the main project.
|
||||
|
||||
If you do not want to commit the lock file and you are using git, add it to
|
||||
the `.gitignore`.
|
||||
|
||||
## Publishing to a VCS
|
||||
|
||||
Once you have a VCS repository (version control system, e.g. git) containing a
|
||||
`composer.json` file, your library is already composer-installable. In this
|
||||
example we will publish the `acme/hello-world` library on GitHub under
|
||||
`github.com/username/hello-world`.
|
||||
|
||||
Now, to test installing the `acme/hello-world` package, we create a new
|
||||
project locally. We will call it `acme/blog`. This blog will depend on
|
||||
`acme/hello-world`, which in turn depends on `monolog/monolog`. We can
|
||||
accomplish this by creating a new `blog` directory somewhere, containing a
|
||||
`composer.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "acme/blog",
|
||||
"require": {
|
||||
"acme/hello-world": "dev-master"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The name is not needed in this case, since we don't want to publish the blog
|
||||
as a library. It is added here to clarify which `composer.json` is being
|
||||
described.
|
||||
|
||||
Now we need to tell the blog app where to find the `hello-world` dependency.
|
||||
We do this by adding a package repository specification to the blog's
|
||||
`composer.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "acme/blog",
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/username/hello-world"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"acme/hello-world": "dev-master"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For more details on how package repositories work and what other types are
|
||||
available, see [Repositories](05-repositories.md).
|
||||
|
||||
That's all. You can now install the dependencies by running Composer's
|
||||
[`install`](03-cli.md#install) command!
|
||||
|
||||
**Recap:** Any git/svn/hg repository containing a `composer.json` can be added
|
||||
to your project by specifying the package repository and declaring the
|
||||
dependency in the [`require`](04-schema.md#require) field.
|
||||
|
||||
## Publishing to packagist
|
||||
|
||||
Alright, so now you can publish packages. But specifying the VCS repository
|
||||
every time is cumbersome. You don't want to force all your users to do that.
|
||||
|
||||
The other thing that you may have noticed is that we did not specify a package
|
||||
repository for `monolog/monolog`. How did that work? The answer is Packagist.
|
||||
|
||||
[Packagist](https://packagist.org/) is the main package repository for
|
||||
Composer, and it is enabled by default. Anything that is published on
|
||||
Packagist is available automatically through Composer. Since
|
||||
[Monolog is on Packagist](https://packagist.org/packages/monolog/monolog), we
|
||||
can depend on it without having to specify any additional repositories.
|
||||
|
||||
If we wanted to share `hello-world` with the world, we would publish it on
|
||||
Packagist as well. Doing so is really easy.
|
||||
|
||||
You simply visit [Packagist](https://packagist.org) and hit the "Submit". This
|
||||
will prompt you to sign up if you haven't already, and then allows you to
|
||||
submit the URL to your VCS repository, at which point Packagist will start
|
||||
crawling it. Once it is done, your package will be available to anyone!
|
||||
|
||||
← [Basic usage](01-basic-usage.md) | [Command-line interface](03-cli.md) →
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,189 +0,0 @@
|
||||
# Config
|
||||
|
||||
This chapter will describe the `config` section of the `composer.json`
|
||||
[schema](04-schema.md).
|
||||
|
||||
## process-timeout
|
||||
|
||||
Defaults to `300`. The duration processes like git clones can run before
|
||||
Composer assumes they died out. You may need to make this higher if you have a
|
||||
slow connection or huge vendors.
|
||||
|
||||
## use-include-path
|
||||
|
||||
Defaults to `false`. If `true`, the Composer autoloader will also look for classes
|
||||
in the PHP include path.
|
||||
|
||||
## preferred-install
|
||||
|
||||
Defaults to `auto` and can be any of `source`, `dist` or `auto`. This option
|
||||
allows you to set the install method Composer will prefer to use.
|
||||
|
||||
## store-auths
|
||||
|
||||
What to do after prompting for authentication, one of: `true` (always store),
|
||||
`false` (do not store) and `"prompt"` (ask every time), defaults to `"prompt"`.
|
||||
|
||||
## github-protocols
|
||||
|
||||
Defaults to `["git", "https", "ssh"]`. A list of protocols to use when cloning
|
||||
from github.com, in priority order. You can reconfigure it to for example
|
||||
prioritize the https protocol if you are behind a proxy or have somehow bad
|
||||
performances with the git protocol.
|
||||
|
||||
## github-oauth
|
||||
|
||||
A list of domain names and oauth keys. For example using `{"github.com":
|
||||
"oauthtoken"}` as the value of this option will use `oauthtoken` to access
|
||||
private repositories on github and to circumvent the low IP-based rate limiting
|
||||
of their API. [Read
|
||||
more](articles/troubleshooting.md#api-rate-limit-and-oauth-tokens) on how to get
|
||||
an OAuth token for GitHub.
|
||||
|
||||
## http-basic
|
||||
|
||||
A list of domain names and username/passwords to authenticate against them. For
|
||||
example using `{"example.org": {"username": "alice", "password": "foo"}` as the
|
||||
value of this option will let Composer authenticate against example.org.
|
||||
|
||||
> **Note:** Authentication-related config options like `http-basic` and
|
||||
> `github-oauth` can also be specified inside a `auth.json` file that goes
|
||||
> besides your `composer.json`. That way you can gitignore it and every
|
||||
> developer can place their own credentials in there.
|
||||
|
||||
## platform
|
||||
|
||||
Lets you fake platform packages (PHP and extensions) so that you can emulate a
|
||||
production env or define your target platform in the config. Example: `{"php":
|
||||
"5.4", "ext-something": "4.0"}`.
|
||||
|
||||
## vendor-dir
|
||||
|
||||
Defaults to `vendor`. You can install dependencies into a different directory if
|
||||
you want to. `$HOME` and `~` will be replaced by your home directory's path in
|
||||
vendor-dir and all `*-dir` options below.
|
||||
|
||||
## bin-dir
|
||||
|
||||
Defaults to `vendor/bin`. If a project includes binaries, they will be symlinked
|
||||
into this directory.
|
||||
|
||||
## cache-dir
|
||||
|
||||
Defaults to `$COMPOSER_HOME/cache` on unix systems and
|
||||
`C:\Users\<user>\AppData\Local\Composer` on Windows. Stores all the caches used
|
||||
by Composer. See also [COMPOSER_HOME](03-cli.md#composer-home).
|
||||
|
||||
## cache-files-dir
|
||||
|
||||
Defaults to `$cache-dir/files`. Stores the zip archives of packages.
|
||||
|
||||
## cache-repo-dir
|
||||
|
||||
Defaults to `$cache-dir/repo`. Stores repository metadata for the `composer`
|
||||
type and the VCS repos of type `svn`, `github` and `bitbucket`.
|
||||
|
||||
## cache-vcs-dir
|
||||
|
||||
Defaults to `$cache-dir/vcs`. Stores VCS clones for loading VCS repository
|
||||
metadata for the `git`/`hg` types and to speed up installs.
|
||||
|
||||
## cache-files-ttl
|
||||
|
||||
Defaults to `15552000` (6 months). Composer caches all dist (zip, tar, ..)
|
||||
packages that it downloads. Those are purged after six months of being unused by
|
||||
default. This option allows you to tweak this duration (in seconds) or disable
|
||||
it completely by setting it to 0.
|
||||
|
||||
## cache-files-maxsize
|
||||
|
||||
Defaults to `300MiB`. Composer caches all dist (zip, tar, ..) packages that it
|
||||
downloads. When the garbage collection is periodically ran, this is the maximum
|
||||
size the cache will be able to use. Older (less used) files will be removed
|
||||
first until the cache fits.
|
||||
|
||||
## bin-compat
|
||||
|
||||
Defaults to `auto`. Determines the compatibility of the binaries to be installed.
|
||||
If it is `auto` then Composer only installs .bat proxy files when on Windows. If
|
||||
set to `full` then both .bat files for Windows and scripts for Unix-based
|
||||
operating systems will be installed for each binary. This is mainly useful if you
|
||||
run Composer inside a linux VM but still want the .bat proxies available for use
|
||||
in the Windows host OS.
|
||||
|
||||
## prepend-autoloader
|
||||
|
||||
Defaults to `true`. If `false`, the Composer autoloader will not be prepended to
|
||||
existing autoloaders. This is sometimes required to fix interoperability issues
|
||||
with other autoloaders.
|
||||
|
||||
## autoloader-suffix
|
||||
|
||||
Defaults to `null`. String to be used as a suffix for the generated Composer
|
||||
autoloader. When null a random one will be generated.
|
||||
|
||||
## optimize-autoloader
|
||||
|
||||
Defaults to `false`. If `true`, always optimize when dumping the autoloader.
|
||||
|
||||
## sort-packages
|
||||
|
||||
Defaults to `false`. If `true`, the `require` command keeps packages sorted
|
||||
by name in `composer.json` when adding a new package.
|
||||
|
||||
## classmap-authoritative
|
||||
|
||||
Defaults to `false`. If `true`, the Composer autoloader will only load classes
|
||||
from the classmap. Implies `optimize-autoloader`.
|
||||
|
||||
## github-domains
|
||||
|
||||
Defaults to `["github.com"]`. A list of domains to use in github mode. This is
|
||||
used for GitHub Enterprise setups.
|
||||
|
||||
## github-expose-hostname
|
||||
|
||||
Defaults to `true`. If `false`, the OAuth tokens created to access the
|
||||
github API will have a date instead of the machine hostname.
|
||||
|
||||
## gitlab-domains
|
||||
|
||||
Defaults to `["gitlab.com"]`. A list of domains of GitLab servers.
|
||||
This is used if you use the `gitlab` repository type.
|
||||
|
||||
## notify-on-install
|
||||
|
||||
Defaults to `true`. Composer allows repositories to define a notification URL,
|
||||
so that they get notified whenever a package from that repository is installed.
|
||||
This option allows you to disable that behaviour.
|
||||
|
||||
## discard-changes
|
||||
|
||||
Defaults to `false` and can be any of `true`, `false` or `"stash"`. This option
|
||||
allows you to set the default style of handling dirty updates when in
|
||||
non-interactive mode. `true` will always discard changes in vendors, while
|
||||
`"stash"` will try to stash and reapply. Use this for CI servers or deploy
|
||||
scripts if you tend to have modified vendors.
|
||||
|
||||
## archive-format
|
||||
|
||||
Defaults to `tar`. Composer allows you to add a default archive format when the
|
||||
workflow needs to create a dedicated archiving format.
|
||||
|
||||
## archive-dir
|
||||
|
||||
Defaults to `.`. Composer allows you to add a default archive directory when the
|
||||
workflow needs to create a dedicated archiving format. Or for easier development
|
||||
between modules.
|
||||
|
||||
Example:
|
||||
|
||||
```json
|
||||
{
|
||||
"config": {
|
||||
"archive-dir": "/home/user/.composer/repo"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
← [Repositories](05-repositories.md) | [Community](07-community.md) →
|
||||
@@ -1,35 +0,0 @@
|
||||
# Community
|
||||
|
||||
There are many people using Composer already, and quite a few of them are
|
||||
contributing.
|
||||
|
||||
## Contributing
|
||||
|
||||
If you would like to contribute to Composer, please read the
|
||||
[README](https://github.com/composer/composer) and
|
||||
[CONTRIBUTING](https://github.com//composer/composer/blob/master/CONTRIBUTING.md)
|
||||
documents.
|
||||
|
||||
The most important guidelines are described as follows:
|
||||
|
||||
> All code contributions - including those of people having commit access - must
|
||||
> go through a pull request and approved by a core developer before being
|
||||
> merged. This is to ensure proper review of all the code.
|
||||
>
|
||||
> Fork the project, create a feature branch, and send us a pull request.
|
||||
>
|
||||
> To ensure a consistent code base, you should make sure the code follows
|
||||
> the [PSR-2 Coding Standards](http://www.php-fig.org/psr/psr-2/).
|
||||
|
||||
## IRC / mailing list
|
||||
|
||||
Mailing lists for [user support](https://groups.google.com/group/composer-users) and
|
||||
[development](https://groups.google.com/group/composer-dev).
|
||||
|
||||
IRC channels are on irc.freenode.org: [#composer](irc://irc.freenode.org/composer)
|
||||
for users and [#composer-dev](irc://irc.freenode.org/composer-dev) for development.
|
||||
|
||||
Stack Overflow has a growing collection of
|
||||
[Composer related questions](https://stackoverflow.com/questions/tagged/composer-php).
|
||||
|
||||
← [Config](06-config.md)
|
||||
@@ -1,100 +0,0 @@
|
||||
<!--
|
||||
tagline: Alias branch names to versions
|
||||
-->
|
||||
|
||||
# Aliases
|
||||
|
||||
## Why aliases?
|
||||
|
||||
When you are using a VCS repository, you will only get comparable versions for
|
||||
branches that look like versions, such as `2.0` or `2.0.x`. For your `master` branch, you
|
||||
will get a `dev-master` version. For your `bugfix` branch, you will get a
|
||||
`dev-bugfix` version.
|
||||
|
||||
If your `master` branch is used to tag releases of the `1.0` development line,
|
||||
i.e. `1.0.1`, `1.0.2`, `1.0.3`, etc., any package depending on it will
|
||||
probably require version `1.0.*`.
|
||||
|
||||
If anyone wants to require the latest `dev-master`, they have a problem: Other
|
||||
packages may require `1.0.*`, so requiring that dev version will lead to
|
||||
conflicts, since `dev-master` does not match the `1.0.*` constraint.
|
||||
|
||||
Enter aliases.
|
||||
|
||||
## Branch alias
|
||||
|
||||
The `dev-master` branch is one in your main VCS repo. It is rather common that
|
||||
someone will want the latest master dev version. Thus, Composer allows you to
|
||||
alias your `dev-master` branch to a `1.0.x-dev` version. It is done by
|
||||
specifying a `branch-alias` field under `extra` in `composer.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The branch version must begin with `dev-` (non-comparable version), the alias
|
||||
must be a comparable dev version (i.e. start with numbers, and end with
|
||||
`.x-dev`). The `branch-alias` must be present on the branch that it references.
|
||||
For `dev-master`, you need to commit it on the `master` branch.
|
||||
|
||||
As a result, anyone can now require `1.0.*` and it will happily install
|
||||
`dev-master`.
|
||||
|
||||
In order to use branch aliasing, you must own the repository of the package
|
||||
being aliased. If you want to alias a third party package without maintaining
|
||||
a fork of it, use inline aliases as described below.
|
||||
|
||||
## Require inline alias
|
||||
|
||||
Branch aliases are great for aliasing main development lines. But in order to
|
||||
use them you need to have control over the source repository, and you need to
|
||||
commit changes to version control.
|
||||
|
||||
This is not really fun when you just want to try a bugfix of some library that
|
||||
is a dependency of your local project.
|
||||
|
||||
For this reason, you can alias packages in your `require` and `require-dev`
|
||||
fields. Let's say you found a bug in the `monolog/monolog` package. You cloned
|
||||
[Monolog](https://github.com/Seldaek/monolog) on GitHub and fixed the issue in
|
||||
a branch named `bugfix`. Now you want to install that version of monolog in your
|
||||
local project.
|
||||
|
||||
You are using `symfony/monolog-bundle` which requires `monolog/monolog` version
|
||||
`1.*`. So you need your `dev-bugfix` to match that constraint.
|
||||
|
||||
Just add this to your project's root `composer.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/you/monolog"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"symfony/monolog-bundle": "2.0",
|
||||
"monolog/monolog": "dev-bugfix as 1.0.x-dev"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
That will fetch the `dev-bugfix` version of `monolog/monolog` from your GitHub
|
||||
and alias it to `1.0.x-dev`.
|
||||
|
||||
> **Note:** If a package with inline aliases is required, the alias (right of
|
||||
> the `as`) is used as the version constraint. The part left of the `as` is
|
||||
> discarded. As a consequence, if A requires B and B requires `monolog/monolog`
|
||||
> version `dev-bugfix as 1.0.x-dev`, installing A will make B require
|
||||
> `1.0.x-dev`, which may exist as a branch alias or an actual `1.0` branch. If
|
||||
> it does not, it must be re-inline-aliased in A's `composer.json`.
|
||||
|
||||
> **Note:** Inline aliasing should be avoided, especially for published
|
||||
> packages. If you found a bug, try and get your fix merged upstream. This
|
||||
> helps to avoid issues for users of your package.
|
||||
@@ -1,200 +0,0 @@
|
||||
<!--
|
||||
tagline: Host your own composer repository
|
||||
-->
|
||||
|
||||
# Handling private packages with Satis
|
||||
|
||||
Satis is a static `composer` repository generator. It is a bit like an ultra-
|
||||
lightweight, static file-based version of packagist and can be used to host the
|
||||
metadata of your company's private packages, or your own. It basically acts as
|
||||
a micro-packagist. You can get it from
|
||||
[GitHub](http://github.com/composer/satis) or install via CLI:
|
||||
`composer.phar create-project composer/satis --stability=dev`.
|
||||
|
||||
## Setup
|
||||
|
||||
For example let's assume you have a few packages you want to reuse across your
|
||||
company but don't really want to open-source. You would first define a Satis
|
||||
configuration: a json file with an arbitrary name that lists your curated
|
||||
[repositories](../05-repositories.md).
|
||||
|
||||
Here is an example configuration, you see that it holds a few VCS repositories,
|
||||
but those could be any types of [repositories](../05-repositories.md). Then it
|
||||
uses `"require-all": true` which selects all versions of all packages in the
|
||||
repositories you defined.
|
||||
|
||||
The default file Satis looks for is `satis.json` in the root of the repository.
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "My Repository",
|
||||
"homepage": "http://packages.example.org",
|
||||
"repositories": [
|
||||
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo" },
|
||||
{ "type": "vcs", "url": "http://svn.example.org/private/repo" },
|
||||
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" }
|
||||
],
|
||||
"require-all": true
|
||||
}
|
||||
```
|
||||
|
||||
If you want to cherry pick which packages you want, you can list all the packages
|
||||
you want to have in your satis repository inside the classic composer `require` key,
|
||||
using a `"*"` constraint to make sure all versions are selected, or another
|
||||
constraint if you want really specific versions.
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo" },
|
||||
{ "type": "vcs", "url": "http://svn.example.org/private/repo" },
|
||||
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" }
|
||||
],
|
||||
"require": {
|
||||
"company/package": "*",
|
||||
"company/package2": "*",
|
||||
"company/package3": "2.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Once you did this, you just run `php bin/satis build <configuration file> <build dir>`.
|
||||
For example `php bin/satis build config.json web/` would read the `config.json`
|
||||
file and build a static repository inside the `web/` directory.
|
||||
|
||||
When you ironed out that process, what you would typically do is run this
|
||||
command as a cron job on a server. It would then update all your package info
|
||||
much like Packagist does.
|
||||
|
||||
Note that if your private packages are hosted on GitHub, your server should have
|
||||
an ssh key that gives it access to those packages, and then you should add
|
||||
the `--no-interaction` (or `-n`) flag to the command to make sure it falls back
|
||||
to ssh key authentication instead of prompting for a password. This is also a
|
||||
good trick for continuous integration servers.
|
||||
|
||||
Set up a virtual-host that points to that `web/` directory, let's say it is
|
||||
`packages.example.org`. Alternatively, with PHP >= 5.4.0, you can use the built-in
|
||||
CLI server `php -S localhost:port -t satis-output-dir/` for a temporary solution.
|
||||
|
||||
## Usage
|
||||
|
||||
In your projects all you need to add now is your own composer repository using
|
||||
the `packages.example.org` as URL, then you can require your private packages and
|
||||
everything should work smoothly. You don't need to copy all your repositories
|
||||
in every project anymore. Only that one unique repository that will update
|
||||
itself.
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [ { "type": "composer", "url": "http://packages.example.org/" } ],
|
||||
"require": {
|
||||
"company/package": "1.2.0",
|
||||
"company/package2": "1.5.2",
|
||||
"company/package3": "dev-master"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Security
|
||||
|
||||
To secure your private repository you can host it over SSH or SSL using a client
|
||||
certificate. In your project you can use the `options` parameter to specify the
|
||||
connection options for the server.
|
||||
|
||||
Example using a custom repository using SSH (requires the SSH2 PECL extension):
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "ssh2.sftp://example.org",
|
||||
"options": {
|
||||
"ssh2": {
|
||||
"username": "composer",
|
||||
"pubkey_file": "/home/composer/.ssh/id_rsa.pub",
|
||||
"privkey_file": "/home/composer/.ssh/id_rsa"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
> **Tip:** See [ssh2 context options](http://www.php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-options) for more information.
|
||||
|
||||
Example using HTTP over SSL using a client certificate:
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "https://example.org",
|
||||
"options": {
|
||||
"ssl": {
|
||||
"local_cert": "/home/composer/.ssl/composer.pem"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
> **Tip:** See [ssl context options](http://www.php.net/manual/en/context.ssl.php) for more information.
|
||||
|
||||
### Downloads
|
||||
|
||||
When GitHub or BitBucket repositories are mirrored on your local satis, the build process will include
|
||||
the location of the downloads these platforms make available. This means that the repository and your setup depend
|
||||
on the availability of these services.
|
||||
|
||||
At the same time, this implies that all code which is hosted somewhere else (on another service or for example in
|
||||
Subversion) will not have downloads available and thus installations usually take a lot longer.
|
||||
|
||||
To enable your satis installation to create downloads for all (Git, Mercurial and Subversion) your packages, add the
|
||||
following to your `satis.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"archive": {
|
||||
"directory": "dist",
|
||||
"format": "tar",
|
||||
"prefix-url": "https://amazing.cdn.example.org",
|
||||
"skip-dev": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Options explained
|
||||
|
||||
* `directory`: the location of the dist files (inside the `output-dir`)
|
||||
* `format`: optional, `zip` (default) or `tar`
|
||||
* `prefix-url`: optional, location of the downloads, homepage (from `satis.json`) followed by `directory` by default
|
||||
* `skip-dev`: optional, `false` by default, when enabled (`true`) satis will not create downloads for branches
|
||||
|
||||
Once enabled, all downloads (include those from GitHub and BitBucket) will be replaced with a _local_ version.
|
||||
|
||||
#### prefix-url
|
||||
|
||||
Prefixing the URL with another host is especially helpful if the downloads end up in a private Amazon S3
|
||||
bucket or on a CDN host. A CDN would drastically improve download times and therefore package installation.
|
||||
|
||||
Example: A `prefix-url` of `http://my-bucket.s3.amazonaws.com` (and `directory` set to `dist`) creates download URLs
|
||||
which look like the following: `http://my-bucket.s3.amazonaws.com/dist/vendor-package-version-ref.zip`.
|
||||
|
||||
|
||||
### Resolving dependencies
|
||||
|
||||
It is possible to make satis automatically resolve and add all dependencies for your projects. This can be used
|
||||
with the Downloads functionality to have a complete local mirror of packages. Just add the following
|
||||
to your `satis.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"require-dependencies": true
|
||||
}
|
||||
```
|
||||
|
||||
When searching for packages, satis will attempt to resolve all the required packages from the listed repositories.
|
||||
Therefore, if you are requiring a package from Packagist, you will need to define it in your `satis.json`.
|
||||
@@ -1,160 +0,0 @@
|
||||
<!--
|
||||
tagline: Modify and extend Composer's functionality
|
||||
-->
|
||||
|
||||
# Setting up and using plugins
|
||||
|
||||
## Synopsis
|
||||
|
||||
You may wish to alter or expand Composer's functionality with your own. For
|
||||
example if your environment poses special requirements on the behaviour of
|
||||
Composer which do not apply to the majority of its users or if you wish to
|
||||
accomplish something with composer in a way that is not desired by most users.
|
||||
|
||||
In these cases you could consider creating a plugin to handle your
|
||||
specific logic.
|
||||
|
||||
## Creating a Plugin
|
||||
|
||||
A plugin is a regular composer package which ships its code as part of the
|
||||
package and may also depend on further packages.
|
||||
|
||||
### Plugin Package
|
||||
|
||||
The package file is the same as any other package file but with the following
|
||||
requirements:
|
||||
|
||||
1. the [type][1] attribute must be `composer-plugin`.
|
||||
2. the [extra][2] attribute must contain an element `class` defining the
|
||||
class name of the plugin (including namespace). If a package contains
|
||||
multiple plugins this can be array of class names.
|
||||
|
||||
Additionally you must require the special package called `composer-plugin-api`
|
||||
to define which composer API versions your plugin is compatible with. The
|
||||
current composer plugin API version is 1.0.0.
|
||||
|
||||
For example
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my/plugin-package",
|
||||
"type": "composer-plugin",
|
||||
"require": {
|
||||
"composer-plugin-api": "1.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Plugin Class
|
||||
|
||||
Every plugin has to supply a class which implements the
|
||||
[`Composer\Plugin\PluginInterface`][3]. The `activate()` method of the plugin
|
||||
is called after the plugin is loaded and receives an instance of
|
||||
[`Composer\Composer`][4] as well as an instance of
|
||||
[`Composer\IO\IOInterface`][5]. Using these two objects all configuration can
|
||||
be read and all internal objects and state can be manipulated as desired.
|
||||
|
||||
Example:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace phpDocumentor\Composer;
|
||||
|
||||
use Composer\Composer;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Plugin\PluginInterface;
|
||||
|
||||
class TemplateInstallerPlugin implements PluginInterface
|
||||
{
|
||||
public function activate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
$installer = new TemplateInstaller($io, $composer);
|
||||
$composer->getInstallationManager()->addInstaller($installer);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Event Handler
|
||||
|
||||
Furthermore plugins may implement the
|
||||
[`Composer\EventDispatcher\EventSubscriberInterface`][6] in order to have its
|
||||
event handlers automatically registered with the `EventDispatcher` when the
|
||||
plugin is loaded.
|
||||
|
||||
The events available for plugins are:
|
||||
|
||||
* **COMMAND**, is called at the beginning of all commands that load plugins.
|
||||
It provides you with access to the input and output objects of the program.
|
||||
* **PRE_FILE_DOWNLOAD**, is triggered before files are downloaded and allows
|
||||
you to manipulate the `RemoteFilesystem` object prior to downloading files
|
||||
based on the URL to be downloaded.
|
||||
|
||||
> A plugin can also subscribe to [script events][7].
|
||||
|
||||
Example:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace Naderman\Composer\AWS;
|
||||
|
||||
use Composer\Composer;
|
||||
use Composer\EventDispatcher\EventSubscriberInterface;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Plugin\PluginInterface;
|
||||
use Composer\Plugin\PluginEvents;
|
||||
use Composer\Plugin\PreFileDownloadEvent;
|
||||
|
||||
class AwsPlugin implements PluginInterface, EventSubscriberInterface
|
||||
{
|
||||
protected $composer;
|
||||
protected $io;
|
||||
|
||||
public function activate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->io = $io;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
PluginEvents::PRE_FILE_DOWNLOAD => array(
|
||||
array('onPreFileDownload', 0)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function onPreFileDownload(PreFileDownloadEvent $event)
|
||||
{
|
||||
$protocol = parse_url($event->getProcessedUrl(), PHP_URL_SCHEME);
|
||||
|
||||
if ($protocol === 's3') {
|
||||
$awsClient = new AwsClient($this->io, $this->composer->getConfig());
|
||||
$s3RemoteFilesystem = new S3RemoteFilesystem($this->io, $event->getRemoteFilesystem()->getOptions(), $awsClient);
|
||||
$event->setRemoteFilesystem($s3RemoteFilesystem);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Using Plugins
|
||||
|
||||
Plugin packages are automatically loaded as soon as they are installed and will
|
||||
be loaded when composer starts up if they are found in the current project's
|
||||
list of installed packages. Additionally all plugin packages installed in the
|
||||
`COMPOSER_HOME` directory using the composer global command are loaded before
|
||||
local project plugins are loaded.
|
||||
|
||||
> You may pass the `--no-plugins` option to composer commands to disable all
|
||||
> installed commands. This may be particularly helpful if any of the plugins
|
||||
> causes errors and you wish to update or uninstall it.
|
||||
|
||||
[1]: ../04-schema.md#type
|
||||
[2]: ../04-schema.md#extra
|
||||
[3]: https://github.com/composer/composer/blob/master/src/Composer/Plugin/PluginInterface.php
|
||||
[4]: https://github.com/composer/composer/blob/master/src/Composer/Composer.php
|
||||
[5]: https://github.com/composer/composer/blob/master/src/Composer/IO/IOInterface.php
|
||||
[6]: https://github.com/composer/composer/blob/master/src/Composer/EventDispatcher/EventSubscriberInterface.php
|
||||
[7]: ./scripts.md#event-names
|
||||
@@ -1,133 +0,0 @@
|
||||
<!--
|
||||
tagline: Script are callbacks that are called before/after installing packages
|
||||
-->
|
||||
|
||||
# Scripts
|
||||
|
||||
## What is a script?
|
||||
|
||||
A script, in Composer's terms, can either be a PHP callback (defined as a
|
||||
static method) or any command-line executable command. Scripts are useful
|
||||
for executing a package's custom code or package-specific commands during
|
||||
the Composer execution process.
|
||||
|
||||
**NOTE: Only scripts defined in the root package's `composer.json` are
|
||||
executed. If a dependency of the root package specifies its own scripts,
|
||||
Composer does not execute those additional scripts.**
|
||||
|
||||
|
||||
## Event names
|
||||
|
||||
Composer fires the following named events during its execution process:
|
||||
|
||||
- **pre-install-cmd**: occurs before the `install` command is executed.
|
||||
- **post-install-cmd**: occurs after the `install` command is executed.
|
||||
- **pre-update-cmd**: occurs before the `update` command is executed.
|
||||
- **post-update-cmd**: occurs after the `update` command is executed.
|
||||
- **pre-status-cmd**: occurs before the `status` command is executed.
|
||||
- **post-status-cmd**: occurs after the `status` command is executed.
|
||||
- **pre-package-install**: occurs before a package is installed.
|
||||
- **post-package-install**: occurs after a package is installed.
|
||||
- **pre-package-update**: occurs before a package is updated.
|
||||
- **post-package-update**: occurs after a package is updated.
|
||||
- **pre-package-uninstall**: occurs before a package has been uninstalled.
|
||||
- **post-package-uninstall**: occurs after a package has been uninstalled.
|
||||
- **pre-autoload-dump**: occurs before the autoloader is dumped, either
|
||||
during `install`/`update`, or via the `dump-autoload` command.
|
||||
- **post-autoload-dump**: occurs after the autoloader is dumped, either
|
||||
during `install`/`update`, or via the `dump-autoload` command.
|
||||
- **post-root-package-install**: occurs after the root package has been
|
||||
installed, during the `create-project` command.
|
||||
- **post-create-project-cmd**: occurs after the `create-project` command is
|
||||
executed.
|
||||
- **pre-archive-cmd**: occurs before the `archive` command is executed.
|
||||
- **post-archive-cmd**: occurs after the `archive` command is executed.
|
||||
|
||||
**NOTE: Composer makes no assumptions about the state of your dependencies
|
||||
prior to `install` or `update`. Therefore, you should not specify scripts that
|
||||
require Composer-managed dependencies in the `pre-update-cmd` or
|
||||
`pre-install-cmd` event hooks. If you need to execute scripts prior to
|
||||
`install` or `update` please make sure they are self-contained within your
|
||||
root package.**
|
||||
|
||||
## Defining scripts
|
||||
|
||||
The root JSON object in `composer.json` should have a property called
|
||||
`"scripts"`, which contains pairs of named events and each event's
|
||||
corresponding scripts. An event's scripts can be defined as either as a string
|
||||
(only for a single script) or an array (for single or multiple scripts.)
|
||||
|
||||
For any given event:
|
||||
|
||||
- Scripts execute in the order defined when their corresponding event is fired.
|
||||
- An array of scripts wired to a single event can contain both PHP callbacks
|
||||
and command-line executables commands.
|
||||
- PHP classes containing defined callbacks must be autoloadable via Composer's
|
||||
autoload functionality.
|
||||
|
||||
Script definition example:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"post-update-cmd": "MyVendor\\MyClass::postUpdate",
|
||||
"post-package-install": [
|
||||
"MyVendor\\MyClass::postPackageInstall"
|
||||
],
|
||||
"post-install-cmd": [
|
||||
"MyVendor\\MyClass::warmCache",
|
||||
"phpunit -c app/"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Using the previous definition example, here's the class `MyVendor\MyClass`
|
||||
that might be used to execute the PHP callbacks:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace MyVendor;
|
||||
|
||||
use Composer\Script\Event;
|
||||
|
||||
class MyClass
|
||||
{
|
||||
public static function postUpdate(Event $event)
|
||||
{
|
||||
$composer = $event->getComposer();
|
||||
// do stuff
|
||||
}
|
||||
|
||||
public static function postPackageInstall(Event $event)
|
||||
{
|
||||
$installedPackage = $event->getOperation()->getPackage();
|
||||
// do stuff
|
||||
}
|
||||
|
||||
public static function warmCache(Event $event)
|
||||
{
|
||||
// make cache toasty
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When an event is fired, Composer's internal event handler receives a
|
||||
`Composer\Script\Event` object, which is passed as the first argument to your
|
||||
PHP callback. This `Event` object has getters for other contextual objects:
|
||||
|
||||
- `getComposer()`: returns the current instance of `Composer\Composer`
|
||||
- `getName()`: returns the name of the event being fired as a string
|
||||
- `getIO()`: returns the current input/output stream which implements
|
||||
`Composer\IO\IOInterface` for writing to the console
|
||||
|
||||
## Running scripts manually
|
||||
|
||||
If you would like to run the scripts for an event manually, the syntax is:
|
||||
|
||||
```sh
|
||||
composer run-script [--dev] [--no-dev] script
|
||||
```
|
||||
|
||||
For example `composer run-script post-install-cmd` will run any **post-install-cmd** scripts that have been defined.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user