{"action":"created","issue":{"url":"https://api.github.com/repos/NetCommons3/NetCommons3/issues/60","labels_url":"https://api.github.com/repos/NetCommons3/NetCommons3/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/NetCommons3/NetCommons3/issues/60/comments","events_url":"https://api.github.com/repos/NetCommons3/NetCommons3/issues/60/events","html_url":"https://github.com/NetCommons3/NetCommons3/issues/60","id":121182125,"number":60,"title":"PermissionComponent::initialize()メソッド処理","user":{"login":"kteraguchi","id":3079266,"avatar_url":"https://avatars.githubusercontent.com/u/3079266?v=3","gravatar_id":"","url":"https://api.github.com/users/kteraguchi","html_url":"https://github.com/kteraguchi","followers_url":"https://api.github.com/users/kteraguchi/followers","following_url":"https://api.github.com/users/kteraguchi/following{/other_user}","gists_url":"https://api.github.com/users/kteraguchi/gists{/gist_id}","starred_url":"https://api.github.com/users/kteraguchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kteraguchi/subscriptions","organizations_url":"https://api.github.com/users/kteraguchi/orgs","repos_url":"https://api.github.com/users/kteraguchi/repos","events_url":"https://api.github.com/users/kteraguchi/events{/privacy}","received_events_url":"https://api.github.com/users/kteraguchi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NetCommons3/NetCommons3/labels/00Inbox","name":"00Inbox","color":"bfdadc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-09T07:53:23Z","updated_at":"2015-12-16T03:08:24Z","closed_at":null,"body":"https://github.com/NetCommons3/NetCommons/blob/master/Controller/Component/PermissionComponent.php#L119-L144\r\n\r\nのループ処理の正常結果が、よく分からないです。\r\n\r\nPermissionComponent::allowプロパティのデフォルトがarray('index,view' => null);になっています。\r\nデフォルト値のまま、PermissionComponent::initialize()メソッドを通ると、\r\nPermissionComponent::allowプロパティの値は\r\narray('index' => null)になります。\r\n\r\narray(\r\n    'index' => 'content_readable',\r\n    'view' => 'content_readable'\r\n)\r\nが正しい値だと思っているのですが、違うのでしょうか？"},"comment":{"url":"https://api.github.com/repos/NetCommons3/NetCommons3/issues/comments/164972557","html_url":"https://github.com/NetCommons3/NetCommons3/issues/60#issuecomment-164972557","issue_url":"https://api.github.com/repos/NetCommons3/NetCommons3/issues/60","id":164972557,"user":{"login":"kteraguchi","id":3079266,"avatar_url":"https://avatars.githubusercontent.com/u/3079266?v=3","gravatar_id":"","url":"https://api.github.com/users/kteraguchi","html_url":"https://github.com/kteraguchi","followers_url":"https://api.github.com/users/kteraguchi/followers","following_url":"https://api.github.com/users/kteraguchi/following{/other_user}","gists_url":"https://api.github.com/users/kteraguchi/gists{/gist_id}","starred_url":"https://api.github.com/users/kteraguchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kteraguchi/subscriptions","organizations_url":"https://api.github.com/users/kteraguchi/orgs","repos_url":"https://api.github.com/users/kteraguchi/repos","events_url":"https://api.github.com/users/kteraguchi/events{/privacy}","received_events_url":"https://api.github.com/users/kteraguchi/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T03:08:24Z","updated_at":"2015-12-16T03:08:24Z","body":"参考情報です。\r\n\r\nPermissionComponent::allowプロパティは、カンマ区切り指定されてるkeyをばらして操作してます。\r\n例えば、\r\n```\r\nPermissionComponent::allow =  array(\r\n    'foo,bar' => 'content_readable'\r\n);\r\n ```\r\nだと、PermissionComponent::initialize()の結果、\r\n```\r\nPermissionComponent::allow =  array(\r\n    'foo' => 'content_readable',\r\n    'bar' => 'content_readable'\r\n);\r\n```\r\nになります。\r\n\r\nアクションが実行されると、\r\n[NetCommonsAppControllerで設定されている値](https://github.com/NetCommons3/NetCommons/blob/6232f8c9ab7b7ca1d30645b286bfc832446a7dc3/Controller/NetCommonsAppController.php#L66-L72)と、プラグインのコントローラーで設定されている値がマージされます。\r\nhttps://github.com/cakephp/cakephp/blob/2a290e3e85468e045e9830308d549dc96762eebc/lib/Cake/Controller/Controller.php#L558-L567\r\n\r\nマージはkey値で行われるため、\r\n例えば、\r\n```\r\npublic $components = array(\r\n    'NetCommons.Permission' => array(\r\n        'allow' => array(\r\n            'foo' => '111',\r\n            'bar' => '222'\r\n        )\r\n    );\r\n```\r\nと\r\n```\r\npublic $components = array(\r\n    'NetCommons.Permission' => array(\r\n        'allow' => array(\r\n            'foo,bar' => '333'\r\n        )\r\n    );\r\n```\r\nをマージすると、PermissionComponent::allowは\r\n```\r\narray(\r\n    'foo' => '111',\r\n    'bar' => '222',\r\n     'foo,bar' => '333'\r\n);\r\n```\r\nになります。\r\nこの状態で、PermissionComponent::initialize()通ると、\r\n```\r\nPermissionComponent::allow =  array(\r\n    'foo' => array('333'),\r\n    'bar' => array('333')\r\n);\r\n```\r\nになります。\r\n\r\nマージ処理は、配列の値に空配列を指定すると上書きされない点も要注意です。\r\n```\r\npublic $components = array(\r\n    'NetCommons.Permission' => array(\r\n        'allow' => array(\r\n            'foo,bar' => '111'\r\n        )\r\n    );\r\n```\r\nと\r\n```\r\npublic $components = array(\r\n    'NetCommons.Permission' => array(\r\n        'allow' => array()\r\n    );\r\n```\r\nをマージすると、PermissionComponent::allowは\r\n```\r\narray(\r\n    'foo,bar' => '111'\r\n);\r\n```\r\nのままです。\r\n\r\nレビュー時に自分で整理しときたいのでためあげときます。\r\n"}}