Plugin Directory

Changeset 2786914


Ignore:
Timestamp:
09/19/2022 11:39:41 AM (3 years ago)
Author:
pmpr
Message:

fix a bug

Location:
pmpr-ir
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pmpr-ir/tags/1.2.1/src/Pmpr/Plugin/Pmpr/Ajax.php

    r2784464 r2786914  
    178178                        case 'update':
    179179
     180                            $this->fetchCommonComponents(true);
    180181                            $fetched = API::getInstance()->getComponent($name);
    181182                            if ($fetched && !is_wp_error($fetched)
  • pmpr-ir/tags/1.2.1/src/Pmpr/Plugin/Pmpr/Component/Item.php

    r2784023 r2786914  
    33namespace Pmpr\Plugin\Pmpr\Component;
    44
     5use Exception;
    56use Pmpr\Plugin\Pmpr\Interfaces\ConstantInterface;
    67use Pmpr\Plugin\Pmpr\Manipulate;
     
    1920
    2021    /**
     22     * @var array|object
     23     */
     24    protected $composer = [];
     25
     26    /**
    2127     * @var int|string|null
    2228     */
     
    126132                }
    127133            }
     134
     135            $composerPath = trailingslashit(Manipulate::getComponentsRootPath($this->getTypeSlug())) . trailingslashit($this->getName()) . 'composer.json';
     136            if (file_exists($composerPath)) {
     137
     138                $fields = wp_json_file_decode($composerPath);
     139                if (is_array($fields) || is_object($fields)) {
     140
     141                    $this->composer = (array)$fields;
     142                }
     143            }
    128144        }
    129145    }
     
    132148     * @return array|object
    133149     */
     150    public function getComposer()
     151    {
     152        return $this->composer;
     153    }
     154
     155    /**
     156     * @param $key
     157     * @param $default
     158     *
     159     * @return mixed
     160     */
     161    public function getComposerField($key, $default = null)
     162    {
     163        return Manipulate::getArrayItem($this->getComposer(), $key, $default);
     164    }
     165
     166    /**
     167     * @return array|object
     168     */
    134169    public function getData()
    135170    {
     
    166201    public function getVersion(): ?string
    167202    {
    168         return $this->version;
     203        return $this->getComposerField(self::VERSION, $this->version);
    169204    }
    170205
     
    242277
    243278    /**
    244      * @return string|null
    245      */
    246     public function getSlug(): ?string
     279     * @return string
     280     */
     281    public function getTypeSlug(): string
    247282    {
    248283        $type = '';
     
    261296                break;
    262297        }
    263 
     298        return $type;
     299    }
     300
     301    /**
     302     * @return string|null
     303     */
     304    public function getSlug(): ?string
     305    {
     306        $type = $this->getTypeSlug();
    264307        $name = str_replace("wp-{$type}-", '', $this->getName());
    265308        return "pr__{$type}__" . str_replace('-', '_', $name);
  • pmpr-ir/trunk/src/Pmpr/Plugin/Pmpr/Ajax.php

    r2784464 r2786914  
    178178                        case 'update':
    179179
     180                            $this->fetchCommonComponents(true);
    180181                            $fetched = API::getInstance()->getComponent($name);
    181182                            if ($fetched && !is_wp_error($fetched)
  • pmpr-ir/trunk/src/Pmpr/Plugin/Pmpr/Component/Item.php

    r2784023 r2786914  
    33namespace Pmpr\Plugin\Pmpr\Component;
    44
     5use Exception;
    56use Pmpr\Plugin\Pmpr\Interfaces\ConstantInterface;
    67use Pmpr\Plugin\Pmpr\Manipulate;
     
    1920
    2021    /**
     22     * @var array|object
     23     */
     24    protected $composer = [];
     25
     26    /**
    2127     * @var int|string|null
    2228     */
     
    126132                }
    127133            }
     134
     135            $composerPath = trailingslashit(Manipulate::getComponentsRootPath($this->getTypeSlug())) . trailingslashit($this->getName()) . 'composer.json';
     136            if (file_exists($composerPath)) {
     137
     138                $fields = wp_json_file_decode($composerPath);
     139                if (is_array($fields) || is_object($fields)) {
     140
     141                    $this->composer = (array)$fields;
     142                }
     143            }
    128144        }
    129145    }
     
    132148     * @return array|object
    133149     */
     150    public function getComposer()
     151    {
     152        return $this->composer;
     153    }
     154
     155    /**
     156     * @param $key
     157     * @param $default
     158     *
     159     * @return mixed
     160     */
     161    public function getComposerField($key, $default = null)
     162    {
     163        return Manipulate::getArrayItem($this->getComposer(), $key, $default);
     164    }
     165
     166    /**
     167     * @return array|object
     168     */
    134169    public function getData()
    135170    {
     
    166201    public function getVersion(): ?string
    167202    {
    168         return $this->version;
     203        return $this->getComposerField(self::VERSION, $this->version);
    169204    }
    170205
     
    242277
    243278    /**
    244      * @return string|null
    245      */
    246     public function getSlug(): ?string
     279     * @return string
     280     */
     281    public function getTypeSlug(): string
    247282    {
    248283        $type = '';
     
    261296                break;
    262297        }
    263 
     298        return $type;
     299    }
     300
     301    /**
     302     * @return string|null
     303     */
     304    public function getSlug(): ?string
     305    {
     306        $type = $this->getTypeSlug();
    264307        $name = str_replace("wp-{$type}-", '', $this->getName());
    265308        return "pr__{$type}__" . str_replace('-', '_', $name);
Note: See TracChangeset for help on using the changeset viewer.