小编JCM*_*JCM的帖子

这是策略模式的一个很好的用例吗?

我正在使用需要接收多个视频的应用程序,并将其显示在特定页面上,目前这些视频只能来自YouTube,因为实现不允许其他提供商,因为获取视频数据的代码作为预览图像,直接放置在负责显示视频的View Helper中.

我想改变这种结构,可以很容易地添加新的供应商,如Vimeo的,我认为策略模式将是理想的,我会在我的视图助手的方法setVideoUrl( string $url ),这种方法会调用该方法getProviderStrategy( string $url )class VideoProviderFactory,这然后,工厂类将返回策略类(如果可用),该类interface VideoProvider为视频URL的提供者实现.

你怎么看?这是对的?我需要改变什么?

细节:我最初考虑过将一个开关直接选择到View Helper中,但在阅读完这个问题之后:我没有'switch'语句的策略模式?我看到我错了,然后class VideoProviderFactory出现了.

php language-agnostic design-patterns strategy-pattern factory-pattern

4
推荐指数
1
解决办法
532
查看次数

使用igbinary安装php redis,找不到头文件

我正在尝试安装phpredis扩展,但没有运气.

运行该命令后./configure --enable-redis-igbinary,我收到以下错误:

检查igbinary包括... configure:错误:找不到igbinary.h

igbinary是使用PECL安装的,但看起来没有找到头文件.

php centos pecl igbinary phpredis

4
推荐指数
1
解决办法
8711
查看次数

Symfony2从具有ManyToMany关系的倒置实体获取对象

我正面临着我的学说实体关系的问题.这是事情:

我有2个实体:文章和类别文章是主文章,类别是奴隶

我想从文章中获取分类,而从类别中获取文章.

我做了一个像这样的ManyToMany关系:

