src/Service/Cdn.php
public function bucketCreate($sSlug, $sLabel = null, $aAllowedTypes = [])
    {
        if (is_array($sSlug)) {
            $aBucketData = $sSlug;
        } else {
            $aBucketData = [
                'slug'          => $sSlug,
                'label'         => $sLabel,
                'allowed_types' => $aAllowedTypes,
            ];
        }

        $sSlug = getFromArray('slug', $aBucketData);

        //  Test if bucket exists, if it does stop, job done.
        $oBucket = $this->getBucket($sSlug);

        if ($oBucket) {
            return $oBucket->id;
        }

        // --------------------------------------------------------------------------

        $bResult = $this->callDriver('bucketCreate', [$sSlug]);

        if ($bResult) {

            $oBucketModel = Factory::model('Bucket', 'nails/module-cdn');

            if (empty($aBucketData['label'])) {
                $aBucketData['label'] = ucwords(str_replace('-', ' ', $sSlug));
            }

            if (!empty($aBucketData['allowed_types'])) {
                if (!is_array($aBucketData['allowed_types'])) {
                    $aBucketData['allowed_types'] = (array) $aBucketData['allowed_types'];
                }

                $aBucketData['allowed_types'] = array_filter($aBucketData['allowed_types']);
                $aBucketData['allowed_types'] = array_unique($aBucketData['allowed_types']);
                $aBucketData['allowed_types'] = implode('|', $aBucketData['allowed_types']);
            }

            $iBucketId = $oBucketModel->create($aBucketData);

            if ($iBucketId) {
                return $iBucketId;
            } else {
                $this->callDriver('destroy', [$sSlug]);
                $this->setError('Failed to create bucket record');
                return false;
            }
        } else {
            $this->setError($this->callDriver('lastError'));
            return false;
        }
    }
public function bucketCreate($sSlug, $sLabel = null, $aAllowedTypes = [])
    {
        if (is_array($sSlug)) {
            $aBucketData = $sSlug;
        } else {
            $aBucketData = [
                'slug'          => $sSlug,
                'label'         => $sLabel,
                'allowed_types' => $aAllowedTypes,
            ];
        }

        $sSlug = getFromArray('slug', $aBucketData);

        //  Test if bucket exists, if it does stop, job done.
        $oBucket = $this->getBucket($sSlug);

        if ($oBucket) {
            return $oBucket->id;
        }

        // --------------------------------------------------------------------------

        $bResult = $this->callDriver('bucketCreate', [$sSlug]);

        if ($bResult) {

            $oBucketModel = Factory::model('Bucket', 'nails/module-cdn');

            if (empty($aBucketData['label'])) {
                $aBucketData['label'] = ucwords(str_replace('-', ' ', $sSlug));
            }

            if (!empty($aBucketData['allowed_types'])) {
                if (!is_array($aBucketData['allowed_types'])) {
                    $aBucketData['allowed_types'] = (array) $aBucketData['allowed_types'];
                }

                $aBucketData['allowed_types'] = array_filter($aBucketData['allowed_types']);
                $aBucketData['allowed_types'] = array_unique($aBucketData['allowed_types']);
                $aBucketData['allowed_types'] = implode('|', $aBucketData['allowed_types']);
            }

            $iBucketId = $oBucketModel->create($aBucketData);

            if ($iBucketId) {
                return $iBucketId;
            } else {
                $this->callDriver('destroy', [$sSlug]);
                $this->setError('Failed to create bucket record');
                return false;
            }
        } else {
            $this->setError($this->callDriver('lastError'));
            return false;
        }
    }
public function bucketCreate ( $ sSlug , $ sLabel = null , $ aAllowedTypes = [ ] ) { if ( is_array ( $ sSlug ) ) { $ aBucketData = $ sSlug ; } else { $ aBucketData = [ 'slug' => $ sSlug , 'label' => $ sLabel , 'allowed_types' => $ aAllowedTypes , ] ; } $ sSlug = getFromArray ( 'slug' , $ aBucketData ) ; //  Test if bucket exists, if it does stop, job done. $ oBucket = $ this -> getBucket ( $ sSlug ) ; if ( $ oBucket ) { return $ oBucket -> id ; } // -------------------------------------------------------------------------- $ bResult = $ this -> callDriver ( 'bucketCreate' , [ $ sSlug ] ) ; if ( $ bResult ) { $ oBucketModel = Factory :: model ( 'Bucket' , 'nails/module-cdn' ) ; if ( empty ( $ aBucketData [ 'label' ] ) ) { $ aBucketData [ 'label' ] = ucwords ( str_replace ( '-' , ' ' , $ sSlug ) ) ; } if ( ! empty ( $ aBucketData [ 'allowed_types' ] ) ) { if ( ! is_array ( $ aBucketData [ 'allowed_types' ] ) ) { $ aBucketData [ 'allowed_types' ] = ( array ) $ aBucketData [ 'allowed_types' ] ; } $ aBucketData [ 'allowed_types' ] = array_filter ( $ aBucketData [ 'allowed_types' ] ) ; $ aBucketData [ 'allowed_types' ] = array_unique ( $ aBucketData [ 'allowed_types' ] ) ; $ aBucketData [ 'allowed_types' ] = implode ( '|' , $ aBucketData [ 'allowed_types' ] ) ; } $ iBucketId = $ oBucketModel -> create ( $ aBucketData ) ; if ( $ iBucketId ) { return $ iBucketId ; } else { $ this -> callDriver ( 'destroy' , [ $ sSlug ] ) ; $ this -> setError ( 'Failed to create bucket record' ) ; return false ; } } else { $ this -> setError ( $ this -> callDriver ( 'lastError' ) ) ; return false ; } }
Create a new bucket

@param string $sSlug         The slug to give the bucket
@param string $sLabel        The label to give the bucket
@param array  $aAllowedTypes An array of file types the bucket will accept

@return boolean
Create a new bucket