idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
40,900
private function build ( ) { $ this -> getAbstractClass ( ) -> setDocumentation ( $ this -> getComment ( ) ) ; $ this -> getAbstractClass ( ) -> setName ( ucfirst ( $ this -> getTableName ( ) ) ) ; $ this -> getAbstractClass ( ) -> addUse ( $ this -> getConfiguration ( ) -> getRootNamespace ( ) . '\Models\\' . $ this -> getConfiguration ( ) -> getModelSubNamespace ( ) . '\Base' ) ; $ this -> getAbstractClass ( ) -> addUse ( 'Bullhorn\FastRest\Api\Models\GeneratedInterface' ) ; $ this -> getAbstractClass ( ) -> setImplements ( [ 'GeneratedInterface' ] ) ; $ this -> getAbstractClass ( ) -> setNamespace ( $ this -> getConfiguration ( ) -> getRootNamespace ( ) . '\Models\\' . $ this -> getConfiguration ( ) -> getModelSubNamespace ( ) . '\Generated' ) ; $ this -> getAbstractClass ( ) -> addUse ( $ this -> getConfiguration ( ) -> getRootNamespace ( ) . '\Models\\' . $ this -> getConfiguration ( ) -> getModelSubNamespace ( ) . '\\' . ucfirst ( $ this -> getTableName ( ) ) . ' as ChildModel' ) ; $ this -> getAbstractClass ( ) -> setExtends ( 'Base' ) ; $ this -> getAbstractClass ( ) -> setAbstract ( true ) ; $ this -> buildIdField ( ) ; $ this -> buildEnumConstants ( ) ; $ this -> buildInitialize ( ) ; $ this -> buildFieldsTypes ( ) ; $ this -> buildVariableDefinitions ( ) ; $ this -> buildOnConstruct ( ) ; $ this -> buildGetSource ( ) ; $ this -> buildAddJoin ( ) ; $ this -> buildFindFirst ( ) ; $ this -> buildFind ( ) ; $ this -> buildGettersAndSetters ( ) ; $ this -> buildRelationshipGetters ( ) ; $ this -> buildColumnMap ( ) ; $ this -> buildRelationshipsList ( ) ; }
Builds the buffer
40,901
private function buildChild ( ) { $ class = new Object \ Index ( $ this -> getConfiguration ( ) ) ; $ class -> setName ( ucfirst ( $ this -> getTableName ( ) ) ) ; $ class -> setAbstract ( false ) ; $ class -> setExtends ( 'GeneratedParent' ) ; $ class -> setNamespace ( $ this -> getConfiguration ( ) -> getRootNamespace ( ) . '\Models\\' . $ this -> getConfiguration ( ) -> getModelSubNamespace ( ) ) ; $ class -> addUse ( $ this -> getConfiguration ( ) -> getRootNamespace ( ) . '\Models\\' . $ this -> getConfiguration ( ) -> getModelSubNamespace ( ) . '\Generated\\' . ucfirst ( $ this -> getTableName ( ) ) . ' as GeneratedParent' ) ; $ method = new Object \ Method ( ) ; $ method -> setDescription ( 'This should set any defaults to the current object' ) ; $ method -> setName ( 'loadDefaults' ) ; $ method -> setContent ( '//TODO' ) ; $ method -> setAccess ( 'public' ) ; $ method -> setReturnType ( 'void' ) ; $ class -> addMethod ( $ method ) ; return $ class ; }
Builds the child buffer
40,902
public function write ( ) { $ this -> getAbstractClass ( ) -> write ( ) ; $ child = $ this -> buildChild ( ) ; if ( ! file_exists ( $ child -> getFileName ( ) ) ) { $ child -> write ( ) ; } $ this -> buildTestTable ( ) -> write ( ) ; $ this -> getValidationClass ( ) -> write ( ) ; if ( ! file_exists ( $ this -> getValidationChildClass ( ) -> getFileName ( ) ) ) { $ this -> getValidationChildClass ( ) -> write ( ) ; } }
Writes to a file
40,903
private function buildRelatedModels ( ) { $ relatedModels = array ( ) ; $ relatedBuilders = array ( ) ; $ automaticallyUpdatedFields = $ this -> getModel ( ) -> getAutomaticallyUpdatedFields ( ) ; foreach ( $ this -> getModel ( ) -> getDefaultRelationships ( ) as $ alias ) { $ relation = $ this -> getModel ( ) -> getModelsManager ( ) -> getRelationByAlias ( get_class ( $ this -> getModel ( ) ) , $ alias ) ; if ( $ relation !== false ) { if ( in_array ( $ relation -> getFields ( ) , $ automaticallyUpdatedFields ) ) { $ referencedModel = $ relation -> getReferencedModel ( ) ; $ relatedModel = new $ referencedModel ( ) ; $ relatedModels [ $ alias ] = $ relatedModel ; $ relatedBuilders [ $ alias ] = new ModelBuilder ( $ this -> getConfiguration ( ) , $ relatedModel -> getSource ( ) ) ; } } } $ this -> setRelatedModels ( $ relatedModels ) ; $ this -> setRelatedBuilders ( $ relatedBuilders ) ; }
Builds the related required models such as user to employee
40,904
private function buildDocumentation ( ) { $ model = new Swagger \ Model ( ) ; $ model -> setId ( $ this -> getClassName ( ) ) ; $ this -> buildProperties ( $ model ) ; foreach ( $ this -> getRelatedModels ( ) as $ alias => $ relatedModel ) { $ this -> buildProperties ( $ model , $ alias ) ; } $ resource = new Swagger \ Resource ( ) ; $ resource -> setApiVersion ( '1.0' ) -> setBasePath ( '/v1.0' ) -> setResourcePath ( $ this -> getClassName ( ) ) ; $ resource -> setDescription ( '' ) ; $ documentation = $ model . "\n" . $ resource ; $ this -> getObject ( ) -> setDocumentation ( $ documentation ) ; }
Builds the class documentation
40,905
private function buildIndexAction ( ) { $ api = new Swagger \ Api ( ) ; $ api -> setPath ( '/' . $ this -> getClassName ( ) ) ; $ operation = new Swagger \ Operation ( ) ; $ operation -> setMethod ( 'GET' ) ; $ operation -> setSummary ( 'Lists all ' . $ this -> getClassName ( ) . '.' ) ; $ operation -> setNotes ( 'Only returns the first 50 by default. Using the actual API you can search by parent fields and any field on the model as opposed to the brief list provided below.' ) ; $ responseMessage = new Swagger \ ResponseMessage ( ) ; $ responseMessage -> setCode ( 200 ) ; $ responseMessage -> setMessage ( 'List of ' . $ this -> getClassName ( ) . '.' ) ; $ responseMessage -> setResponseModel ( $ this -> getClassName ( ) ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> invalidFieldSpecifiedError ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> notAuthorizedResponse ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ operation -> addParameter ( $ this -> buildStartParameter ( ) ) ; $ operation -> addParameter ( $ this -> buildCountParameter ( ) ) ; $ operation -> addParameter ( $ this -> buildSortParameter ( ) ) ; $ operation -> addParameter ( $ this -> buildFieldsParameter ( ) ) ; $ searchParameters = $ this -> buildSearchParameters ( ) ; foreach ( $ searchParameters as $ searchParameter ) { $ operation -> addParameter ( $ searchParameter ) ; } $ api -> addOperation ( $ operation ) ; $ method = new Object \ Method ( ) ; $ method -> setDescription ( $ api -> __toString ( ) ) ; $ method -> setReturnType ( 'void' ) ; $ method -> setAccess ( 'public' ) ; $ method -> setName ( 'indexAction' ) ; $ method -> setContent ( 'parent::indexAction();' ) ; $ this -> getObject ( ) -> addMethod ( $ method ) ; }
Builds the index action
40,906
private function buildUpdateAction ( ) { $ api = new Swagger \ Api ( ) ; $ api -> setPath ( '/' . $ this -> getClassName ( ) . '/{id}' ) ; $ operation = new Swagger \ Operation ( ) ; $ operation -> setMethod ( 'PUT' ) ; $ operation -> setSummary ( 'Update ' . $ this -> singularModelA_Or_An ( ) . '.' ) ; $ operation -> setNotes ( 'Update ' . $ this -> singularModelA_Or_An ( ) . '.' ) ; $ operation -> addParameter ( $ this -> buildIdParameter ( ) ) ; $ operation -> addParameter ( $ this -> buildFieldsParameter ( ) ) ; $ parameter = new Swagger \ Parameter ( ) ; $ parameter -> setName ( 'body' ) ; $ parameter -> setDescription ( $ this -> getPutPostBodyDescription ( false ) ) ; $ parameter -> setParamType ( 'body' ) ; $ parameter -> setType ( $ this -> getClassName ( ) ) ; $ operation -> addParameter ( $ parameter ) ; $ responseMessage = new Swagger \ ResponseMessage ( ) ; $ responseMessage -> setCode ( 200 ) ; $ responseMessage -> setMessage ( ucfirst ( $ this -> getModel ( ) -> getSource ( ) ) . ' was updated.' ) ; $ responseMessage -> setResponseModel ( $ this -> getClassName ( ) ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = new Swagger \ ResponseMessage ( ) ; $ responseMessage -> setCode ( 304 ) ; $ responseMessage -> setMessage ( ucfirst ( $ this -> getModel ( ) -> getSource ( ) ) . ' was not changed.' ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> invalidFieldSpecifiedError ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> notAuthorizedResponse ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> notFoundResponse ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> invalidValuePassed ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ api -> addOperation ( $ operation ) ; $ method = new Object \ Method ( ) ; $ method -> setDescription ( $ api -> __toString ( ) ) ; $ method -> setReturnType ( 'void' ) ; $ method -> setAccess ( 'public' ) ; $ method -> setName ( 'updateAction' ) ; $ method -> setContent ( 'parent::updateAction();' ) ; $ this -> getObject ( ) -> addMethod ( $ method ) ; }
Builds the update action
40,907
private function buildShowAction ( ) { $ api = new Swagger \ Api ( ) ; $ api -> setPath ( '/' . $ this -> getClassName ( ) . '/{id}' ) ; $ operation = new Swagger \ Operation ( ) ; $ operation -> setMethod ( 'GET' ) ; $ operation -> setSummary ( 'Find ' . ucfirst ( $ this -> getModel ( ) -> getSource ( ) ) . ' by id.' ) ; $ operation -> setNotes ( 'Returns ' . $ this -> singularModelA_Or_An ( ) . ' based on ID.' ) ; $ responseMessage = new Swagger \ ResponseMessage ( ) ; $ responseMessage -> setCode ( 200 ) ; $ responseMessage -> setMessage ( ucfirst ( $ this -> getModel ( ) -> getSource ( ) ) ) ; $ responseMessage -> setResponseModel ( $ this -> getClassName ( ) ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> invalidFieldSpecifiedError ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> notAuthorizedResponse ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ responseMessage = $ this -> notFoundResponse ( ) ; $ operation -> addResponseMessage ( $ responseMessage ) ; $ operation -> addParameter ( $ this -> buildIdParameter ( ) ) ; $ operation -> addParameter ( $ this -> buildFieldsParameter ( ) ) ; $ api -> addOperation ( $ operation ) ; $ method = new Object \ Method ( ) ; $ method -> setDescription ( $ api -> __toString ( ) ) ; $ method -> setReturnType ( 'void' ) ; $ method -> setAccess ( 'public' ) ; $ method -> setName ( 'showAction' ) ; $ method -> setContent ( 'parent::showAction();' ) ; $ this -> getObject ( ) -> addMethod ( $ method ) ; }
Builds the show action
40,908
private function buildFieldsParameter ( ) { list ( $ parentEntities , $ childrenEntities ) = $ this -> getParentAndChildrenEntities ( ) ; $ parameter = new Swagger \ Parameter ( ) ; $ parameter -> setName ( 'fields' ) ; $ parameter -> setDescription ( 'Can be fields on this entity, parent entities, or children entities. Specify entities other than this one with type.field. Eligible entities are: ' . implode ( ', ' , array_merge ( $ parentEntities , $ childrenEntities ) ) . '. Optional.' ) ; $ parameter -> setParamType ( 'query' ) ; $ parameter -> setType ( 'string' ) ; $ parameter -> setAllowMultiple ( true ) ; return $ parameter ; }
Builds and returns the parameter of fields
40,909
private function buildIdParameter ( ) { $ parameter = new Swagger \ Parameter ( ) ; $ parameter -> setName ( 'id' ) ; $ parameter -> setDescription ( 'Which ' . ucfirst ( $ this -> getModel ( ) -> getSource ( ) ) . ' to target.' ) ; $ parameter -> setParamType ( 'path' ) ; $ parameter -> setType ( 'integer' ) ; $ parameter -> setRequired ( true ) ; return $ parameter ; }
Builds the id parameter
40,910
private function buildStartParameter ( ) { $ parameter = new Swagger \ Parameter ( ) ; $ parameter -> setName ( 'start' ) ; $ parameter -> setDescription ( 'Which record to start retrieving results from in the database. Defaults to 0 which is the first record. Optional.' ) ; $ parameter -> setParamType ( 'query' ) ; $ parameter -> setType ( 'integer' ) ; return $ parameter ; }
Builds the start parameter
40,911
private function buildCountParameter ( ) { $ parameter = new Swagger \ Parameter ( ) ; $ parameter -> setName ( 'count' ) ; $ parameter -> setDescription ( 'How many records to retrieve from the start point. Optional.' ) ; $ parameter -> setParamType ( 'query' ) ; $ parameter -> setType ( 'integer' ) ; return $ parameter ; }
Builds the count parameter
40,912
private function buildSortParameter ( ) { $ parameter = new Swagger \ Parameter ( ) ; $ parameter -> setName ( 'sort' ) ; $ parameter -> setDescription ( 'Any field on the model can be a sort field. The sort can contain multiple fields, comma separated. It is also possible to get a reverse sort by adding a - in front of the field . Optional.' ) ; $ parameter -> setParamType ( 'query' ) ; $ parameter -> setType ( 'string' ) ; return $ parameter ; }
Builds the sort parameter
40,913
private function buildSearchParameters ( ) { $ fields = $ this -> getModelBuilder ( ) -> getFields ( ) ; $ numberOfFields = sizeof ( $ fields ) ; if ( $ numberOfFields > 5 ) { $ numberOfFields = 5 ; } $ parameters = array ( ) ; for ( $ i = 0 ; $ i < $ numberOfFields ; $ i ++ ) { $ parameter = new Swagger \ Parameter ( ) ; $ parameter -> setName ( $ fields [ $ i ] -> getShortName ( ) ) ; $ parameter -> setDescription ( $ fields [ $ i ] -> getComment ( ) ) ; $ parameter -> setParamType ( 'query' ) ; $ parameter -> setType ( $ fields [ $ i ] -> getSwaggerType ( ) ) ; $ parameters [ ] = $ parameter ; } return $ parameters ; }
Builds a list of search parameters
40,914
private function build ( ) { $ this -> getObject ( ) -> addUse ( 'Bullhorn\FastRest\Api\Models\ApiInterface as ModelInterface' ) ; $ this -> getObject ( ) -> setName ( ucfirst ( strtolower ( $ this -> getClassName ( ) ) ) . 'Controller' ) ; $ this -> getObject ( ) -> setNamespace ( $ this -> getConfiguration ( ) -> getRootNamespace ( ) . '\Controllers' ) ; $ this -> getObject ( ) -> setExtends ( 'ControllerBase' ) ; $ this -> buildFactory ( ) ; $ this -> buildIndexAction ( ) ; $ this -> buildShowAction ( ) ; $ this -> buildCreateAction ( ) ; $ this -> buildUpdateAction ( ) ; $ this -> buildDeleteAction ( ) ; $ this -> buildDocumentation ( ) ; }
Builds the class
40,915
private function notFoundResponse ( ) { $ responseMessage = new Swagger \ ResponseMessage ( ) ; $ responseMessage -> setCode ( 404 ) ; $ responseMessage -> setMessage ( ucfirst ( $ this -> getModel ( ) -> getSource ( ) ) . ' not found.' ) ; return $ responseMessage ; }
Unable to find the requested resource .
40,916
private function getParentAndChildrenEntities ( ) { $ parentEntities = array ( ) ; $ childrenEntities = array ( ) ; foreach ( $ this -> getModelBuilder ( ) -> getRelationships ( ) as $ relationship ) { if ( $ relationship -> isPlural ( ) ) { $ parentEntities [ ] = $ relationship -> getAlias ( ) . '.*' ; } else { $ childrenEntities [ ] = $ relationship -> getAlias ( ) . '.*' ; } } return array ( $ parentEntities , $ childrenEntities ) ; }
Return the parent and children entities for this model
40,917
private function getDeletionPreventingParents ( ) { $ parentEntities = array ( ) ; foreach ( $ this -> getModelBuilder ( ) -> getRelationships ( ) as $ relationship ) { if ( $ relationship -> isPlural ( ) && ! $ relationship -> isNullable ( ) && $ relationship -> getAction ( ) != 'ACTION_CASCADE' ) { $ parentEntities [ ] = $ relationship -> getAlias ( ) ; } } return $ parentEntities ; }
Return the parents that prevent deletion
40,918
private function loadParams ( ) { if ( $ this -> getRequest ( ) -> getRawBody ( ) == '' && empty ( $ this -> getRequest ( ) -> getPost ( ) ) && empty ( $ this -> getRequest ( ) -> getPut ( ) ) && empty ( $ this -> getRequest ( ) -> getUploadedFiles ( ) ) ) { throw new Exception ( 'No Data Passed' , 400 ) ; } $ bulkCreation = false ; if ( ! is_null ( $ this -> getRequest ( ) -> getJsonRawBody ( ) ) ) { $ params = $ this -> getRequest ( ) -> getJsonRawBody ( ) ; $ delimiter = '.' ; if ( is_array ( $ params ) ) { $ bulkCreation = true ; } } else { if ( $ this -> getRequest ( ) -> isPost ( ) ) { $ params = $ this -> getRequest ( ) -> getPost ( ) ; } else { $ params = $ this -> getPut ( ) ; } $ delimiter = '_' ; } if ( $ this -> request -> getRawBody ( ) != '' && sizeOf ( $ params ) == 0 && json_last_error ( ) != JSON_ERROR_NONE ) { $ this -> dispatchJsonError ( ) ; } if ( $ bulkCreation ) { $ outputParams = [ ] ; foreach ( $ params as $ param ) { $ helper = new SplitHelper ( $ delimiter ) ; $ outputParams [ ] = $ helper -> convert ( ( array ) $ param ) ; } $ this -> setParams ( $ outputParams ) ; } else { $ helper = new SplitHelper ( $ delimiter ) ; $ this -> setParams ( $ helper -> convert ( ( array ) $ params ) ) ; } }
Gets the parameters sorted from parent to child
40,919
public function getTransaction ( ) { if ( ! $ this -> isInTransaction ( ) ) { throw new \ Exception ( 'This transaction has already been rolled back, or committed, or has not began yet' ) ; } $ transactions = $ this -> getTransactions ( ) ; return $ transactions [ $ this -> getDbService ( ) ] ; }
Gets the current transaction throws an exception if there isn t one
40,920
public function addColumn ( $ column ) { $ columns = $ this -> getColumns ( ) ; $ columns [ ] = $ column ; $ this -> setColumns ( $ columns ) ; }
Adds a new column
40,921
public static function pluralize ( $ string ) { $ string = trim ( $ string ) ; $ testString = strtolower ( $ string ) ; if ( $ testString == '' ) { return '' ; } elseif ( substr ( $ testString , - 3 ) == 'day' ) { return $ string . 's' ; } elseif ( substr ( $ testString , - 2 ) == 'ch' ) { return $ string . 'es' ; } elseif ( substr ( $ testString , - 1 ) == 'x' ) { return $ string . 'es' ; } elseif ( substr ( $ testString , - 1 ) == 'y' ) { return substr ( $ string , 0 , - 1 ) . 'ies' ; } else { return $ string . 's' ; } }
pluralizes a string
40,922
public function getDi ( ) { if ( is_null ( $ this -> di ) ) { $ this -> di = FactoryDefault :: getDefault ( ) ; if ( is_null ( $ this -> di ) ) { $ this -> di = new FactoryDefault ( ) ; } } return $ this -> di ; }
Gets the dependency injector
40,923
public function parse ( $ date ) { if ( is_int ( $ date ) || is_double ( $ date ) || ( is_string ( $ date ) && preg_match ( '@^[0-9]+$@' , $ date ) ) ) { return ( double ) $ date ; } elseif ( $ date instanceof Date ) { return $ date -> getEpoch ( ) ; } elseif ( is_null ( $ date ) ) { return false ; } else { $ date = trim ( Assert :: isString ( $ date ) ) ; } $ date = $ this -> parseHoursMinutes ( $ date ) ; if ( preg_match ( '@^[0-9]+$@' , $ date ) ) { return ( int ) $ date ; } $ date = $ this -> stripTimezone ( $ date ) ; $ date = $ this -> stripRange ( $ date ) ; if ( preg_match ( '@^(\d{4}-\d{2}-\d{2} )?24:00(:00)?$@' , trim ( $ date ) , $ matches ) ) { if ( isset ( $ matches [ 1 ] ) && strlen ( $ matches [ 1 ] ) > 0 ) { $ date = strtotime ( $ matches [ 1 ] ) ; } else { $ date = time ( ) ; } return mktime ( 0 , 0 , 0 , date ( 'n' , $ date ) , date ( 'j' , $ date ) + 1 , date ( 'Y' , $ date ) ) ; } $ date = preg_replace ( '@(^|[^a-z])(a|p)([^a-z]|$)@i' , '\\1\\2m\\3' , $ date ) ; $ date = preg_replace ( '@(^|[^0-9])(\d{1,2})(\d{2})\s*(am|pm)@i' , '\\1\\2:\\3\\4' , $ date ) ; $ date = preg_replace ( '@(\d{2})-(\d{2})-(\d{4})@' , '\\1/\\2/\\3' , $ date ) ; $ date = preg_replace ( '@(\d{2})\.(\d{2})\.(\d{4})@' , '\\1/\\2/\\3' , $ date ) ; if ( in_array ( Formatter :: getDefault ( ) -> getDateFormat ( ) , array ( Formatter :: DATE_FORMAT_UK , Formatter :: DATE_FORMAT_EURO ) ) ) { $ date = preg_replace ( '@(\d{2})/(\d{2})/(\d{4})@' , '\\2/\\1/\\3' , $ date ) ; } switch ( strtolower ( $ date ) ) { case '9999-12-31' : return 253402232400 ; break ; case '0000-00-00' : return 0 ; break ; case '0000-00-00 00:00:00' : return 0 ; break ; case '24:00:00' : case '24:00' : return mktime ( 0 , 0 , 0 , date ( 'n' ) , date ( 'j' ) + 1 , date ( 'Y' ) ) ; break ; case 'thanksgiving' : $ firstDay = mktime ( 0 , 0 , 0 , 11 , 1 ) ; $ add = 26 - date ( 'w' , $ firstDay ) ; if ( $ add < 22 ) { $ add += 7 ; } return mktime ( 0 , 0 , 0 , 11 , $ add ) ; break ; default : return strtotime ( $ date ) ; } }
Converts a string of any date to a timestamp
40,924
public function addResponseMessage ( ResponseMessage $ responseMessage ) { $ responseMessages = $ this -> getResponseMessages ( ) ; $ responseMessages [ ] = $ responseMessage ; $ this -> setResponseMessages ( $ responseMessages ) ; }
Adds new responseMessage
40,925
public function addProperty ( Property $ property ) { $ properties = $ this -> getProperties ( ) ; $ properties [ ] = $ property ; $ this -> setProperties ( $ properties ) ; }
Adds new property
40,926
public static function isBool ( $ input ) { if ( is_bool ( $ input ) ) { return $ input ; } if ( is_int ( $ input ) || is_float ( $ input ) ) { return $ input != 0 ; } $ input = strtolower ( self :: isString ( $ input ) ) ; return in_array ( $ input , array ( 'active' , 'true' , 'yes' , '1' , 'on' , 'y' ) , TRUE ) ; }
Cleans bool input
40,927
private function validateServicesDefined ( ) { if ( ! $ this -> getDi ( ) -> has ( AclInterface :: DI_NAME ) ) { throw new \ Exception ( 'Service ' . AclInterface :: class . '::DI_NAME must be defined with a type of: ' . AclInterface :: class ) ; } if ( ! $ this -> getDi ( ) -> has ( OutputInterface :: DI_NAME ) ) { throw new \ Exception ( 'Service ' . OutputInterface :: class . '::DI_NAME must be defined with a type of: ' . OutputInterface :: class ) ; } }
Validates to make sure all required services are defined
40,928
protected function indexAction ( ) { try { $ entity = $ this -> generateEntity ( ) ; $ query = new Index ( $ this -> request , $ entity , $ this -> getQueryWhiteList ( ) ) ; $ this -> response -> setHeader ( 'link' , $ query -> generateLinks ( ) ) ; $ entities = $ query -> getResultSet ( ) ; $ entities = $ this -> filterEntities ( $ entities ) ; $ this -> indexActionInternal ( $ entities ) ; if ( $ this -> hasFlag ( ( new FlagEnum ( FlagEnum :: PAGE_COUNTS ) ) ) ) { $ this -> getOutputObject ( ) -> PageCounts = $ query -> generatePageCounts ( ) ; } } catch ( Exception $ e ) { $ this -> handleError ( $ e ) ; } catch ( ValidationException $ e ) { $ this -> handleValidationError ( $ e ) ; } catch ( AclException $ e ) { $ this -> handleAclError ( $ e ) ; } catch ( CatchableException $ e ) { $ this -> handleCatchableError ( $ e ) ; } }
This provides a list of the entities
40,929
public function optionsAction ( ) { $ this -> response -> setHeader ( 'Access-Control-Allow-Methods' , 'POST, GET, PUT, DELETE, OPTIONS' ) ; $ allowedHeaders = array_merge ( [ 'X-Requested-With' , 'X-HTTP-Method-Override' , 'Content-Type' , 'Accept' , 'Cache-Control' ] , $ this -> getExtraAllowedHeaders ( ) ) ; $ this -> response -> setHeader ( 'Access-Control-Allow-Headers' , implode ( ', ' , $ allowedHeaders ) ) ; $ this -> setStatusCode ( 200 ) ; }
Needed for CORs
40,930
private function createActionProcess ( ) { $ createObjects = [ ] ; try { $ params = new Params ( $ this -> request ) ; } catch ( Exception $ e ) { $ this -> handleError ( $ e ) ; return $ createObjects ; } $ postParams = $ params -> getParams ( ) ; if ( ! is_array ( $ postParams ) ) { $ postParams = [ $ postParams ] ; } foreach ( $ postParams as $ postParam ) { $ createObject = new CreateObject ( $ postParam ) ; try { $ entity = $ this -> createActionInternal ( $ postParam ) ; $ createObject -> setEntity ( $ entity ) ; } catch ( Exception $ e ) { $ this -> handleError ( $ e ) ; } catch ( ValidationException $ e ) { $ this -> handleValidationError ( $ e ) ; } catch ( AclException $ e ) { $ this -> handleAclError ( $ e ) ; } catch ( CatchableException $ e ) { $ this -> handleCatchableError ( $ e ) ; } $ createObject -> setStatusCode ( $ this -> getStatusCode ( ) ) ; $ createObject -> setErrors ( $ this -> getErrors ( ) ) ; $ this -> setErrors ( [ ] ) ; $ createObjects [ ] = $ createObject ; } return $ createObjects ; }
Creates the entities returns a list of createObjects to process accordingly
40,931
private function createActionInternal ( \ stdClass $ postParams ) { $ entity = $ this -> generateEntity ( ) ; $ this -> saveEntity ( $ postParams , $ entity , true ) ; $ newEntity = $ entity -> findFirst ( $ entity -> getId ( ) ) ; $ reflectionClass = new \ ReflectionClass ( $ newEntity ) ; $ reflectionProperty = $ reflectionClass -> getProperty ( '_errorMessages' ) ; $ reflectionProperty -> setAccessible ( true ) ; $ reflectionProperty -> setValue ( $ newEntity , [ ] ) ; return $ newEntity ; }
Provides the actual creating of a new entity .
40,932
protected function showActionInternal ( ModelInterface $ entity ) { $ outputObject = $ this -> getOutputObject ( ) ; $ outputObject -> { $ entity -> getEntityName ( ) } = $ this -> generateEntityAction ( $ entity ) ; $ this -> setOutputObject ( $ outputObject ) ; }
Looks up an individual entity
40,933
private function generateEntityAction ( ModelInterface $ entity ) { session_write_close ( ) ; $ show = new Show ( $ entity ) ; $ showCriteria = new ShowCriteria ( $ this -> request ) ; return $ show -> generate ( $ showCriteria -> getField ( ) ) ; }
Generates the output of an entity
40,934
private function findPostParams ( \ stdClass $ postParams , ModelInterface $ entity ) { $ dataTransformer = $ this -> getDataTransformer ( $ postParams ) ; if ( ! is_null ( $ dataTransformer ) ) { $ dataTransformer -> transform ( $ entity ) ; $ postParams = $ dataTransformer -> getParams ( ) ; } return $ postParams ; }
Finds the post parameters
40,935
public function deleteAction ( ) { try { if ( sizeOf ( $ this -> dispatcher -> getParams ( ) ) == 0 ) { throw new Exception ( 'Invalid Entity Id Passed In' , 400 ) ; } $ entity = $ this -> validateEntityId ( $ this -> dispatcher -> getParam ( 0 ) ) ; $ this -> deleteActionInternal ( $ entity ) ; } catch ( Exception $ e ) { $ this -> handleError ( $ e ) ; } catch ( ValidationException $ e ) { $ this -> handleValidationError ( $ e ) ; } catch ( AclException $ e ) { $ this -> handleAclError ( $ e ) ; } }
Deletes an individual entity
40,936
public function getAcl ( ) { $ returnVar = $ this -> getDi ( ) -> get ( AclInterface :: DI_NAME ) ; if ( ! ( $ returnVar instanceof AclInterface ) ) { throw new \ Exception ( 'The Acl must implement: ' . AclInterface :: class ) ; } return $ returnVar ; }
Gets the Access Control Layer
40,937
protected function deleteActionInternal ( ModelInterface $ entity ) { $ this -> setStatusCode ( 204 ) ; $ delete = new Delete ( $ entity ) ; $ delete -> process ( $ this -> getAcl ( ) ) ; }
Default delete action for our entities .
40,938
protected function lookUpEntity ( $ entityId ) { $ entity = $ this -> generateEntity ( ) ; $ entityInstance = $ entity -> findFirst ( $ entityId ) ; if ( $ entityInstance === false ) { throw new Exception ( "Invalid Entity Id: Entity not found." , 404 ) ; } return $ entityInstance ; }
This looks up an entity based off of the entity id
40,939
public function afterExecuteRoute ( ) { $ output = $ this -> getDI ( ) -> get ( OutputInterface :: DI_NAME ) ; if ( ! ( $ output instanceof OutputInterface ) ) { throw new \ Exception ( 'The Output must implement: ' . OutputInterface :: class ) ; } $ object = $ this -> getOutputObject ( ) ; $ errors = $ this -> getErrors ( ) ; $ code = $ this -> getStatusCode ( ) ; $ object = $ this -> addErrorsAndStatus ( $ errors , $ code , $ object ) ; $ this -> response -> setStatusCode ( $ object -> statusCode , 'Check Document Body For More Details' ) ; $ output -> output ( $ object , $ this -> response ) ; $ this -> view -> disable ( ) ; }
Executed after it is routed
40,940
protected function handleValidationError ( ValidationException $ e , $ errorCode = 409 ) { $ entity = $ e -> getEntity ( ) ; foreach ( $ entity -> getMessages ( ) as $ message ) { $ this -> addError ( new Exception ( $ message -> getMessage ( ) , $ errorCode ) ) ; } }
Handles exceptions from validations
40,941
protected function handleAclError ( AclException $ e ) { if ( ! empty ( $ e -> getMessage ( ) ) ) { $ this -> addError ( new Exception ( $ e -> getMessage ( ) , 401 ) ) ; } $ entity = $ e -> getEntity ( ) ; if ( ! is_null ( $ entity ) ) { foreach ( $ entity -> getMessages ( ) as $ message ) { $ this -> addError ( new Exception ( $ message -> getMessage ( ) , 401 ) ) ; } } }
Handles exceptions from acl
40,942
public function getShortName ( ) { $ name = $ this -> getName ( ) ; if ( substr ( $ name , 0 , strlen ( $ this -> getTableName ( ) ) ) == $ this -> getTableName ( ) && lcfirst ( substr ( $ name , strlen ( $ this -> getTableName ( ) ) ) ) != 'source' ) { $ name = lcfirst ( substr ( $ name , strlen ( $ this -> getTableName ( ) ) ) ) ; } return $ name ; }
Gets the name without the table name
40,943
public function generate ( Field $ field ) { $ output = new \ stdClass ( ) ; $ this -> showRecursive ( $ output , $ field , $ this -> getEntity ( ) ) ; return $ output ; }
Generates the std object to show
40,944
private function showRecursive ( \ stdClass $ output , Field $ field , ApiInterface $ entity ) { $ this -> getAcl ( ) -> canRead ( $ entity ) ; $ columns = $ entity -> getModelsMetaData ( ) -> getColumnMap ( $ entity ) ; $ columns = array_merge ( $ columns , $ entity -> getExtraProperties ( ) ) ; foreach ( $ field -> getChildren ( ) as $ child ) { $ this -> showParentsAndChildren ( $ output , $ entity , $ child ) ; } foreach ( $ field -> getFields ( ) as $ subField ) { if ( $ subField == '*' ) { $ lazyProperties = $ entity -> getLazyProperties ( ) ; foreach ( array_diff ( $ columns , $ lazyProperties ) as $ column ) { $ this -> showField ( $ output , $ entity , $ column ) ; } } elseif ( in_array ( $ subField , $ columns ) ) { $ this -> showField ( $ output , $ entity , $ subField ) ; } elseif ( in_array ( $ subField , $ entity -> getChildrenRelationships ( ) ) || in_array ( $ subField , $ entity -> getParentRelationships ( ) ) ) { throw new Exception ( 'Invalid Field, child or parent: ' . $ entity -> getEntityName ( ) . ' with "' . $ subField . '". Please add .* to the end to get all related fields' , 400 ) ; } else { throw new Exception ( 'Invalid Field, not on the current object: ' . $ entity -> getEntityName ( ) . ' with ' . $ subField , 400 ) ; } } }
Adds to the output object the specified field
40,945
private function showField ( \ stdClass $ output , ApiInterface $ entity , $ column ) { if ( $ this -> getAcl ( ) -> canReadField ( $ entity , $ column ) ) { if ( in_array ( $ column , $ entity -> getUnReadableFields ( ) ) ) { $ value = null ; } else { $ value = $ entity -> readAttribute ( $ column ) ; if ( is_object ( $ value ) && method_exists ( $ value , '__toString' ) ) { $ value = $ value -> __toString ( ) ; } } $ output -> { $ column } = $ value ; } }
Shows an individual field
40,946
public function getAlias ( ) { $ multipleFound = false ; foreach ( $ this -> getRelationships ( ) as $ relationship ) { if ( $ relationship !== $ this && $ relationship -> getRemoteTable ( ) == $ this -> getRemoteTable ( ) ) { $ multipleFound = true ; } } $ returnVar = '' ; if ( $ multipleFound ) { if ( $ this -> isPlural ( ) ) { $ name = $ this -> getRemoteColumn ( ) ; if ( stripos ( $ name , $ this -> getRemoteTable ( ) ) === 0 ) { $ name = substr ( $ name , strlen ( $ this -> getRemoteTable ( ) ) ) ; } if ( stripos ( substr ( $ name , strlen ( $ this -> getLocalTable ( ) . 'Id' ) * - 1 ) , $ this -> getLocalTable ( ) . 'Id' ) === 0 ) { $ name = substr ( $ name , 0 , strlen ( $ this -> getLocalTable ( ) . 'Id' ) * - 1 ) ; } } else { $ name = $ this -> getLocalColumn ( ) ; if ( stripos ( $ name , $ this -> getLocalTable ( ) ) === 0 ) { $ name = substr ( $ name , strlen ( $ this -> getLocalTable ( ) ) ) ; } if ( stripos ( substr ( $ name , strlen ( $ this -> getRemoteTable ( ) . 'Id' ) * - 1 ) , $ this -> getRemoteTable ( ) . 'Id' ) === 0 ) { $ name = substr ( $ name , 0 , strlen ( $ this -> getRemoteTable ( ) . 'Id' ) * - 1 ) ; } } $ returnVar .= $ name ; } $ returnVar .= $ this -> getRemoteShortModel ( ) ; if ( $ this -> isPlural ( ) ) { $ pluralHelper = new PluralHelper ( ) ; $ returnVar = $ pluralHelper -> pluralize ( $ returnVar ) ; } return ucfirst ( $ returnVar ) ; }
Gets the alias
40,947
public function getRemoteShortColumn ( ) { $ name = $ this -> getRemoteColumn ( ) ; if ( substr ( $ name , 0 , strlen ( $ this -> getRemoteTable ( ) ) ) == $ this -> getRemoteTable ( ) && lcfirst ( substr ( $ name , strlen ( $ this -> getRemoteTable ( ) ) ) ) != 'source' ) { $ name = lcfirst ( substr ( $ name , strlen ( $ this -> getRemoteTable ( ) ) ) ) ; } return $ name ; }
Gets the shortened version of a column
40,948
public function andWhere ( $ conditions , array $ bindParams = null , array $ bindTypes = null ) { if ( ! is_null ( $ bindParams ) ) { $ tmpBindParams = array ( ) ; foreach ( $ bindParams as $ key => $ value ) { if ( is_int ( $ key ) ) { $ param = 'criteriaHelper' . $ this -> incrementLocalParamCount ( ) ; $ tmpBindParams [ $ param ] = $ value ; $ conditions = str_replace ( '?' . $ key , ':' . $ param . ':' , $ conditions ) ; } else { $ tmpBindParams [ $ key ] = $ value ; } } $ bindParams = $ tmpBindParams ; } $ this -> getCriteria ( ) -> andWhere ( $ conditions , $ bindParams , $ bindTypes ) ; return $ this ; }
Appends a condition to the current conditions using an AND operator
40,949
public function execute ( ) { $ modelName = $ this -> getCriteria ( ) -> getModelName ( ) ; $ params = $ this -> getCriteria ( ) -> getParams ( ) ; if ( ! empty ( $ this -> getGroupBys ( ) ) ) { $ params [ 'group' ] = $ this -> getGroupBys ( ) ; } return $ modelName :: find ( $ params ) ; }
Executes a find using the parameters built with the criteria
40,950
public function setCurrentFormat ( $ currentFormat ) { $ allowedFormats = $ this -> getAllowedFormats ( ) ; if ( ! in_array ( $ currentFormat , $ allowedFormats ) ) { throw new InvalidArgumentException ( 'Invalid Date Format: ' . $ currentFormat . ', expected: ' . implode ( ', ' , $ allowedFormats ) ) ; } $ allFormats = $ this -> getPreviousFormats ( ) ; $ allFormats [ ] = $ this -> getCurrentFormat ( ) ; $ this -> setPreviousFormats ( $ allFormats ) ; $ this -> currentFormat = $ currentFormat ; }
Sets the current format
40,951
public function revertFormat ( ) { $ allFormats = $ this -> getPreviousFormats ( ) ; if ( ! empty ( $ allFormats ) ) { $ this -> currentFormat = array_pop ( $ allFormats ) ; $ this -> setPreviousFormats ( $ allFormats ) ; } }
reverts to the previous format does nothing if there are no previous formats
40,952
public function initialize ( ) { $ this -> keepSnapshots ( true ) ; $ this -> setup ( array ( 'exceptionOnFailedSave' => true , 'notNullValidations' => false ) ) ; $ this -> useDynamicUpdate ( true ) ; }
Initializes the class
40,953
public function addAutomaticallyUpdatedFields ( array $ automaticallyUpdatedFields ) { $ fields = $ this -> getAutomaticallyUpdatedFields ( ) ; foreach ( $ automaticallyUpdatedFields as $ field ) { if ( ! in_array ( $ field , $ fields ) ) { $ fields [ ] = $ field ; } } $ this -> setAutomaticallyUpdatedFields ( $ fields ) ; }
Adds any new automatically updated fields so they cannot be updated by the controller
40,954
public function readAttribute ( $ name ) { $ method = 'get' . ucfirst ( $ name ) ; if ( method_exists ( $ this , $ method ) ) { return $ this -> $ method ( ) ; } else { return parent :: readAttribute ( $ name ) ; } }
Override readAttribute to allow for having custom setMethods
40,955
public function writeAttribute ( $ name , $ value ) { $ method = 'set' . ucfirst ( $ name ) ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( $ value ) ; } else { parent :: writeAttribute ( $ name , $ value ) ; } }
Override writeAttribute to allow for having custom setMethods
40,956
private function convertColumnsToRawFields ( array $ columns ) { $ columnMaps = $ this -> getModelsMetaData ( ) -> getColumnMap ( $ this ) ; foreach ( $ columns as $ key => $ value ) { if ( ! array_key_exists ( $ value , $ columnMaps ) ) { $ index = array_search ( $ value , $ columnMaps ) ; if ( $ index === false ) { throw new \ InvalidArgumentException ( 'Invalid Column, could not find: ' . $ value ) ; } else { $ columns [ $ key ] = $ index ; } } } return $ columns ; }
Converts the columns into their original raw fields
40,957
public function getRelationship ( $ alias ) { if ( array_key_exists ( $ alias , $ this -> getCustomParentRelationships ( ) ) ) { return $ this -> getCustomParentRelationships ( ) [ $ alias ] ; } else { return $ this -> getModelsManager ( ) -> getRelationByAlias ( get_class ( $ this ) , $ alias ) ; } }
Finds a relationship
40,958
public function setRelated ( $ alias , Model $ entity ) { $ foundRelation = $ this -> getRelationship ( $ alias ) ; if ( $ foundRelation instanceof CustomRelationship ) { call_user_func ( array ( $ this , 'set' . ucfirst ( $ alias ) ) , $ entity ) ; } else { $ attribute = $ foundRelation -> getFields ( ) ; $ value = $ foundRelation -> getReferencedFields ( ) ; if ( is_array ( $ attribute ) ) { $ count = sizeOf ( $ attribute ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ this -> writeAttribute ( $ attribute [ $ i ] , $ entity -> readAttribute ( $ value [ $ i ] ) ) ; } } else { $ this -> writeAttribute ( $ attribute , $ entity -> readAttribute ( $ value ) ) ; } } }
Sets a related entity
40,959
public function getRelated ( $ alias , $ arguments = null ) { $ relationship = $ this -> getRelationship ( $ alias ) ; if ( ( $ relationship === false || $ relationship instanceof CustomRelationship ) && method_exists ( $ this , "get" . ucfirst ( $ alias ) ) ) { return call_user_func ( array ( $ this , "get" . ucfirst ( $ alias ) ) ) ; } return parent :: getRelated ( $ alias , $ arguments ) ; }
Gets related entities .
40,960
public function selectReadConnection ( ) { $ transaction = new Transaction ( $ this -> getReadConnectionService ( ) ) ; if ( $ transaction -> isInTransaction ( ) ) { return $ transaction -> getTransaction ( ) -> getConnection ( ) ; } else { return $ this -> getReadConnection ( ) ; } }
Used to be able to make a call inside of a transaction
40,961
public function getAllBehaviorsByClassName ( $ className ) { $ modelsManager = $ this -> getModelsManager ( ) ; $ reflectionClass = new \ ReflectionClass ( $ modelsManager ) ; $ reflectionBehavior = $ reflectionClass -> getProperty ( '_behaviors' ) ; $ reflectionBehavior -> setAccessible ( true ) ; $ allBehaviors = $ reflectionBehavior -> getValue ( $ modelsManager ) ; $ behaviors = $ allBehaviors [ strtolower ( get_class ( $ this ) ) ] ; $ returnVar = [ ] ; foreach ( $ behaviors as $ behavior ) { if ( get_class ( $ behavior ) == $ className || is_subclass_of ( $ behavior , $ className ) ) { $ returnVar [ ] = $ behavior ; } } return $ returnVar ; }
Returns all behaviors associated with the class
40,962
public function addConstant ( $ name , $ value ) { $ constants = $ this -> getConstants ( ) ; if ( array_key_exists ( $ name , $ constants ) ) { throw new \ Exception ( 'Constant Already Exists: ' . $ name ) ; } $ constants [ $ name ] = $ value ; asort ( $ constants ) ; $ this -> setConstants ( $ constants ) ; }
Adds a new class constant
40,963
public function hasConstant ( $ name ) { $ hasConstant = false ; if ( array_key_exists ( $ name , $ this -> getConstants ( ) ) ) { $ hasConstant = true ; } return $ hasConstant ; }
Checks if the constant exists
40,964
public function addUse ( $ use ) { $ use = trim ( $ use , '\\' ) ; $ uses = $ this -> getUses ( ) ; if ( ! in_array ( $ use , $ uses ) ) { $ uses [ ] = $ use ; } sort ( $ uses ) ; $ this -> setUses ( $ uses ) ; }
Adds a new use
40,965
public function toString ( ) { $ documentation = preg_replace_callback ( '@\r?\n@' , function ( $ matches ) { return $ matches [ 0 ] . ' * ' ; } , trim ( $ this -> getDocumentation ( ) ) ) ; if ( $ documentation == '' ) { $ documentation = $ this -> getName ( ) ; } $ buffer = '<?phpnamespace ' . $ this -> getNamespace ( ) . ';' ; foreach ( $ this -> getUses ( ) as $ use ) { $ buffer .= 'use ' . $ use . ';' . "\n" ; } $ buffer .= '/** * ' . $ documentation . ' */' . ( $ this -> isAbstract ( ) ? 'abstract ' : '' ) . 'class ' . $ this -> getName ( ) . ' extends ' . $ this -> getExtends ( ) . ( sizeOf ( $ this -> getImplements ( ) ) > 0 ? ' implements ' . implode ( ', ' , $ this -> getImplements ( ) ) : '' ) . ' {' ; foreach ( $ this -> getTraits ( ) as $ trait ) { $ buffer .= ' use ' . $ trait . ';' ; } foreach ( $ this -> getConstants ( ) as $ name => $ value ) { $ buffer .= ' const ' . $ name . ' = \'' . str_replace ( "'" , "\\'" , $ value ) . '\';' ; } foreach ( $ this -> getVariables ( ) as $ variable ) { $ buffer .= $ variable -> toString ( ) ; } foreach ( $ this -> getMethods ( ) as $ method ) { $ buffer .= $ method -> toString ( ) ; } $ buffer .= '}' ; return str_replace ( "\r\n" , "\n" , $ buffer ) ; }
Converts this class to a string
40,966
public function getFileName ( ) { $ isTestClass = substr ( $ this -> getName ( ) , - 4 ) == 'Test' ; if ( $ isTestClass ) { $ rootDirectory = $ this -> getConfiguration ( ) -> getRootTestDirectory ( ) ; } else { $ rootDirectory = $ this -> getConfiguration ( ) -> getRootDirectory ( ) ; } if ( substr ( $ this -> getNamespace ( ) , 0 , strlen ( $ this -> getConfiguration ( ) -> getRootNamespace ( ) ) ) != $ this -> getConfiguration ( ) -> getRootNamespace ( ) ) { throw new \ Exception ( 'The Root namespace does not match this classes namespace, could not get the file name' . "\n" . $ this -> getNamespace ( ) . "\n" . $ this -> getConfiguration ( ) -> getRootNamespace ( ) ) ; } if ( $ isTestClass ) { $ namespace = $ this -> getNamespace ( ) ; } else { $ namespace = substr ( $ this -> getNamespace ( ) , strlen ( $ this -> getConfiguration ( ) -> getRootNamespace ( ) ) ) ; } if ( DIRECTORY_SEPARATOR != '\\' ) { $ namespace = str_replace ( '\\' , DIRECTORY_SEPARATOR , $ namespace ) ; } return $ rootDirectory . DIRECTORY_SEPARATOR . $ namespace . DIRECTORY_SEPARATOR . $ this -> getName ( ) . '.php' ; }
Gets the filename for this class
40,967
public function write ( ) { $ filename = $ this -> getFileName ( ) ; if ( basename ( $ filename ) == '.php' ) { throw new CatchableException ( 'Invalid Filename: ' . $ filename ) ; } if ( ! is_dir ( dirname ( $ filename ) ) ) { mkdir ( dirname ( $ filename ) , 0777 , true ) ; } file_put_contents ( $ filename , $ this -> toString ( ) ) ; }
Writes this class to the server
40,968
public function getOffsetDay ( $ offsetNumDays ) { return new self ( mktime ( 0 , 0 , 0 , date ( 'n' , $ this -> getEpoch ( ) ) , date ( 'j' , $ this -> getEpoch ( ) ) + $ offsetNumDays , date ( 'Y' , $ this -> getEpoch ( ) ) ) ) ; }
Gets an offset day
40,969
public function getOffsetYear ( $ offsetNumYears ) { return new self ( mktime ( 0 , 0 , 0 , date ( 'n' , $ this -> getEpoch ( ) ) , date ( 'j' , $ this -> getEpoch ( ) ) , date ( 'Y' , $ this -> getEpoch ( ) ) + $ offsetNumYears ) ) ; }
Gets an offset of years
40,970
public function getOffsetMonth ( $ offsetNumMonths ) { return new self ( mktime ( 0 , 0 , 0 , date ( 'n' , $ this -> getEpoch ( ) ) + $ offsetNumMonths , date ( 'j' , $ this -> getEpoch ( ) ) , date ( 'Y' , $ this -> getEpoch ( ) ) ) ) ; }
Gets an offset of months
40,971
public function getStartOfWeek ( $ offset = null ) { $ dayInWeek = $ this -> getEpoch ( ) ; if ( date ( 'G' , $ dayInWeek ) < 6 ) { $ dayInWeek += 60 * 60 * 12 ; } $ week = date ( 'w' , $ dayInWeek ) ; if ( is_null ( $ offset ) ) { $ offset = $ this -> getFormatter ( ) -> getWeekOffset ( ) ; } if ( $ week >= $ offset ) { $ day = date ( 'j' , $ dayInWeek ) - date ( 'w' , $ dayInWeek ) + $ offset ; } else { $ day = date ( 'j' , $ dayInWeek ) - date ( 'w' , $ dayInWeek ) + $ offset - 7 ; } return new self ( mktime ( 12 , 0 , 0 , date ( 'n' , $ dayInWeek ) , $ day , date ( 'Y' , $ dayInWeek ) ) ) ; }
Gets the first second in a week
40,972
public function addOperation ( Operation $ operation ) { $ operations = $ this -> getOperations ( ) ; $ operations [ ] = $ operation ; $ this -> setOperations ( $ operations ) ; }
Adds new operation
40,973
public function equals ( Line $ line , $ prefix ) { $ prefix .= ': Column (' . $ this -> getName ( ) . '):' ; $ errors = [ ] ; if ( $ line -> getName ( ) !== $ this -> getName ( ) ) { throw new \ Exception ( 'Comparing Incomparable columns' ) ; } if ( $ line -> getType ( ) !== $ this -> getType ( ) ) { $ errors [ ] = $ prefix . 'Type Does Not Match:' . "\n" . $ line -> getType ( ) . "\n" . $ this -> getType ( ) ; } if ( $ line -> isUnsigned ( ) !== $ this -> isUnsigned ( ) ) { $ errors [ ] = $ prefix . 'Unsigned Does Not Match:' . "\n" . $ line -> isUnsigned ( ) . "\n" . $ this -> isUnsigned ( ) ; } if ( $ line -> isNullable ( ) !== $ this -> isNullable ( ) ) { $ errors [ ] = $ prefix . 'Nullable Does Not Match:' . "\n" . $ line -> isNullable ( ) . "\n" . $ this -> isNullable ( ) ; } if ( $ line -> isAutoIncrement ( ) !== $ this -> isAutoIncrement ( ) ) { $ errors [ ] = $ prefix . 'AutoIncrement Does Not Match:' . "\n" . $ line -> isAutoIncrement ( ) . "\n" . $ this -> isAutoIncrement ( ) ; } if ( $ line -> getCollate ( ) !== $ this -> getCollate ( ) ) { $ errors [ ] = $ prefix . 'Collate Does Not Match:' . "\n" . $ line -> getCollate ( ) . "\n" . $ this -> getCollate ( ) ; } if ( $ line -> getComment ( ) !== $ this -> getComment ( ) ) { $ errors [ ] = $ prefix . 'Comment Does Not Match:' . "\n" . $ line -> getComment ( ) . "\n" . $ this -> getComment ( ) ; } if ( $ line -> getDefault ( ) !== $ this -> getDefault ( ) ) { $ errors [ ] = $ prefix . 'Default Does Not Match:' . "\n" . $ line -> getDefault ( ) . "\n" . $ this -> getDefault ( ) ; } return $ errors ; }
Compares two lines and returns any errors of non matches
40,974
protected function addFile ( File $ file ) { $ files = $ this -> getFiles ( ) ; $ files [ $ file -> getName ( ) ] = $ file ; $ this -> setFiles ( $ files ) ; }
Add a new file
40,975
private function validateAllRequired ( $ isCreating ) { foreach ( $ this -> getFiles ( ) as $ file ) { if ( ! $ file -> isUsed ( ) ) { if ( $ isCreating ? $ file -> isRequiredOnCreate ( ) : $ file -> isRequiredOnUpdate ( ) ) { $ this -> getEntity ( ) -> appendMessage ( new Message ( 'Missing the required file of: ' . $ file -> getName ( ) ) ) ; } } } if ( $ this -> getEntity ( ) -> validationHasFailed ( ) == true ) { $ validationException = new ValidationException ( ) ; $ validationException -> setEntity ( $ this -> getEntity ( ) ) ; throw $ validationException ; } }
Validates that all required files were passed in
40,976
private function lookUpAutomaticFields ( ApiInterface $ entity , $ isCreating ) { if ( $ isCreating ) { $ automaticAttributes = $ entity -> getModelsMetaData ( ) -> getAutomaticCreateAttributes ( $ entity ) ; } else { $ automaticAttributes = $ entity -> getModelsMetaData ( ) -> getAutomaticUpdateAttributes ( $ entity ) ; } $ columnMap = $ entity -> getModelsMetaData ( ) -> getColumnMap ( $ entity ) ; $ automaticFields = array_fill_keys ( $ entity -> getAutomaticallyUpdatedFields ( ) , null ) ; foreach ( $ automaticAttributes as $ fullName => $ null ) { $ automaticFields [ $ columnMap [ $ fullName ] ] = null ; } return $ automaticFields ; }
Looks up which fields are automatically updated
40,977
private function filterFields ( \ stdClass $ params , ApiInterface $ entity , $ isCreating ) { $ automaticFields = $ this -> lookUpAutomaticFields ( $ entity , $ isCreating ) ; $ customParentRelationshipFields = [ ] ; foreach ( $ entity -> getCustomParentRelationships ( ) as $ customParentRelationshipField ) { $ customParentRelationshipFields [ ] = $ customParentRelationshipField -> getFields ( ) ; } $ fields = array ( ) ; foreach ( $ params as $ key => $ value ) { if ( ! ( is_object ( $ value ) && get_class ( $ value ) == 'stdClass' ) ) { if ( array_key_exists ( $ key , $ entity -> getChildrenUpdaters ( ) ) ) { $ fields [ $ key ] = $ value ; } elseif ( in_array ( $ key , $ entity -> getModelsMetaData ( ) -> getColumnMap ( $ entity ) ) || in_array ( $ key , $ customParentRelationshipFields ) ) { if ( array_key_exists ( $ key , $ automaticFields ) && $ entity -> readAttribute ( $ key ) != $ value ) { throw new Exception ( 'The field of: ' . $ key . ' cannot be manually updated' , 409 ) ; } $ fields [ $ key ] = $ value ; } else { throw new Exception ( 'Could not find the field: ' . $ key , 400 ) ; } } } return $ fields ; }
Filters the params down to just the instance fields
40,978
private function filterParents ( \ stdClass $ params , ApiInterface $ entity ) { $ parents = array ( ) ; foreach ( $ params as $ key => $ value ) { if ( is_object ( $ value ) && get_class ( $ value ) == 'stdClass' ) { $ alias = ucfirst ( $ key ) ; if ( in_array ( $ alias , $ entity -> getParentRelationships ( ) ) ) { $ parents [ $ alias ] = $ value ; } else { throw new Exception ( 'Could not find the parent field: ' . $ key , 400 ) ; } } } return $ parents ; }
Filters the params down to just the instance parents
40,979
private function writeFields ( $ fields , ApiInterface $ entity , bool $ writeChildren ) : bool { $ isChanged = false ; foreach ( $ fields as $ name => $ value ) { if ( $ this -> getAcl ( ) -> canWriteField ( $ entity , $ name ) ) { try { if ( array_key_exists ( $ name , $ entity -> getChildrenUpdaters ( ) ) ) { if ( $ writeChildren ) { $ entity -> getChildrenUpdaters ( ) [ $ name ] -> setData ( $ entity , $ value ) ; $ isChanged = true ; } } else { $ entity -> writeAttribute ( $ name , $ value ) ; } } catch ( \ InvalidArgumentException $ e ) { throw new CatchableException ( $ e -> getMessage ( ) ) ; } } } return $ isChanged ; }
Writes the actual fields
40,980
private function writeCustomParents ( $ fields , ApiInterface $ entity ) { foreach ( $ entity -> getCustomParentRelationships ( ) as $ customRelationship ) { $ name = $ customRelationship -> getReferencedFields ( ) ; if ( array_key_exists ( $ name , $ fields ) ) { $ entity -> writeAttribute ( $ name , $ fields [ $ name ] ) ; } } }
Writes the custom parent fields
40,981
public function image ( $ email , array $ options = [ ] ) { $ imageUrl = $ this -> url ( $ email , $ options ) ; unset ( $ options [ 'default' ] , $ options [ 'size' ] , $ options [ 'rating' ] , $ options [ 'ext' ] ) ; return $ this -> Html -> image ( $ imageUrl , $ options ) ; }
Show gravatar for the supplied email address
40,982
public function defaultImages ( $ options = [ ] ) { $ options = $ this -> _cleanOptions ( $ options + $ this -> _config ) ; $ images = [ ] ; foreach ( $ this -> _defaultIcons as $ defaultIcon ) { $ options [ 'default' ] = $ defaultIcon ; $ images [ $ defaultIcon ] = $ this -> image ( null , $ options ) ; } return $ images ; }
Generate an array of default images for preview purposes
40,983
protected function _cleanOptions ( $ options ) { if ( ! isset ( $ options [ 'size' ] ) || empty ( $ options [ 'size' ] ) || ! is_numeric ( $ options [ 'size' ] ) ) { unset ( $ options [ 'size' ] ) ; } else { $ options [ 'size' ] = min ( max ( $ options [ 'size' ] , 1 ) , 512 ) ; } if ( ! $ options [ 'rating' ] || ! in_array ( mb_strtolower ( $ options [ 'rating' ] ) , $ this -> _allowedRatings ) ) { unset ( $ options [ 'rating' ] ) ; } if ( ! $ options [ 'default' ] ) { unset ( $ options [ 'default' ] ) ; } else { if ( ! in_array ( $ options [ 'default' ] , $ this -> _defaultIcons ) && ! Validation :: url ( $ options [ 'default' ] ) ) { unset ( $ options [ 'default' ] ) ; } } return $ options ; }
Sanitize the options array
40,984
protected function _buildOptions ( $ options = [ ] ) { $ gravatarOptions = array_intersect ( array_keys ( $ options ) , array_keys ( $ this -> _defaultConfig ) ) ; if ( ! empty ( $ gravatarOptions ) ) { $ optionArray = [ ] ; foreach ( $ gravatarOptions as $ key ) { $ value = $ options [ $ key ] ; $ optionArray [ ] = $ key . '=' . mb_strtolower ( $ value ) ; } return '?' . implode ( '&amp;' , $ optionArray ) ; } return '' ; }
Build Options URL string
40,985
protected function _wrap ( $ message , $ wrapLength = CakeEmail :: LINE_LENGTH_MUST ) { if ( $ this -> _wrapLength !== null ) { $ wrapLength = $ this -> _wrapLength ; } return parent :: _wrap ( $ message , $ wrapLength ) ; }
Fix line length
40,986
public function setProfile ( $ config ) { if ( ! is_array ( $ config ) ) { $ config = ( string ) $ config ; } $ this -> _applyConfig ( $ config ) ; $ fromEmail = Configure :: read ( 'Config.systemEmail' ) ; if ( $ fromEmail ) { $ fromName = Configure :: read ( 'Config.systemName' ) ; } else { $ fromEmail = Configure :: read ( 'Config.adminEmail' ) ; $ fromName = Configure :: read ( 'Config.adminName' ) ; } if ( $ fromEmail ) { $ this -> setFrom ( $ fromEmail , $ fromName ) ; } $ xMailer = Configure :: read ( 'Config.xMailer' ) ; if ( $ xMailer ) { $ this -> addHeaders ( [ 'X-Mailer' => $ xMailer ] ) ; } return $ this ; }
Ovewrite to allow custom enhancements
40,987
public function setAttachments ( $ attachments ) { $ attach = [ ] ; foreach ( ( array ) $ attachments as $ name => $ fileInfo ) { if ( ! is_array ( $ fileInfo ) ) { $ fileInfo = [ 'file' => $ fileInfo ] ; } if ( ! isset ( $ fileInfo [ 'file' ] ) ) { if ( ! isset ( $ fileInfo [ 'data' ] ) ) { throw new InvalidArgumentException ( 'No file or data specified.' ) ; } if ( is_int ( $ name ) ) { throw new InvalidArgumentException ( 'No filename specified.' ) ; } } else { $ fileName = $ fileInfo [ 'file' ] ; if ( ! preg_match ( '~^https?://~i' , $ fileInfo [ 'file' ] ) ) { $ fileInfo [ 'file' ] = realpath ( $ fileInfo [ 'file' ] ) ; } if ( $ fileInfo [ 'file' ] === false || ! Utility :: fileExists ( $ fileInfo [ 'file' ] ) ) { throw new InvalidArgumentException ( sprintf ( 'File not found: "%s"' , $ fileName ) ) ; } if ( is_int ( $ name ) ) { $ name = basename ( $ fileInfo [ 'file' ] ) ; } } if ( ! isset ( $ fileInfo [ 'mimetype' ] ) ) { $ ext = pathinfo ( $ name , PATHINFO_EXTENSION ) ; $ fileInfo [ 'mimetype' ] = $ this -> _getMimeByExtension ( $ ext ) ; } $ attach [ $ name ] = $ fileInfo ; } $ this -> _attachments = $ attach ; return $ this ; }
Overwrite to allow mimetype detection
40,988
public function addAttachment ( $ file , $ name = null , $ fileInfo = [ ] ) { $ fileInfo [ 'file' ] = $ file ; if ( ! empty ( $ name ) ) { $ fileInfo = [ $ name => $ fileInfo ] ; } else { $ fileInfo = [ $ fileInfo ] ; } return $ this -> addAttachments ( $ fileInfo ) ; }
Add an attachment from file
40,989
public function addBlobAttachment ( $ content , $ filename , $ mimeType = null , $ fileInfo = [ ] ) { if ( $ mimeType === null ) { $ ext = pathinfo ( $ filename , PATHINFO_EXTENSION ) ; $ mimeType = $ this -> _getMimeByExtension ( $ ext ) ; } $ fileInfo [ 'data' ] = $ content ; $ fileInfo [ 'mimetype' ] = $ mimeType ; $ file = [ $ filename => $ fileInfo ] ; return $ this -> addAttachments ( $ file ) ; }
Add an attachment as blob
40,990
public function addEmbeddedBlobAttachment ( $ content , $ filename , $ mimeType = null , $ options = null , array $ notUsed = [ ] ) { if ( $ mimeType === null ) { $ ext = pathinfo ( $ filename , PATHINFO_EXTENSION ) ; $ mimeType = $ this -> _getMimeByExtension ( $ ext ) ; } $ contentId = null ; if ( ! is_array ( $ options ) ) { $ contentId = $ options ; $ options = $ notUsed ; } $ filename = pathinfo ( $ filename , PATHINFO_FILENAME ) . '_' . md5 ( $ content ) . '.' . pathinfo ( $ filename , PATHINFO_EXTENSION ) ; if ( $ contentId === null && ( $ cid = $ this -> _isEmbeddedBlobAttachment ( $ content , $ filename ) ) ) { return $ cid ; } $ options [ 'data' ] = $ content ; $ options [ 'mimetype' ] = $ mimeType ; $ options [ 'contentId' ] = $ contentId ? $ contentId : str_replace ( '-' , '' , Text :: uuid ( ) ) . '@' . $ this -> _domain ; $ file = [ $ filename => $ options ] ; $ this -> addAttachments ( $ file ) ; if ( $ contentId === null ) { return $ options [ 'contentId' ] ; } return $ contentId ; }
Add an inline attachment as blob
40,991
protected function _getMime ( $ filename , $ default = 'application/octet-stream' ) { if ( ! isset ( $ this -> _Mime ) ) { $ this -> _Mime = new Mime ( ) ; } $ mime = $ this -> _Mime -> detectMimeType ( $ filename ) ; if ( ! $ mime || $ mime === $ default ) { $ ext = pathinfo ( $ filename , PATHINFO_EXTENSION ) ; $ mime = $ this -> _Mime -> getMimeTypeByAlias ( $ ext ) ; } return $ mime ; }
Try to find mimetype by file extension
40,992
public function map ( $ mixed = null ) { if ( is_array ( $ mixed ) ) { $ result = [ ] ; foreach ( $ mixed as $ _mixed ) { $ _result = $ this -> map ( $ _mixed ) ; if ( $ _result ) { $ result [ $ _mixed ] = $ _result ; } } return $ result ; } if ( is_string ( $ mixed ) ) { if ( strlen ( $ mixed ) === 2 && in_array ( $ mixed , $ this -> _l10nMap ) ) { return array_search ( $ mixed , $ this -> _l10nMap ) ; } if ( isset ( $ this -> _l10nMap [ $ mixed ] ) ) { return $ this -> _l10nMap [ $ mixed ] ; } return false ; } return $ this -> _l10nMap ; }
Attempts to find locale for language or language for locale
40,993
public function catalog ( $ language = null ) { if ( is_array ( $ language ) ) { $ result = [ ] ; foreach ( $ language as $ _language ) { $ _result = $ this -> catalog ( $ _language ) ; if ( $ _result ) { $ result [ $ _language ] = $ _result ; } } return $ result ; } if ( is_string ( $ language ) ) { if ( isset ( $ this -> _l10nCatalog [ $ language ] ) ) { return $ this -> _l10nCatalog [ $ language ] ; } if ( isset ( $ this -> _l10nMap [ $ language ] ) && isset ( $ this -> _l10nCatalog [ $ this -> _l10nMap [ $ language ] ] ) ) { return $ this -> _l10nCatalog [ $ this -> _l10nMap [ $ language ] ] ; } return false ; } return $ this -> _l10nCatalog ; }
Attempts to find catalog record for requested language
40,994
public static function setConfig ( $ options = [ ] ) { $ config = $ options + ( array ) Configure :: read ( 'Localization' ) ; foreach ( $ config as $ key => $ value ) { $ key = '_' . $ key ; if ( ! isset ( static :: $ { $ key } ) ) { continue ; } static :: $ { $ key } = $ value ; } }
Correct the default values according to localization
40,995
public static function currency ( $ number , $ currency = null , array $ options = [ ] ) { $ defaults = [ 'positive' => '+' , 'signed' => false ] ; $ options += $ defaults ; $ sign = '' ; if ( $ number > 0 && ! empty ( $ options [ 'signed' ] ) ) { $ sign = $ options [ 'positive' ] ; } return $ sign . parent :: currency ( $ number , $ currency , $ options ) ; }
Overwrite to allow
40,996
public static function average ( $ values , $ precision = 0 ) { if ( empty ( $ values ) ) { return 0.0 ; } return round ( array_sum ( $ values ) / count ( $ values ) , $ precision ) ; }
Get the rounded average .
40,997
public static function roundTo ( $ number , $ increment = 1.0 ) { $ precision = static :: getDecimalPlaces ( $ increment ) ; $ res = round ( $ number , $ precision ) ; if ( $ precision <= 0 ) { $ res = ( int ) $ res ; } return $ res ; }
Round value .
40,998
public static function getDecimalPlaces ( $ number ) { $ decimalPlaces = 0 ; while ( $ number > 1 && $ number != 0 ) { $ number /= 10 ; $ decimalPlaces -= 1 ; } while ( $ number < 1 && $ number != 0 ) { $ number *= 10 ; $ decimalPlaces += 1 ; } return $ decimalPlaces ; }
Get decimal places
40,999
public static function isFloatEqual ( $ x , $ y , $ precision = 0.0000001 ) { return ( $ x + $ precision >= $ y ) && ( $ x - $ precision <= $ y ) ; }
Can compare two float values