class Article
{
    /**
     * @ORM\ManyToMany(targetEntity="Alpha\BlogBundle\Entity\Category", cascade={"persist"}, inversedBy="Article")
     * @ORM\JoinTable(name="article_category")
     */
    private $categories;
Run Code Online (Sandbox Code Playgroud)

public function __construct(){
    $this->categories = new \Doctrine\Common\Collections\ArrayCollection();
Run Code Online (Sandbox Code Playgroud)

和类别实体:

class Category
{
    /**
     * @ORM\ManyToMany(targetEntity="Alpha\BlogBundle\Entity\Article", cascade={"persist"}, mappedBy="Category")
     */
    private $articles;
Run Code Online (Sandbox Code Playgroud)

public function __construct(){
    $this->articles = new \Doctrine\Common\Collections\ArrayCollection();
Run Code Online (Sandbox Code Playgroud)

在我的文章实体中,我还添加了以下内容:

public function addCategory(\Alpha\BlogBundle\Entity\Category $categories)
{
    $this->categories[] = $categories;
    $categories->addArticle($this);
    return $this;
}
Run Code Online (Sandbox Code Playgroud)

(第四行$categories->addArticle($this);)

在我的控制器中:

public function ajouterAction($data = null, $id = null) {

    // On récupère l'EM pour enregistrer en BDD
    $em …
Run Code Online (Sandbox Code Playgroud)

php orm entity-relationship symfony doctrine-orm

4
推荐指数
1
解决办法
1856
查看次数

我可以将jQuery UI对话框置于div中吗?

我有一个主内容div,我想把对话框放在那个div上,而不是页面上.有任何想法吗?我知道有一个位置实用程序,但我无法弄清楚如何将它与对话框位置选项一起使用.

jquery jquery-ui jquery-ui-dialog

3
推荐指数
1
解决办法
4016
查看次数

Zend Acl - 模块,控制器,动作和模型

我花了一天时间寻找有关如何在SO处实现Zend_Acl的教程和答案,就像在其他站点一样.我很头疼.:X

我看到有人使用它来允许或禁止访问某些控制器/操作,而其他人则说这种方式不正确,并且应该允许或禁止基于模型的访问.嗯,第二个似乎可行,但是,这意味着对于每个控制器我需要一个模型?因为看起来,在第二种选择之后,我只能阻止用户访问,例如编辑帖子.但我想阻止访问编辑帖子的控制器的操作.

如果我想阻止对角色X的用户访问控制器Z的动作Y,如果我遵循第二种选择,我该怎么做?

一个真正的应用程序的例子将非常受欢迎.

这些信息可以改善您的答案: 我使用Doctrine 2作为ORM,我有一个模块Admin.我的应用程序的实际结构是这样的:

application
  - MYAPP
    - configs
    - controllers
    - layouts
    - views
    - library
       - MYAPP ;This folder is in the include path
    - modules
       - admin
Run Code Online (Sandbox Code Playgroud)

php model-view-controller zend-framework zend-acl doctrine-orm

2
推荐指数
1
解决办法
1082
查看次数

Relay使用什么来决定在变异响应中包含哪些outputFields?

我通过修改TODO示例创建了我的第一个React/Relay应用程序.我正在为一个具有参数bookCount的对象Distributor添加我自己的变异.该变异称为AddBook,只是将书数增加1.此时,突变执行时没有错误,乐观地将bookCount正确地增加1,但是当它从服务器接收响应时恢复模型更改.我相信这是因为来自服务器的响应神秘地不包含任何我指定的outputFields.

这是我的突变:

var GraphQLAddBookMutation = mutationWithClientMutationId({
  name: 'AddBook',
  inputFields: {
  },
  outputFields: {
    distributor: {
      type: GraphQlDistributor,
      resolve: () => getDistributor(),
    },
  },
  mutateAndGetPayload: () => {
    console.log("Trying to mutate.");
    addBook();
    return {};
  },
});
Run Code Online (Sandbox Code Playgroud)

它包含outputFields中的字段"distributor",但graphql响应中不包含"distributor"数据.

graphql响应是:

{
  "data": {
  "addBook": {
    "clientMutationId": "0"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我已经验证了mutateAndGetPayload函数被调用但是分发器解析函数没有被调用.

我希望outputFields中的每个字段都包含在graphql响应中,并调用outputFields中的每个resolve函数来填充响应中的相应参数,但事实并非如此

这对我来说尤其令人困惑,因为生成的schema.json包含我在AddBookPayload中指定的任何outputField:

{
      "kind": "OBJECT",
      "name": "AddBookPayload",
      "description": null,
      "fields": [
        {
          "name": "distributor",
          "description": null,
          "args": [],
          "type": {
            "kind": "OBJECT",
            "name": "Distributor",
            "ofType": null
          },
          "isDeprecated": false,
          "deprecationReason": null
        }, …
Run Code Online (Sandbox Code Playgroud)

javascript relayjs

2
推荐指数
1
解决办法
847
查看次数

React Relay更新根查询作为变异胖查询的一部分

我正在尝试使用GraphQL和React Relay构建应用程序.

作为其中的一部分,我使用以下规范创建了一个根查询:

query {
  AllServices {
    edges {
      node {
        id
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

所以我创建了一个名为CreateGithubService的突变 - 效果很好.

以下是Relay变异的片段:

getFatQuery() {
      return Relay.QL`
        fragment on CreateGithubServicePayload {
          createdService
        }
      `
  }

  getConfigs() {
      return [{
          type: "REQUIRED_CHILDREN",
          children: [
              Relay.QL`
                  fragment on CreateGithubServicePayload {
                      createdService {
                          id
                      }
                  }
              `
          ]
      }]
  }
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是这不会导致依赖于信息更新的视图.

我的AllServices查询未被重新获取,我无法在Fat Query中指定它.

如何设置我的变异以将元素添加到所有服务查询?

谢谢!

reactjs graphql graphql-js relayjs

2
推荐指数
1
解决办法
825
查看次数

Relay抱怨片段变量,但没有片段有变量

我正在学习接力,我让它工作,但有时感觉就像是偶然的:)

我很抱歉,如果我在这里犯了初学者的错误,我已经阅读了手册和所有的例子,但我似乎无法绕过这一切.

无论如何,我现在有以下问题.

我的架构如下所示:

{
    viewer(token:$anAuthToken) {
        actor {
          id,
          email,
          ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

所有数据都在{viewer}下访问,后者负责身份验证.演员领域只是其中之一.

Actor是UserType的实例,即当前登录的用户.

我想要一个理智的组件层次结构,其中顶级组件仅将用户作为props(并为其所需的属性提供片段).但据Relay说,我做得不对,而且我不确定我做错了什么.

我的代码看起来像这样(此刻非常混乱,因为我测试了一些东西):

class UserRegistrationPage extends React.Component {

    render() {
        const user = this.props.user;
        return (
            <View>
                <Text>Email: {user.email}</Text>
            </View>
        );
    }

    submit(model) {
        const user = this.props.user;

        this.props.relay.commitUpdate(
            new UpdateUserMutation({
                id: user.id,
                ...model
            }, {
                onSuccess: response => {
                    console.log("SUCCESS!");
                    console.log(response);
                },
                onFailure: () => {
                    console.log("FAIL!");
                }
            }));
    }

}

UserRegistrationPage = Relay.createContainer(UserRegistrationPage, {
    fragments: {
        user: () => Relay.QL`
            fragment on …
Run Code Online (Sandbox Code Playgroud)

graphql relayjs

2
推荐指数
1
解决办法
921
查看次数

如何增加在 Typescript 模块上声明但未导出的类

hubot类型定义有以下类:

declare namespace Hubot {
    // ...

    class Message {
        user: User;
        text: string;
        id: string;
    }

    // ...
}

// Compatibility with CommonJS syntax exported by Hubot's CoffeeScript.
// tslint:disable-next-line export-just-namespace
export = Hubot;
export as namespace Hubot;
Run Code Online (Sandbox Code Playgroud)

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a6b283d1d43d8c7c82a4a4e22d0fc27c9964154c/types/hubot/index.d.ts#L18-L22

我想Message从我的代码中增加这个类,在hubot.d.ts我编写的文件中:

import * as hubot from 'hubot';

declare namespace Hubot {
  export class Message {
    mentions: string[]
  }
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用: 在此处输入图片说明

hubot.d.ts文件包含在代码中

  "files": ["types/custom/hubot.d.ts"]
Run Code Online (Sandbox Code Playgroud)

tsconfig.json文件中。

我缺少什么?有没有办法做到这一点?

javascript types typescript

2
推荐指数
1
解决办法
656
查看次数

如何用变量组合查询片段

我正在使用Relay并且react-router-relay正在尝试组合几个Relay容器.内部容器需要一个查询片段变量,该变量必须从路由器向下传递到其父容器.它没有得到这个变量.

以下是代码的外观:

//  A "viewer":

const UserQueries = { user: () => Relay.QL`query { user }` };

//  A route to compose a message:

<Route                                                                                                                                                                                  
  path='/compose/:id'                                                                                                                                                                          
  component={ ComposeContainer }                                                                                                                                                               
  queries={ UserQueries }                                                                                                                                                             
/>

//  A container:

const ComposeContainer = Relay.createContainer(
  Compose,
  {
    initialVariables: {
      id: null
    },                                                                                                                                                                                                                                                                                                                                                                                                  
    fragments: {                                                                                                                                                                                        
      user: () => Relay.QL`                                                                                                                                                                           
        fragment on User {                                                                                                                                                                          
          ${ BodyContainer.getFragment('user') }                                                                                                                                                           
          // other fragments                                                                                                                                              
        }                                                                                                                                                                                            
      `                                                                                                                                                                                               
     }
  }
);

//  And the composed container:

const BodyContainer = React.createContainer(
  Body, …
Run Code Online (Sandbox Code Playgroud)

javascript relayjs

1
推荐指数
1
解决办法
1865
查看次数

使用RelayRouter投掷无效状态更改错误导航relay.js应用程序

我正在写一个relay.js应用程序,我正在使用react-relay-router进行路由.路由工作,但我相信它暴露了我如何跨不同视图组织查询片段的误解.

app.js中定义的路由

const rootComponent =
  (<RelayRouter history={hashHistory}>
    <Route path="/"
      component={App}
      queries={ViewerQueries}
      onReadyStateChange={this.handleStateChange}
    >
      <IndexRoute
        component={Dashboard}
        queries={ViewerQueries}
      />
      <Route
        path="/org_setup"
        component={OrgSetup}
        queries={ViewerQueries}
      />
      <Route
        path="/admin/data_models"
        component={DataModelList}
        queries={ViewerQueries}
      />
    </Route>
  </RelayRouter>);
ReactDOM.render(rootComponent, mountNode);
Run Code Online (Sandbox Code Playgroud)

DataModelList.js中的查询片段声明

export default Relay.createContainer(DataModelList, {
  fragments: {
    viewer: () => Relay.QL`
      fragment on User {
        dataModels(first: 10) {
          edges {
            node {
              id,
              name,
              isAuthority,
              categories(first: 10) {
                edges {
                  node {
                    id,
                    name,
                    tags(first: 10) {
                      edges {
                        node {
                          id,
                          code,
                          label,
                        } …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router graphql relayjs

1
推荐指数
1
解决办法
676
查看次数