doushaju4901 2016-03-29 13:40
浏览 54
已采纳

使用公共资源为Composer创建PHP库

I'm creating a Template library for a client. The goal of the library is to provide a standardized shell for all the websites the company owns. Other developers should be able to import the library with Composer and create a base template with a few lines of code, e.g.:

$Template = new Template;
$Template->setContent('Hello world!');
$Template->render();

This will render the content inside the standardized shell. This is a simplified example, the library provides much more functionality such as standardized sliders, menu's etc...

This library depends on Twig, but it also depends on a bunch of front-end assets; like custom images, javascripts, css and 3rd party stuff like Jquery and Bootstrap CSS. Those assets are stored in the /assets/ folder.

After installing the library with Composer, everything is stored in the /vendors/ folder, which is in the root of the website. But the /assets/ folder needs to be in the /public_html/ to be accessible.

The solution for now: just copy the /assets/ folder to the /public_html/. But I'm sure there are more repositories depending on front-end assets, what is the most common way to make those assets available in /public_html/?

  • 写回答

2条回答 默认 最新

  • dongyuelian9602 2016-03-29 13:53
    关注

    The closes thing which comes into my mind is the Symfony2 Bundle system. Each bundle you define must be registered in the AppKernel. If the bundle contains assets that will be linked or copied under the /web/bundles/short_bundle_name/ folder.

    So to be able to follow up your dependencies' assets you will need some kind of registry mechanism, so you can register which libs has assets what needs to be copied over / linked under the public_html folder.

    Also consider using assetic to process your plain assets (merge, rewrite and other filters) with cache-busting capabilities.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示