商业与职场
PHP十二要素应用合规检查
提供PHP源码,按十二要素定位硬编码配置、本地持久化等部署隐患,并结合代码用途排除误报。
# 12-Factor App 合规性检查
分析 PHP 代码,找出违反 [12-Factor App](https://12factor.net/) 方法论、妨碍部署、可扩展性和卓越运维的情况。
## 检测模式
### 1. 硬编码配置(Factor III:配置)
```php
<?php
declare(strict_types=1);
// BAD: Configuration values embedded in source code
final class MailerConfig
{
private string $smtpHost = 'smtp.gmail.com';
private int $smtpPort = 587;
private string $apiKey = 'sk-live-abc123xyz';
}
// BAD: Database credentials in code
final class DatabaseConfig
{
public function getDsn(): string
{
return 'mysql:host=localhost;port=3306;dbname=myapp';
}
public function getUser(): string
{
return 'root';
}
public function getPassword(): string
{
return 'secret123';
}
}
// GOOD: All configuration from environment variables
final readonly class MailerConfig
{
public function __construct(
private string $smtpHost,
private int $smtpPort,
private string $apiKey,
) {}
public static function fromEnvironment(): self
{
return new self(
smtpHost: self::requireEnv('SMTP_HOST'),
smtpPort: (int) self::requireEnv('SMTP_PORT'),
apiKey: self::requireEnv('MAILER_API_KEY'),
);
}
private static function requireEnv(string $name): string
{
return getenv($name) ?: throw new \RuntimeException(
sprintf('Environment variable %s is required', $name),
);
}
}
```
### 2. 基于文件的状态(Factor VI:进程)
```php
<?php
declare(strict_types=1);
// BAD: Persistent state in local filesystem
final class CounterService
{
public function increment(string $key): int
{
$file = '/var/data/counters/' . $key . '.txt';
$current = (int) file_get_contents($file);
file_put_contents($file, (string) ($current + 1));
return $current + 1;
// State lost on container restart, inconsistent across instances
}
}
// BAD: Cache stored in local files
final class FileCacheService
{
public function get(string $key): mixed
{
$path = '/tmp/cache/' . md5($key);
if (!file_exists($path)) {
return null;
}
return unserialize(file_get_contents($path));
}
}
// GOOD: State in external backing service
final readonly class CounterService
{
public function __construct(
private \Redis $redis,
) {}
public function increment(string $key): int
{
return $this->redis->incr('counter:' . $key);
}
}
```
### 3. 特定于环境的条件判断(Factor X:开发环境与生产环境等价)
```php
<?php
declare(strict_types=1);
// BAD: Behavior branches based on environment name
final class NotificationService
{
public function send(Notification $notification): void
{
if (getenv('APP_ENV') === 'production') {
$this->smsGateway->send($notification);
} else {
// Skip SMS in dev/staging
error_log('SMS skipped: ' . $notification->message());
}
}
}
// BAD: Different logic per environment
if ($_SERVER['APP_ENV'] === 'production') {
$cache = new RedisCache($redisHost);
} elseif ($_SERVER['APP_ENV'] === 'staging') {
$cache = new FileCache('/tmp/cache');
} else {
$cache = new ArrayCache();
}
// GOOD: Same code, different config per environment
// Use interfaces and inject implementation via DI container
final readonly class NotificationService
{
public function __construct(
private SmsGatewayInterface $smsGateway, // Real in prod, null/fake in dev
) {}
public function send(Notification $notification): void
{
$this->smsGateway->send($notification);
}
}
// services.yaml (production):
// SmsGatewayInterface: '@TwilioSmsGateway'
// services.yaml (development):
// SmsGatewayInterface: '@NullSmsGateway'
```
### 4. 非流式日志(Factor XI:日志)
```php
<?php
declare(strict_types=1);
// BAD: Writing logs to local files
final class Logger
{
public function log(string $message): void
{
file_put_contents(
'/var/log/app/application.log',
date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL,
FILE_APPEND,
);
// Log files grow unbounded, lost on container death
}
}
// BAD: Custom log rotation in application
final class RotatingLogger
{
public function log(string $message): void
{
$file = '/var/log/app/app-' . date('Y-m-d') . '.log';
file_put_contents($file, $message . PHP_EOL, FILE_APPEND);
// Application should NOT manage log rotation
$this->cleanOldLogs();
}
}
// GOOD: Write to stdout/stderr (event stream)
final readonly class StreamLogger implements LoggerInterface
{
public function log(mixed $level, string|\Stringable $message, array $context = []): void
{
$entry = json_encode([
'timestamp' => (new DateTimeImmutable())->format(DateTimeInterface::RFC3339),
'level' => $level,
'message' => (string) $message,
'context' => $context,
], JSON_THROW_ON_ERROR);
// Write to stderr -- container runtime captures this
fwrite(STDERR, $entry . PHP_EOL);
}
}
// GOOD: Monolog with stderr handler
// monolog.yaml:
// monolog:
// handlers:
// main:
// type: stream
// path: "php://stderr"
// level: info
// formatter: json
```
### 5. 缺少环境变量的使用(Factor III:配置)
```php
<?php
declare(strict_types=1);
// BAD: Configuration not driven by environment
final class AppConfig
{
public function getCacheDriver(): string
{
return 'redis'; // Hardcoded, cannot change without deploy
}
public function getMaxUploadSize(): int
{
return 10 * 1024 * 1024; // 10MB hardcoded
}
public function getApiBaseUrl(): string
{
return 'https://api.example.com/v2'; // Hardcoded URL
}
}
// GOOD: Environment-driven configuration
final readonly class AppConfig
{
public function __construct(
private string $cacheDriver,
private int $maxUploadSize,
private string $apiBaseUrl,
) {}
public static function fromEnvironment(): self
{
return new self(
cacheDriver: getenv('CACHE_DRIVER') ?: 'redis',
maxUploadSize: (int) (getenv('MAX_UPLOAD_SIZE') ?: '10485760'),
apiBaseUrl: getenv('API_BASE_URL') ?: throw new \RuntimeException('API_BASE_URL required'),
);
}
}
```
### 6. 硬编码后端服务(Factor IV:后端服务)
```php
<?php
declare(strict_types=1);
// BAD: Backing service URLs hardcoded
final class ExternalServices
{
public function getPaymentGateway(): PaymentClient
{
return new PaymentClient('https://api.stripe.com/v1');
}
public function getSearchEngine(): SearchClient
{
return new SearchClient('http://elasticsearch:9200');
}
public function getQueueConnection(): AMQPConnection
{
return new AMQPConnection('amqp://guest:guest@rabbitmq:5672/');
}
}
// GOOD: Backing services as attached resources via config
final readonly class ExternalServices
{
public function __construct(
private string $paymentGatewayUrl,
private string $searchEngineUrl,
private string $queueDsn,
) {}
public static function fromEnvironment(): self
{
return new self(
paymentGatewayUrl: getenv('PAYMENT_GATEWAY_URL')
?: throw new \RuntimeException('PAYMENT_GATEWAY_URL required'),
searchEngineUrl: getenv('SEARCH_ENGINE_URL')
?: throw new \RuntimeException('SEARCH_ENGINE_URL required'),
queueDsn: getenv('QUEUE_DSN')
?: throw new \RuntimeException('QUEUE_DSN required'),
);
}
public function getPaymentGateway(): PaymentClient
{
return new PaymentClient($this->paymentGatewayUrl);
}
public function getSearchEngine(): SearchClient
{
return new SearchClient($this->searchEngineUrl);
}
public function getQueueConnection(): AMQPConnection
{
return new AMQPConnection($this->queueDsn);
}
}
```
## Grep 模式
```bash
# Hardcoded configuration values (Factor III)
Grep: "= 'smtp\.|= 'redis://|= 'mysql://|= 'amqp://|= 'https?://" --glob "**/src/**/*.php"
Grep: "'localhost'|'127\.0\.0\.1'|:3306|:6379|:5672|:9200" --glob "**/src/**/*.php"
# Hardcoded credentials
Grep: "password.*=.*['\"]|apiKey.*=.*['\"]|secret.*=.*['\"]" --glob "**/src/**/*.php"
# File-based state (Factor VI)
Grep: "file_put_contents\(|file_get_contents\(.*var|fwrite\(.*tmp" --glob "**/src/**/*.php"
# Environment-specific conditionals (Factor X)
Grep: "APP_ENV.*===|getenv\(['\"]APP_ENV|SERVER\[.APP_ENV" --glob "**/src/**/*.php"
Grep: "=== 'production'|=== 'staging'|=== 'development'" --glob "**/src/**/*.php"
# Non-streaming logs (Factor XI)
Grep: "file_put_contents\(.*\.log|fopen\(.*\.log|error_log\(" --glob "**/src/**/*.php"
# Missing env var usage (Factor III)
Grep: "getenv\(|env\(|\\\$_ENV|_SERVER\[" --glob "**/src/**/*.php"
# Backing service URLs in code (Factor IV)
Grep: "new.*Client\(['\"]https?://|new.*Connection\(['\"]" --glob "**/src/**/*.php"
```
## 12-Factor 对照表
| 要素 | 名称 | 检查内容 |
|--------|------|---------------|
| I | 代码库 | 单一仓库,多次部署 |
| II | 依赖 | composer.json 声明所有依赖 |
| III | 配置 | 源码中没有硬编码配置 |
| IV | 后端服务 | URL/DSN 从环境中获取 |
| V | 构建、发布、运行 | 分离构建和运行阶段 |
| VI | 进程 | 无状态、无共享 |
| VII | 端口绑定 | 自包含,不依赖外部 Web 服务器 |
| VIII | 并发 | 通过进程模型扩展 |
| IX | 易处置性 | 快速启动,优雅关闭 |
| X | 开发环境与生产环境等价 | 尽量缩小环境之间的差异 |
| XI | 日志 | 将日志视为事件流 |
| XII | 管理进程 | 将一次性管理任务作为进程运行 |
## 严重程度分类
| 模式 | 严重程度 |
|---------|----------|
| 源代码中的硬编码凭据 | 🔴 严重 |
| 硬编码的数据库/服务 URL | 🟠 重大 |
| 基于文件的持久状态 | 🟠 重大 |
| 特定于环境的条件判断 | 🟠 重大 |
| 非流式日志(基于文件)| 🟠 重大 |
| 硬编码的非机密配置值 | 🟡 次要 |
| 可选设置缺少环境变量 | 🟡 次要 |
## 输出格式
```markdown
### 12-Factor Violation: [Factor Name] -- [Brief Description]
**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Factor:** [III Config|IV Backing Services|VI Processes|X Dev/Prod Parity|XI Logs]
**Issue:**
[Description of the 12-Factor violation]
**Impact:**
- Cannot deploy to different environments without code change
- State lost on container restart
- Logs lost when instance terminates
**Code:**
```php
// Non-compliant code
```
**Fix:**
```php
// 12-Factor compliant code
```
```
## When This Is Acceptable
- **Framework defaults** -- Framework-provided defaults (like Monolog file handler in dev) are standard practice
- **Constants** -- Truly constant values (HTTP status codes, mathematical constants) belong in code
- **Test configuration** -- Test suites may use hardcoded config for reproducibility
- **CLI tools** -- Local development tools may use filesystem legitimately
### False Positive Indicators
- Value is a mathematical or protocol constant, not a deployment config
- Hardcoded value is a default with environment override: `getenv('X') ?: 'default'`
- File path is for temporary processing, not persistent state
- Code is in a test file, fixture, or seed script同类提示词
商业与职场
招聘面试轮次与面试官排期
提供岗位要求和面试官的可用时间,规划各轮评估内容、人员搭配及面试顺序,并起草题库和候选人通知。
# 面试安排 > 设计高效的面试流程,优化面试小组构成和日程安排,带来良好的候选人体验。 ## 何时使用此技能 - 设置多轮面试流程 - 协调面试小组日程 - 设计面试阶段 - 优化候选人体验 - 创建面试执行手册 ## 方法论基础 基于**结构化面试最佳实践**和**候选人体验研究**,结合: - 与阶段相适应的评估 - 面试小组多样性要求 - 招聘周期优化 - 候选人沟通 ## Claude的工作与由你决定的事项 | Claude的工作 | 由你决定 | |-------------|------------| | 设计面试阶段 | 最
可填 1 项
商业与职场
十五镜头产品营销视频分镜
填写营销文案与产品外观描述,按开场钩子、故事和促销安排分镜,逐条标明产品镜头或场景镜头。
你是一位精通营销心理学的商业视频分镜师。请根据营销文本和产品外观描述,创建具有强营销力的15个分镜。 营销文本:{text} 产品外观描述:{image} 【核心标记规则】⚠️ 极其重要 每个分镜必须在开头使用以下标记之一: - [产品镜头] - 画面中包含产品实体,需要保持产品外观一致性 - [场景镜头] - 不包含产品的纯环境、人物或情境画面 标记决定后端使用哪个生成模型,必须准确标注! 【营销策略分析】(内部分析,不输出) 分析营销文本,提取以下信息用于指导分镜创作: 1. 目标受众:识别目标人群特征,确定画面风格和场景选择 2. 核心卖点可填 2 项中文原创
商业与职场
等距分层与爆炸图动画
为产品演示或信息图制作 2.5D 场景,用统一投影和分面明暗表现立体感,支持层叠展开及爆炸图动画。
# 等轴测(2.5D)动画 等轴测场景无需使用真正的透视,就能让讲解动画、UI 操作演示和信息图呈现出搭建而成的立体感:各轴等比例缩短、Z 轴方向堆叠的层级、拉伸立体块、爆炸图。整体风格几何感强、构图讲究——深度来自一致的轴向和各面的明暗处理,动效则通过逐层展示结构来实现。 ## 适用场景 - 用于讲解动画、产品 UI 或“工作原理”信息图的 2.5D 场景。 - 从下往上搭建的堆叠层级 / 楼层 / 技术栈塔。 - 拉伸立体块、等轴测网格、等轴测城市 / 服务器机架场景。 - 沿 Z 轴拆开再重新组装的爆炸图。 - 需要增添轻微生动感的静态等轴测
商业与职场
六页电影感演示文稿设计总览
选择浅色或深色方向,用图像模型把六页幻灯片合成一张电影感概览图,适合演示提案和版式评审。
# 演示文稿设计 创建一张**高端 6 页演示文稿设计展板**,将所有幻灯片合成为一张图片——让用户一眼看完整套演示文稿,适合电视屏幕展示,具有电影感。 主要用途:PPT 设计概念、主题演讲风格的幻灯片设计稿、战略演示文稿视觉方案、活动 / 新闻 / 体育 / 商业分析演示文稿、编辑式数据故事、高管演示文稿。 ## 图像生成要求 最终展板必须由**图像生成模型**生成(默认使用内置的 `image_gen` 工具,或经批准的项目图像生成工作流)。不要使用代码、SVG、HTML/CSS、canvas、图表、占位图或确定性形状脚本创建展板。这些方法只
商业与职场
十五款AI视频模型选型顾问
回答三至四个需求问题,按中文表现、音频、编辑能力、时长和可用性等条件获取模型推荐及理由。
# model-selector 15 个主流 AI 视频模型(11 商业 + 4 开源)的"购物顾问"。问用户 3-4 个关键问题,给出推荐 + 理由。 ## 何时不用此 skill - 用户已经确定要用某个模型 → 用对应的 `<model>-prompter` skill - 用户问"提示词怎么写" → 用 `seedance-prompter` / `kling-prompter` / `happyhorse-prompter` - 用户的提示词不工作 → 用 `seedance-debugger` ## 11 模型能力速查矩阵 | 模
中文原创
商业与职场
界面创意转视觉设计规格
填写界面用途、受众、尺寸和文案,将初步构想细化为包含网格、字体、配色与图像风格的设计规格。
# 设计优先的 UI 提示词技能 此技能适用于**设计优先的提示词编写**:将模糊的想法转化为严谨的规格说明,生成风格一致的 UI。 ## 核心原则 **像设计系统一样编写提示词,而不是许愿。** ## 提示词结构(复制/粘贴) 使用以下框架,然后填入空白。 ```text GOAL - What are we making? (e.g., landing page hero / onboarding / dashboard / carousel slide) - Who is it for? (persona) - What’s the suc