Skip to content

Commit 00bddb7

Browse files
committed
初始化
0 parents commit 00bddb7

22 files changed

+492
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
!/bin/.gitkeep
2+
3+
/vendor/
4+
/node_modules/
5+
/composer.lock
6+
7+
/etc/build/*
8+
!/etc/build/.gitkeep
9+
10+
.idea/*

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# PHPDish Plugin Skeleton
2+
3+
创建 PHPDish 用到的样例代码。
4+
5+
## Installation
6+
7+
1. 在你的 PHPDish 项目下执行下面命令下载代码;
8+
9+
```
10+
$ composer create-project phpdish/plugin-skeleton ProjectName
11+
```
12+
13+
2. 重命名 `src/AcmePHPDishExamplePlugin.php` 文件为你的插件名称;
14+
15+
例如:你的插件名称为 `phpdish-email-plugin`,那么本文件名为 `VendorPHPDishEmailPlugin`
16+
其中vendor是你的名称代号,表示你是这个插件的提供商。
17+
18+
3. 替换命名空间为你的名称开头,如果你不想做这个事情可以省略。
19+
20+
4. 修改的 `composer.json` 文件,把这个插件的命名空间写入自动加载;
21+
22+
```json
23+
{
24+
"autoload": {
25+
"psr-4": {
26+
"Vendor\\PHPDishEmailPlugin\\": "src/"
27+
}
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"Vendor\\PHPDishEmailPlugin\\Tests\\": "tests/"
32+
}
33+
},
34+
}
35+
```
36+
注意,在插件的开发阶段,为确保你的插件会被项目加载,你需要把上面提到的加载项也写入到 `PHPDish``composer.json` 文件
37+
里去。
38+
39+
40+

bin/.gitkeep

Whitespace-only changes.

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "phpdish/daily-song-plugin",
3+
"type": "phpdish-plugin",
4+
"description": "Daily song plugin for phpdish application",
5+
"license": "MIT",
6+
"require": {
7+
"php": "^7.1",
8+
"phpdish/phpdish": "*@beta"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "^5.6|^6.0"
12+
},
13+
"prefer-stable": true,
14+
"autoload": {
15+
"psr-4": {
16+
"PHPDish\\DailySongPlugin\\": "src/"
17+
}
18+
},
19+
"autoload-dev": {
20+
"psr-4": {
21+
"PHPDish\\DailySongPlugin\\Tests\\": "tests/"
22+
}
23+
},
24+
"config": {
25+
"bin-dir": "bin"
26+
}
27+
}

phpunit.xml.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.6/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php">
8+
<testsuites>
9+
<testsuite name="AcmePHPDishExamplePlugin Test Suite">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
14+
<php>
15+
<server name="KERNEL_CLASS_PATH" value="/tests/Application/AppKernel.php" />
16+
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
17+
</php>
18+
</phpunit>

src/Admin/SongAdmin.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace PHPDish\DailySongPlugin\Admin;
4+
5+
use Sonata\AdminBundle\Admin\AbstractAdmin;
6+
use Sonata\AdminBundle\Datagrid\DatagridMapper;
7+
use Sonata\AdminBundle\Datagrid\ListMapper;
8+
use Sonata\AdminBundle\Form\FormMapper;
9+
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
10+
use Sonata\AdminBundle\Route\RouteCollection;
11+
use Sonata\CoreBundle\Form\FormHelper;
12+
13+
class SongAdmin extends AbstractAdmin
14+
{
15+
protected function configureDatagridFilters(DatagridMapper $filter)
16+
{
17+
$filter
18+
->add('name', null);
19+
}
20+
21+
protected function configureListFields(ListMapper $list)
22+
{
23+
$list
24+
->addIdentifier('name', null, ['label'=>'标题'])
25+
->add('src', null, ['label'=>'URL'])
26+
->add('srcId', null, ['label'=>'歌曲ID'])
27+
->add('enabled', null, ['editable'=>true, 'label' => '状态']);
28+
}
29+
30+
protected function configureFormFields(FormMapper $form)
31+
{
32+
$form
33+
->add('name', null, ['label'=>'标题'])
34+
->add('src', null, ['label'=>'URL'])
35+
->add('srcId', null, ['label'=>'歌曲ID'])
36+
->add('enabled', null, ['label' => '状态']);
37+
}
38+
}

src/Controller/SongController.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace PHPDish\DailySongPlugin\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Response;
7+
8+
class SongController extends Controller
9+
{
10+
/**
11+
* 获取最近的一首歌
12+
*
13+
* @return Response
14+
*/
15+
public function getSongAction()
16+
{
17+
$manager = $this->get('phpdish.manager.song');
18+
dump($manager->getLatestSong());
19+
return $this->render('PHPDishDailySongPlugin::_daily_song.html.twig', [
20+
'song' => $manager->getLatestSong()
21+
]);
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPDish\DailySongPlugin\DependencyInjection;
6+
7+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8+
use Symfony\Component\Config\Definition\ConfigurationInterface;
9+
10+
final class Configuration implements ConfigurationInterface
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function getConfigTreeBuilder(): TreeBuilder
16+
{
17+
$treeBuilder = new TreeBuilder();
18+
$rootNode = $treeBuilder->root('phpdish_daily_song');
19+
20+
return $treeBuilder;
21+
}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPDish\DailySongPlugin\DependencyInjection;
6+
7+
use Symfony\Component\Config\FileLocator;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\DependencyInjection\Extension\Extension;
10+
use Symfony\Component\DependencyInjection\Loader;
11+
12+
final class PHPDishDailySongExtension extends Extension
13+
{
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
public function load(array $config, ContainerBuilder $container): void
18+
{
19+
$config = $this->processConfiguration($this->getConfiguration([], $container), $config);
20+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
21+
22+
$loader->load('services.yml');
23+
}
24+
}

src/Entity/Song.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace PHPDish\DailySongPlugin\Entity;
4+
5+
use Carbon\Carbon;
6+
use PHPDish\Bundle\CoreBundle\Model\DateTimeTrait;
7+
use PHPDish\Bundle\CoreBundle\Model\EnabledTrait;
8+
use PHPDish\Bundle\CoreBundle\Model\IdentifiableTrait;
9+
use PHPDish\DailySongPlugin\Model\SongInterface;
10+
11+
class Song implements SongInterface
12+
{
13+
use IdentifiableTrait;
14+
use DateTimeTrait;
15+
use EnabledTrait;
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $name;
21+
22+
/**
23+
* @var string
24+
*/
25+
protected $srcId;
26+
27+
/**
28+
* @var string
29+
*/
30+
protected $src;
31+
32+
public function __construct()
33+
{
34+
$this->createdAt = $this->updatedAt = Carbon::now();
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getName()
41+
{
42+
return $this->name;
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function setName($name)
49+
{
50+
$this->name = $name;
51+
return $this;
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function getSrcId()
58+
{
59+
return $this->srcId;
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
public function setSrcId($srcId)
66+
{
67+
$this->srcId = $srcId;
68+
return $this;
69+
}
70+
71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public function getSrc()
75+
{
76+
return $this->src;
77+
}
78+
79+
/**
80+
* {@inheritdoc}
81+
*/
82+
public function setSrc($src)
83+
{
84+
$this->src = $src;
85+
return $this;
86+
}
87+
}

0 commit comments

Comments
 (0)